@expressive-ui/native 0.2.1 → 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.
Files changed (48) hide show
  1. package/README.md +10 -0
  2. package/dist/Feedback.d.ts +3 -3
  3. package/dist/Feedback.d.ts.map +1 -1
  4. package/dist/Feedback.js +73 -14
  5. package/dist/Feedback.js.map +1 -1
  6. package/dist/Fields.d.ts +10 -6
  7. package/dist/Fields.d.ts.map +1 -1
  8. package/dist/Fields.js +125 -29
  9. package/dist/Fields.js.map +1 -1
  10. package/dist/FileUpload.d.ts.map +1 -1
  11. package/dist/FileUpload.js +61 -19
  12. package/dist/FileUpload.js.map +1 -1
  13. package/dist/NumberField.d.ts +6 -2
  14. package/dist/NumberField.d.ts.map +1 -1
  15. package/dist/NumberField.js +71 -11
  16. package/dist/NumberField.js.map +1 -1
  17. package/dist/Pickers.d.ts.map +1 -1
  18. package/dist/Pickers.js +227 -36
  19. package/dist/Pickers.js.map +1 -1
  20. package/dist/RenderUI.d.ts +3 -0
  21. package/dist/RenderUI.d.ts.map +1 -0
  22. package/dist/RenderUI.js +45 -0
  23. package/dist/RenderUI.js.map +1 -0
  24. package/dist/Search.js +1 -1
  25. package/dist/Search.js.map +1 -1
  26. package/dist/Select.d.ts +5 -1
  27. package/dist/Select.d.ts.map +1 -1
  28. package/dist/Select.js +52 -10
  29. package/dist/Select.js.map +1 -1
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +1 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/theme.d.ts +3 -1
  35. package/dist/theme.d.ts.map +1 -1
  36. package/dist/theme.js +36 -11
  37. package/dist/theme.js.map +1 -1
  38. package/package.json +4 -4
  39. package/src/Feedback.tsx +211 -16
  40. package/src/Fields.tsx +341 -58
  41. package/src/FileUpload.tsx +169 -7
  42. package/src/NumberField.tsx +187 -9
  43. package/src/Pickers.tsx +783 -86
  44. package/src/RenderUI.tsx +47 -0
  45. package/src/Search.tsx +1 -1
  46. package/src/Select.tsx +209 -27
  47. package/src/index.ts +2 -0
  48. package/src/theme.tsx +77 -14
package/src/Pickers.tsx CHANGED
@@ -1,9 +1,32 @@
1
1
  import { Fragment, useEffect, useRef, type ReactNode } from 'react';
2
- import { Keyboard, Pressable, ScrollView, StyleSheet, TextInput, useWindowDimensions, View, type StyleProp, type ViewStyle } from 'react-native';
2
+ import {
3
+ Keyboard,
4
+ Pressable,
5
+ ScrollView,
6
+ StyleSheet,
7
+ TextInput,
8
+ useWindowDimensions,
9
+ View,
10
+ type StyleProp,
11
+ type ViewStyle,
12
+ } from 'react-native';
3
13
  import Svg, { Circle, Line, Path, Rect } from 'react-native-svg';
4
14
  import {
5
- resolveTimePickerLayout, calendarDays, dateInputPattern, dateKey, dialValueAt, padTime, parseDate, pickerLabels, pickerYears,
6
- useDatePickerState, useDateRangePickerState, useTimePickerState, type DatePickerOptions, type DateRangePickerOptions, type TimePickerOptions,
15
+ resolveTimePickerLayout,
16
+ calendarDays,
17
+ dateInputPattern,
18
+ dateKey,
19
+ dialValueAt,
20
+ padTime,
21
+ parseDate,
22
+ pickerLabels,
23
+ pickerYears,
24
+ useDatePickerState,
25
+ useDateRangePickerState,
26
+ useTimePickerState,
27
+ type DatePickerOptions,
28
+ type DateRangePickerOptions,
29
+ type TimePickerOptions,
7
30
  } from '@expressive-ui/core';
8
31
  import { Dialog } from './Dialogs.js';
9
32
  import { Button } from './Button.js';
@@ -11,25 +34,130 @@ import { TextField } from './Fields.js';
11
34
  import { Icon, T } from './primitives.js';
12
35
  import { useExpressiveTheme } from './theme.js';
13
36
 
