enriched-text-input 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API_REFERENCE.md +119 -0
- package/CONTRIBUTING.md +33 -0
- package/README.md +58 -48
- package/example/App.tsx +38 -35
- package/example/package.json +3 -2
- package/index.ts +3 -2
- package/package.json +1 -1
- package/src/{RichTextInput.tsx → EnrichedTextInput.tsx} +251 -246
- package/src/Toolbar.tsx +24 -23
- package/src/components/StyledText.tsx +106 -0
- package/src/markdownStyles.ts +12 -0
package/src/Toolbar.tsx
CHANGED
|
@@ -45,49 +45,50 @@ export default function Toolbar({
|
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
Toolbar.Bold = () => {
|
|
48
|
+
Toolbar.Bold = ({ color = "black" }) => {
|
|
49
|
+
console.log("COLOR:", color);
|
|
49
50
|
const richTextInputRef = useToolbarContext();
|
|
50
51
|
|
|
51
52
|
const handleBold = () => {
|
|
52
|
-
richTextInputRef
|
|
53
|
+
richTextInputRef?.current?.toggleStyle("bold");
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
return (
|
|
56
57
|
<TouchableOpacity style={styles.toolbarButton} onPress={handleBold}>
|
|
57
|
-
<FontAwesome6 name="bold" size={16} color=
|
|
58
|
+
<FontAwesome6 name="bold" size={16} color={color} />
|
|
58
59
|
</TouchableOpacity>
|
|
59
60
|
)
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
Toolbar.Italic = () => {
|
|
63
|
+
Toolbar.Italic = ({ color = "black" }) => {
|
|
63
64
|
const richTextInputRef = useToolbarContext();
|
|
64
65
|
|
|
65
66
|
const handleItalic = () => {
|
|
66
|
-
richTextInputRef
|
|
67
|
+
richTextInputRef?.current?.toggleStyle("italic");
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
return (
|
|
70
71
|
<TouchableOpacity style={styles.toolbarButton} onPress={handleItalic}>
|
|
71
|
-
<FontAwesome6 name="italic" size={16} color=
|
|
72
|
+
<FontAwesome6 name="italic" size={16} color={color} />
|
|
72
73
|
</TouchableOpacity>
|
|
73
74
|
)
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
Toolbar.Strikethrough = () => {
|
|
77
|
+
Toolbar.Strikethrough = ({ color = "black" }) => {
|
|
77
78
|
const richTextInputRef = useToolbarContext();
|
|
78
79
|
|
|
79
80
|
const handleLineThrough = () => {
|
|
80
|
-
richTextInputRef
|
|
81
|
+
richTextInputRef?.current?.toggleStyle("lineThrough");
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
return (
|
|
84
85
|
<TouchableOpacity style={styles.toolbarButton} onPress={handleLineThrough}>
|
|
85
|
-
<FontAwesome6 name="strikethrough" size={16} color=
|
|
86
|
+
<FontAwesome6 name="strikethrough" size={16} color={color} />
|
|
86
87
|
</TouchableOpacity>
|
|
87
88
|
)
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
Toolbar.Underline = () => {
|
|
91
|
+
Toolbar.Underline = ({ color = "black" }) => {
|
|
91
92
|
const richTextInputRef = useToolbarContext();
|
|
92
93
|
|
|
93
94
|
const handleUnderline = () => {
|
|
@@ -96,7 +97,7 @@ Toolbar.Underline = () => {
|
|
|
96
97
|
|
|
97
98
|
return (
|
|
98
99
|
<TouchableOpacity style={styles.toolbarButton} onPress={handleUnderline}>
|
|
99
|
-
<FontAwesome6 name="underline" size={16} color=
|
|
100
|
+
<FontAwesome6 name="underline" size={16} color={color} />
|
|
100
101
|
</TouchableOpacity>
|
|
101
102
|
)
|
|
102
103
|
}
|
|
@@ -110,8 +111,8 @@ Toolbar.Heading = () => {
|
|
|
110
111
|
|
|
111
112
|
return (
|
|
112
113
|
<TouchableOpacity style={[styles.toolbarButton, styles.heading]} onPress={handleHeading}>
|
|
113
|
-
<FontAwesome6 name="heading" size={16} color=
|
|
114
|
-
<FontAwesome6 name="1" size={16} color=
|
|
114
|
+
<FontAwesome6 name="heading" size={16} color={color} />
|
|
115
|
+
<FontAwesome6 name="1" size={16} color={color} />
|
|
115
116
|
</TouchableOpacity>
|
|
116
117
|
)
|
|
117
118
|
}
|
|
@@ -125,8 +126,8 @@ Toolbar.SubHeading = () => {
|
|
|
125
126
|
|
|
126
127
|
return (
|
|
127
128
|
<TouchableOpacity style={[styles.toolbarButton, styles.heading]} onPress={handleSubHeading}>
|
|
128
|
-
<FontAwesome6 name="heading" size={16} color=
|
|
129
|
-
<FontAwesome6 name="2" size={16} color=
|
|
129
|
+
<FontAwesome6 name="heading" size={16} color={color} />
|
|
130
|
+
<FontAwesome6 name="2" size={16} color={color} />
|
|
130
131
|
</TouchableOpacity>
|
|
131
132
|
)
|
|
132
133
|
}
|
|
@@ -140,36 +141,36 @@ Toolbar.SubSubHeading = () => {
|
|
|
140
141
|
|
|
141
142
|
return (
|
|
142
143
|
<TouchableOpacity style={[styles.toolbarButton, styles.heading]} onPress={handleSubSubHeading}>
|
|
143
|
-
<FontAwesome6 name="heading" size={16} color=
|
|
144
|
-
<FontAwesome6 name="3" size={16} color=
|
|
144
|
+
<FontAwesome6 name="heading" size={16} color={color} />
|
|
145
|
+
<FontAwesome6 name="3" size={16} color={color} />
|
|
145
146
|
</TouchableOpacity>
|
|
146
147
|
)
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
Toolbar.Code = () => {
|
|
150
|
+
Toolbar.Code = ({ color = "black" }) => {
|
|
150
151
|
const richTextInputRef = useToolbarContext();
|
|
151
152
|
|
|
152
153
|
const handleCode = () => {
|
|
153
|
-
richTextInputRef
|
|
154
|
+
richTextInputRef?.current?.toggleStyle("code");
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
return (
|
|
157
158
|
<TouchableOpacity style={styles.toolbarButton} onPress={handleCode}>
|
|
158
|
-
<FontAwesome6 name="code" size={16} color=
|
|
159
|
+
<FontAwesome6 name="code" size={16} color={color} />
|
|
159
160
|
</TouchableOpacity>
|
|
160
161
|
)
|
|
161
162
|
}
|
|
162
163
|
|
|
163
|
-
Toolbar.Keyboard = () => {
|
|
164
|
+
Toolbar.Keyboard = ({ color = "black" }) => {
|
|
164
165
|
const handleKeyboardDismiss = () => {
|
|
165
166
|
Keyboard.dismiss();
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
return (
|
|
169
170
|
<TouchableOpacity style={[styles.toolbarButton, styles.keyboardDown]} onPress={handleKeyboardDismiss}>
|
|
170
|
-
<FontAwesome6 name="keyboard" size={16} color=
|
|
171
|
+
<FontAwesome6 name="keyboard" size={16} color={color} />
|
|
171
172
|
<View style={styles.keyboardArrowContainer}>
|
|
172
|
-
<FontAwesome6 name="chevron-down" size={8} color=
|
|
173
|
+
<FontAwesome6 name="chevron-down" size={8} color={color}/>
|
|
173
174
|
</View>
|
|
174
175
|
</TouchableOpacity>
|
|
175
176
|
)
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Text, StyleSheet } from "react-native";
|
|
2
|
+
|
|
3
|
+
export function Code({ children }) {
|
|
4
|
+
return (
|
|
5
|
+
<Text style={styles.code}>{children}</Text>
|
|
6
|
+
)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function Bold({ children }) {
|
|
10
|
+
return (
|
|
11
|
+
<Text style={styles.bold}>{children}</Text>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Italic({ children }) {
|
|
16
|
+
return (
|
|
17
|
+
<Text style={styles.italic}>{children}</Text>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Underline({ children }) {
|
|
22
|
+
return (
|
|
23
|
+
<Text style={styles.underline}>{children}</Text>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function Strikethrough({ children }) {
|
|
28
|
+
return (
|
|
29
|
+
<Text style={styles.lineThrough}>{children}</Text>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function UnderlineStrikethrough({ children }) {
|
|
34
|
+
return (
|
|
35
|
+
<Text style={styles.underlineLineThrough}>{children}</Text>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function Heading({ children }) {
|
|
40
|
+
return (
|
|
41
|
+
<Text style={styles.heading}>{children}</Text>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function SubHeading({ children }) {
|
|
46
|
+
return (
|
|
47
|
+
<Text style={styles.subHeading}>{children}</Text>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function SubSubHeading({ children }) {
|
|
52
|
+
return (
|
|
53
|
+
<Text style={styles.subSubHeading}>{children}</Text>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const styles = StyleSheet.create({
|
|
58
|
+
bold: {
|
|
59
|
+
fontWeight: 'bold',
|
|
60
|
+
},
|
|
61
|
+
italic: {
|
|
62
|
+
fontStyle: "italic"
|
|
63
|
+
},
|
|
64
|
+
lineThrough: {
|
|
65
|
+
textDecorationLine: "line-through"
|
|
66
|
+
},
|
|
67
|
+
underline: {
|
|
68
|
+
textDecorationLine: "underline",
|
|
69
|
+
},
|
|
70
|
+
underlineLineThrough: {
|
|
71
|
+
textDecorationLine: "underline line-through"
|
|
72
|
+
},
|
|
73
|
+
codeContainer: {
|
|
74
|
+
backgroundColor: "lightgray",
|
|
75
|
+
paddingHorizontal: 4,
|
|
76
|
+
borderRadius: 4,
|
|
77
|
+
height: 24,
|
|
78
|
+
position: "absolute",
|
|
79
|
+
top: 10
|
|
80
|
+
},
|
|
81
|
+
code: {
|
|
82
|
+
fontFamily: "ui-monospace",
|
|
83
|
+
color: "#EB5757",
|
|
84
|
+
fontSize: 20,
|
|
85
|
+
backgroundColor: "rgba(135, 131, 120, .15)"
|
|
86
|
+
},
|
|
87
|
+
highlight: {
|
|
88
|
+
width: "100%",
|
|
89
|
+
position: "absolute",
|
|
90
|
+
padding: 20,
|
|
91
|
+
height: 24,
|
|
92
|
+
backgroundColor: "blue"
|
|
93
|
+
},
|
|
94
|
+
heading: {
|
|
95
|
+
fontSize: 32,
|
|
96
|
+
fontWeight: "bold"
|
|
97
|
+
},
|
|
98
|
+
subHeading: {
|
|
99
|
+
fontSize: 28,
|
|
100
|
+
fontWeight: "bold"
|
|
101
|
+
},
|
|
102
|
+
subSubHeading: {
|
|
103
|
+
fontSize: 24,
|
|
104
|
+
fontWeight: "bold"
|
|
105
|
+
}
|
|
106
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Bold, Code, Heading, Italic, SubHeading, SubSubHeading, Strikethrough, Underline } from "./components/StyledText";
|
|
2
|
+
|
|
3
|
+
export const markdownStyles = [
|
|
4
|
+
{ style: "bold", regex: "\\*([^*]+)\\*", render: Bold, opening: "*", closing: "*" },
|
|
5
|
+
{ style: "italic", regex: "_([^_]+)_", render: Italic, opening: "_", closing: "_" },
|
|
6
|
+
{ style: "lineThrough", regex: "~([^~]+)~", render: Strikethrough, opening: "~", closing: "~" },
|
|
7
|
+
{ style: "code", regex: "`([^`]+)`", render: Code, opening: "`", closing: "`" },
|
|
8
|
+
{ style: "underline", regex: "__([^_]+)__", render: Underline, opening: "__", closing: "__" },
|
|
9
|
+
{ style: "heading", regex: null, render: Heading, opening: "#", closing: null },
|
|
10
|
+
{ style: "subHeading", regex: null, render: SubHeading, opening: "##", closing: null },
|
|
11
|
+
{ style: "subSubHeading", regex: null, render: SubSubHeading, opening: "###", closing: null }
|
|
12
|
+
];
|