Skip to content

Commit 44ee9fe

Browse files
committed
fix: proper example code
1 parent b240fb8 commit 44ee9fe

2 files changed

Lines changed: 78 additions & 22 deletions

File tree

docs/docs/fundamentals/getting-started.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ your own. Let's dive in.
1515
## What is React Native Enriched HTML?
1616

1717
React Native Enriched HTML is a rich text solution for React Native built by
18-
[Software Mansion](https://swmansion.com/).
18+
[Software Mansion](https://swmansion.com/). It supports iOS, Android and Web.
1919

2020
It ships two fully native components: `EnrichedTextInput`, a rich text editor
2121
that styles text live as you type, and `EnrichedText`, a read-only display component that
@@ -26,9 +26,6 @@ Not only does this library allow you to apply basic rich text styles you know we
2626
like *bold* or _italic_, but also provides more powerful tools like `mentions`, something
2727
you will learn more about in the next chapters.
2828

29-
iOS, Android, and Web are all supported. iOS and Android are stable; Web is still experimental, so expect
30-
its behavior to change between releases.
31-
3229
## Prerequisites
3330

3431
The library works only with the

docs/docs/fundamentals/your-first-editor.mdx

Lines changed: 77 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ export default function App() {
3434
}
3535

3636
const styles = StyleSheet.create({
37-
container: { flex: 1, justifyContent: 'center', padding: 16 },
37+
container: { gap: 12 },
3838
input: {
3939
fontSize: 18,
40+
color: '#232736',
4041
padding: 12,
41-
maxHeight: 200,
42-
backgroundColor: 'gainsboro',
42+
borderRadius: 12,
43+
minHeight: 96,
44+
backgroundColor: '#eef0ff',
4345
},
4446
});
4547
```
@@ -53,11 +55,11 @@ Add a ref and a button that calls `toggleBold`. Each call flips bold on the
5355
current selection, or arms it for the next characters you type if nothing is
5456
selected.
5557

56-
```tsx {2-4,9,12-15}
58+
```tsx {2-4,7,12,16-18,33-44}
5759
import { EnrichedTextInput } from 'react-native-enriched-html';
5860
import type { EnrichedTextInputInstance } from 'react-native-enriched-html';
5961
import { useRef } from 'react';
60-
import { View, Button, StyleSheet } from 'react-native';
62+
import { View, StyleSheet, Pressable, Text } from 'react-native';
6163

6264
export default function App() {
6365
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -69,32 +71,57 @@ export default function App() {
6971
style={styles.input}
7072
placeholder="Type something here..."
7173
/>
72-
<Button title="Bold" onPress={() => ref.current?.toggleBold()} />
74+
<Pressable style={styles.button} onPress={() => ref.current?.toggleBold()}>
75+
<Text style={styles.text}>Bold</Text>
76+
</Pressable>
7377
</View>
7478
);
7579
}
80+
81+
const styles = StyleSheet.create({
82+
container: { gap: 12 },
83+
input: {
84+
fontSize: 18,
85+
color: '#232736',
86+
padding: 12,
87+
borderRadius: 12,
88+
minHeight: 96,
89+
backgroundColor: '#eef0ff',
90+
},
91+
button: {
92+
alignSelf: 'center',
93+
width: 100,
94+
padding: 8,
95+
borderRadius: 24,
96+
borderWidth: 1,
97+
borderColor: '#919fcf',
98+
},
99+
text: {
100+
textAlign: 'center',
101+
color: '#919fcf',
102+
},
103+
});
76104
```
77105

78-
Every other style works the same way — there's a `toggleItalic`,
106+
Every other style is toggled similarly via `ref` — there's a `toggleItalic`,
79107
`toggleUnderline`, `toggleH1`, `toggleOrderedList`, and so on.
80108

81109
## Reading the state back
82110

83111
A toolbar button should also show whether bold is _currently_ active, so the
84112
user knows what they're about to change. The input reports this through the
85-
`onChangeState` event, which fires whenever the active styles change — including
86-
when the user just moves the cursor.
113+
`onChangeState` event, which fires whenever the active styles change.
87114

88115
The payload holds an entry per style. Use `bold.isActive` to drive the button:
89116

90-
```tsx {8,15-19,22-26}
117+
```tsx {4,6,11,19,22,24,50-53,58-60}
91118
import { EnrichedTextInput } from 'react-native-enriched-html';
92119
import type {
93120
EnrichedTextInputInstance,
94121
OnChangeStateEvent,
95122
} from 'react-native-enriched-html';
96123
import { useRef, useState } from 'react';
97-
import { View, Button, StyleSheet } from 'react-native';
124+
import { View, StyleSheet, Pressable, Text } from 'react-native';
98125

99126
export default function App() {
100127
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -106,16 +133,49 @@ export default function App() {
106133
ref={ref}
107134
style={styles.input}
108135
placeholder="Type something here..."
109-
onChangeState={(e) => setState(e.nativeEvent)}
110-
/>
111-
<Button
112-
title={state?.bold.isActive ? 'Unbold' : 'Bold'}
113-
color={state?.bold.isActive ? 'green' : 'gray'}
114-
onPress={() => ref.current?.toggleBold()}
136+
onChangeState={e => setState(e.nativeEvent)}
115137
/>
138+
<Pressable
139+
style={[styles.button, state?.bold.isActive && styles.buttonActive]}
140+
onPress={() => ref.current?.toggleBold()}>
141+
<Text style={[styles.text, state?.bold.isActive && styles.textActive]}>
142+
Bold
143+
</Text>
144+
</Pressable>
116145
</View>
117146
);
118147
}
148+
149+
const styles = StyleSheet.create({
150+
container: { gap: 12 },
151+
input: {
152+
fontSize: 18,
153+
color: '#232736',
154+
padding: 12,
155+
borderRadius: 12,
156+
minHeight: 96,
157+
backgroundColor: '#eef0ff',
158+
},
159+
button: {
160+
alignSelf: 'center',
161+
width: 100,
162+
padding: 8,
163+
borderRadius: 24,
164+
borderWidth: 1,
165+
borderColor: '#919fcf',
166+
},
167+
buttonActive: {
168+
borderColor: '#57b495',
169+
backgroundColor: '#57b495',
170+
},
171+
text: {
172+
textAlign: 'center',
173+
color: '#919fcf',
174+
},
175+
textActive: {
176+
color: '#eef0ff',
177+
},
178+
});
119179
```
120180

121181
That's the full loop: the button **acts** on the input with `toggleBold`, and
@@ -139,4 +199,3 @@ notice the button turns green whenever the cursor sits on bold text. Switch to
139199
the **Code** tab to see the exact source.
140200

141201
<InteractiveExample src={FirstEditorSrc} component={FirstEditor} />
142-

0 commit comments

Comments
 (0)