glacia-native 0.3.2 → 0.3.4
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/LICENSE +1 -7
- package/README.md +178 -0
- package/lib/module/Dialog.js +128 -0
- package/lib/module/Form.js +125 -0
- package/lib/module/Input.js +64 -0
- package/lib/module/Table.js +81 -0
- package/lib/module/ai.js +246 -0
- package/lib/module/charts/AreaChart.js +32 -0
- package/lib/module/charts/BarChart.js +65 -0
- package/lib/module/charts/FunnelChart.js +48 -0
- package/lib/module/charts/HeatmapChart.js +69 -0
- package/lib/module/charts/LineChart.js +79 -0
- package/lib/module/charts/PlotChart.js +44 -0
- package/lib/module/charts/RadarChart.js +76 -0
- package/lib/module/charts/RingChart.js +50 -0
- package/lib/module/charts/ScatterChart.js +78 -0
- package/lib/module/charts/WaterfallChart.js +76 -0
- package/lib/module/charts/advanced.js +307 -0
- package/lib/module/charts/extra.js +105 -0
- package/lib/module/charts/index.js +50 -0
- package/lib/module/charts/primitives.js +212 -0
- package/lib/module/charts/scales.js +140 -0
- package/lib/module/index.js +48 -1
- package/lib/module/internal/tokens.js +3 -0
- package/lib/typescript/Dialog.d.ts +71 -0
- package/lib/typescript/Form.d.ts +81 -0
- package/lib/typescript/Input.d.ts +47 -0
- package/lib/typescript/Table.d.ts +55 -0
- package/lib/typescript/ai.d.ts +163 -0
- package/lib/typescript/charts/AreaChart.d.ts +44 -0
- package/lib/typescript/charts/BarChart.d.ts +19 -0
- package/lib/typescript/charts/FunnelChart.d.ts +25 -0
- package/lib/typescript/charts/HeatmapChart.d.ts +23 -0
- package/lib/typescript/charts/LineChart.d.ts +30 -0
- package/lib/typescript/charts/PlotChart.d.ts +31 -0
- package/lib/typescript/charts/RadarChart.d.ts +27 -0
- package/lib/typescript/charts/RingChart.d.ts +28 -0
- package/lib/typescript/charts/ScatterChart.d.ts +34 -0
- package/lib/typescript/charts/WaterfallChart.d.ts +22 -0
- package/lib/typescript/charts/advanced.d.ts +107 -0
- package/lib/typescript/charts/extra.d.ts +63 -0
- package/lib/typescript/charts/index.d.ts +13 -0
- package/lib/typescript/charts/primitives.d.ts +23 -0
- package/lib/typescript/charts/scales.d.ts +35 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/internal/tokens.d.ts +2 -0
- package/package.json +10 -3
- package/src/Dialog.tsx +345 -0
- package/src/Form.tsx +360 -0
- package/src/Input.tsx +172 -0
- package/src/Table.tsx +207 -0
- package/src/ai.tsx +655 -0
- package/src/charts/AreaChart.tsx +73 -0
- package/src/charts/BarChart.tsx +181 -0
- package/src/charts/FunnelChart.tsx +123 -0
- package/src/charts/HeatmapChart.tsx +153 -0
- package/src/charts/LineChart.tsx +245 -0
- package/src/charts/PlotChart.tsx +148 -0
- package/src/charts/RadarChart.tsx +206 -0
- package/src/charts/RingChart.tsx +131 -0
- package/src/charts/ScatterChart.tsx +202 -0
- package/src/charts/WaterfallChart.tsx +183 -0
- package/src/charts/advanced.tsx +670 -0
- package/src/charts/extra.tsx +239 -0
- package/src/charts/index.ts +86 -0
- package/src/charts/primitives.ts +262 -0
- package/src/charts/scales.ts +163 -0
- package/src/index.ts +68 -0
- package/src/internal/tokens.ts +3 -0
package/src/Form.tsx
ADDED
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { forwardRef, useState, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { colors, radii } from "./internal/tokens";
|
|
4
|
+
import { primitives } from "./charts/primitives";
|
|
5
|
+
|
|
6
|
+
export interface LabelProps {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
/** Marks the field required with a visible asterisk. */
|
|
9
|
+
required?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Ties the label to the control for screen readers. */
|
|
12
|
+
htmlFor?: string;
|
|
13
|
+
isDark?: boolean;
|
|
14
|
+
style?: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The text above a control. */
|
|
18
|
+
export const Label = forwardRef<any, LabelProps>(function Label(
|
|
19
|
+
{ children, required = false, disabled = false, htmlFor, isDark = false, style },
|
|
20
|
+
ref,
|
|
21
|
+
) {
|
|
22
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
23
|
+
const { Text } = primitives();
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Text
|
|
27
|
+
ref={ref}
|
|
28
|
+
nativeID={htmlFor}
|
|
29
|
+
accessibilityRole="text"
|
|
30
|
+
style={{
|
|
31
|
+
fontSize: 13,
|
|
32
|
+
fontWeight: "600",
|
|
33
|
+
color: disabled ? theme.muted : theme.foreground,
|
|
34
|
+
opacity: disabled ? 0.6 : 1,
|
|
35
|
+
...style,
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
{children}
|
|
39
|
+
{required && <Text style={{ color: theme.destructive }}> *</Text>}
|
|
40
|
+
</Text>
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export interface FieldProps {
|
|
45
|
+
label?: string;
|
|
46
|
+
/** Helper text shown under the control. */
|
|
47
|
+
description?: string;
|
|
48
|
+
/** Error text. Overrides `description` and tints the label. */
|
|
49
|
+
error?: string;
|
|
50
|
+
required?: boolean;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
isDark?: boolean;
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
style?: any;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Label, control and message stacked in the order assistive tech announces
|
|
59
|
+
* them, so a caller never has to place these three by hand.
|
|
60
|
+
*/
|
|
61
|
+
export function Field({
|
|
62
|
+
label,
|
|
63
|
+
description,
|
|
64
|
+
error,
|
|
65
|
+
required = false,
|
|
66
|
+
disabled = false,
|
|
67
|
+
isDark = false,
|
|
68
|
+
children,
|
|
69
|
+
style,
|
|
70
|
+
}: FieldProps) {
|
|
71
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
72
|
+
const { View, Text } = primitives();
|
|
73
|
+
const message = error ?? description;
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<View style={{ gap: 6, ...style }}>
|
|
77
|
+
{label && (
|
|
78
|
+
<Label required={required} disabled={disabled} isDark={isDark}>
|
|
79
|
+
{label}
|
|
80
|
+
</Label>
|
|
81
|
+
)}
|
|
82
|
+
|
|
83
|
+
{children}
|
|
84
|
+
|
|
85
|
+
{message && (
|
|
86
|
+
<Text
|
|
87
|
+
accessibilityRole={error ? "alert" : "text"}
|
|
88
|
+
style={{
|
|
89
|
+
fontSize: 11,
|
|
90
|
+
color: error ? theme.destructive : theme.muted,
|
|
91
|
+
}}
|
|
92
|
+
>
|
|
93
|
+
{message}
|
|
94
|
+
</Text>
|
|
95
|
+
)}
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface CheckboxProps {
|
|
101
|
+
checked?: boolean;
|
|
102
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
103
|
+
label?: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
indeterminate?: boolean;
|
|
106
|
+
disabled?: boolean;
|
|
107
|
+
isDark?: boolean;
|
|
108
|
+
style?: any;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** A tick box for a single boolean, with an optional label and description. */
|
|
112
|
+
export function Checkbox({
|
|
113
|
+
checked = false,
|
|
114
|
+
onCheckedChange,
|
|
115
|
+
label,
|
|
116
|
+
description,
|
|
117
|
+
indeterminate = false,
|
|
118
|
+
disabled = false,
|
|
119
|
+
isDark = false,
|
|
120
|
+
style,
|
|
121
|
+
}: CheckboxProps) {
|
|
122
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
123
|
+
const { View, Text, Pressable } = primitives();
|
|
124
|
+
|
|
125
|
+
const filled = checked || indeterminate;
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<Pressable
|
|
129
|
+
accessibilityRole="checkbox"
|
|
130
|
+
accessibilityState={{ checked, disabled }}
|
|
131
|
+
accessibilityLabel={label}
|
|
132
|
+
disabled={disabled}
|
|
133
|
+
onPress={() => !disabled && onCheckedChange?.(!checked)}
|
|
134
|
+
style={{
|
|
135
|
+
flexDirection: "row",
|
|
136
|
+
alignItems: "flex-start",
|
|
137
|
+
gap: 10,
|
|
138
|
+
opacity: disabled ? 0.45 : 1,
|
|
139
|
+
...style,
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<View
|
|
143
|
+
style={{
|
|
144
|
+
width: 20,
|
|
145
|
+
height: 20,
|
|
146
|
+
borderRadius: 6,
|
|
147
|
+
borderWidth: filled ? 0 : 1.5,
|
|
148
|
+
borderColor: theme.edge,
|
|
149
|
+
backgroundColor: filled ? theme.fill : "transparent",
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
justifyContent: "center",
|
|
152
|
+
marginTop: 1,
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
{indeterminate ? (
|
|
156
|
+
<View style={{ width: 10, height: 2, borderRadius: 1, backgroundColor: "#fff" }} />
|
|
157
|
+
) : checked ? (
|
|
158
|
+
// A glyph rather than an icon dependency: one text node, no package.
|
|
159
|
+
<Text style={{ color: "#fff", fontSize: 12, fontWeight: "700", lineHeight: 14 }}>
|
|
160
|
+
✓
|
|
161
|
+
</Text>
|
|
162
|
+
) : null}
|
|
163
|
+
</View>
|
|
164
|
+
|
|
165
|
+
{(label || description) && (
|
|
166
|
+
<View style={{ flex: 1 }}>
|
|
167
|
+
{label && (
|
|
168
|
+
<Text style={{ fontSize: 14, color: theme.foreground, fontWeight: "500" }}>{label}</Text>
|
|
169
|
+
)}
|
|
170
|
+
{description && (
|
|
171
|
+
<Text style={{ fontSize: 11, color: theme.muted, marginTop: 2 }}>{description}</Text>
|
|
172
|
+
)}
|
|
173
|
+
</View>
|
|
174
|
+
)}
|
|
175
|
+
</Pressable>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export interface RadioOption {
|
|
180
|
+
value: string;
|
|
181
|
+
label: string;
|
|
182
|
+
description?: string;
|
|
183
|
+
disabled?: boolean;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface RadioGroupProps {
|
|
187
|
+
value?: string;
|
|
188
|
+
onValueChange?: (value: string) => void;
|
|
189
|
+
options: RadioOption[];
|
|
190
|
+
/** Lay the options out in a row instead of a column. */
|
|
191
|
+
horizontal?: boolean;
|
|
192
|
+
disabled?: boolean;
|
|
193
|
+
isDark?: boolean;
|
|
194
|
+
style?: any;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** One choice from a small, always-visible set. */
|
|
198
|
+
export function RadioGroup({
|
|
199
|
+
value,
|
|
200
|
+
onValueChange,
|
|
201
|
+
options,
|
|
202
|
+
horizontal = false,
|
|
203
|
+
disabled = false,
|
|
204
|
+
isDark = false,
|
|
205
|
+
style,
|
|
206
|
+
}: RadioGroupProps) {
|
|
207
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
208
|
+
const { View, Text, Pressable } = primitives();
|
|
209
|
+
|
|
210
|
+
return (
|
|
211
|
+
<View
|
|
212
|
+
accessibilityRole="radiogroup"
|
|
213
|
+
style={{ gap: horizontal ? 14 : 10, flexDirection: horizontal ? "row" : "column", ...style }}
|
|
214
|
+
>
|
|
215
|
+
{options.map((option) => {
|
|
216
|
+
const isSelected = option.value === value;
|
|
217
|
+
const isDisabled = disabled || option.disabled;
|
|
218
|
+
|
|
219
|
+
return (
|
|
220
|
+
<Pressable
|
|
221
|
+
key={option.value}
|
|
222
|
+
accessibilityRole="radio"
|
|
223
|
+
accessibilityState={{ checked: isSelected, disabled: isDisabled }}
|
|
224
|
+
accessibilityLabel={option.label}
|
|
225
|
+
disabled={isDisabled}
|
|
226
|
+
onPress={() => !isDisabled && onValueChange?.(option.value)}
|
|
227
|
+
style={{
|
|
228
|
+
flexDirection: "row",
|
|
229
|
+
alignItems: "flex-start",
|
|
230
|
+
gap: 9,
|
|
231
|
+
opacity: isDisabled ? 0.45 : 1,
|
|
232
|
+
}}
|
|
233
|
+
>
|
|
234
|
+
<View
|
|
235
|
+
style={{
|
|
236
|
+
width: 20,
|
|
237
|
+
height: 20,
|
|
238
|
+
borderRadius: 10,
|
|
239
|
+
borderWidth: isSelected ? 6 : 1.5,
|
|
240
|
+
borderColor: isSelected ? theme.fill : theme.edge,
|
|
241
|
+
marginTop: 1,
|
|
242
|
+
}}
|
|
243
|
+
/>
|
|
244
|
+
<View style={{ flex: 1 }}>
|
|
245
|
+
<Text style={{ fontSize: 14, color: theme.foreground }}>{option.label}</Text>
|
|
246
|
+
{option.description && (
|
|
247
|
+
<Text style={{ fontSize: 11, color: theme.muted, marginTop: 2 }}>
|
|
248
|
+
{option.description}
|
|
249
|
+
</Text>
|
|
250
|
+
)}
|
|
251
|
+
</View>
|
|
252
|
+
</Pressable>
|
|
253
|
+
);
|
|
254
|
+
})}
|
|
255
|
+
</View>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface SelectOption {
|
|
260
|
+
value: string;
|
|
261
|
+
label: string;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export interface SelectProps {
|
|
265
|
+
value?: string;
|
|
266
|
+
onValueChange?: (value: string) => void;
|
|
267
|
+
options: SelectOption[];
|
|
268
|
+
placeholder?: string;
|
|
269
|
+
disabled?: boolean;
|
|
270
|
+
isDark?: boolean;
|
|
271
|
+
style?: any;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* A dropdown of mutually exclusive options.
|
|
276
|
+
*
|
|
277
|
+
* Native has no built-in picker that looks the same on iOS and Android, so the
|
|
278
|
+
* list opens inline: predictable across platforms and reachable without a
|
|
279
|
+
* modal. A long list scrolls naturally with the page.
|
|
280
|
+
*/
|
|
281
|
+
export function Select({
|
|
282
|
+
value,
|
|
283
|
+
onValueChange,
|
|
284
|
+
options,
|
|
285
|
+
placeholder = "Select an option",
|
|
286
|
+
disabled = false,
|
|
287
|
+
isDark = false,
|
|
288
|
+
style,
|
|
289
|
+
}: SelectProps) {
|
|
290
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
291
|
+
const { View, Text, Pressable } = primitives();
|
|
292
|
+
const [open, setOpen] = useState(false);
|
|
293
|
+
|
|
294
|
+
const selected = options.find((option) => option.value === value);
|
|
295
|
+
|
|
296
|
+
return (
|
|
297
|
+
<View style={style}>
|
|
298
|
+
<Pressable
|
|
299
|
+
accessibilityRole="button"
|
|
300
|
+
accessibilityState={{ expanded: open, disabled }}
|
|
301
|
+
accessibilityLabel={selected?.label ?? placeholder}
|
|
302
|
+
disabled={disabled}
|
|
303
|
+
onPress={() => setOpen(!open)}
|
|
304
|
+
style={{
|
|
305
|
+
minHeight: 42,
|
|
306
|
+
flexDirection: "row",
|
|
307
|
+
alignItems: "center",
|
|
308
|
+
justifyContent: "space-between",
|
|
309
|
+
paddingHorizontal: 12,
|
|
310
|
+
borderRadius: radii.md,
|
|
311
|
+
borderWidth: 1,
|
|
312
|
+
borderColor: theme.edge,
|
|
313
|
+
backgroundColor: theme.glass,
|
|
314
|
+
opacity: disabled ? 0.5 : 1,
|
|
315
|
+
}}
|
|
316
|
+
>
|
|
317
|
+
<Text style={{ fontSize: 15, color: selected ? theme.foreground : theme.muted }}>
|
|
318
|
+
{selected?.label ?? placeholder}
|
|
319
|
+
</Text>
|
|
320
|
+
<Text style={{ fontSize: 10, color: theme.muted }}>{open ? "▲" : "▼"}</Text>
|
|
321
|
+
</Pressable>
|
|
322
|
+
|
|
323
|
+
{open && (
|
|
324
|
+
<View
|
|
325
|
+
style={{
|
|
326
|
+
marginTop: 6,
|
|
327
|
+
borderRadius: radii.md,
|
|
328
|
+
borderWidth: 1,
|
|
329
|
+
borderColor: theme.edge,
|
|
330
|
+
backgroundColor: theme.glass,
|
|
331
|
+
overflow: "hidden",
|
|
332
|
+
}}
|
|
333
|
+
>
|
|
334
|
+
{options.map((option) => {
|
|
335
|
+
const isSelected = option.value === value;
|
|
336
|
+
return (
|
|
337
|
+
<Pressable
|
|
338
|
+
key={option.value}
|
|
339
|
+
accessibilityRole="button"
|
|
340
|
+
accessibilityState={{ selected: isSelected }}
|
|
341
|
+
accessibilityLabel={option.label}
|
|
342
|
+
onPress={() => {
|
|
343
|
+
onValueChange?.(option.value);
|
|
344
|
+
setOpen(false);
|
|
345
|
+
}}
|
|
346
|
+
style={{
|
|
347
|
+
paddingVertical: 10,
|
|
348
|
+
paddingHorizontal: 12,
|
|
349
|
+
backgroundColor: isSelected ? theme.glassActive : "transparent",
|
|
350
|
+
}}
|
|
351
|
+
>
|
|
352
|
+
<Text style={{ fontSize: 14, color: theme.foreground }}>{option.label}</Text>
|
|
353
|
+
</Pressable>
|
|
354
|
+
);
|
|
355
|
+
})}
|
|
356
|
+
</View>
|
|
357
|
+
)}
|
|
358
|
+
</View>
|
|
359
|
+
);
|
|
360
|
+
}
|
package/src/Input.tsx
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { forwardRef, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { colors, radii } from "./internal/tokens";
|
|
4
|
+
import { primitives } from "./charts/primitives";
|
|
5
|
+
|
|
6
|
+
export interface InputProps {
|
|
7
|
+
value?: string;
|
|
8
|
+
onChangeText?: (text: string) => void;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
/** Renders the field in an error state. Pair with a Field message. */
|
|
11
|
+
invalid?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
secureTextEntry?: boolean;
|
|
14
|
+
keyboardType?: "default" | "email-address" | "numeric" | "phone-pad" | "url";
|
|
15
|
+
autoCapitalize?: "none" | "sentences" | "words" | "characters";
|
|
16
|
+
autoCorrect?: boolean;
|
|
17
|
+
multiline?: boolean;
|
|
18
|
+
/** Grows with its content when `multiline` is set. */
|
|
19
|
+
minLines?: number;
|
|
20
|
+
size?: "sm" | "md" | "lg";
|
|
21
|
+
accessibilityLabel?: string;
|
|
22
|
+
returnKeyType?: "done" | "next" | "go" | "search" | "send";
|
|
23
|
+
onSubmitEditing?: () => void;
|
|
24
|
+
prefix?: ReactNode;
|
|
25
|
+
suffix?: ReactNode;
|
|
26
|
+
isDark?: boolean;
|
|
27
|
+
style?: any;
|
|
28
|
+
// Standard TextInput props a caller may still want to pass through.
|
|
29
|
+
maxLength?: number;
|
|
30
|
+
editable?: boolean;
|
|
31
|
+
onFocus?: () => void;
|
|
32
|
+
onBlur?: () => void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const heights = { sm: 34, md: 42, lg: 50 };
|
|
36
|
+
const fontSizes = { sm: 14, md: 15, lg: 16 };
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A single-line or multiline text field.
|
|
40
|
+
*
|
|
41
|
+
* The native TextInput has no placeholder styling prop, so the placeholder is
|
|
42
|
+
* drawn as a sibling Text: that keeps its colour tied to the theme instead of
|
|
43
|
+
* the OS default, which changes between iOS versions.
|
|
44
|
+
*/
|
|
45
|
+
export const Input = forwardRef<any, InputProps>(function Input(
|
|
46
|
+
{
|
|
47
|
+
value,
|
|
48
|
+
onChangeText,
|
|
49
|
+
placeholder,
|
|
50
|
+
invalid = false,
|
|
51
|
+
disabled = false,
|
|
52
|
+
secureTextEntry = false,
|
|
53
|
+
keyboardType = "default",
|
|
54
|
+
autoCapitalize,
|
|
55
|
+
autoCorrect,
|
|
56
|
+
multiline = false,
|
|
57
|
+
minLines = 3,
|
|
58
|
+
size = "md",
|
|
59
|
+
accessibilityLabel,
|
|
60
|
+
returnKeyType,
|
|
61
|
+
onSubmitEditing,
|
|
62
|
+
prefix,
|
|
63
|
+
suffix,
|
|
64
|
+
isDark = false,
|
|
65
|
+
style,
|
|
66
|
+
maxLength,
|
|
67
|
+
editable,
|
|
68
|
+
onFocus,
|
|
69
|
+
onBlur,
|
|
70
|
+
},
|
|
71
|
+
ref,
|
|
72
|
+
) {
|
|
73
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
74
|
+
const { View, Text, TextInput } = primitives();
|
|
75
|
+
|
|
76
|
+
const isEditable = editable !== undefined ? editable : !disabled;
|
|
77
|
+
const showPlaceholder = !value && placeholder;
|
|
78
|
+
|
|
79
|
+
const fieldStyle: any = {
|
|
80
|
+
flex: 1,
|
|
81
|
+
paddingVertical: height_padding(size),
|
|
82
|
+
paddingHorizontal: 0,
|
|
83
|
+
fontSize: fontSizes[size],
|
|
84
|
+
color: theme.foreground,
|
|
85
|
+
// RN draws its own underline on Android; the border is ours.
|
|
86
|
+
outlineStyle: "none",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<View
|
|
91
|
+
style={{
|
|
92
|
+
flexDirection: "row",
|
|
93
|
+
alignItems: multiline ? "flex-start" : "center",
|
|
94
|
+
gap: 8,
|
|
95
|
+
minHeight: multiline ? undefined : heights[size],
|
|
96
|
+
borderRadius: radii.md,
|
|
97
|
+
borderWidth: 1,
|
|
98
|
+
borderColor: invalid ? theme.destructive : theme.edge,
|
|
99
|
+
backgroundColor: theme.glass,
|
|
100
|
+
paddingHorizontal: 12,
|
|
101
|
+
opacity: disabled ? 0.5 : 1,
|
|
102
|
+
...style,
|
|
103
|
+
}}
|
|
104
|
+
>
|
|
105
|
+
{prefix}
|
|
106
|
+
|
|
107
|
+
<View style={{ flex: 1, justifyContent: "center" }}>
|
|
108
|
+
{showPlaceholder && (
|
|
109
|
+
<Text
|
|
110
|
+
style={{
|
|
111
|
+
position: "absolute",
|
|
112
|
+
left: 0,
|
|
113
|
+
top: multiline ? 0 : undefined,
|
|
114
|
+
fontSize: fontSizes[size],
|
|
115
|
+
color: theme.muted,
|
|
116
|
+
pointerEvents: "none",
|
|
117
|
+
}}
|
|
118
|
+
numberOfLines={1}
|
|
119
|
+
>
|
|
120
|
+
{placeholder}
|
|
121
|
+
</Text>
|
|
122
|
+
)}
|
|
123
|
+
|
|
124
|
+
<TextInput
|
|
125
|
+
ref={ref}
|
|
126
|
+
value={value}
|
|
127
|
+
onChangeText={onChangeText}
|
|
128
|
+
editable={isEditable}
|
|
129
|
+
secureTextEntry={secureTextEntry}
|
|
130
|
+
keyboardType={keyboardType}
|
|
131
|
+
autoCapitalize={autoCapitalize}
|
|
132
|
+
autoCorrect={autoCorrect}
|
|
133
|
+
multiline={multiline}
|
|
134
|
+
numberOfLines={multiline ? minLines : undefined}
|
|
135
|
+
maxLength={maxLength}
|
|
136
|
+
returnKeyType={returnKeyType}
|
|
137
|
+
onSubmitEditing={onSubmitEditing}
|
|
138
|
+
onFocus={onFocus}
|
|
139
|
+
onBlur={onBlur}
|
|
140
|
+
accessibilityLabel={accessibilityLabel ?? placeholder}
|
|
141
|
+
accessibilityState={{ disabled: !isEditable }}
|
|
142
|
+
style={fieldStyle}
|
|
143
|
+
/>
|
|
144
|
+
</View>
|
|
145
|
+
|
|
146
|
+
{suffix}
|
|
147
|
+
</View>
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/** Vertical padding tuned per size so the text sits optically centred. */
|
|
152
|
+
function height_padding(size: "sm" | "md" | "lg") {
|
|
153
|
+
return size === "sm" ? 6 : size === "lg" ? 12 : 9;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface TextareaProps extends Omit<InputProps, "size" | "multiline" | "minLines"> {
|
|
157
|
+
/** Visible height in text lines. */
|
|
158
|
+
rows?: number;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* A multi-line field.
|
|
163
|
+
*
|
|
164
|
+
* Separate from Input so `multiline` cannot silently turn off the single-line
|
|
165
|
+
* sizing, and so callers get a `rows` prop instead of guessing a pixel height.
|
|
166
|
+
*/
|
|
167
|
+
export const Textarea = forwardRef<any, TextareaProps>(function Textarea(
|
|
168
|
+
{ rows = 4, ...props },
|
|
169
|
+
ref,
|
|
170
|
+
) {
|
|
171
|
+
return <Input ref={ref} {...props} multiline minLines={rows} />;
|
|
172
|
+
});
|