Skip to content

Commit e5fa7a3

Browse files
authored
docs: htmlStyle for interactive examples components (#719)
# Summary Provided an `htmlStyle` for the `EnrichedTextInput` and `EnrichedText` components in the interactive examples. The internal default values didn't look too well, so this `htmlStyle` provides colorings that match the docs' style both in dark and light mode. That makes the interactive examples' code not directly copiable, as `htmlStyle` is not present there to reduce noise. Added a note explaining that in the `your-first-editor` section.
1 parent 858a90d commit e5fa7a3

11 files changed

Lines changed: 108 additions & 1 deletion

docs/src/css/typography.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ code {
171171
border-bottom: 1px solid currentColor;
172172
}
173173

174+
.eti-editor a {
175+
border-bottom: none;
176+
}
177+
174178
/* Sidebar */
175179
[class*='menu__list-item-collapsible'] a {
176180
font-family: var(--swm-title-font);

docs/src/examples/BasicStylesEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
} from 'react-native-enriched-html';
66
import { useRef, useState } from 'react';
77
import { View, StyleSheet, Pressable, Text } from 'react-native';
8+
import { htmlStyle } from './htmlStyle';
89

910
export default function App() {
1011
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -73,6 +74,7 @@ export default function App() {
7374
<EnrichedTextInput
7475
ref={ref}
7576
style={styles.input}
77+
htmlStyle={htmlStyle}
7678
placeholder="Type something here..."
7779
onChangeState={e => setState(e.nativeEvent)}
7880
/>

docs/src/examples/FirstEditor.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
} from 'react-native-enriched-html';
66
import { useRef, useState } from 'react';
77
import { View, StyleSheet, Pressable, Text } from 'react-native';
8+
import { htmlStyle } from './htmlStyle';
89

910
export default function App() {
1011
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -15,6 +16,11 @@ export default function App() {
1516
<EnrichedTextInput
1617
ref={ref}
1718
style={styles.input}
19+
// The `htmlStyle` here is only there to make the rendered
20+
// input match these docs' color palette, so don't worry
21+
// about it here. If you want to learn more, see the
22+
// "Styling the input" section.
23+
htmlStyle={htmlStyle}
1824
placeholder="Type something here..."
1925
onChangeState={e => setState(e.nativeEvent)}
2026
/>

docs/src/examples/ImagesEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EnrichedTextInput } from 'react-native-enriched-html';
22
import type { EnrichedTextInputInstance } from 'react-native-enriched-html';
33
import { useRef } from 'react';
44
import { View, StyleSheet, Pressable, Text } from 'react-native';
5+
import { htmlStyle } from './htmlStyle';
56

67
export default function App() {
78
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -23,6 +24,7 @@ export default function App() {
2324
<EnrichedTextInput
2425
ref={ref}
2526
style={styles.input}
27+
htmlStyle={htmlStyle}
2628
placeholder="Place the cursor, then insert an image below..."
2729
/>
2830
<View style={styles.row}>

docs/src/examples/LinksEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
} from 'react-native-enriched-html';
66
import { useRef, useState } from 'react';
77
import { View, StyleSheet, Pressable, Text } from 'react-native';
8+
import { htmlStyle } from './htmlStyle';
89

910
// Detect "enriched://" URLs as links.
1011
const linkRegex = /enriched:\/\/\S+/g;
@@ -33,6 +34,7 @@ export default function App() {
3334
<EnrichedTextInput
3435
ref={ref}
3536
style={styles.input}
37+
htmlStyle={htmlStyle}
3638
placeholder="Type enriched://home, or select text below..."
3739
linkRegex={linkRegex}
3840
onChangeSelection={e => setSelection(e.nativeEvent)}

docs/src/examples/ListsEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
} from 'react-native-enriched-html';
66
import { useRef, useState } from 'react';
77
import { View, StyleSheet, Pressable, Text } from 'react-native';
8+
import { htmlStyle } from './htmlStyle';
89

910
export default function App() {
1011
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -52,6 +53,7 @@ export default function App() {
5253
<EnrichedTextInput
5354
ref={ref}
5455
style={styles.input}
56+
htmlStyle={htmlStyle}
5557
placeholder="Type a few lines, then turn them into a list..."
5658
onChangeState={e => setState(e.nativeEvent)}
5759
/>

docs/src/examples/MentionEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EnrichedTextInput } from 'react-native-enriched-html';
22
import type { EnrichedTextInputInstance } from 'react-native-enriched-html';
33
import { useRef } from 'react';
44
import { View, StyleSheet, Pressable, Text } from 'react-native';
5+
import { htmlStyle } from './htmlStyle';
56

67
const user = { id: '1', name: 'John' };
78

@@ -18,6 +19,7 @@ export default function App() {
1819
<EnrichedTextInput
1920
ref={ref}
2021
style={styles.input}
22+
htmlStyle={htmlStyle}
2123
placeholder="Type '@', then tap the button below..."
2224
/>
2325
<Pressable style={styles.button} onPress={insertMention}>

docs/src/examples/RenderingEditor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
} from 'react-native-enriched-html';
66
import { useRef, useState } from 'react';
77
import { View, StyleSheet, Pressable, Text } from 'react-native';
8+
import { htmlStyle, enrichedTextHtmlStyle } from './htmlStyle';
89

910
export default function App() {
1011
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -43,6 +44,7 @@ export default function App() {
4344
<EnrichedTextInput
4445
ref={ref}
4546
style={styles.input}
47+
htmlStyle={htmlStyle}
4648
placeholder="Type something here..."
4749
onChangeState={e => setState(e.nativeEvent)}
4850
/>
@@ -74,7 +76,10 @@ export default function App() {
7476
</Pressable>
7577
</View>
7678

77-
<EnrichedText style={styles.viewer} selectable>
79+
<EnrichedText
80+
style={styles.viewer}
81+
htmlStyle={enrichedTextHtmlStyle}
82+
selectable>
7883
{html}
7984
</EnrichedText>
8085
</View>

docs/src/examples/TextAlignmentEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
} from 'react-native-enriched-html';
66
import { useRef, useState } from 'react';
77
import { View, StyleSheet, Pressable, Text } from 'react-native';
8+
import { htmlStyle } from './htmlStyle';
89

910
const alignments = ['left', 'center', 'right', 'justify'] as const;
1011

@@ -32,6 +33,7 @@ export default function App() {
3233
<EnrichedTextInput
3334
ref={ref}
3435
style={styles.input}
36+
htmlStyle={htmlStyle}
3537
placeholder="Type a paragraph, then align it below..."
3638
onChangeState={e => setState(e.nativeEvent)}
3739
/>

docs/src/examples/TextShortcutsEditor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { EnrichedTextInput } from 'react-native-enriched-html';
22
import type { EnrichedTextInputInstance } from 'react-native-enriched-html';
33
import { useRef } from 'react';
44
import { View, StyleSheet } from 'react-native';
5+
import { htmlStyle } from './htmlStyle';
56

67
export default function App() {
78
const ref = useRef<EnrichedTextInputInstance>(null);
@@ -11,6 +12,7 @@ export default function App() {
1112
<EnrichedTextInput
1213
ref={ref}
1314
style={styles.input}
15+
htmlStyle={htmlStyle}
1416
// Two shortcuts, one of each kind:
1517
// - '# ' at the start of a paragraph turns the line into an H1 (paragraph style)
1618
// - '**text**' wraps the delimited text in bold (inline style)

0 commit comments

Comments
 (0)