14
- function PickerIcon({ name, label, onPress, disabled }: { name: string; label: string; onPress: () => void; disabled?: boolean }) {
37
+ function PickerIcon({
38
+ name,
39
+ label,
40
+ onPress,
41
+ disabled,
42
+ }: {
43
+ name: string;
44
+ label: string;
45
+ onPress: () => void;
46
+ disabled?: boolean;
47
+ }) {
15
48
  const { colors } = useExpressiveTheme();
16
- return <Pressable accessibilityRole="button" accessibilityLabel={label} accessibilityState={{ disabled }} disabled={disabled} onPress={onPress} style={({ pressed }) => [styles.icon, { opacity: disabled ? .38 : 1, backgroundColor: pressed ? colors.surfaceContainerHighest : undefined }]}><Icon name={name} color="onSurfaceVariant" /></Pressable>;
49
+ return (
50
+ <Pressable
51
+ accessibilityRole="button"
52
+ accessibilityLabel={label}
53
+ accessibilityState={{ disabled }}
54
+ disabled={disabled}
55
+ onPress={onPress}
56
+ style={({ pressed }) => [
57
+ styles.icon,
58
+ {
59
+ opacity: disabled ? 0.38 : 1,
60
+ backgroundColor: pressed ? colors.surfaceContainerHighest : undefined,
61
+ },
62
+ ]}
63
+ >
64
+ <Icon name={name} color="onSurfaceVariant" />
65
+ </Pressable>
66
+ );
17
67
  }
18
- function PickerActions({ cancel, confirm, onClose, onConfirm, valid, toggle }: { cancel: string; confirm: string; onClose: () => void; onConfirm: () => void; valid: boolean; toggle?: ReactNode }) {
19
- return <View style={styles.actions}>{toggle}<View style={{ flex: 1 }} /><Button variant="text" action={{ id: 'cancel', label: cancel }} onPress={onClose} /><Button variant="text" action={{ id: 'confirm', label: confirm }} disabled={!valid} onPress={onConfirm} /></View>;
68
+ function PickerActions({
69
+ cancel,
70
+ confirm,
71
+ onClose,
72
+ onConfirm,
73
+ valid,
74
+ toggle,
75
+ }: {
76
+ cancel: string;
77
+ confirm: string;
78
+ onClose: () => void;
79
+ onConfirm: () => void;
80
+ valid: boolean;
81
+ toggle?: ReactNode;
82
+ }) {
83
+ return (
84
+ <View style={styles.actions}>
85
+ {toggle}
86
+ <View style={{ flex: 1 }} />
87
+ <Button variant="text" action={{ id: 'cancel', label: cancel }} onPress={onClose} />
88
+ <Button
89
+ variant="text"
90
+ action={{ id: 'confirm', label: confirm }}
91
+ disabled={!valid}
92
+ onPress={onConfirm}
93
+ />
94
+ </View>
95
+ );
20
96
  }
21
97
 
22
- function TimeModeToggle({ input, label, onPress }: { input: boolean; label: string; onPress: () => void }) {
98
+ function TimeModeToggle({
99
+ input,
100
+ label,
101
+ onPress,
102
+ }: {
103
+ input: boolean;
104
+ label: string;
105
+ onPress: () => void;
106
+ }) {
23
107
  const { colors } = useExpressiveTheme();
24
- return <Pressable accessibilityRole="button" accessibilityLabel={label} accessibilityState={{ selected: input }} onPress={() => { if (input) Keyboard.dismiss(); onPress(); }} style={({ pressed }) => ({ width: 48, height: 48, borderRadius: 24, alignItems: 'center', justifyContent: 'center', backgroundColor: pressed ? colors.surfaceContainerHighest : undefined })}>
25
- <Svg width={24} height={24} viewBox="0 0 24 24" fill="none" stroke={colors.onSurfaceVariant} strokeWidth={1.8} strokeLinecap="round" strokeLinejoin="round" accessible={false}>
26
- {input ? <><Circle cx={12} cy={12} r={9} /><Path d="M12 7v5l3 2" /></> : <><Rect x={2} y={5} width={20} height={14} rx={2} /><Path d="M5 9h1m3 0h1m3 0h1m3 0h1M5 12h1m3 0h1m3 0h1m3 0h1M7 15h10" /></>}
27
- </Svg>
28
- </Pressable>;
108
+ return (
109
+ <Pressable
110
+ accessibilityRole="button"
111
+ accessibilityLabel={label}
112
+ accessibilityState={{ selected: input }}
113
+ onPress={() => {
114
+ if (input) Keyboard.dismiss();
115
+ onPress();
116
+ }}
117
+ style={({ pressed }) => ({
118
+ width: 48,
119
+ height: 48,
120
+ borderRadius: 24,
121
+ alignItems: 'center',
122
+ justifyContent: 'center',
123
+ backgroundColor: pressed ? colors.surfaceContainerHighest : undefined,
124
+ })}
125
+ >
126
+ <Svg
127
+ width={24}
128
+ height={24}
129
+ viewBox="0 0 24 24"
130
+ fill="none"
131
+ stroke={colors.onSurfaceVariant}
132
+ strokeWidth={1.8}
133
+ strokeLinecap="round"
134
+ strokeLinejoin="round"
135
+ accessible={false}
136
+ >
137
+ {input ? (
138
+ <>
139
+ <Circle cx={12} cy={12} r={9} />
140
+ <Path d="M12 7v5l3 2" />
141
+ </>
142
+ ) : (
143
+ <>
144
+ <Rect x={2} y={5} width={20} height={14} rx={2} />
145
+ <Path d="M5 9h1m3 0h1m3 0h1m3 0h1M5 12h1m3 0h1m3 0h1m3 0h1M7 15h10" />
146
+ </>
147
+ )}
148
+ </Svg>
149
+ </Pressable>
150
+ );
29
151
  }
30
152
 
31
- export type DatePickerProps = DatePickerOptions & { variant?: 'modal' | 'docked'; style?: StyleProp<ViewStyle> };
32
- export type DateRangePickerProps = DateRangePickerOptions & { variant?: 'modal' | 'docked'; style?: StyleProp<ViewStyle> };
153
+ export type DatePickerProps = DatePickerOptions & {
154
+ variant?: 'modal' | 'docked';
155
+ style?: StyleProp<ViewStyle>;
156
+ };
157
+ export type DateRangePickerProps = DateRangePickerOptions & {
158
+ variant?: 'modal' | 'docked';
159
+ style?: StyleProp<ViewStyle>;
160
+ };
33
161
  export type { DateRange } from '@expressive-ui/core';
34
162
  export function DatePicker(props: DatePickerProps) {
35
163
  const { locale: themeLocale } = useExpressiveTheme();
@@ -52,98 +180,667 @@ type DatePickerSurfaceProps = Omit<DatePickerProps, 'value' | 'onConfirm'> & {
52
180
  };
53
181
  function DatePickerSurface(props: DatePickerSurfaceProps) {
54
182
  const { colors } = useExpressiveTheme();
55
- const { open, onClose, title, fieldLabel, cancelLabel, confirmLabel, min, max, style, locale, state, range, startLabel, endLabel, variant = 'modal' } = props;
56
- const labels = pickerLabels(locale);
183
+ const {
184
+ open,
185
+ onClose,
186
+ title,
187
+ fieldLabel,
188
+ cancelLabel,
189
+ confirmLabel,
190
+ min,
191
+ max,
192
+ style,
193
+ locale,
194
+ state,
195
+ range,
196
+ startLabel,
197
+ endLabel,
198
+ variant = 'modal',
199
+ } = props;
200
+ const labels = pickerLabels(locale, useExpressiveTheme().labels?.pickerLabels);
57
201
  const rangeEnd = range?.range.end ?? '';
58
- const shortDate = (date: string) => parseDate(date)?.toLocaleDateString(locale, { month: 'short', day: 'numeric' });
202
+ const shortDate = (date: string) =>
203
+ parseDate(date)?.toLocaleDateString(locale, { month: 'short', day: 'numeric' });
59
204
  const list = useRef<ScrollView>(null);
60
205
  const years = pickerYears(state.month, min, max);
61
206
  useEffect(() => {
62
- const index = state.view === 'months' ? state.month.getMonth() : years.indexOf(state.month.getFullYear());
63
- if (state.view !== 'days') list.current?.scrollTo({ y: Math.max(0, index * 48 - 96), animated: false });
207
+ const index =
208
+ state.view === 'months' ? state.month.getMonth() : years.indexOf(state.month.getFullYear());
209
+ if (state.view !== 'days')
210
+ list.current?.scrollTo({ y: Math.max(0, index * 48 - 96), animated: false });
64
211
  }, [state.view]);
65
- const monthName = (m: number, long = false) => new Date(2024, m, 1).toLocaleDateString(locale, { month: long ? 'long' : 'short' });
66
- const menu = (view: 'months' | 'years', label: string, text: string) => <Pressable accessibilityRole="button" accessibilityLabel={label} accessibilityState={{ expanded: state.view === view, disabled: state.view !== 'days' && state.view !== view }} disabled={state.view !== 'days' && state.view !== view} onPress={() => state.setView(state.view === view ? 'days' : view)} style={[styles.menuTrigger, { opacity: state.view !== 'days' && state.view !== view ? .38 : 1 }]}><T variant="labelLarge" color={state.view === view ? 'primary' : 'onSurfaceVariant'}>{text}</T><Icon name="arrow_drop_down" size={18} /></Pressable>;
67
- const content = <View style={{ gap: 16 }}>
68
- <T variant="labelLarge" color="onSurfaceVariant">{title ?? (range ? labels.range : labels.date)}</T>
69
- <View style={[styles.headline, { borderBottomColor: colors.outlineVariant, borderBottomWidth: 1, paddingBottom: 12 }]}><T variant={range ? "headlineSmall" : "headlineLarge"} style={{ flex: 1 }}>{range ? `${shortDate(range.range.start) ?? labels.start} – ${shortDate(range.range.end) ?? labels.end}` : parseDate(state.draft)?.toLocaleDateString(locale, { weekday: 'short', month: 'short', day: 'numeric' }) ?? '—'}</T><PickerIcon name={state.mode === 'calendar' ? 'edit' : 'calendar_today'} label={state.mode === 'calendar' ? labels.input : labels.calendar} onPress={() => { state.setMode(state.mode === 'calendar' ? 'input' : 'calendar'); state.setView('days'); }} /></View>
70
- {state.mode === 'input' || variant === 'docked' ? range ? <View style={{ gap: 16 }}>{(['start', 'end'] as const).map(part => <TextField key={part} 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) && (!range.available(range.range[part]) || !!(range.range.start && range.range.end && !range.valid)) ? labels.rangeInvalid : undefined} />)}</View> : <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}
71
- {state.mode === 'calendar' || variant === 'docked' ? <View>
72
- <View style={styles.navigation}>
73
- <View style={styles.navGroup}><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()))}<PickerIcon name="chevron_right" label={labels.next} disabled={state.view === 'years' || !state.canNavigate(1)} onPress={() => state.navigate(1)} /></View>
74
- <View style={styles.navGroup}><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()))}<PickerIcon name="chevron_right" label={labels.nextYear} disabled={state.view === 'months' || !state.canNavigate(12)} onPress={() => state.navigate(12)} /></View>
212
+ const monthName = (m: number, long = false) =>
213
+ new Date(2024, m, 1).toLocaleDateString(locale, { month: long ? 'long' : 'short' });
214
+ const menu = (view: 'months' | 'years', label: string, text: string) => (
215
+ <Pressable
216
+ accessibilityRole="button"
217
+ accessibilityLabel={label}
218
+ accessibilityState={{
219
+ expanded: state.view === view,
220
+ disabled: state.view !== 'days' && state.view !== view,
221
+ }}
222
+ disabled={state.view !== 'days' && state.view !== view}
223
+ onPress={() => state.setView(state.view === view ? 'days' : view)}
224
+ style={[
225
+ styles.menuTrigger,
226
+ { opacity: state.view !== 'days' && state.view !== view ? 0.38 : 1 },
227
+ ]}
228
+ >
229
+ <T variant="labelLarge" color={state.view === view ? 'primary' : 'onSurfaceVariant'}>
230
+ {text}
231
+ </T>
232
+ <Icon name="arrow_drop_down" size={18} />
233
+ </Pressable>
234
+ );
235
+ const content = (
236
+ <View style={{ gap: 16 }}>
237
+ <T variant="labelLarge" color="onSurfaceVariant">
238
+ {title ?? (range ? labels.range : labels.date)}
239
+ </T>
240
+ <View
241
+ style={[
242
+ styles.headline,
243
+ { borderBottomColor: colors.outlineVariant, borderBottomWidth: 1, paddingBottom: 12 },
244
+ ]}
245
+ >
246
+ <T variant={range ? 'headlineSmall' : 'headlineLarge'} style={{ flex: 1 }}>
247
+ {range
248
+ ? `${shortDate(range.range.start) ?? labels.start} – ${
249
+ shortDate(range.range.end) ?? labels.end
250
+ }`
251
+ : parseDate(state.draft)?.toLocaleDateString(locale, {
252
+ weekday: 'short',
253
+ month: 'short',
254
+ day: 'numeric',
255
+ }) ?? '—'}
256
+ </T>
257
+ <PickerIcon
258
+ name={state.mode === 'calendar' ? 'edit' : 'calendar_today'}
259
+ label={state.mode === 'calendar' ? labels.input : labels.calendar}
260
+ onPress={() => {
261
+ state.setMode(state.mode === 'calendar' ? 'input' : 'calendar');
262
+ state.setView('days');
263
+ }}
264
+ />
265
+ </View>
266
+ {state.mode === 'input' || variant === 'docked' ? (
267
+ range ? (
268
+ <View style={{ gap: 16 }}>
269
+ {(['start', 'end'] as const).map((part) => (
270
+ <TextField
271
+ key={part}
272
+ variant="outlined"
273
+ label={part === 'start' ? startLabel ?? labels.start : endLabel ?? labels.end}
274
+ value={part === 'start' ? range.startText : range.endText}
275
+ onChange={(text) => range.editPart(text, part)}
276
+ keyboardType="numbers-and-punctuation"
277
+ placeholder={dateInputPattern(locale)}
278
+ supportingText={dateInputPattern(locale)}
279
+ error={
280
+ (part === 'start' ? range.startText : range.endText) &&
281
+ (!range.available(range.range[part]) ||
282
+ !!(range.range.start && range.range.end && !range.valid))
283
+ ? labels.rangeInvalid
284
+ : undefined
285
+ }
286
+ />
287
+ ))}
288
+ </View>
289
+ ) : (
290
+ <TextField
291
+ variant="outlined"
292
+ label={fieldLabel ?? labels.dateField}
293
+ value={state.text}
294
+ onChange={state.edit}
295
+ keyboardType="numbers-and-punctuation"
296
+ placeholder={dateInputPattern(locale)}
297
+ supportingText={dateInputPattern(locale)}
298
+ error={state.text && !state.valid ? labels.invalid : undefined}
299
+ />
300
+ )
301
+ ) : null}
302
+ {state.mode === 'calendar' || variant === 'docked' ? (
303
+ <View>
304
+ <View style={styles.navigation}>
305
+ <View style={styles.navGroup}>
306
+ <PickerIcon
307
+ name="chevron_left"
308
+ label={labels.previous}
309
+ disabled={state.view === 'years' || !state.canNavigate(-1)}
310
+ onPress={() => state.navigate(-1)}
311
+ />
312
+ {menu('months', labels.month, monthName(state.month.getMonth()))}
313
+ <PickerIcon
314
+ name="chevron_right"
315
+ label={labels.next}
316
+ disabled={state.view === 'years' || !state.canNavigate(1)}
317
+ onPress={() => state.navigate(1)}
318
+ />
319
+ </View>
320
+ <View style={styles.navGroup}>
321
+ <PickerIcon
322
+ name="chevron_left"
323
+ label={labels.previousYear}
324
+ disabled={state.view === 'months' || !state.canNavigate(-12)}
325
+ onPress={() => state.navigate(-12)}
326
+ />
327
+ {menu('years', labels.year, String(state.month.getFullYear()))}
328
+ <PickerIcon
329
+ name="chevron_right"
330
+ label={labels.nextYear}
331
+ disabled={state.view === 'months' || !state.canNavigate(12)}
332
+ onPress={() => state.navigate(12)}
333
+ />
334
+ </View>
335
+ </View>
336
+ {state.view === 'days' ? (
337
+ <View style={styles.calendar}>
338
+ {Array.from({ length: 7 }, (_, i) => (
339
+ <View key={i} style={styles.day}>
340
+ <T variant="labelSmall" color="onSurfaceVariant">
341
+ {new Date(2024, 0, 7 + i).toLocaleDateString(locale, { weekday: 'narrow' })}
342
+ </T>
343
+ </View>
344
+ ))}
345
+ {calendarDays(state.month).map((date) => {
346
+ const start = !!range && date === range.range.start,
347
+ end = !!range && date === range.range.end;
348
+ const selected = range ? start || end : state.draft === date,
349
+ today = dateKey(new Date()) === date,
350
+ enabled = state.available(date);
351
+ const inRange = !!(
352
+ range?.range.start &&
353
+ rangeEnd &&
354
+ date >= range.range.start &&
355
+ date <= rangeEnd
356
+ );
357
+ return (
358
+ <Pressable
359
+ key={date}
360
+ accessibilityRole="button"
361
+ accessibilityLabel={`${parseDate(date)!.toLocaleDateString(locale, {
362
+ dateStyle: 'full',
363
+ })}${start ? `, ${startLabel ?? labels.start}` : ''}${
364
+ end ? `, ${endLabel ?? labels.end}` : ''
365
+ }`}
366
+ accessibilityHint={range ? labels.rangeHelp : undefined}
367
+ accessibilityState={{ selected, disabled: !enabled }}
368
+ disabled={!enabled}
369
+ onPress={() => state.select(date)}
370
+ style={[
371
+ styles.day,
372
+ {
373
+ opacity: !enabled
374
+ ? 0.38
375
+ : selected || inRange
376
+ ? 1
377
+ : parseDate(date)!.getMonth() !== state.month.getMonth()
378
+ ? 0.38
379
+ : 1,
380
+ },
381
+ ]}
382
+ >
383
+ {inRange && !(start && end) ? (
384
+ <View
385
+ pointerEvents="none"
386
+ style={{
387
+ position: 'absolute',
388
+ top: 5,
389
+ bottom: 5,
390
+ left: start ? '50%' : 0,
391
+ right: end ? '50%' : 0,
392
+ backgroundColor: colors.secondaryContainer,
393
+ }}
394
+ />
395
+ ) : null}
396
+ <View
397
+ style={{
398
+ width: 34,
399
+ height: 34,
400
+ borderRadius: 17,
401
+ alignItems: 'center',
402
+ justifyContent: 'center',
403
+ backgroundColor: selected ? colors.primary : undefined,
404
+ borderWidth: today ? 1 : 0,
405
+ borderColor: colors.primary,
406
+ }}
407
+ >
408
+ <T
409
+ color={
410
+ selected
411
+ ? 'onPrimary'
412
+ : today
413
+ ? 'primary'
414
+ : inRange
415
+ ? 'onSecondaryContainer'
416
+ : 'onSurface'
417
+ }
418
+ >
419
+ {parseDate(date)!.getDate()}
420
+ </T>
421
+ </View>
422
+ </Pressable>
423
+ );
424
+ })}
425
+ </View>
426
+ ) : (
427
+ <ScrollView
428
+ ref={list}
429
+ style={{ height: 308, borderTopWidth: 1, borderColor: colors.outlineVariant }}
430
+ nestedScrollEnabled
431
+ >
432
+ {(state.view === 'months' ? Array.from({ length: 12 }, (_, i) => i) : years).map(
433
+ (n) => {
434
+ const selected =
435
+ n ===
436
+ (state.view === 'months' ? state.month.getMonth() : state.month.getFullYear());
437
+ const start = new Date(state.month);
438
+ start.setDate(1);
439
+ state.view === 'months' ? start.setMonth(n) : start.setFullYear(n, 0, 1);
440
+ const end = new Date(start);
441
+ state.view === 'months'
442
+ ? end.setMonth(end.getMonth() + 1, 0)
443
+ : end.setFullYear(n + 1, 0, 0);
444
+ const disabled = !!((min && dateKey(end) < min) || (max && dateKey(start) > max));
445
+ return (
446
+ <Pressable
447
+ key={n}
448
+ accessibilityRole="button"
449
+ accessibilityState={{ selected, disabled }}
450
+ disabled={disabled}
451
+ onPress={() =>
452
+ state.view === 'months' ? state.chooseMonth(n) : state.chooseYear(n)
453
+ }
454
+ style={{
455
+ minHeight: 48,
456
+ paddingHorizontal: 16,
457
+ flexDirection: 'row',
458
+ alignItems: 'center',
459
+ gap: 16,
460
+ opacity: disabled ? 0.38 : 1,
461
+ backgroundColor: selected ? colors.secondaryContainer : undefined,
462
+ }}
463
+ >
464
+ <View style={{ width: 20 }}>
465
+ {selected ? (
466
+ <Icon name="check" size={20} color="onSecondaryContainer" />
467
+ ) : null}
468
+ </View>
469
+ <T color={selected ? 'onSecondaryContainer' : 'onSurface'}>
470
+ {state.view === 'months' ? monthName(n, true) : n}
471
+ </T>
472
+ </Pressable>
473
+ );
474
+ },
475
+ )}
476
+ </ScrollView>
477
+ )}
75
478
  </View>
76
- {state.view === 'days' ? <View style={styles.calendar}>
77
- {Array.from({ length: 7 }, (_, i) => <View key={i} style={styles.day}><T variant="labelSmall" color="onSurfaceVariant">{new Date(2024, 0, 7 + i).toLocaleDateString(locale, { weekday: 'narrow' })}</T></View>)}
78
- {calendarDays(state.month).map(date => {
79
- const start = !!range && date === range.range.start, end = !!range && date === range.range.end;
80
- const selected = range ? start || end : state.draft === date, today = dateKey(new Date()) === date, enabled = state.available(date);
81
- const inRange = !!(range?.range.start && rangeEnd && date >= range.range.start && date <= rangeEnd);
82
- return <Pressable key={date} accessibilityRole="button" accessibilityLabel={`${parseDate(date)!.toLocaleDateString(locale, { dateStyle: 'full' })}${start ? `, ${startLabel ?? labels.start}` : ''}${end ? `, ${endLabel ?? labels.end}` : ''}`}
83
- accessibilityHint={range ? labels.rangeHelp : undefined} accessibilityState={{ selected, disabled: !enabled }} disabled={!enabled} onPress={() => state.select(date)} style={[styles.day, { opacity: !enabled ? .38 : selected || inRange ? 1 : parseDate(date)!.getMonth() !== state.month.getMonth() ? .38 : 1 }]}>{inRange && !(start && end) ? <View pointerEvents="none" style={{ position: 'absolute', top: 5, bottom: 5, left: start ? '50%' : 0, right: end ? '50%' : 0, backgroundColor: colors.secondaryContainer }} /> : null}<View style={{ width: 34, height: 34, borderRadius: 17, alignItems: 'center', justifyContent: 'center', backgroundColor: selected ? colors.primary : undefined, borderWidth: today ? 1 : 0, borderColor: colors.primary }}><T color={selected ? 'onPrimary' : today ? 'primary' : inRange ? 'onSecondaryContainer' : 'onSurface'}>{parseDate(date)!.getDate()}</T></View></Pressable>;
84
- })}
85
- </View> : <ScrollView ref={list} style={{ height: 308, borderTopWidth: 1, borderColor: colors.outlineVariant }} nestedScrollEnabled>
86
- {(state.view === 'months' ? Array.from({ length: 12 }, (_, i) => i) : years).map(n => {
87
- const selected = n === (state.view === 'months' ? state.month.getMonth() : state.month.getFullYear());
88
- const start = new Date(state.month); start.setDate(1); state.view === 'months' ? start.setMonth(n) : start.setFullYear(n, 0, 1);
89
- const end = new Date(start); state.view === 'months' ? end.setMonth(end.getMonth() + 1, 0) : end.setFullYear(n + 1, 0, 0);
90
- const disabled = !!((min && dateKey(end) < min) || (max && dateKey(start) > max));
91
- return <Pressable key={n} accessibilityRole="button" accessibilityState={{ selected, disabled }} disabled={disabled} onPress={() => state.view === 'months' ? state.chooseMonth(n) : state.chooseYear(n)} style={{ minHeight: 48, paddingHorizontal: 16, flexDirection: 'row', alignItems: 'center', gap: 16, opacity: disabled ? .38 : 1, backgroundColor: selected ? colors.secondaryContainer : undefined }}><View style={{ width: 20 }}>{selected ? <Icon name="check" size={20} color="onSecondaryContainer" /> : null}</View><T color={selected ? 'onSecondaryContainer' : 'onSurface'}>{state.view === 'months' ? monthName(n, true) : n}</T></Pressable>;
92
- })}
93
- </ScrollView>}
94
- </View> : null}
95
- {range ? <T variant="bodySmall" color="onSurfaceVariant" accessibilityLiveRegion="polite">{range.range.start && !range.range.end ? labels.end : range.range.end && !range.valid ? labels.rangeInvalid : labels.rangeHelp}</T> : null}
96
- <PickerActions cancel={cancelLabel ?? labels.cancel} confirm={confirmLabel ?? labels.confirm} onClose={onClose} onConfirm={state.confirm} valid={state.valid} />
97
- </View>;
98
- if (variant === 'docked') return open ? <View style={[{ maxWidth: 360, alignSelf: 'stretch', borderRadius: 16, padding: 16, backgroundColor: colors.surfaceContainerHigh }, style]}>{content}</View> : null;
99
- return <Dialog open={open} onClose={onClose} style={[{ maxWidth: 360, borderRadius: 28 }, style]}>{content}</Dialog>;
479
+ ) : null}
480
+ {range ? (
481
+ <T variant="bodySmall" color="onSurfaceVariant" accessibilityLiveRegion="polite">
482
+ {range.range.start && !range.range.end
483
+ ? labels.end
484
+ : range.range.end && !range.valid
485
+ ? labels.rangeInvalid
486
+ : labels.rangeHelp}
487
+ </T>
488
+ ) : null}
489
+ <PickerActions
490
+ cancel={cancelLabel ?? labels.cancel}
491
+ confirm={confirmLabel ?? labels.confirm}
492
+ onClose={onClose}
493
+ onConfirm={state.confirm}
494
+ valid={state.valid}
495
+ />
496
+ </View>
497
+ );
498
+ if (variant === 'docked')
499
+ return open ? (
500
+ <View
501
+ style={[
502
+ {
503
+ maxWidth: 360,
504
+ alignSelf: 'stretch',
505
+ borderRadius: 16,
506
+ padding: 16,
507
+ backgroundColor: colors.surfaceContainerHigh,
508
+ },
509
+ style,
510
+ ]}
511
+ >
512
+ {content}
513
+ </View>
514
+ ) : null;
515
+ return (
516
+ <Dialog open={open} onClose={onClose} style={[{ maxWidth: 360, borderRadius: 28 }, style]}>
517
+ {content}
518
+ </Dialog>
519
+ );
100
520
  }
