@expressive-ui/native 0.2.0 → 0.3.0
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/README.md +10 -0
- package/dist/Feedback.d.ts +3 -3
- package/dist/Feedback.d.ts.map +1 -1
- package/dist/Feedback.js +73 -14
- package/dist/Feedback.js.map +1 -1
- package/dist/Fields.d.ts +10 -6
- package/dist/Fields.d.ts.map +1 -1
- package/dist/Fields.js +125 -29
- package/dist/Fields.js.map +1 -1
- package/dist/FileUpload.d.ts.map +1 -1
- package/dist/FileUpload.js +61 -19
- package/dist/FileUpload.js.map +1 -1
- package/dist/NumberField.d.ts +6 -2
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/NumberField.js +71 -11
- package/dist/NumberField.js.map +1 -1
- package/dist/Pickers.d.ts.map +1 -1
- package/dist/Pickers.js +227 -36
- package/dist/Pickers.js.map +1 -1
- package/dist/RenderUI.d.ts +3 -0
- package/dist/RenderUI.d.ts.map +1 -0
- package/dist/RenderUI.js +45 -0
- package/dist/RenderUI.js.map +1 -0
- package/dist/Search.js +1 -1
- package/dist/Search.js.map +1 -1
- package/dist/Select.d.ts +5 -1
- package/dist/Select.d.ts.map +1 -1
- package/dist/Select.js +52 -10
- package/dist/Select.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/theme.d.ts +3 -1
- package/dist/theme.d.ts.map +1 -1
- package/dist/theme.js +36 -11
- package/dist/theme.js.map +1 -1
- package/package.json +4 -4
- package/src/Feedback.tsx +211 -16
- package/src/Fields.tsx +341 -58
- package/src/FileUpload.tsx +169 -7
- package/src/NumberField.tsx +187 -9
- package/src/Pickers.tsx +783 -86
- package/src/RenderUI.tsx +47 -0
- package/src/Search.tsx +1 -1
- package/src/Select.tsx +209 -27
- package/src/index.ts +2 -0
- package/src/theme.tsx +77 -14
package/src/FileUpload.tsx
CHANGED
|
@@ -6,11 +6,173 @@ import { Icon, T } from './primitives.js';
|
|
|
6
6
|
import { useExpressiveTheme } from './theme.js';
|
|
7
7
|
export type { NativeUploadFile } from '@expressive-ui/core';
|
|
8
8
|
/** Inject an Expo DocumentPicker or platform picker adapter; this package does not install a picker dependency. */
|
|
9
|
-
export type FileUploadProps=FileUploadOptions<NativeUploadFile
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export type FileUploadProps = FileUploadOptions<NativeUploadFile> & {
|
|
10
|
+
label: string;
|
|
11
|
+
pickFiles: () => Promise<readonly NativeUploadFile[]>;
|
|
12
|
+
supportingText?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
style?: StyleProp<ViewStyle>;
|
|
15
|
+
};
|
|
16
|
+
export function FileUpload({
|
|
17
|
+
label,
|
|
18
|
+
pickFiles,
|
|
19
|
+
supportingText,
|
|
20
|
+
disabled,
|
|
21
|
+
style,
|
|
22
|
+
...options
|
|
23
|
+
}: FileUploadProps) {
|
|
24
|
+
const { colors, labels } = useExpressiveTheme(),
|
|
25
|
+
[picking, setPicking] = useState(false),
|
|
26
|
+
[error, setError] = useState(''),
|
|
27
|
+
mounted = useRef(true),
|
|
28
|
+
inflight = useRef(false);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
mounted.current = true;
|
|
31
|
+
return () => {
|
|
32
|
+
mounted.current = false;
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
const queue = useFileUpload({
|
|
36
|
+
...options,
|
|
37
|
+
onReject: (rejected) => {
|
|
38
|
+
setError(
|
|
39
|
+
rejected
|
|
40
|
+
.map(
|
|
41
|
+
(item) =>
|
|
42
|
+
`${item.file.name}: ${
|
|
43
|
+
item.reason === 'type'
|
|
44
|
+
? labels.uploadTypeError
|
|
45
|
+
: item.reason === 'size'
|
|
46
|
+
? labels.uploadSizeError
|
|
47
|
+
: labels.uploadCountError
|
|
48
|
+
}`,
|
|
49
|
+
)
|
|
50
|
+
.join(', '),
|
|
51
|
+
);
|
|
52
|
+
options.onReject?.(rejected);
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
const choose = async () => {
|
|
56
|
+
if (inflight.current || disabled) return;
|
|
57
|
+
inflight.current = true;
|
|
58
|
+
setPicking(true);
|
|
59
|
+
setError('');
|
|
60
|
+
try {
|
|
61
|
+
const files = await pickFiles();
|
|
62
|
+
if (mounted.current) queue.add(files);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (mounted.current) setError(error instanceof Error ? error.message : String(error));
|
|
65
|
+
} finally {
|
|
66
|
+
inflight.current = false;
|
|
67
|
+
if (mounted.current) setPicking(false);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
return (
|
|
71
|
+
<View style={[{ gap: 14 }, style]}>
|
|
72
|
+
<T variant="titleSmall">{label}</T>
|
|
73
|
+
{supportingText ? <T color="onSurfaceVariant">{supportingText}</T> : null}
|
|
74
|
+
<View
|
|
75
|
+
style={{
|
|
76
|
+
padding: 24,
|
|
77
|
+
borderWidth: 2,
|
|
78
|
+
borderStyle: 'dashed',
|
|
79
|
+
borderColor: colors.outlineVariant,
|
|
80
|
+
borderRadius: 20,
|
|
81
|
+
alignItems: 'center',
|
|
82
|
+
gap: 12,
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
<Icon name="upload" size={32} />
|
|
86
|
+
<Button
|
|
87
|
+
action={{ id: 'upload.choose', label: labels.chooseFiles }}
|
|
88
|
+
loading={picking}
|
|
89
|
+
disabled={disabled || picking}
|
|
90
|
+
onPress={choose}
|
|
91
|
+
/>
|
|
92
|
+
</View>
|
|
93
|
+
{error ? (
|
|
94
|
+
<T accessibilityRole="alert" color="error">
|
|
95
|
+
{error}
|
|
96
|
+
</T>
|
|
97
|
+
) : null}
|
|
98
|
+
{queue.entries.map((entry) => (
|
|
99
|
+
<View
|
|
100
|
+
key={entry.id}
|
|
101
|
+
style={{
|
|
102
|
+
padding: 12,
|
|
103
|
+
borderRadius: 16,
|
|
104
|
+
backgroundColor: colors.surfaceContainer,
|
|
105
|
+
gap: 8,
|
|
106
|
+
}}
|
|
107
|
+
>
|
|
108
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 12 }}>
|
|
109
|
+
{entry.file.type.startsWith('image/') ? (
|
|
110
|
+
<Image
|
|
111
|
+
source={{ uri: entry.file.uri }}
|
|
112
|
+
accessibilityIgnoresInvertColors
|
|
113
|
+
style={{ width: 48, height: 48, borderRadius: 8 }}
|
|
114
|
+
/>
|
|
115
|
+
) : (
|
|
116
|
+
<Icon name="description" />
|
|
117
|
+
)}
|
|
118
|
+
<View style={{ flex: 1 }}>
|
|
119
|
+
<T>{entry.file.name}</T>
|
|
120
|
+
<T variant="bodySmall" color="onSurfaceVariant">
|
|
121
|
+
{Math.ceil(entry.file.size / 1024)} KB ·{' '}
|
|
122
|
+
{
|
|
123
|
+
{
|
|
124
|
+
ready: labels.uploadReady,
|
|
125
|
+
uploading: labels.uploading,
|
|
126
|
+
complete: labels.uploadComplete,
|
|
127
|
+
error: labels.uploadFailed,
|
|
128
|
+
cancelled: labels.uploadCancelled,
|
|
129
|
+
}[entry.status]
|
|
130
|
+
}
|
|
131
|
+
</T>
|
|
132
|
+
</View>
|
|
133
|
+
</View>
|
|
134
|
+
{entry.status === 'uploading' ? (
|
|
135
|
+
<View
|
|
136
|
+
accessibilityRole="progressbar"
|
|
137
|
+
accessibilityLabel={entry.file.name}
|
|
138
|
+
accessibilityValue={{ min: 0, max: 100, now: entry.progress }}
|
|
139
|
+
style={{ height: 4, borderRadius: 2, backgroundColor: colors.outlineVariant }}
|
|
140
|
+
>
|
|
141
|
+
<View
|
|
142
|
+
style={{ height: 4, width: `${entry.progress}%`, backgroundColor: colors.primary }}
|
|
143
|
+
/>
|
|
144
|
+
</View>
|
|
145
|
+
) : null}
|
|
146
|
+
{entry.error ? (
|
|
147
|
+
<T accessibilityRole="alert" color="error">
|
|
148
|
+
{entry.error}
|
|
149
|
+
</T>
|
|
150
|
+
) : null}
|
|
151
|
+
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 8 }}>
|
|
152
|
+
{entry.status === 'uploading' ? (
|
|
153
|
+
<Button
|
|
154
|
+
variant="text"
|
|
155
|
+
action={{ id: 'upload.cancel', label: labels.cancel }}
|
|
156
|
+
onPress={() => queue.cancel(entry.id)}
|
|
157
|
+
/>
|
|
158
|
+
) : null}
|
|
159
|
+
{options.onUpload && ['error', 'cancelled'].includes(entry.status) ? (
|
|
160
|
+
<Button
|
|
161
|
+
variant="text"
|
|
162
|
+
disabled={disabled}
|
|
163
|
+
action={{ id: 'upload.retry', label: labels.retry }}
|
|
164
|
+
onPress={() => queue.retry(entry.id)}
|
|
165
|
+
/>
|
|
166
|
+
) : null}
|
|
167
|
+
<Button
|
|
168
|
+
variant="text"
|
|
169
|
+
disabled={disabled}
|
|
170
|
+
action={{ id: 'upload.remove', label: labels.remove }}
|
|
171
|
+
onPress={() => queue.remove(entry.id)}
|
|
172
|
+
/>
|
|
173
|
+
</View>
|
|
174
|
+
</View>
|
|
175
|
+
))}
|
|
176
|
+
</View>
|
|
177
|
+
);
|
|
16
178
|
}
|
package/src/NumberField.tsx
CHANGED
|
@@ -1,13 +1,191 @@
|
|
|
1
|
-
import { useId, useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { useId, type Ref, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
TextInput,
|
|
5
|
+
View,
|
|
6
|
+
type TextInputProps,
|
|
7
|
+
type StyleProp,
|
|
8
|
+
type ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
3
10
|
import { useNumberField, type NumberFieldOptions } from '@expressive-ui/core';
|
|
4
11
|
import { Icon, T } from './primitives.js';
|
|
5
12
|
import { useExpressiveTheme } from './theme.js';
|
|
6
|
-
export type NumberFieldProps=NumberFieldOptions&{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
export type NumberFieldProps = NumberFieldOptions & {
|
|
14
|
+
ref?: Ref<TextInput>;
|
|
15
|
+
id?: string;
|
|
16
|
+
inputProps?: Omit<TextInputProps, 'value' | 'defaultValue' | 'onChangeText'>;
|
|
17
|
+
label: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
variant?: 'filled' | 'outlined';
|
|
22
|
+
controlsPosition?: 'split' | 'end';
|
|
23
|
+
controlsOrientation?: 'horizontal' | 'vertical';
|
|
24
|
+
prefix?: string;
|
|
25
|
+
suffix?: string;
|
|
26
|
+
supportingText?: string;
|
|
27
|
+
error?: string | boolean;
|
|
28
|
+
style?: StyleProp<ViewStyle>;
|
|
29
|
+
};
|
|
30
|
+
export function NumberField({
|
|
31
|
+
ref,
|
|
32
|
+
id: providedId,
|
|
33
|
+
inputProps,
|
|
34
|
+
label,
|
|
35
|
+
disabled,
|
|
36
|
+
required,
|
|
37
|
+
readOnly,
|
|
38
|
+
variant = 'outlined',
|
|
39
|
+
controlsPosition = 'split',
|
|
40
|
+
controlsOrientation = 'horizontal',
|
|
41
|
+
prefix,
|
|
42
|
+
suffix,
|
|
43
|
+
supportingText,
|
|
44
|
+
error,
|
|
45
|
+
style,
|
|
46
|
+
...options
|
|
47
|
+
}: NumberFieldProps) {
|
|
48
|
+
const { colors, locale, labels } = useExpressiveTheme(),
|
|
49
|
+
state = useNumberField({ locale, ...options }),
|
|
50
|
+
generatedId = useId(),
|
|
51
|
+
id = providedId ?? generatedId;
|
|
52
|
+
const [selection, setSelection] = useState<{ start: number; end: number } | undefined>();
|
|
53
|
+
const vertical = controlsPosition === 'end' && controlsOrientation === 'vertical';
|
|
54
|
+
const stepButton = (direction: 1 | -1) => (
|
|
55
|
+
<Pressable
|
|
56
|
+
accessibilityRole="button"
|
|
57
|
+
accessibilityLabel={`${direction === 1 ? labels.increase : labels.decrease} ${label}`}
|
|
58
|
+
disabled={
|
|
59
|
+
disabled ||
|
|
60
|
+
readOnly ||
|
|
61
|
+
(options.value !== null &&
|
|
62
|
+
(direction === 1
|
|
63
|
+
? options.value >= (options.max ?? Infinity)
|
|
64
|
+
: options.value <= (options.min ?? -Infinity)))
|
|
65
|
+
}
|
|
66
|
+
onPress={() => state.increment(direction)}
|
|
67
|
+
style={({ pressed }) => ({
|
|
68
|
+
width: vertical ? 48 : 44,
|
|
69
|
+
height: vertical ? 48 : 44,
|
|
70
|
+
borderRadius: vertical ? 0 : 22,
|
|
71
|
+
borderTopWidth: vertical && direction === -1 ? 1 : 0,
|
|
72
|
+
borderTopColor: colors.outlineVariant,
|
|
73
|
+
alignItems: 'center',
|
|
74
|
+
justifyContent: 'center',
|
|
75
|
+
backgroundColor: vertical ? 'transparent' : colors.secondaryContainer,
|
|
76
|
+
opacity: disabled || readOnly ? 0.38 : pressed ? 0.7 : 1,
|
|
77
|
+
})}
|
|
78
|
+
>
|
|
79
|
+
<Icon name={direction === 1 ? 'add' : 'remove'} />
|
|
80
|
+
</Pressable>
|
|
81
|
+
);
|
|
82
|
+
return (
|
|
83
|
+
<View style={[{ gap: 6, opacity: disabled ? 0.38 : 1 }, style]}>
|
|
84
|
+
<T variant="labelMedium" nativeID={`${id}-label`}>
|
|
85
|
+
{label}
|
|
86
|
+
{required ? ' *' : ''}
|
|
87
|
+
</T>
|
|
88
|
+
<View
|
|
89
|
+
style={{
|
|
90
|
+
flexDirection: 'row',
|
|
91
|
+
alignItems: 'center',
|
|
92
|
+
gap: 8,
|
|
93
|
+
minHeight: 56,
|
|
94
|
+
padding: 6,
|
|
95
|
+
borderWidth: variant === 'outlined' ? 1 : 0,
|
|
96
|
+
borderBottomWidth: 1,
|
|
97
|
+
borderColor: error ? colors.error : colors.outline,
|
|
98
|
+
borderRadius: 12,
|
|
99
|
+
backgroundColor: variant === 'filled' ? colors.surfaceContainerHighest : colors.surface,
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
{controlsPosition === 'split' ? stepButton(-1) : null}
|
|
103
|
+
{prefix ?? state.currencySymbol ? <T>{prefix ?? state.currencySymbol}</T> : null}
|
|
104
|
+
<TextInput
|
|
105
|
+
{...inputProps}
|
|
106
|
+
ref={ref}
|
|
107
|
+
nativeID={id}
|
|
108
|
+
accessibilityLabel={label}
|
|
109
|
+
accessibilityRole="adjustable"
|
|
110
|
+
accessibilityValue={{
|
|
111
|
+
...(options.min !== undefined ? { min: options.min } : {}),
|
|
112
|
+
...(options.max !== undefined ? { max: options.max } : {}),
|
|
113
|
+
...(options.value !== null ? { now: options.value } : {}),
|
|
114
|
+
text: state.text,
|
|
115
|
+
}}
|
|
116
|
+
accessibilityState={{ disabled: !!disabled }}
|
|
117
|
+
accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}
|
|
118
|
+
onAccessibilityAction={(event) => {
|
|
119
|
+
if (!disabled && !readOnly)
|
|
120
|
+
state.increment(event.nativeEvent.actionName === 'increment' ? 1 : -1);
|
|
121
|
+
}}
|
|
122
|
+
editable={!disabled && !readOnly}
|
|
123
|
+
value={state.text}
|
|
124
|
+
selection={options.format === 'currency' ? selection : undefined}
|
|
125
|
+
onSelectionChange={(event) => {
|
|
126
|
+
if (options.format === 'currency') setSelection(event.nativeEvent.selection);
|
|
127
|
+
}}
|
|
128
|
+
onFocus={(event) => {
|
|
129
|
+
inputProps?.onFocus?.(event);
|
|
130
|
+
if (options.format === 'currency' && (options.value === null || options.value === 0)) {
|
|
131
|
+
const point = state.text.indexOf(state.decimalSeparator);
|
|
132
|
+
setSelection({ start: 0, end: point < 0 ? state.text.length : point });
|
|
133
|
+
}
|
|
134
|
+
}}
|
|
135
|
+
onChangeText={(text) => {
|
|
136
|
+
const result = state.editText(text);
|
|
137
|
+
if (options.format === 'currency')
|
|
138
|
+
setSelection({ start: result.caret, end: result.caret });
|
|
139
|
+
}}
|
|
140
|
+
onEndEditing={(event) => {
|
|
141
|
+
state.commit();
|
|
142
|
+
inputProps?.onEndEditing?.(event);
|
|
143
|
+
}}
|
|
144
|
+
keyboardType="numbers-and-punctuation"
|
|
145
|
+
style={{
|
|
146
|
+
flex: 1,
|
|
147
|
+
minWidth: 0,
|
|
148
|
+
padding: 10,
|
|
149
|
+
textAlign: controlsPosition === 'end' ? 'auto' : 'center',
|
|
150
|
+
color: colors.onSurface,
|
|
151
|
+
fontSize: 16,
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
{suffix ? <T>{suffix}</T> : null}
|
|
155
|
+
{controlsPosition === 'end' ? (
|
|
156
|
+
<View
|
|
157
|
+
style={{
|
|
158
|
+
flexDirection: vertical ? 'column' : 'row',
|
|
159
|
+
flexShrink: 0,
|
|
160
|
+
gap: vertical ? 0 : 6,
|
|
161
|
+
borderWidth: vertical ? 1 : 0,
|
|
162
|
+
borderColor: colors.outlineVariant,
|
|
163
|
+
borderRadius: vertical ? 16 : 0,
|
|
164
|
+
overflow: 'hidden',
|
|
165
|
+
backgroundColor: vertical ? colors.secondaryContainer : undefined,
|
|
166
|
+
}}
|
|
167
|
+
>
|
|
168
|
+
{vertical ? (
|
|
169
|
+
<>
|
|
170
|
+
{stepButton(1)}
|
|
171
|
+
{stepButton(-1)}
|
|
172
|
+
</>
|
|
173
|
+
) : (
|
|
174
|
+
<>
|
|
175
|
+
{stepButton(-1)}
|
|
176
|
+
{stepButton(1)}
|
|
177
|
+
</>
|
|
178
|
+
)}
|
|
179
|
+
</View>
|
|
180
|
+
) : (
|
|
181
|
+
stepButton(1)
|
|
182
|
+
)}
|
|
183
|
+
</View>
|
|
184
|
+
{error || supportingText ? (
|
|
185
|
+
<T variant="bodySmall" color={error ? 'error' : 'onSurfaceVariant'}>
|
|
186
|
+
{typeof error === 'string' ? error : supportingText}
|
|
187
|
+
</T>
|
|
188
|
+
) : null}
|
|
189
|
+
</View>
|
|
190
|
+
);
|
|
13
191
|
}
|