-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathLinksEditor.tsx
More file actions
77 lines (71 loc) · 1.9 KB
/
Copy pathLinksEditor.tsx
File metadata and controls
77 lines (71 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { EnrichedTextInput } from 'react-native-enriched-html';
import type {
EnrichedTextInputInstance,
OnChangeSelectionEvent,
} from 'react-native-enriched-html';
import { useRef, useState } from 'react';
import { View, StyleSheet, Pressable, Text } from 'react-native';
import { htmlStyle } from './htmlStyle';
// Detect "enriched://" URLs as links.
const linkRegex = /enriched:\/\/\S+/g;
export default function App() {
const ref = useRef<EnrichedTextInputInstance>(null);
const [selection, setSelection] = useState<OnChangeSelectionEvent | null>(
null
);
const hasSelection = !!selection && selection.start !== selection.end;
const addLink = () => {
if (!selection) return;
// Turn the current selection into a link pointing at our docs.
ref.current?.setLink(
selection.start,
selection.end,
selection.text,
'https://swmansion.com'
);
};
return (
<View style={styles.container}>
<EnrichedTextInput
ref={ref}
style={styles.input}
htmlStyle={htmlStyle}
placeholder="Type enriched://home, or select text below..."
linkRegex={linkRegex}
onChangeSelection={e => setSelection(e.nativeEvent)}
/>
<Pressable
disabled={!hasSelection}
style={[styles.button, !hasSelection && styles.buttonDisabled]}
onPress={addLink}>
<Text style={styles.text}>Link the selection</Text>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
container: { gap: 12 },
input: {
fontSize: 18,
color: '#232736',
padding: 12,
borderRadius: 12,
minHeight: 96,
backgroundColor: '#eef0ff',
},
button: {
alignSelf: 'center',
padding: 8,
paddingHorizontal: 16,
borderRadius: 24,
borderWidth: 1,
borderColor: '#919fcf',
},
buttonDisabled: {
opacity: 0.4,
},
text: {
textAlign: 'center',
color: '#919fcf',
},
});