101
521
 
102
522
  export type TimePickerProps = TimePickerOptions & { style?: StyleProp<ViewStyle> };
103
523
  export function TimePicker(props: TimePickerProps) {
104
524
  const { locale, colors } = useExpressiveTheme();
105
- const { open, onClose, title, cancelLabel, confirmLabel, format = '24h', layout = 'auto', style } = props;
106
- const labels = pickerLabels(props.locale ?? locale), state = useTimePickerState(props);
107
- const hourInput = useRef<TextInput>(null), minuteInput = useRef<TextInput>(null);
525
+ const {
526
+ open,
527
+ onClose,
528
+ title,
529
+ cancelLabel,
530
+ confirmLabel,
531
+ format = '24h',
532
+ layout = 'auto',
533
+ style,
534
+ } = props;
535
+ const labels = pickerLabels(props.locale ?? locale, useExpressiveTheme().labels?.pickerLabels),
536
+ state = useTimePickerState(props);
537
+ const hourInput = useRef<TextInput>(null),
538
+ minuteInput = useRef<TextInput>(null);
108
539
  const { width, height } = useWindowDimensions();
109
540
  const inputMode = state.mode === 'input';
110
541
  const horizontal = resolveTimePickerLayout(layout, width, height, state.mode) === 'horizontal';
111
- const size = horizontal ? Math.min(256, (Math.min(560, width - 48) - 72) * 1.1 / 2.1) : Math.min(256, width - 96), scale = size / 256, center = size / 2;
112
- useEffect(() => { if (open && inputMode) (state.part === 'hour' ? hourInput : minuteInput).current?.focus(); }, [inputMode, open]);
113
- const angle = (state.part === 'minute' ? state.minute / 60 : state.h24 % 12 / 12) * Math.PI * 2;
542
+ const size = horizontal
543
+ ? Math.min(256, ((Math.min(560, width - 48) - 72) * 1.1) / 2.1)
544
+ : Math.min(256, width - 96),
545
+ scale = size / 256,
546
+ center = size / 2;
547
+ useEffect(() => {
548
+ if (open && inputMode) (state.part === 'hour' ? hourInput : minuteInput).current?.focus();
549
+ }, [inputMode, open]);
550
+ const angle = (state.part === 'minute' ? state.minute / 60 : (state.h24 % 12) / 12) * Math.PI * 2;
114
551
  const radius = (state.h24 >= 12 && format === '24h' && state.part === 'hour' ? 65 : 100) * scale;
115
552
  const selected = state.part === 'hour' ? state.hour : state.minute;
116
- const periodSelector = format === '12h' ? <View style={{ borderWidth: 1, borderColor: colors.outline, borderRadius: 8, overflow: 'hidden', flexDirection: horizontal ? 'row' : 'column', width: horizontal ? '100%' : 52 }}>{['AM', 'PM'].map((period, i) => <Pressable key={period} accessibilityRole="button" accessibilityState={{ selected: state.period === i }} onPress={() => state.setPeriod(i)} style={{ minWidth: 46, flex: horizontal ? 1 : undefined, height: 39, alignItems: 'center', justifyContent: 'center', borderTopWidth: horizontal ? 0 : i, borderLeftWidth: horizontal ? i : 0, borderColor: colors.outline, backgroundColor: state.period === i ? colors.tertiaryContainer : undefined }}><T color={state.period === i ? 'onTertiaryContainer' : 'onSurfaceVariant'}>{period}</T></Pressable>)}</View> : null;
117
- return <Dialog open={open} onClose={onClose} style={[{ maxWidth: horizontal ? 560 : 360, borderRadius: 28 }, style]}>
118
- <View style={{ gap: 24 }}>
119
- <T variant="labelLarge" color="onSurfaceVariant">{title ?? (inputMode ? labels.enterTime : labels.time)}</T>
120
- <View style={{ flexDirection: horizontal ? 'row' : 'column', gap: 24, alignItems: 'center' }}><View style={{ flex: horizontal ? 1 : undefined, width: horizontal ? undefined : '100%' }}><View style={{ gap: 16, width: '100%', maxWidth: format === '12h' && !horizontal ? 284 : 256, alignSelf: 'center' }}><View style={[styles.time, { gap: format === '12h' ? 8 : 4 }]}>
121
- {(['hour', 'minute'] as const).map((part, i) => <Fragment key={part}>{i ? <T accessible={false} style={{ width: 16, height: 80, fontSize: 56, lineHeight: 80, textAlign: 'center' }}>:</T> : null}<View style={{ gap: 7, flex: 1, minWidth: 0 }}>
122
- {inputMode ? <TextInput ref={part === 'hour' ? hourInput : minuteInput} accessibilityLabel={labels[part]} keyboardType="number-pad" selectTextOnFocus 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={{ width: '100%', height: 80, fontSize: 56, textAlign: 'center', borderRadius: 8, borderWidth: 2, borderColor: !(part === 'hour' ? state.hourValid : state.minuteValid) ? colors.error : state.part === part ? colors.primary : 'transparent', color: state.part === part ? colors.onPrimaryContainer : colors.onSurface, backgroundColor: state.part === part ? colors.primaryContainer : colors.surfaceContainerHighest }} /> : <Pressable accessibilityRole="button" accessibilityLabel={labels[part]} accessibilityState={{ selected: state.part === part }} onPress={() => state.setPart(part)} onLongPress={() => { state.setPart(part); state.setMode('input'); }} style={{ width: '100%', height: 80, justifyContent: 'center', alignItems: 'center', borderRadius: 8, backgroundColor: state.part === part ? colors.primaryContainer : colors.surfaceContainerHighest }}><T style={{ fontSize: 56, lineHeight: 68 }} color={state.part === part ? 'onPrimaryContainer' : 'onSurface'}>{padTime(part === 'hour' ? state.hour : state.minute)}</T></Pressable>}
123
- {inputMode ? <T variant="labelSmall" color="onSurfaceVariant">{labels[part]}</T> : null}
124
- </View></Fragment>)}
125
- {!horizontal ? periodSelector : null}
126
- </View>{horizontal ? periodSelector : null}</View>
127
- {inputMode && !state.valid ? <T color="error" accessibilityRole="alert">{labels.invalid}</T> : null}</View>
128
- {!inputMode ? <View accessibilityLabel={labels[state.part]} style={{ width: size, height: size, alignSelf: 'center', borderRadius: center, backgroundColor: colors.surfaceContainerHighest }}>
129
- <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={() => { if (state.part === 'hour') state.setPart('minute'); }} />
130
- <Svg width={size} height={size} style={StyleSheet.absoluteFill} pointerEvents="none"><Line x1={center} y1={center} x2={center + Math.sin(angle) * radius} y2={center - Math.cos(angle) * radius} stroke={colors.primary} strokeWidth={2} /><Circle cx={center} cy={center} r={4} fill={colors.primary} /><Circle cx={center + Math.sin(angle) * radius} cy={center - Math.cos(angle) * radius} r={20 * scale} fill={colors.primary} /></Svg>
131
- {Array.from({ length: state.part === 'hour' && format === '24h' ? 24 : 12 }, (_, i) => {
132
- const n = state.part === 'minute' ? i * 5 : format === '12h' ? i || 12 : i;
133
- const a = i % 12 / 12 * Math.PI * 2, r = (i >= 12 ? 65 : 100) * scale;
134
- return <Pressable key={n} accessibilityRole="button" accessibilityLabel={`${labels[state.part]} ${n}`} accessibilityState={{ selected: selected === n }} onPress={() => { state.select(n); if (state.part === 'hour') state.setPart('minute'); }} style={{ position: 'absolute', left: center - 20 * scale + Math.sin(a) * r, top: center - 20 * scale - Math.cos(a) * r, width: 40 * scale, height: 40 * scale, borderRadius: 20, alignItems: 'center', justifyContent: 'center' }}><T variant={i >= 12 ? 'labelSmall' : 'bodyLarge'} color={selected === n ? 'onPrimary' : 'onSurface'}>{state.part === 'minute' || format === '24h' && n === 0 ? padTime(n) : n}</T></Pressable>;
135
- })}
136
- </View> : null}
553
+ const periodSelector =
554
+ format === '12h' ? (
555
+ <View
556
+ style={{
557
+ borderWidth: 1,
558
+ borderColor: colors.outline,
559
+ borderRadius: 8,
560
+ overflow: 'hidden',
561
+ flexDirection: horizontal ? 'row' : 'column',
562
+ width: horizontal ? '100%' : 52,
563
+ }}
564
+ >
565
+ {['AM', 'PM'].map((period, i) => (
566
+ <Pressable
567
+ key={period}
568
+ accessibilityRole="button"
569
+ accessibilityState={{ selected: state.period === i }}
570
+ onPress={() => state.setPeriod(i)}
571
+ style={{
572
+ minWidth: 46,
573
+ flex: horizontal ? 1 : undefined,
574
+ height: 39,
575
+ alignItems: 'center',
576
+ justifyContent: 'center',
577
+ borderTopWidth: horizontal ? 0 : i,
578
+ borderLeftWidth: horizontal ? i : 0,
579
+ borderColor: colors.outline,
580
+ backgroundColor: state.period === i ? colors.tertiaryContainer : undefined,
581
+ }}
582
+ >
583
+ <T color={state.period === i ? 'onTertiaryContainer' : 'onSurfaceVariant'}>{period}</T>
584
+ </Pressable>
585
+ ))}
137
586
  </View>
138
- <PickerActions cancel={cancelLabel ?? labels.cancel} confirm={confirmLabel ?? labels.confirm} onClose={onClose} onConfirm={state.confirm} valid={state.valid} toggle={<TimeModeToggle input={inputMode} label={inputMode ? labels.dial : labels.input} onPress={state.toggle} />} />
139
- </View>
140
- </Dialog>;
587
+ ) : null;
588
+ return (
589
+ <Dialog
590
+ open={open}
591
+ onClose={onClose}
592
+ style={[{ maxWidth: horizontal ? 560 : 360, borderRadius: 28 }, style]}
593
+ >
594
+ <View style={{ gap: 24 }}>
595
+ <T variant="labelLarge" color="onSurfaceVariant">
596
+ {title ?? (inputMode ? labels.enterTime : labels.time)}
597
+ </T>
598
+ <View
599
+ style={{ flexDirection: horizontal ? 'row' : 'column', gap: 24, alignItems: 'center' }}
600
+ >
601
+ <View
602
+ style={{ flex: horizontal ? 1 : undefined, width: horizontal ? undefined : '100%' }}
603
+ >
604
+ <View
605
+ style={{
606
+ gap: 16,
607
+ width: '100%',
608
+ maxWidth: format === '12h' && !horizontal ? 284 : 256,
609
+ alignSelf: 'center',
610
+ }}
611
+ >
612
+ <View style={[styles.time, { gap: format === '12h' ? 8 : 4 }]}>
613
+ {(['hour', 'minute'] as const).map((part, i) => (
614
+ <Fragment key={part}>
615
+ {i ? (
616
+ <T
617
+ accessible={false}
618
+ style={{
619
+ width: 16,
620
+ height: 80,
621
+ fontSize: 56,
622
+ lineHeight: 80,
623
+ textAlign: 'center',
624
+ }}
625
+ >
626
+ :
627
+ </T>
628
+ ) : null}
629
+ <View style={{ gap: 7, flex: 1, minWidth: 0 }}>
630
+ {inputMode ? (
631
+ <TextInput
632
+ ref={part === 'hour' ? hourInput : minuteInput}
633
+ accessibilityLabel={labels[part]}
634
+ keyboardType="number-pad"
635
+ selectTextOnFocus
636
+ maxLength={2}
637
+ value={part === 'hour' ? state.hourText : state.minuteText}
638
+ onFocus={() => state.setPart(part)}
639
+ onBlur={() => state.normalize(part)}
640
+ onChangeText={(text) => state.edit(text, part)}
641
+ onSubmitEditing={() =>
642
+ part === 'hour' ? minuteInput.current?.focus() : state.confirm()
643
+ }
644
+ style={{
645
+ width: '100%',
646
+ height: 80,
647
+ fontSize: 56,
648
+ textAlign: 'center',
649
+ borderRadius: 8,
650
+ borderWidth: 2,
651
+ borderColor: !(part === 'hour' ? state.hourValid : state.minuteValid)
652
+ ? colors.error
653
+ : state.part === part
654
+ ? colors.primary
655
+ : 'transparent',
656
+ color:
657
+ state.part === part ? colors.onPrimaryContainer : colors.onSurface,
658
+ backgroundColor:
659
+ state.part === part
660
+ ? colors.primaryContainer
661
+ : colors.surfaceContainerHighest,
662
+ }}
663
+ />
664
+ ) : (
665
+ <Pressable
666
+ accessibilityRole="button"
667
+ accessibilityLabel={labels[part]}
668
+ accessibilityState={{ selected: state.part === part }}
669
+ onPress={() => state.setPart(part)}
670
+ onLongPress={() => {
671
+ state.setPart(part);
672
+ state.setMode('input');
673
+ }}
674
+ style={{
675
+ width: '100%',
676
+ height: 80,
677
+ justifyContent: 'center',
678
+ alignItems: 'center',
679
+ borderRadius: 8,
680
+ backgroundColor:
681
+ state.part === part
682
+ ? colors.primaryContainer
683
+ : colors.surfaceContainerHighest,
684
+ }}
685
+ >
686
+ <T
687
+ style={{ fontSize: 56, lineHeight: 68 }}
688
+ color={state.part === part ? 'onPrimaryContainer' : 'onSurface'}
689
+ >
690
+ {padTime(part === 'hour' ? state.hour : state.minute)}
691
+ </T>
692
+ </Pressable>
693
+ )}
694
+ {inputMode ? (
695
+ <T variant="labelSmall" color="onSurfaceVariant">
696
+ {labels[part]}
697
+ </T>
698
+ ) : null}
699
+ </View>
700
+ </Fragment>
701
+ ))}
702
+ {!horizontal ? periodSelector : null}
703
+ </View>
704
+ {horizontal ? periodSelector : null}
705
+ </View>
706
+ {inputMode && !state.valid ? (
707
+ <T color="error" accessibilityRole="alert">
708
+ {labels.invalid}
709
+ </T>
710
+ ) : null}
711
+ </View>
712
+ {!inputMode ? (
713
+ <View
714
+ accessibilityLabel={labels[state.part]}
715
+ style={{
716
+ width: size,
717
+ height: size,
718
+ alignSelf: 'center',
719
+ borderRadius: center,
720
+ backgroundColor: colors.surfaceContainerHighest,
721
+ }}
722
+ >
723
+ <View
724
+ style={StyleSheet.absoluteFill}
725
+ onStartShouldSetResponder={() => true}
726
+ onMoveShouldSetResponder={() => true}
727
+ onResponderGrant={(event) =>
728
+ state.select(
729
+ dialValueAt(
730
+ event.nativeEvent.locationX,
731
+ event.nativeEvent.locationY,
732
+ size,
733
+ state.part,
734
+ format,
735
+ ),
736
+ )
737
+ }
738
+ onResponderMove={(event) =>
739
+ state.select(
740
+ dialValueAt(
741
+ event.nativeEvent.locationX,
742
+ event.nativeEvent.locationY,
743
+ size,
744
+ state.part,
745
+ format,
746
+ ),
747
+ )
748
+ }
749
+ onResponderRelease={() => {
750
+ if (state.part === 'hour') state.setPart('minute');
751
+ }}
752
+ />
753
+ <Svg width={size} height={size} style={StyleSheet.absoluteFill} pointerEvents="none">
754
+ <Line
755
+ x1={center}
756
+ y1={center}
757
+ x2={center + Math.sin(angle) * radius}
758
+ y2={center - Math.cos(angle) * radius}
759
+ stroke={colors.primary}
760
+ strokeWidth={2}
761
+ />
762
+ <Circle cx={center} cy={center} r={4} fill={colors.primary} />
763
+ <Circle
764
+ cx={center + Math.sin(angle) * radius}
765
+ cy={center - Math.cos(angle) * radius}
766
+ r={20 * scale}
767
+ fill={colors.primary}
768
+ />
769
+ </Svg>
770
+ {Array.from(
771
+ { length: state.part === 'hour' && format === '24h' ? 24 : 12 },
772
+ (_, i) => {
773
+ const n = state.part === 'minute' ? i * 5 : format === '12h' ? i || 12 : i;
774
+ const a = ((i % 12) / 12) * Math.PI * 2,
775
+ r = (i >= 12 ? 65 : 100) * scale;
776
+ return (
777
+ <Pressable
778
+ key={n}
779
+ accessibilityRole="button"
780
+ accessibilityLabel={`${labels[state.part]} ${n}`}
781
+ accessibilityState={{ selected: selected === n }}
782
+ onPress={() => {
783
+ state.select(n);
784
+ if (state.part === 'hour') state.setPart('minute');
785
+ }}
786
+ style={{
787
+ position: 'absolute',
788
+ left: center - 20 * scale + Math.sin(a) * r,
789
+ top: center - 20 * scale - Math.cos(a) * r,
790
+ width: 40 * scale,
791
+ height: 40 * scale,
792
+ borderRadius: 20,
793
+ alignItems: 'center',
794
+ justifyContent: 'center',
795
+ }}
796
+ >
797
+ <T
798
+ variant={i >= 12 ? 'labelSmall' : 'bodyLarge'}
799
+ color={selected === n ? 'onPrimary' : 'onSurface'}
800
+ >
801
+ {state.part === 'minute' || (format === '24h' && n === 0) ? padTime(n) : n}
802
+ </T>
803
+ </Pressable>
804
+ );
805
+ },
806
+ )}
807
+ </View>
808
+ ) : null}
809
+ </View>
810
+ <PickerActions
811
+ cancel={cancelLabel ?? labels.cancel}
812
+ confirm={confirmLabel ?? labels.confirm}
813
+ onClose={onClose}
814
+ onConfirm={state.confirm}
815
+ valid={state.valid}
816
+ toggle={
817
+ <TimeModeToggle
818
+ input={inputMode}
819
+ label={inputMode ? labels.dial : labels.input}
820
+ onPress={state.toggle}
821
+ />
822
+ }
823
+ />
824
+ </View>
825
+ </Dialog>
826
+ );
141
827
  }
142
828
  const styles = StyleSheet.create({
143
- icon: { width: 28, minHeight: 48, borderRadius: 24, alignItems: 'center', justifyContent: 'center' },
829
+ icon: {
830
+ width: 28,
831
+ minHeight: 48,
832
+ borderRadius: 24,
833
+ alignItems: 'center',
834
+ justifyContent: 'center',
835
+ },
144
836
  actions: { flexDirection: 'row', alignItems: 'center', gap: 8 },
145
837
  headline: { flexDirection: 'row', alignItems: 'center', gap: 8 },
146
- navigation: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', minHeight: 48 },
838
+ navigation: {
839
+ flexDirection: 'row',
840
+ alignItems: 'center',
841
+ justifyContent: 'space-between',
842
+ minHeight: 48,
843
+ },
147
844
  navGroup: { flexDirection: 'row', alignItems: 'center', flexShrink: 1 },
148
845
  menuTrigger: { flexDirection: 'row', alignItems: 'center', gap: 2, minHeight: 48 },
149
846
  calendar: { flexDirection: 'row', flexWrap: 'wrap' },