@expressive-ui/native 0.2.1 → 0.4.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 +11 -1
- 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/OtpField.d.ts +34 -0
- package/dist/OtpField.d.ts.map +1 -0
- package/dist/OtpField.js +156 -0
- package/dist/OtpField.js.map +1 -0
- 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 +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -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/OtpField.tsx +353 -0
- 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 +3 -0
- package/src/theme.tsx +77 -14
package/dist/OtpField.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Animated, StyleSheet, TextInput, View, } from 'react-native';
|
|
4
|
+
import Svg, { Path } from 'react-native-svg';
|
|
5
|
+
import { otpCellRadius, otpShapePoints, resolveOtp, useOtp, } from '@expressive-ui/core';
|
|
6
|
+
import { T } from './primitives.js';
|
|
7
|
+
import { useExpressiveTheme, useSpringValue } from './theme.js';
|
|
8
|
+
const paths = Object.fromEntries(['empty', 'active', 'filled', 'verifying', 'success', 'error'].map((state) => [
|
|
9
|
+
state,
|
|
10
|
+
`M${otpShapePoints(state)
|
|
11
|
+
.map(([x, y]) => `${x} ${y}`)
|
|
12
|
+
.join('L')}Z`,
|
|
13
|
+
]));
|
|
14
|
+
function Caret({ color }) {
|
|
15
|
+
const { reduceMotion } = useExpressiveTheme();
|
|
16
|
+
const opacity = useRef(new Animated.Value(1)).current;
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (reduceMotion)
|
|
19
|
+
return;
|
|
20
|
+
const blink = Animated.loop(Animated.sequence([
|
|
21
|
+
Animated.timing(opacity, { toValue: 1, duration: 550, useNativeDriver: true }),
|
|
22
|
+
Animated.timing(opacity, { toValue: 0, duration: 1, useNativeDriver: true }),
|
|
23
|
+
Animated.timing(opacity, { toValue: 0, duration: 550, useNativeDriver: true }),
|
|
24
|
+
Animated.timing(opacity, { toValue: 1, duration: 1, useNativeDriver: true }),
|
|
25
|
+
]));
|
|
26
|
+
blink.start();
|
|
27
|
+
return () => {
|
|
28
|
+
blink.stop();
|
|
29
|
+
opacity.setValue(1);
|
|
30
|
+
};
|
|
31
|
+
}, [opacity, reduceMotion]);
|
|
32
|
+
return _jsx(Animated.View, { style: [styles.caret, { backgroundColor: color, opacity }] });
|
|
33
|
+
}
|
|
34
|
+
/** Dígito que entra crescendo com a mola (remontado a cada troca pela key). */
|
|
35
|
+
function Digit({ char, color, spec }) {
|
|
36
|
+
const [target, setTarget] = useState(0.4);
|
|
37
|
+
useEffect(() => setTarget(1), []);
|
|
38
|
+
const scale = useSpringValue(target, 'spatialFast');
|
|
39
|
+
return (_jsx(Animated.View, { style: { transform: [{ scale }] }, children: _jsx(T, { variant: spec.type, emphasized: true, maxFontSizeMultiplier: 1.3, style: [styles.digit, { color }], children: char }) }));
|
|
40
|
+
}
|
|
41
|
+
function Cell({ cell, length, variant, status, invalid, spec, }) {
|
|
42
|
+
const { colors, reduceMotion } = useExpressiveTheme();
|
|
43
|
+
const [startTarget, endTarget] = otpCellRadius(variant, cell.state, cell.index, length);
|
|
44
|
+
const start = useSpringValue(startTarget, 'spatialFast');
|
|
45
|
+
const end = useSpringValue(endTarget, 'spatialFast');
|
|
46
|
+
const lift = useRef(new Animated.Value(0)).current;
|
|
47
|
+
const verifying = status === 'verifying' && !reduceMotion;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!verifying)
|
|
50
|
+
return;
|
|
51
|
+
const delay = cell.index * 80;
|
|
52
|
+
const step = (toValue) => Animated.timing(lift, { toValue, duration: 280, useNativeDriver: false });
|
|
53
|
+
const wave = Animated.loop(Animated.sequence([
|
|
54
|
+
Animated.delay(delay),
|
|
55
|
+
step(-6),
|
|
56
|
+
step(0),
|
|
57
|
+
Animated.delay(Math.max(0, length * 80 - delay)),
|
|
58
|
+
]));
|
|
59
|
+
wave.start();
|
|
60
|
+
return () => {
|
|
61
|
+
wave.stop();
|
|
62
|
+
lift.setValue(0);
|
|
63
|
+
};
|
|
64
|
+
}, [verifying, cell.index, length, lift]);
|
|
65
|
+
const focus = colors[invalid ? spec.indicator.error : spec.indicator.color];
|
|
66
|
+
const { container, content } = spec.colors[cell.state];
|
|
67
|
+
const shapes = variant === 'shapes';
|
|
68
|
+
const active = cell.state === 'active';
|
|
69
|
+
return (_jsxs(Animated.View, { style: [
|
|
70
|
+
styles.cell,
|
|
71
|
+
{
|
|
72
|
+
transform: [{ translateY: lift }],
|
|
73
|
+
marginLeft: cell.index === 0 ? 0 : cell.groupStart ? spec.groupGap : spec.gap,
|
|
74
|
+
},
|
|
75
|
+
!shapes && {
|
|
76
|
+
backgroundColor: colors[container],
|
|
77
|
+
borderWidth: spec.indicator.width,
|
|
78
|
+
borderColor: cell.focused ? focus : 'transparent',
|
|
79
|
+
borderTopLeftRadius: start,
|
|
80
|
+
borderBottomLeftRadius: start,
|
|
81
|
+
borderTopRightRadius: end,
|
|
82
|
+
borderBottomRightRadius: end,
|
|
83
|
+
},
|
|
84
|
+
], children: [shapes ? (_jsx(Svg, { width: "100%", height: "100%", viewBox: "0 0 100 100", style: StyleSheet.absoluteFill, children: _jsx(Path, { d: paths[cell.state], fill: colors[container], stroke: active ? focus : undefined, strokeWidth: active ? 4 : 0 }) })) : null, shapes && cell.focused && !active ? (_jsx(View, { style: [styles.underline, { backgroundColor: focus }] })) : null, cell.char ? (_jsx(Digit, { char: cell.char, color: colors[content], spec: spec }, cell.char)) : cell.caret ? (_jsx(Caret, { color: focus })) : null] }));
|
|
85
|
+
}
|
|
86
|
+
/** Código de uso único num único TextInput: colar, autopreenchimento e leitores de tela funcionam. */
|
|
87
|
+
export function OtpField({ id, ref, inputProps, label, value, defaultValue, onChange, onComplete, length, groupSize, variant = 'capsule', status = 'idle', supportingText, error, required, disabled = false, readOnly = false, autoFocus, autoComplete = 'one-time-code', style, }) {
|
|
88
|
+
const { colors, mode, reduceMotion } = useExpressiveTheme();
|
|
89
|
+
const spec = resolveOtp(variant);
|
|
90
|
+
const otp = useOtp({
|
|
91
|
+
value,
|
|
92
|
+
defaultValue,
|
|
93
|
+
onChange,
|
|
94
|
+
onComplete,
|
|
95
|
+
length,
|
|
96
|
+
groupSize,
|
|
97
|
+
variant,
|
|
98
|
+
status,
|
|
99
|
+
disabled,
|
|
100
|
+
readOnly,
|
|
101
|
+
error,
|
|
102
|
+
supportingText,
|
|
103
|
+
required,
|
|
104
|
+
label,
|
|
105
|
+
id,
|
|
106
|
+
});
|
|
107
|
+
const { field } = otp;
|
|
108
|
+
const shake = useRef(new Animated.Value(0)).current;
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (!field.invalid || reduceMotion)
|
|
111
|
+
return;
|
|
112
|
+
const animation = Animated.sequence([-6, 6, -6, 6, 0].map((toValue) => Animated.timing(shake, { toValue, duration: 80, useNativeDriver: true })));
|
|
113
|
+
animation.start();
|
|
114
|
+
return () => {
|
|
115
|
+
animation.stop();
|
|
116
|
+
shake.setValue(0);
|
|
117
|
+
};
|
|
118
|
+
}, [field.invalid, reduceMotion, shake]);
|
|
119
|
+
return (_jsxs(View, { style: [
|
|
120
|
+
styles.root,
|
|
121
|
+
{
|
|
122
|
+
maxWidth: otp.length * spec.maxCellWidth + (otp.length - 1) * spec.gap,
|
|
123
|
+
opacity: disabled ? spec.disabledOpacity : 1,
|
|
124
|
+
},
|
|
125
|
+
style,
|
|
126
|
+
], children: [_jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", children: _jsx(T, { variant: "labelLarge", color: "onSurfaceVariant", children: field.labelText }) }), _jsxs(View, { style: { height: spec.height }, children: [_jsx(Animated.View, { pointerEvents: "none", accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: [styles.cells, { transform: [{ translateX: shake }] }], children: otp.cells.map((cell) => (_jsx(Cell, { cell: cell, length: otp.length, variant: variant, status: status, invalid: field.invalid, spec: spec }, cell.index))) }), _jsx(TextInput, { ...inputProps, ref: ref, nativeID: field.ids.input, accessibilityLabel: field.labelText, accessibilityHint: field.help ?? undefined, accessibilityState: { disabled, busy: status === 'verifying' }, value: otp.text, onChangeText: otp.change, editable: !otp.locked && inputProps?.editable !== false, autoFocus: autoFocus, keyboardType: "number-pad", textContentType: autoComplete === 'one-time-code' ? 'oneTimeCode' : undefined, autoComplete: autoComplete, autoCorrect: false, keyboardAppearance: mode, underlineColorAndroid: "transparent", selectionColor: "transparent", caretHidden: true, onFocus: (event) => {
|
|
127
|
+
otp.setFocused(true);
|
|
128
|
+
inputProps?.onFocus?.(event);
|
|
129
|
+
}, onBlur: (event) => {
|
|
130
|
+
otp.setFocused(false);
|
|
131
|
+
inputProps?.onBlur?.(event);
|
|
132
|
+
}, style: [StyleSheet.absoluteFill, styles.input] })] }), field.help ? (_jsx(T, { variant: spec.supporting.type, color: field.invalid
|
|
133
|
+
? spec.supporting.error
|
|
134
|
+
: status === 'success'
|
|
135
|
+
? spec.supporting.success
|
|
136
|
+
: spec.supporting.color, accessibilityLiveRegion: "polite", style: { minHeight: 16 }, children: field.help })) : null] }));
|
|
137
|
+
}
|
|
138
|
+
const styles = StyleSheet.create({
|
|
139
|
+
root: { width: '100%', gap: 8 },
|
|
140
|
+
// Códigos são lidos da esquerda para a direita também em RTL.
|
|
141
|
+
cells: { flex: 1, flexDirection: 'row', direction: 'ltr' },
|
|
142
|
+
cell: { flex: 1, minWidth: 0, alignItems: 'center', justifyContent: 'center' },
|
|
143
|
+
caret: { width: 2, height: 24, borderRadius: 1 },
|
|
144
|
+
digit: { fontVariant: ['tabular-nums'], textAlign: 'center' },
|
|
145
|
+
underline: {
|
|
146
|
+
position: 'absolute',
|
|
147
|
+
bottom: -5,
|
|
148
|
+
left: '25%',
|
|
149
|
+
right: '25%',
|
|
150
|
+
height: 3,
|
|
151
|
+
borderRadius: 2,
|
|
152
|
+
},
|
|
153
|
+
// O texto do input fica invisível; os espaços acima desenham o código.
|
|
154
|
+
input: { color: 'transparent', backgroundColor: 'transparent', padding: 0, fontSize: 16 },
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=OtpField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OtpField.js","sourceRoot":"","sources":["../src/OtpField.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,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B;IACD,uEAAuE;IACvE,KAAK,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;CAC1F,CAAC,CAAC"}
|
package/dist/Pickers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Pickers.d.ts","sourceRoot":"","sources":["../src/Pickers.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"Pickers.d.ts","sourceRoot":"","sources":["../src/Pickers.tsx"],"names":[],"mappings":"AACA,OAAO,EAQL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAaL,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AA2H7B,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG;IAChD,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,sBAAsB,GAAG;IAC1D,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC;AACF,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BAKhD;AACD,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,+BAK1D;AA6VD,MAAM,MAAM,eAAe,GAAG,iBAAiB,GAAG;IAAE,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;CAAE,CAAC;AACnF,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,+BAgThD"}
|
package/dist/Pickers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment, useEffect, useRef } from 'react';
|
|
3
|
-
import { Keyboard, Pressable, ScrollView, StyleSheet, TextInput, useWindowDimensions, View } from 'react-native';
|
|
3
|
+
import { Keyboard, Pressable, ScrollView, StyleSheet, TextInput, useWindowDimensions, View, } from 'react-native';
|
|
4
4
|
import Svg, { Circle, Line, Path, Rect } from 'react-native-svg';
|
|
5
5
|
import { resolveTimePickerLayout, calendarDays, dateInputPattern, dateKey, dialValueAt, padTime, parseDate, pickerLabels, pickerYears, useDatePickerState, useDateRangePickerState, useTimePickerState, } from '@expressive-ui/core';
|
|
6
6
|
import { Dialog } from './Dialogs.js';
|
|
@@ -8,17 +8,33 @@ import { Button } from './Button.js';
|
|
|
8
8
|
import { TextField } from './Fields.js';
|
|
9
9
|
import { Icon, T } from './primitives.js';
|
|
10
10
|
import { useExpressiveTheme } from './theme.js';
|
|
11
|
-
function PickerIcon({ name, label, onPress, disabled }) {
|
|
11
|
+
function PickerIcon({ name, label, onPress, disabled, }) {
|
|
12
12
|
const { colors } = useExpressiveTheme();
|
|
13
|
-
return _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { disabled }, disabled: disabled, onPress: onPress, style: ({ pressed }) => [
|
|
13
|
+
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { disabled }, disabled: disabled, onPress: onPress, style: ({ pressed }) => [
|
|
14
|
+
styles.icon,
|
|
15
|
+
{
|
|
16
|
+
opacity: disabled ? 0.38 : 1,
|
|
17
|
+
backgroundColor: pressed ? colors.surfaceContainerHighest : undefined,
|
|
18
|
+
},
|
|
19
|
+
], children: _jsx(Icon, { name: name, color: "onSurfaceVariant" }) }));
|
|
14
20
|
}
|
|
15
|
-
function PickerActions({ cancel, confirm, onClose, onConfirm, valid, toggle }) {
|
|
16
|
-
return _jsxs(View, { style: styles.actions, children: [toggle, _jsx(View, { style: { flex: 1 } }), _jsx(Button, { variant: "text", action: { id: 'cancel', label: cancel }, onPress: onClose }), _jsx(Button, { variant: "text", action: { id: 'confirm', label: confirm }, disabled: !valid, onPress: onConfirm })] });
|
|
21
|
+
function PickerActions({ cancel, confirm, onClose, onConfirm, valid, toggle, }) {
|
|
22
|
+
return (_jsxs(View, { style: styles.actions, children: [toggle, _jsx(View, { style: { flex: 1 } }), _jsx(Button, { variant: "text", action: { id: 'cancel', label: cancel }, onPress: onClose }), _jsx(Button, { variant: "text", action: { id: 'confirm', label: confirm }, disabled: !valid, onPress: onConfirm })] }));
|
|
17
23
|
}
|
|
18
|
-
function TimeModeToggle({ input, label, onPress }) {
|
|
24
|
+
function TimeModeToggle({ input, label, onPress, }) {
|
|
19
25
|
const { colors } = useExpressiveTheme();
|
|
20
|
-
return _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: input }, onPress: () => {
|
|
21
|
-
|
|
26
|
+
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: { selected: input }, onPress: () => {
|
|
27
|
+
if (input)
|
|
28
|
+
Keyboard.dismiss();
|
|
29
|
+
onPress();
|
|
30
|
+
}, style: ({ pressed }) => ({
|
|
31
|
+
width: 48,
|
|
32
|
+
height: 48,
|
|
33
|
+
borderRadius: 24,
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
backgroundColor: pressed ? colors.surfaceContainerHighest : undefined,
|
|
37
|
+
}), children: _jsx(Svg, { width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", stroke: colors.onSurfaceVariant, strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", accessible: false, children: input ? (_jsxs(_Fragment, { children: [_jsx(Circle, { cx: 12, cy: 12, r: 9 }), _jsx(Path, { d: "M12 7v5l3 2" })] })) : (_jsxs(_Fragment, { children: [_jsx(Rect, { x: 2, y: 5, width: 20, height: 14, rx: 2 }), _jsx(Path, { d: "M5 9h1m3 0h1m3 0h1m3 0h1M5 12h1m3 0h1m3 0h1m3 0h1M7 15h10" })] })) }) }));
|
|
22
38
|
}
|
|
23
39
|
export function DatePicker(props) {
|
|
24
40
|
const { locale: themeLocale } = useExpressiveTheme();
|
|
@@ -34,8 +50,8 @@ export function DateRangePicker(props) {
|
|
|
34
50
|
}
|
|
35
51
|
function DatePickerSurface(props) {
|
|
36
52
|
const { colors } = useExpressiveTheme();
|
|
37
|
-
const { open, onClose, title, fieldLabel, cancelLabel, confirmLabel, min, max, style, locale, state, range, startLabel, endLabel, variant = 'modal' } = props;
|
|
38
|
-
const labels = pickerLabels(locale);
|
|
53
|
+
const { open, onClose, title, fieldLabel, cancelLabel, confirmLabel, min, max, style, locale, state, range, startLabel, endLabel, variant = 'modal', } = props;
|
|
54
|
+
const labels = pickerLabels(locale, useExpressiveTheme().labels?.pickerLabels);
|
|
39
55
|
const rangeEnd = range?.range.end ?? '';
|
|
40
56
|
const shortDate = (date) => parseDate(date)?.toLocaleDateString(locale, { month: 'short', day: 'numeric' });
|
|
41
57
|
const list = useRef(null);
|
|
@@ -46,54 +62,229 @@ function DatePickerSurface(props) {
|
|
|
46
62
|
list.current?.scrollTo({ y: Math.max(0, index * 48 - 96), animated: false });
|
|
47
63
|
}, [state.view]);
|
|
48
64
|
const monthName = (m, long = false) => new Date(2024, m, 1).toLocaleDateString(locale, { month: long ? 'long' : 'short' });
|
|
49
|
-
const menu = (view, label, text) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: {
|
|
50
|
-
|
|
65
|
+
const menu = (view, label, text) => (_jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: label, accessibilityState: {
|
|
66
|
+
expanded: state.view === view,
|
|
67
|
+
disabled: state.view !== 'days' && state.view !== view,
|
|
68
|
+
}, disabled: state.view !== 'days' && state.view !== view, onPress: () => state.setView(state.view === view ? 'days' : view), style: [
|
|
69
|
+
styles.menuTrigger,
|
|
70
|
+
{ opacity: state.view !== 'days' && state.view !== view ? 0.38 : 1 },
|
|
71
|
+
], children: [_jsx(T, { variant: "labelLarge", color: state.view === view ? 'primary' : 'onSurfaceVariant', children: text }), _jsx(Icon, { name: "arrow_drop_down", size: 18 })] }));
|
|
72
|
+
const content = (_jsxs(View, { style: { gap: 16 }, children: [_jsx(T, { variant: "labelLarge", color: "onSurfaceVariant", children: title ?? (range ? labels.range : labels.date) }), _jsxs(View, { style: [
|
|
73
|
+
styles.headline,
|
|
74
|
+
{ borderBottomColor: colors.outlineVariant, borderBottomWidth: 1, paddingBottom: 12 },
|
|
75
|
+
], children: [_jsx(T, { variant: range ? 'headlineSmall' : 'headlineLarge', style: { flex: 1 }, children: range
|
|
76
|
+
? `${shortDate(range.range.start) ?? labels.start} – ${shortDate(range.range.end) ?? labels.end}`
|
|
77
|
+
: parseDate(state.draft)?.toLocaleDateString(locale, {
|
|
78
|
+
weekday: 'short',
|
|
79
|
+
month: 'short',
|
|
80
|
+
day: 'numeric',
|
|
81
|
+
}) ?? '—' }), _jsx(PickerIcon, { name: state.mode === 'calendar' ? 'edit' : 'calendar_today', label: state.mode === 'calendar' ? labels.input : labels.calendar, onPress: () => {
|
|
82
|
+
state.setMode(state.mode === 'calendar' ? 'input' : 'calendar');
|
|
83
|
+
state.setView('days');
|
|
84
|
+
} })] }), state.mode === 'input' || variant === 'docked' ? (range ? (_jsx(View, { style: { gap: 16 }, children: ['start', 'end'].map((part) => (_jsx(TextField, { variant: "outlined", label: part === 'start' ? startLabel ?? labels.start : endLabel ?? labels.end, value: part === 'start' ? range.startText : range.endText, onChange: (text) => range.editPart(text, part), keyboardType: "numbers-and-punctuation", placeholder: dateInputPattern(locale), supportingText: dateInputPattern(locale), error: (part === 'start' ? range.startText : range.endText) &&
|
|
85
|
+
(!range.available(range.range[part]) ||
|
|
86
|
+
!!(range.range.start && range.range.end && !range.valid))
|
|
87
|
+
? labels.rangeInvalid
|
|
88
|
+
: undefined }, part))) })) : (_jsx(TextField, { variant: "outlined", label: fieldLabel ?? labels.dateField, value: state.text, onChange: state.edit, keyboardType: "numbers-and-punctuation", placeholder: dateInputPattern(locale), supportingText: dateInputPattern(locale), error: state.text && !state.valid ? labels.invalid : undefined }))) : null, state.mode === 'calendar' || variant === 'docked' ? (_jsxs(View, { children: [_jsxs(View, { style: styles.navigation, children: [_jsxs(View, { style: styles.navGroup, children: [_jsx(PickerIcon, { name: "chevron_left", label: labels.previous, disabled: state.view === 'years' || !state.canNavigate(-1), onPress: () => state.navigate(-1) }), menu('months', labels.month, monthName(state.month.getMonth())), _jsx(PickerIcon, { name: "chevron_right", label: labels.next, disabled: state.view === 'years' || !state.canNavigate(1), onPress: () => state.navigate(1) })] }), _jsxs(View, { style: styles.navGroup, children: [_jsx(PickerIcon, { name: "chevron_left", label: labels.previousYear, disabled: state.view === 'months' || !state.canNavigate(-12), onPress: () => state.navigate(-12) }), menu('years', labels.year, String(state.month.getFullYear())), _jsx(PickerIcon, { name: "chevron_right", label: labels.nextYear, disabled: state.view === 'months' || !state.canNavigate(12), onPress: () => state.navigate(12) })] })] }), state.view === 'days' ? (_jsxs(View, { style: styles.calendar, children: [Array.from({ length: 7 }, (_, i) => (_jsx(View, { style: styles.day, children: _jsx(T, { variant: "labelSmall", color: "onSurfaceVariant", children: new Date(2024, 0, 7 + i).toLocaleDateString(locale, { weekday: 'narrow' }) }) }, i))), calendarDays(state.month).map((date) => {
|
|
51
89
|
const start = !!range && date === range.range.start, end = !!range && date === range.range.end;
|
|
52
90
|
const selected = range ? start || end : state.draft === date, today = dateKey(new Date()) === date, enabled = state.available(date);
|
|
53
|
-
const inRange = !!(range?.range.start &&
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
91
|
+
const inRange = !!(range?.range.start &&
|
|
92
|
+
rangeEnd &&
|
|
93
|
+
date >= range.range.start &&
|
|
94
|
+
date <= rangeEnd);
|
|
95
|
+
return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: `${parseDate(date).toLocaleDateString(locale, {
|
|
96
|
+
dateStyle: 'full',
|
|
97
|
+
})}${start ? `, ${startLabel ?? labels.start}` : ''}${end ? `, ${endLabel ?? labels.end}` : ''}`, accessibilityHint: range ? labels.rangeHelp : undefined, accessibilityState: { selected, disabled: !enabled }, disabled: !enabled, onPress: () => state.select(date), style: [
|
|
98
|
+
styles.day,
|
|
99
|
+
{
|
|
100
|
+
opacity: !enabled
|
|
101
|
+
? 0.38
|
|
102
|
+
: selected || inRange
|
|
103
|
+
? 1
|
|
104
|
+
: parseDate(date).getMonth() !== state.month.getMonth()
|
|
105
|
+
? 0.38
|
|
106
|
+
: 1,
|
|
107
|
+
},
|
|
108
|
+
], children: [inRange && !(start && end) ? (_jsx(View, { pointerEvents: "none", style: {
|
|
109
|
+
position: 'absolute',
|
|
110
|
+
top: 5,
|
|
111
|
+
bottom: 5,
|
|
112
|
+
left: start ? '50%' : 0,
|
|
113
|
+
right: end ? '50%' : 0,
|
|
114
|
+
backgroundColor: colors.secondaryContainer,
|
|
115
|
+
} })) : null, _jsx(View, { style: {
|
|
116
|
+
width: 34,
|
|
117
|
+
height: 34,
|
|
118
|
+
borderRadius: 17,
|
|
119
|
+
alignItems: 'center',
|
|
120
|
+
justifyContent: 'center',
|
|
121
|
+
backgroundColor: selected ? colors.primary : undefined,
|
|
122
|
+
borderWidth: today ? 1 : 0,
|
|
123
|
+
borderColor: colors.primary,
|
|
124
|
+
}, children: _jsx(T, { color: selected
|
|
125
|
+
? 'onPrimary'
|
|
126
|
+
: today
|
|
127
|
+
? 'primary'
|
|
128
|
+
: inRange
|
|
129
|
+
? 'onSecondaryContainer'
|
|
130
|
+
: 'onSurface', children: parseDate(date).getDate() }) })] }, date));
|
|
131
|
+
})] })) : (_jsx(ScrollView, { ref: list, style: { height: 308, borderTopWidth: 1, borderColor: colors.outlineVariant }, nestedScrollEnabled: true, children: (state.view === 'months' ? Array.from({ length: 12 }, (_, i) => i) : years).map((n) => {
|
|
132
|
+
const selected = n ===
|
|
133
|
+
(state.view === 'months' ? state.month.getMonth() : state.month.getFullYear());
|
|
57
134
|
const start = new Date(state.month);
|
|
58
135
|
start.setDate(1);
|
|
59
136
|
state.view === 'months' ? start.setMonth(n) : start.setFullYear(n, 0, 1);
|
|
60
137
|
const end = new Date(start);
|
|
61
|
-
state.view === 'months'
|
|
138
|
+
state.view === 'months'
|
|
139
|
+
? end.setMonth(end.getMonth() + 1, 0)
|
|
140
|
+
: end.setFullYear(n + 1, 0, 0);
|
|
62
141
|
const disabled = !!((min && dateKey(end) < min) || (max && dateKey(start) > max));
|
|
63
|
-
return _jsxs(Pressable, { accessibilityRole: "button", accessibilityState: { selected, disabled }, disabled: disabled, onPress: () => state.view === 'months' ? state.chooseMonth(n) : state.chooseYear(n), style: {
|
|
64
|
-
|
|
142
|
+
return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityState: { selected, disabled }, disabled: disabled, onPress: () => state.view === 'months' ? state.chooseMonth(n) : state.chooseYear(n), style: {
|
|
143
|
+
minHeight: 48,
|
|
144
|
+
paddingHorizontal: 16,
|
|
145
|
+
flexDirection: 'row',
|
|
146
|
+
alignItems: 'center',
|
|
147
|
+
gap: 16,
|
|
148
|
+
opacity: disabled ? 0.38 : 1,
|
|
149
|
+
backgroundColor: selected ? colors.secondaryContainer : undefined,
|
|
150
|
+
}, children: [_jsx(View, { style: { width: 20 }, children: selected ? (_jsx(Icon, { name: "check", size: 20, color: "onSecondaryContainer" })) : null }), _jsx(T, { color: selected ? 'onSecondaryContainer' : 'onSurface', children: state.view === 'months' ? monthName(n, true) : n })] }, n));
|
|
151
|
+
}) }))] })) : null, range ? (_jsx(T, { variant: "bodySmall", color: "onSurfaceVariant", accessibilityLiveRegion: "polite", children: range.range.start && !range.range.end
|
|
152
|
+
? labels.end
|
|
153
|
+
: range.range.end && !range.valid
|
|
154
|
+
? labels.rangeInvalid
|
|
155
|
+
: labels.rangeHelp })) : null, _jsx(PickerActions, { cancel: cancelLabel ?? labels.cancel, confirm: confirmLabel ?? labels.confirm, onClose: onClose, onConfirm: state.confirm, valid: state.valid })] }));
|
|
65
156
|
if (variant === 'docked')
|
|
66
|
-
return open ? _jsx(View, { style: [
|
|
67
|
-
|
|
157
|
+
return open ? (_jsx(View, { style: [
|
|
158
|
+
{
|
|
159
|
+
maxWidth: 360,
|
|
160
|
+
alignSelf: 'stretch',
|
|
161
|
+
borderRadius: 16,
|
|
162
|
+
padding: 16,
|
|
163
|
+
backgroundColor: colors.surfaceContainerHigh,
|
|
164
|
+
},
|
|
165
|
+
style,
|
|
166
|
+
], children: content })) : null;
|
|
167
|
+
return (_jsx(Dialog, { open: open, onClose: onClose, style: [{ maxWidth: 360, borderRadius: 28 }, style], children: content }));
|
|
68
168
|
}
|
|
69
169
|
export function TimePicker(props) {
|
|
70
170
|
const { locale, colors } = useExpressiveTheme();
|
|
71
|
-
const { open, onClose, title, cancelLabel, confirmLabel, format = '24h', layout = 'auto', style } = props;
|
|
72
|
-
const labels = pickerLabels(props.locale ?? locale), state = useTimePickerState(props);
|
|
171
|
+
const { open, onClose, title, cancelLabel, confirmLabel, format = '24h', layout = 'auto', style, } = props;
|
|
172
|
+
const labels = pickerLabels(props.locale ?? locale, useExpressiveTheme().labels?.pickerLabels), state = useTimePickerState(props);
|
|
73
173
|
const hourInput = useRef(null), minuteInput = useRef(null);
|
|
74
174
|
const { width, height } = useWindowDimensions();
|
|
75
175
|
const inputMode = state.mode === 'input';
|
|
76
176
|
const horizontal = resolveTimePickerLayout(layout, width, height, state.mode) === 'horizontal';
|
|
77
|
-
const size = horizontal
|
|
78
|
-
|
|
79
|
-
(
|
|
80
|
-
|
|
177
|
+
const size = horizontal
|
|
178
|
+
? Math.min(256, ((Math.min(560, width - 48) - 72) * 1.1) / 2.1)
|
|
179
|
+
: Math.min(256, width - 96), scale = size / 256, center = size / 2;
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (open && inputMode)
|
|
182
|
+
(state.part === 'hour' ? hourInput : minuteInput).current?.focus();
|
|
183
|
+
}, [inputMode, open]);
|
|
184
|
+
const angle = (state.part === 'minute' ? state.minute / 60 : (state.h24 % 12) / 12) * Math.PI * 2;
|
|
81
185
|
const radius = (state.h24 >= 12 && format === '24h' && state.part === 'hour' ? 65 : 100) * scale;
|
|
82
186
|
const selected = state.part === 'hour' ? state.hour : state.minute;
|
|
83
|
-
const periodSelector = format === '12h' ? _jsx(View, { style: {
|
|
84
|
-
|
|
85
|
-
|
|
187
|
+
const periodSelector = format === '12h' ? (_jsx(View, { style: {
|
|
188
|
+
borderWidth: 1,
|
|
189
|
+
borderColor: colors.outline,
|
|
190
|
+
borderRadius: 8,
|
|
191
|
+
overflow: 'hidden',
|
|
192
|
+
flexDirection: horizontal ? 'row' : 'column',
|
|
193
|
+
width: horizontal ? '100%' : 52,
|
|
194
|
+
}, children: ['AM', 'PM'].map((period, i) => (_jsx(Pressable, { accessibilityRole: "button", accessibilityState: { selected: state.period === i }, onPress: () => state.setPeriod(i), style: {
|
|
195
|
+
minWidth: 46,
|
|
196
|
+
flex: horizontal ? 1 : undefined,
|
|
197
|
+
height: 39,
|
|
198
|
+
alignItems: 'center',
|
|
199
|
+
justifyContent: 'center',
|
|
200
|
+
borderTopWidth: horizontal ? 0 : i,
|
|
201
|
+
borderLeftWidth: horizontal ? i : 0,
|
|
202
|
+
borderColor: colors.outline,
|
|
203
|
+
backgroundColor: state.period === i ? colors.tertiaryContainer : undefined,
|
|
204
|
+
}, children: _jsx(T, { color: state.period === i ? 'onTertiaryContainer' : 'onSurfaceVariant', children: period }) }, period))) })) : null;
|
|
205
|
+
return (_jsx(Dialog, { open: open, onClose: onClose, style: [{ maxWidth: horizontal ? 560 : 360, borderRadius: 28 }, style], children: _jsxs(View, { style: { gap: 24 }, children: [_jsx(T, { variant: "labelLarge", color: "onSurfaceVariant", children: title ?? (inputMode ? labels.enterTime : labels.time) }), _jsxs(View, { style: { flexDirection: horizontal ? 'row' : 'column', gap: 24, alignItems: 'center' }, children: [_jsxs(View, { style: { flex: horizontal ? 1 : undefined, width: horizontal ? undefined : '100%' }, children: [_jsxs(View, { style: {
|
|
206
|
+
gap: 16,
|
|
207
|
+
width: '100%',
|
|
208
|
+
maxWidth: format === '12h' && !horizontal ? 284 : 256,
|
|
209
|
+
alignSelf: 'center',
|
|
210
|
+
}, children: [_jsxs(View, { style: [styles.time, { gap: format === '12h' ? 8 : 4 }], children: [['hour', 'minute'].map((part, i) => (_jsxs(Fragment, { children: [i ? (_jsx(T, { accessible: false, style: {
|
|
211
|
+
width: 16,
|
|
212
|
+
height: 80,
|
|
213
|
+
fontSize: 56,
|
|
214
|
+
lineHeight: 80,
|
|
215
|
+
textAlign: 'center',
|
|
216
|
+
}, children: ":" })) : null, _jsxs(View, { style: { gap: 7, flex: 1, minWidth: 0 }, children: [inputMode ? (_jsx(TextInput, { ref: part === 'hour' ? hourInput : minuteInput, accessibilityLabel: labels[part], keyboardType: "number-pad", selectTextOnFocus: true, maxLength: 2, value: part === 'hour' ? state.hourText : state.minuteText, onFocus: () => state.setPart(part), onBlur: () => state.normalize(part), onChangeText: (text) => state.edit(text, part), onSubmitEditing: () => part === 'hour' ? minuteInput.current?.focus() : state.confirm(), style: {
|
|
217
|
+
width: '100%',
|
|
218
|
+
height: 80,
|
|
219
|
+
fontSize: 56,
|
|
220
|
+
textAlign: 'center',
|
|
221
|
+
borderRadius: 8,
|
|
222
|
+
borderWidth: 2,
|
|
223
|
+
borderColor: !(part === 'hour' ? state.hourValid : state.minuteValid)
|
|
224
|
+
? colors.error
|
|
225
|
+
: state.part === part
|
|
226
|
+
? colors.primary
|
|
227
|
+
: 'transparent',
|
|
228
|
+
color: state.part === part ? colors.onPrimaryContainer : colors.onSurface,
|
|
229
|
+
backgroundColor: state.part === part
|
|
230
|
+
? colors.primaryContainer
|
|
231
|
+
: colors.surfaceContainerHighest,
|
|
232
|
+
} })) : (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: labels[part], accessibilityState: { selected: state.part === part }, onPress: () => state.setPart(part), onLongPress: () => {
|
|
233
|
+
state.setPart(part);
|
|
234
|
+
state.setMode('input');
|
|
235
|
+
}, style: {
|
|
236
|
+
width: '100%',
|
|
237
|
+
height: 80,
|
|
238
|
+
justifyContent: 'center',
|
|
239
|
+
alignItems: 'center',
|
|
240
|
+
borderRadius: 8,
|
|
241
|
+
backgroundColor: state.part === part
|
|
242
|
+
? colors.primaryContainer
|
|
243
|
+
: colors.surfaceContainerHighest,
|
|
244
|
+
}, children: _jsx(T, { style: { fontSize: 56, lineHeight: 68 }, color: state.part === part ? 'onPrimaryContainer' : 'onSurface', children: padTime(part === 'hour' ? state.hour : state.minute) }) })), inputMode ? (_jsx(T, { variant: "labelSmall", color: "onSurfaceVariant", children: labels[part] })) : null] })] }, part))), !horizontal ? periodSelector : null] }), horizontal ? periodSelector : null] }), inputMode && !state.valid ? (_jsx(T, { color: "error", accessibilityRole: "alert", children: labels.invalid })) : null] }), !inputMode ? (_jsxs(View, { accessibilityLabel: labels[state.part], style: {
|
|
245
|
+
width: size,
|
|
246
|
+
height: size,
|
|
247
|
+
alignSelf: 'center',
|
|
248
|
+
borderRadius: center,
|
|
249
|
+
backgroundColor: colors.surfaceContainerHighest,
|
|
250
|
+
}, children: [_jsx(View, { style: StyleSheet.absoluteFill, onStartShouldSetResponder: () => true, onMoveShouldSetResponder: () => true, onResponderGrant: (event) => state.select(dialValueAt(event.nativeEvent.locationX, event.nativeEvent.locationY, size, state.part, format)), onResponderMove: (event) => state.select(dialValueAt(event.nativeEvent.locationX, event.nativeEvent.locationY, size, state.part, format)), onResponderRelease: () => {
|
|
251
|
+
if (state.part === 'hour')
|
|
252
|
+
state.setPart('minute');
|
|
253
|
+
} }), _jsxs(Svg, { width: size, height: size, style: StyleSheet.absoluteFill, pointerEvents: "none", children: [_jsx(Line, { x1: center, y1: center, x2: center + Math.sin(angle) * radius, y2: center - Math.cos(angle) * radius, stroke: colors.primary, strokeWidth: 2 }), _jsx(Circle, { cx: center, cy: center, r: 4, fill: colors.primary }), _jsx(Circle, { cx: center + Math.sin(angle) * radius, cy: center - Math.cos(angle) * radius, r: 20 * scale, fill: colors.primary })] }), Array.from({ length: state.part === 'hour' && format === '24h' ? 24 : 12 }, (_, i) => {
|
|
86
254
|
const n = state.part === 'minute' ? i * 5 : format === '12h' ? i || 12 : i;
|
|
87
|
-
const a = i % 12 / 12 * Math.PI * 2, r = (i >= 12 ? 65 : 100) * scale;
|
|
88
|
-
return _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: `${labels[state.part]} ${n}`, accessibilityState: { selected: selected === n }, onPress: () => {
|
|
89
|
-
state.
|
|
90
|
-
|
|
255
|
+
const a = ((i % 12) / 12) * Math.PI * 2, r = (i >= 12 ? 65 : 100) * scale;
|
|
256
|
+
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: `${labels[state.part]} ${n}`, accessibilityState: { selected: selected === n }, onPress: () => {
|
|
257
|
+
state.select(n);
|
|
258
|
+
if (state.part === 'hour')
|
|
259
|
+
state.setPart('minute');
|
|
260
|
+
}, style: {
|
|
261
|
+
position: 'absolute',
|
|
262
|
+
left: center - 20 * scale + Math.sin(a) * r,
|
|
263
|
+
top: center - 20 * scale - Math.cos(a) * r,
|
|
264
|
+
width: 40 * scale,
|
|
265
|
+
height: 40 * scale,
|
|
266
|
+
borderRadius: 20,
|
|
267
|
+
alignItems: 'center',
|
|
268
|
+
justifyContent: 'center',
|
|
269
|
+
}, children: _jsx(T, { variant: i >= 12 ? 'labelSmall' : 'bodyLarge', color: selected === n ? 'onPrimary' : 'onSurface', children: state.part === 'minute' || (format === '24h' && n === 0) ? padTime(n) : n }) }, n));
|
|
270
|
+
})] })) : null] }), _jsx(PickerActions, { cancel: cancelLabel ?? labels.cancel, confirm: confirmLabel ?? labels.confirm, onClose: onClose, onConfirm: state.confirm, valid: state.valid, toggle: _jsx(TimeModeToggle, { input: inputMode, label: inputMode ? labels.dial : labels.input, onPress: state.toggle }) })] }) }));
|
|
91
271
|
}
|
|
92
272
|
const styles = StyleSheet.create({
|
|
93
|
-
icon: {
|
|
273
|
+
icon: {
|
|
274
|
+
width: 28,
|
|
275
|
+
minHeight: 48,
|
|
276
|
+
borderRadius: 24,
|
|
277
|
+
alignItems: 'center',
|
|
278
|
+
justifyContent: 'center',
|
|
279
|
+
},
|
|
94
280
|
actions: { flexDirection: 'row', alignItems: 'center', gap: 8 },
|
|
95
281
|
headline: { flexDirection: 'row', alignItems: 'center', gap: 8 },
|
|
96
|
-
navigation: {
|
|
282
|
+
navigation: {
|
|
283
|
+
flexDirection: 'row',
|
|
284
|
+
alignItems: 'center',
|
|
285
|
+
justifyContent: 'space-between',
|
|
286
|
+
minHeight: 48,
|
|
287
|
+
},
|
|
97
288
|
navGroup: { flexDirection: 'row', alignItems: 'center', flexShrink: 1 },
|
|
98
289
|
menuTrigger: { flexDirection: 'row', alignItems: 'center', gap: 2, minHeight: 48 },
|
|
99
290
|
calendar: { flexDirection: 'row', flexWrap: 'wrap' },
|