@plexui/react-native 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/DatePicker/Calendar.js +112 -0
- package/dist/es/components/DatePicker/DatePicker.js +335 -0
- package/dist/es/components/DatePicker/TimeDial.js +123 -0
- package/dist/es/components/DatePicker/Wheel.js +164 -0
- package/dist/es/components/DatePicker/dates.js +147 -0
- package/dist/es/components/Dialog/Dialog.js +21 -0
- package/dist/es/components/Icon/material.js +16 -0
- package/dist/es/index.js +1 -0
- package/dist/types/components/DatePicker/Calendar.d.ts +29 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +57 -0
- package/dist/types/components/DatePicker/TimeDial.d.ts +20 -0
- package/dist/types/components/DatePicker/Wheel.d.ts +40 -0
- package/dist/types/components/DatePicker/dates.d.ts +45 -0
- package/dist/types/components/Dialog/Dialog.d.ts +18 -0
- package/dist/types/components/Icon/material.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/DatePicker/Calendar.tsx +227 -0
- package/src/components/DatePicker/DatePicker.tsx +608 -0
- package/src/components/DatePicker/TimeDial.tsx +201 -0
- package/src/components/DatePicker/Wheel.tsx +247 -0
- package/src/components/DatePicker/dates.ts +161 -0
- package/src/components/Dialog/Dialog.tsx +46 -0
- package/src/components/Icon/material.ts +18 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { Animated, Platform, Pressable, ScrollView, StyleSheet, View } from "react-native";
|
|
4
|
+
import { withAlpha } from "../../theme/material";
|
|
5
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
|
+
/** iOS: a row of UIDatePicker's wheels, 32 apart (the band of iOS 27.2, 32 tall). Android: a NumberPicker's 48dp rows. */
|
|
7
|
+
export const IOS_WHEEL_ROW = 32;
|
|
8
|
+
export const ANDROID_WHEEL_ROW = 48;
|
|
9
|
+
/**
|
|
10
|
+
* The wheels of a time (or date) picker. On iOS UIDatePicker's `.wheels` as iOS 27.2 draws them in a compact time
|
|
11
|
+
* picker's popover: rows 32 apart in Regular 22, a 32 band of the ink at 7% across the columns 20 in from the sides,
|
|
12
|
+
* the rows on the band in the ink and the others in its 35% gray, turning away like a cylinder's. On Android the
|
|
13
|
+
* spinner mode of its DatePicker and TimePicker: three 48dp rows, the middle one between two lines in the ink, the
|
|
14
|
+
* others faded. A wheel stops on a row; a tap on a row turns it there; VoiceOver and TalkBack turn it one row at a time.
|
|
15
|
+
*/
|
|
16
|
+
export function Wheels({ columns, height: heightProp, bandInset = 20, disabled = false, testID }) {
|
|
17
|
+
const theme = useTheme();
|
|
18
|
+
const android = theme.isAndroid;
|
|
19
|
+
const row = android ? ANDROID_WHEEL_ROW : IOS_WHEEL_ROW;
|
|
20
|
+
const height = heightProp ?? (android ? row * 3 : 202);
|
|
21
|
+
const ink = android ? theme.material.onSurface : theme.colors.text;
|
|
22
|
+
const band = (height - row) / 2;
|
|
23
|
+
// Columns wider than the room narrow in step, so the wheels keep inside the band
|
|
24
|
+
const [room, setRoom] = useState(0);
|
|
25
|
+
const total = columns.reduce((sum, column) => sum + column.width, 0);
|
|
26
|
+
const fit = room > 0 ? Math.min(1, (room - 2 * (android ? 0 : bandInset)) / total) : 1;
|
|
27
|
+
return (_jsxs(View, { style: [styles.wheels, { height }], testID: testID, onLayout: (event) => setRoom(event.nativeEvent.layout.width), children: [_jsx(View, { pointerEvents: "none", style: [
|
|
28
|
+
styles.band,
|
|
29
|
+
{ top: band, height: row },
|
|
30
|
+
android
|
|
31
|
+
? { borderTopWidth: 2, borderBottomWidth: 2, borderColor: theme.material.outline, left: 0, right: 0 }
|
|
32
|
+
: { left: bandInset, right: bandInset, borderRadius: 8, backgroundColor: withAlpha(ink, theme.scheme === "dark" ? 0.12 : 0.07) },
|
|
33
|
+
] }), columns.map((column) => (_jsx(Wheel, { column: fit < 1 ? { ...column, width: Math.floor(column.width * fit) } : column, disabled: disabled, row: row, height: height, ink: ink, testID: testID ? `${testID}-${column.key}` : undefined }, column.key)))] }));
|
|
34
|
+
}
|
|
35
|
+
function Wheel({ column, row, height, ink, disabled, testID }) {
|
|
36
|
+
const theme = useTheme();
|
|
37
|
+
const android = theme.isAndroid;
|
|
38
|
+
const { items, index, onChange, width, label, align = "center", inset = 4 } = column;
|
|
39
|
+
const scroll = useRef(null);
|
|
40
|
+
const [offset] = useState(() => new Animated.Value(index * row));
|
|
41
|
+
const last = useRef(index * row);
|
|
42
|
+
const timer = useRef(null);
|
|
43
|
+
const touching = useRef(false);
|
|
44
|
+
const pad = (height - row) / 2;
|
|
45
|
+
const web = Platform.OS === "web";
|
|
46
|
+
const nearestEnabled = (target) => {
|
|
47
|
+
const clamped = Math.max(0, Math.min(items.length - 1, target));
|
|
48
|
+
if (!items[clamped]?.disabled)
|
|
49
|
+
return clamped;
|
|
50
|
+
for (let step = 1; step < items.length; step += 1) {
|
|
51
|
+
if (!items[clamped - step]?.disabled && clamped - step >= 0)
|
|
52
|
+
return clamped - step;
|
|
53
|
+
if (!items[clamped + step]?.disabled && clamped + step < items.length)
|
|
54
|
+
return clamped + step;
|
|
55
|
+
}
|
|
56
|
+
return clamped;
|
|
57
|
+
};
|
|
58
|
+
const turnTo = (next, animated) => {
|
|
59
|
+
scroll.current?.scrollTo({ y: next * row, animated: animated && !theme.reducedMotion });
|
|
60
|
+
};
|
|
61
|
+
// The wheel comes to rest on the row nearest the band, or the nearest one that can be chosen
|
|
62
|
+
const settle = () => {
|
|
63
|
+
timer.current = null;
|
|
64
|
+
if (touching.current)
|
|
65
|
+
return;
|
|
66
|
+
const next = nearestEnabled(Math.round(last.current / row));
|
|
67
|
+
if (Math.abs(last.current - next * row) > 0.5)
|
|
68
|
+
turnTo(next, true);
|
|
69
|
+
if (next !== index)
|
|
70
|
+
onChange(next);
|
|
71
|
+
};
|
|
72
|
+
const onScroll = (event) => {
|
|
73
|
+
const y = event.nativeEvent.contentOffset.y;
|
|
74
|
+
last.current = y;
|
|
75
|
+
offset.setValue(y);
|
|
76
|
+
if (timer.current)
|
|
77
|
+
clearTimeout(timer.current);
|
|
78
|
+
timer.current = setTimeout(settle, web ? 120 : 90);
|
|
79
|
+
};
|
|
80
|
+
useEffect(() => () => {
|
|
81
|
+
if (timer.current)
|
|
82
|
+
clearTimeout(timer.current);
|
|
83
|
+
}, []);
|
|
84
|
+
// A value set from outside turns the wheel to it (a settle still waiting gives way to it)
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (touching.current)
|
|
87
|
+
return;
|
|
88
|
+
if (timer.current) {
|
|
89
|
+
clearTimeout(timer.current);
|
|
90
|
+
timer.current = null;
|
|
91
|
+
}
|
|
92
|
+
if (Math.abs(last.current - index * row) > 0.5)
|
|
93
|
+
turnTo(index, false);
|
|
94
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
|
+
}, [index, row]);
|
|
96
|
+
const textAlign = align === "start" ? "left" : align === "end" ? "right" : "center";
|
|
97
|
+
const fontSize = android ? 20 : 22;
|
|
98
|
+
const lineHeight = android ? 28 : 28;
|
|
99
|
+
// A row's look by its distance from the band: it turns away and fades as on a cylinder (iOS); Android fades it
|
|
100
|
+
const rowStyle = (position) => {
|
|
101
|
+
const distance = Animated.divide(Animated.subtract(offset, position * row), row);
|
|
102
|
+
return {
|
|
103
|
+
opacity: distance.interpolate({ inputRange: [-3, -1, 0, 1, 3], outputRange: [0.25, android ? 0.6 : 0.85, 1, android ? 0.6 : 0.85, 0.25], extrapolate: "clamp" }),
|
|
104
|
+
transform: android
|
|
105
|
+
? []
|
|
106
|
+
: [
|
|
107
|
+
{ perspective: 600 },
|
|
108
|
+
{ rotateX: distance.interpolate({ inputRange: [-4, 4], outputRange: ["72deg", "-72deg"], extrapolate: "clamp" }) },
|
|
109
|
+
{ scale: distance.interpolate({ inputRange: [-3, 0, 3], outputRange: [0.9, 1, 0.9], extrapolate: "clamp" }) },
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
const step = (direction) => {
|
|
114
|
+
if (disabled)
|
|
115
|
+
return;
|
|
116
|
+
const next = nearestEnabled(index + direction);
|
|
117
|
+
if (next === index)
|
|
118
|
+
return;
|
|
119
|
+
turnTo(next, true);
|
|
120
|
+
onChange(next);
|
|
121
|
+
};
|
|
122
|
+
const gray = withAlpha(ink, android ? 0.38 : 0.35);
|
|
123
|
+
const labelFor = (item, position, color, pressable) => {
|
|
124
|
+
const text = (_jsx(Animated.Text, { numberOfLines: 1, style: [
|
|
125
|
+
{ width, height: row, fontSize, lineHeight: row, textAlign, color: item.disabled ? withAlpha(ink, 0.2) : color, paddingStart: align === "end" ? 4 : inset, paddingEnd: align === "start" ? 4 : align === "end" ? inset : 4 },
|
|
126
|
+
theme.font("regular"),
|
|
127
|
+
web ? { userSelect: "none" } : null,
|
|
128
|
+
rowStyle(position),
|
|
129
|
+
], children: item.label }));
|
|
130
|
+
if (!pressable)
|
|
131
|
+
return _jsx(View, { children: text }, position);
|
|
132
|
+
return (_jsx(Pressable, { disabled: item.disabled || disabled, importantForAccessibility: "no", accessibilityElementsHidden: true, onPress: () => {
|
|
133
|
+
turnTo(position, true);
|
|
134
|
+
if (position !== index)
|
|
135
|
+
onChange(position);
|
|
136
|
+
}, children: text }, position));
|
|
137
|
+
};
|
|
138
|
+
return (_jsxs(View, { accessible: true, accessibilityRole: "adjustable", accessibilityLabel: label, accessibilityValue: { text: items[index]?.label }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => step(event.nativeEvent.actionName === "increment" ? 1 : -1), ...(web
|
|
139
|
+
? {
|
|
140
|
+
tabIndex: disabled ? -1 : 0,
|
|
141
|
+
onKeyDown: (event) => {
|
|
142
|
+
if (event.key === "ArrowDown")
|
|
143
|
+
step(1);
|
|
144
|
+
else if (event.key === "ArrowUp")
|
|
145
|
+
step(-1);
|
|
146
|
+
else
|
|
147
|
+
return;
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
: null), style: { width, height }, testID: testID, children: [_jsx(ScrollView, { ref: scroll, scrollEnabled: !disabled, showsVerticalScrollIndicator: false, snapToInterval: row, decelerationRate: "fast", scrollEventThrottle: 16, onScroll: onScroll, onScrollBeginDrag: () => {
|
|
152
|
+
touching.current = true;
|
|
153
|
+
}, onScrollEndDrag: () => {
|
|
154
|
+
touching.current = false;
|
|
155
|
+
if (timer.current)
|
|
156
|
+
clearTimeout(timer.current);
|
|
157
|
+
timer.current = setTimeout(settle, 90);
|
|
158
|
+
}, onLayout: () => turnTo(index, false), contentContainerStyle: { paddingVertical: pad }, style: web ? { scrollbarWidth: "none" } : null, children: items.map((item, position) => labelFor(item, position, gray, true)) }), _jsx(View, { pointerEvents: "none", style: [styles.clip, { top: pad, height: row, width }], children: _jsx(Animated.View, { style: { transform: [{ translateY: Animated.multiply(offset, -1) }] }, children: items.map((item, position) => labelFor(item, position, ink, false)) }) })] }));
|
|
159
|
+
}
|
|
160
|
+
const styles = StyleSheet.create({
|
|
161
|
+
wheels: { flexDirection: "row", justifyContent: "center", alignSelf: "stretch" },
|
|
162
|
+
band: { position: "absolute" },
|
|
163
|
+
clip: { position: "absolute", left: 0, overflow: "hidden" },
|
|
164
|
+
});
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Date helpers of DatePicker: plain `Date`s in the device's time zone, days compared by their calendar date. */
|
|
2
|
+
export function sameDay(a, b) {
|
|
3
|
+
return a != null && b != null && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
4
|
+
}
|
|
5
|
+
export function startOfDay(date) {
|
|
6
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
7
|
+
}
|
|
8
|
+
/** The first day of the month `offset` months from `date`'s. */
|
|
9
|
+
export function monthOf(date, offset = 0) {
|
|
10
|
+
return new Date(date.getFullYear(), date.getMonth() + offset, 1);
|
|
11
|
+
}
|
|
12
|
+
/** A day lies outside `min`…`max` (compared by calendar day). */
|
|
13
|
+
export function dayOutside(day, min, max) {
|
|
14
|
+
const time = startOfDay(day).getTime();
|
|
15
|
+
return (min != null && time < startOfDay(min).getTime()) || (max != null && time > startOfDay(max).getTime());
|
|
16
|
+
}
|
|
17
|
+
/** A moment lies outside `min`…`max` (compared to the minute). */
|
|
18
|
+
export function timeOutside(date, min, max) {
|
|
19
|
+
return (min != null && date.getTime() < min.getTime()) || (max != null && date.getTime() > max.getTime());
|
|
20
|
+
}
|
|
21
|
+
/** The date kept inside `min`…`max`. */
|
|
22
|
+
export function clampDate(date, min, max) {
|
|
23
|
+
if (min != null && date.getTime() < min.getTime())
|
|
24
|
+
return new Date(min.getTime());
|
|
25
|
+
if (max != null && date.getTime() > max.getTime())
|
|
26
|
+
return new Date(max.getTime());
|
|
27
|
+
return date;
|
|
28
|
+
}
|
|
29
|
+
/** The weeks of a month, each of seven days; days of the months around it are `null`. */
|
|
30
|
+
export function monthWeeks(month, weekStartsOn) {
|
|
31
|
+
const year = month.getFullYear();
|
|
32
|
+
const index = month.getMonth();
|
|
33
|
+
const lead = (new Date(year, index, 1).getDay() - weekStartsOn + 7) % 7;
|
|
34
|
+
const days = new Date(year, index + 1, 0).getDate();
|
|
35
|
+
const cells = [...Array(lead).fill(null)];
|
|
36
|
+
for (let day = 1; day <= days; day += 1)
|
|
37
|
+
cells.push(new Date(year, index, day));
|
|
38
|
+
while (cells.length % 7)
|
|
39
|
+
cells.push(null);
|
|
40
|
+
const weeks = [];
|
|
41
|
+
for (let start = 0; start < cells.length; start += 7)
|
|
42
|
+
weeks.push(cells.slice(start, start + 7));
|
|
43
|
+
return weeks;
|
|
44
|
+
}
|
|
45
|
+
/** `value` on `day`: its time kept, the start of the day when there is no value yet. */
|
|
46
|
+
export function withDay(value, day) {
|
|
47
|
+
return new Date(day.getFullYear(), day.getMonth(), day.getDate(), value?.getHours() ?? 0, value?.getMinutes() ?? 0);
|
|
48
|
+
}
|
|
49
|
+
/** `value` at `hours`:`minutes`, today when there is no value yet. */
|
|
50
|
+
export function withTime(value, hours, minutes) {
|
|
51
|
+
const base = value ?? new Date();
|
|
52
|
+
return new Date(base.getFullYear(), base.getMonth(), base.getDate(), hours, minutes);
|
|
53
|
+
}
|
|
54
|
+
/** The day a week starts on in the locale (0 Sunday … 6 Saturday), from `Intl.Locale`'s week info; Monday without it. */
|
|
55
|
+
export function localeWeekStart(locale) {
|
|
56
|
+
try {
|
|
57
|
+
const info = new Intl.Locale(locale ?? Intl.DateTimeFormat().resolvedOptions().locale);
|
|
58
|
+
const first = info.getWeekInfo?.().firstDay ?? info.weekInfo?.firstDay;
|
|
59
|
+
if (first != null)
|
|
60
|
+
return first % 7;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// An engine without Intl.Locale
|
|
64
|
+
}
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
/** The locale reads time on a 12-hour clock. */
|
|
68
|
+
export function localeHour12(locale) {
|
|
69
|
+
try {
|
|
70
|
+
const options = new Intl.DateTimeFormat(locale, { hour: "numeric" }).resolvedOptions();
|
|
71
|
+
if (options.hourCycle)
|
|
72
|
+
return options.hourCycle === "h11" || options.hourCycle === "h12";
|
|
73
|
+
return options.hour12 === true;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function format(locale, options, date) {
|
|
80
|
+
try {
|
|
81
|
+
// The grid and the wheels are Gregorian: the names follow it in every locale (fa-IR, th-TH)
|
|
82
|
+
return new Intl.DateTimeFormat(locale, { calendar: "gregory", ...options }).format(date);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return date.toDateString();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** The date as a compact picker shows it: "13 Nov 2026" (iOS) or "Nov 13, 2026", by the locale. */
|
|
89
|
+
export function formatDate(date, locale) {
|
|
90
|
+
return format(locale, { day: "numeric", month: "short", year: "numeric" }, date);
|
|
91
|
+
}
|
|
92
|
+
/** The time: "09:00", or "9:00 AM" on a 12-hour clock. */
|
|
93
|
+
export function formatTime(date, locale, hour12) {
|
|
94
|
+
return format(locale, { hour: hour12 ? "numeric" : "2-digit", minute: "2-digit", hour12 }, date);
|
|
95
|
+
}
|
|
96
|
+
/** The month's title: "November 2026". */
|
|
97
|
+
export function formatMonth(month, locale) {
|
|
98
|
+
return format(locale, { month: "long", year: "numeric" }, month);
|
|
99
|
+
}
|
|
100
|
+
/** Android's dialog headline: "Tue, Nov 24". */
|
|
101
|
+
export function formatHeadline(date, locale) {
|
|
102
|
+
return format(locale, { weekday: "short", month: "short", day: "numeric" }, date);
|
|
103
|
+
}
|
|
104
|
+
/** A day on a date-and-time wheel: "Wed Nov 25". */
|
|
105
|
+
export function formatWheelDay(date, locale) {
|
|
106
|
+
return format(locale, { weekday: "short", month: "short", day: "numeric" }, date).replace(/,/g, "");
|
|
107
|
+
}
|
|
108
|
+
/** A day read out in full: "Tuesday, 24 November 2026". */
|
|
109
|
+
export function formatFullDay(date, locale) {
|
|
110
|
+
return format(locale, { weekday: "long", day: "numeric", month: "long", year: "numeric" }, date);
|
|
111
|
+
}
|
|
112
|
+
/** The weekdays' labels from `weekStartsOn`: "MON" (`short`, iOS) or "M" (`narrow`, Android). */
|
|
113
|
+
export function weekdayLabels(locale, weekStartsOn, width) {
|
|
114
|
+
// 2023-01-01 was a Sunday
|
|
115
|
+
return Array.from({ length: 7 }, (_, index) => {
|
|
116
|
+
const day = new Date(2023, 0, 1 + ((weekStartsOn + index) % 7));
|
|
117
|
+
return { label: format(locale, { weekday: width }, day), name: format(locale, { weekday: "long" }, day) };
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** The month names of the locale, January first. */
|
|
121
|
+
export function monthNames(locale) {
|
|
122
|
+
return Array.from({ length: 12 }, (_, index) => format(locale, { month: "long" }, new Date(2023, index, 1)));
|
|
123
|
+
}
|
|
124
|
+
/** The order of day, month and year in the locale's dates, for the date wheels. */
|
|
125
|
+
export function dateOrder(locale) {
|
|
126
|
+
try {
|
|
127
|
+
const parts = new Intl.DateTimeFormat(locale, { calendar: "gregory", day: "numeric", month: "long", year: "numeric" }).formatToParts(new Date(2023, 10, 24));
|
|
128
|
+
const order = parts.map((part) => part.type).filter((type) => type === "day" || type === "month" || type === "year");
|
|
129
|
+
if (order.length === 3)
|
|
130
|
+
return order;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// An engine without formatToParts
|
|
134
|
+
}
|
|
135
|
+
return ["month", "day", "year"];
|
|
136
|
+
}
|
|
137
|
+
/** The locale's day period labels: ["AM", "PM"]. */
|
|
138
|
+
export function periodLabels(locale) {
|
|
139
|
+
try {
|
|
140
|
+
const read = (hour) => new Intl.DateTimeFormat(locale, { hour: "numeric", hour12: true }).formatToParts(new Date(2023, 0, 1, hour)).find((part) => part.type === "dayPeriod")?.value;
|
|
141
|
+
return [read(9) ?? "AM", read(21) ?? "PM"];
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return ["AM", "PM"];
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export const pad2 = (value) => String(value).padStart(2, "0");
|
|
@@ -107,6 +107,27 @@ export function ChoiceDialog({ open, onClose, title, cancelLabel, okLabel, onOk,
|
|
|
107
107
|
]
|
|
108
108
|
: [{ label: cancelLabel, testID: testID ? `${testID}-cancel` : undefined }], run: run, ids: ids, list: _jsx(View, { ...listProps, children: children }) }) }));
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Android's picker dialog: the dialog's panel holding a picker of its own (Material 3's date picker or time picker
|
|
112
|
+
* dial), Cancel and OK at the end. DatePicker's dialog on Android; not part of the public API.
|
|
113
|
+
*/
|
|
114
|
+
export function PickerDialog({ open, onClose, onOk, cancelLabel, okLabel, label, children, testID }) {
|
|
115
|
+
const theme = useTheme();
|
|
116
|
+
const ids = { title: useId(), description: useId() };
|
|
117
|
+
const a11y = Platform.OS === "web"
|
|
118
|
+
? { role: "dialog", "aria-modal": true, "aria-label": label }
|
|
119
|
+
: { accessibilityViewIsModal: true, accessibilityLabel: label };
|
|
120
|
+
const run = (action) => {
|
|
121
|
+
if (!open)
|
|
122
|
+
return;
|
|
123
|
+
action.onPress?.();
|
|
124
|
+
onClose();
|
|
125
|
+
};
|
|
126
|
+
return (_jsx(AndroidFrame, { open: open, onClose: onClose, dismissible: true, a11y: a11y, testID: testID, children: _jsx(AndroidDialog, { theme: theme, actions: [
|
|
127
|
+
{ label: cancelLabel, variant: "cancel", testID: testID ? `${testID}-cancel` : undefined },
|
|
128
|
+
{ label: okLabel, preferred: true, onPress: onOk, testID: testID ? `${testID}-ok` : undefined },
|
|
129
|
+
], run: run, ids: ids, list: children }) }));
|
|
130
|
+
}
|
|
110
131
|
/** An iOS alert action's label inset from its capsule's ends. */
|
|
111
132
|
const IOS_ACTION_INSET = 16;
|
|
112
133
|
function IOSAlert({ theme, title, description, actions, run, ids, layout, children }) {
|
|
@@ -32,3 +32,19 @@ export const MaterialCheckSymbol = createIcon("MaterialCheckSymbol", "0 -960 960
|
|
|
32
32
|
* `abc_ic_ab_back_material` that Settings' toolbar shows); it is mirrored right to left.
|
|
33
33
|
*/
|
|
34
34
|
export const MaterialArrowBack = createIcon("MaterialArrowBack", "0 0 24 24", [["path", { d: "M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z", fill: 0 }]]);
|
|
35
|
+
/** Material Symbols' chevron_left and chevron_right (24, the outlined weight 400): a month's arrows in the date picker. */
|
|
36
|
+
export const MaterialChevronLeft = createIcon("MaterialChevronLeft", "0 -960 960 960", [["path", { d: "M560-240 320-480l240-240 56 56-184 184 184 184-56 56Z", fill: 0 }]]);
|
|
37
|
+
export const MaterialChevronRight = createIcon("MaterialChevronRight", "0 -960 960 960", [["path", { d: "M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z", fill: 0 }]]);
|
|
38
|
+
/** Material Symbols' calendar_today and schedule (24, outlined weight 400): the trailing icons of a date and a time field. */
|
|
39
|
+
export const MaterialCalendarToday = createIcon("MaterialCalendarToday", "0 -960 960 960", [
|
|
40
|
+
["path", { d: "M200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z", fill: 0 }],
|
|
41
|
+
]);
|
|
42
|
+
export const MaterialSchedule = createIcon("MaterialSchedule", "0 -960 960 960", [
|
|
43
|
+
[
|
|
44
|
+
"path",
|
|
45
|
+
{
|
|
46
|
+
d: "m612-292 56-56-148-148v-184h-80v216l172 172ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-400Zm0 320q133 0 226.5-93.5T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 133 93.5 226.5T480-160Z",
|
|
47
|
+
fill: 0,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
]);
|
package/dist/es/index.js
CHANGED
|
@@ -26,6 +26,7 @@ export { OTPInput } from "./components/OTPInput/OTPInput";
|
|
|
26
26
|
export { Select } from "./components/Select/Select";
|
|
27
27
|
export { Menu } from "./components/Menu/Menu";
|
|
28
28
|
export { ContextMenu } from "./components/ContextMenu/ContextMenu";
|
|
29
|
+
export { DatePicker } from "./components/DatePicker/DatePicker";
|
|
29
30
|
export { ActionSheet } from "./components/ActionSheet/ActionSheet";
|
|
30
31
|
export { BottomSheet } from "./components/BottomSheet/BottomSheet";
|
|
31
32
|
export { Dialog } from "./components/Dialog/Dialog";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export type CalendarProps = {
|
|
2
|
+
/** The chosen day. */
|
|
3
|
+
value: Date | null;
|
|
4
|
+
/** Called with the day a person taps (its time is midnight). */
|
|
5
|
+
onSelect: (day: Date) => void;
|
|
6
|
+
min?: Date;
|
|
7
|
+
max?: Date;
|
|
8
|
+
locale?: string;
|
|
9
|
+
weekStartsOn: number;
|
|
10
|
+
/** The calendar's width: seven columns across it (44 at the least on iOS). */
|
|
11
|
+
width: number;
|
|
12
|
+
/** Takes no presses (an inline calendar of a disabled picker). */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Labels of the month arrows, read by a screen reader. */
|
|
15
|
+
previousLabel?: string;
|
|
16
|
+
nextLabel?: string;
|
|
17
|
+
testID?: string;
|
|
18
|
+
};
|
|
19
|
+
/** iOS: the corner's inset around the grid of a compact picker's calendar (the web's `--calendar-inner-padding`). */
|
|
20
|
+
export declare const IOS_CALENDAR_INSET = 10;
|
|
21
|
+
/**
|
|
22
|
+
* The month grid of DatePicker. On iOS the phone calendar of @plexui/ui (Calendar.module.css under 768px): the month's
|
|
23
|
+
* title Semibold 17 at the row's text inset, the two arrows as 44 targets at the end, the weekdays Semibold 13 in
|
|
24
|
+
* capitals in the tertiary label, the days Regular 17 in 44 cells side by side and row on row, the chosen day white on
|
|
25
|
+
* a 44 circle of the text's color, today a 4 dot under its digits, days out of range at 40%. On Android Material 3's
|
|
26
|
+
* date picker: the month at the start in Medium 14 with the arrows at the end, the weekdays' letters, the days in 40dp
|
|
27
|
+
* circles, the chosen one filled with the primary color and today ringed in it.
|
|
28
|
+
*/
|
|
29
|
+
export declare function Calendar({ value, onSelect, min, max, locale, weekStartsOn, width, disabled: off, previousLabel, nextLabel, testID }: CalendarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type StyleProp, type ViewStyle } from "react-native";
|
|
2
|
+
export type DatePickerMode = "date" | "time" | "datetime";
|
|
3
|
+
export type DatePickerDisplay = "compact" | "inline" | "wheels";
|
|
4
|
+
export type DatePickerProps = {
|
|
5
|
+
/** The date and time chosen, `null` for none yet. */
|
|
6
|
+
value: Date | null;
|
|
7
|
+
/** Called with the new date (its time kept when only the day changes, its day when only the time does). */
|
|
8
|
+
onChange: (value: Date) => void;
|
|
9
|
+
/** What is chosen: a day, a time, or both. @default "date" */
|
|
10
|
+
mode?: DatePickerMode;
|
|
11
|
+
/**
|
|
12
|
+
* How it is drawn. `compact`: the value in a capsule on iOS that opens the calendar (or the time's wheels) in a
|
|
13
|
+
* popover, Android's field or row value that opens Material's date (or time) dialog. `inline`: the month's calendar
|
|
14
|
+
* in place. `wheels`: the wheels of iOS, Android's spinners. @default "compact"
|
|
15
|
+
*/
|
|
16
|
+
display?: DatePickerDisplay;
|
|
17
|
+
/** The earliest date that can be chosen. */
|
|
18
|
+
min?: Date;
|
|
19
|
+
/** The latest date that can be chosen. */
|
|
20
|
+
max?: Date;
|
|
21
|
+
/** The locale of the names and the formats. @default the device's */
|
|
22
|
+
locale?: string;
|
|
23
|
+
/** The first day of the week, 0 Sunday to 6 Saturday. @default the locale's */
|
|
24
|
+
weekStartsOn?: number;
|
|
25
|
+
/** A 12-hour clock with AM and PM. @default the locale's */
|
|
26
|
+
hour12?: boolean;
|
|
27
|
+
/** Shown while there is no value. @default "Select date" / "Select time" */
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/** The picker's name for a screen reader (a row's label). */
|
|
31
|
+
"aria-label"?: string;
|
|
32
|
+
/** Android: the header of the date dialog. @default "Select date" */
|
|
33
|
+
dateTitle?: string;
|
|
34
|
+
/** Android: the header of the time dialog. @default "Select time" */
|
|
35
|
+
timeTitle?: string;
|
|
36
|
+
/** @default "Cancel" */
|
|
37
|
+
cancelLabel?: string;
|
|
38
|
+
/** @default "OK" */
|
|
39
|
+
okLabel?: string;
|
|
40
|
+
/** The label of the time row under an inline calendar (`mode="datetime"`). @default "Time" */
|
|
41
|
+
timeLabel?: string;
|
|
42
|
+
testID?: string;
|
|
43
|
+
style?: StyleProp<ViewStyle>;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A date and time picker. On iOS UIDatePicker of iOS 27.2: `compact`, the date and the time in two capsules 8 apart
|
|
47
|
+
* (34 tall, 12 in, the secondary soft fill, the text in the accent while open) that open the month's calendar and the
|
|
48
|
+
* time's wheels in the glass popover, at most 32 from the screen's edge; `inline`, the calendar in place (a Time row
|
|
49
|
+
* under it for both); `wheels`, the wheels. On Android Material 3's pickers: the value as a row's value in the accent
|
|
50
|
+
* (or an outlined field with its icon) that opens the date picker dialog (the headline date over the month) or the
|
|
51
|
+
* time picker dial, both applied with OK; `inline` the calendar in place, `wheels` Android's spinners. The value is a
|
|
52
|
+
* plain `Date`; `min` and `max` bound it.
|
|
53
|
+
*/
|
|
54
|
+
export declare function DatePicker({ value, onChange, mode, display, min, max, locale, weekStartsOn, hour12, placeholder, disabled, "aria-label": ariaLabel, dateTitle, timeTitle, cancelLabel, okLabel, timeLabel, testID, style, }: DatePickerProps): import("react").JSX.Element;
|
|
55
|
+
export declare namespace DatePicker {
|
|
56
|
+
var displayName: string;
|
|
57
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type TimeDialProps = {
|
|
2
|
+
hours: number;
|
|
3
|
+
minutes: number;
|
|
4
|
+
onChange: (hours: number, minutes: number) => void;
|
|
5
|
+
hour12: boolean;
|
|
6
|
+
locale?: string;
|
|
7
|
+
/** The header over the time ("Select time"). */
|
|
8
|
+
title: string;
|
|
9
|
+
hoursLabel?: string;
|
|
10
|
+
minutesLabel?: string;
|
|
11
|
+
testID?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Android's time picker dial (Material 3 TimePicker): "Select time" in Medium 12, the hour and the minute in Regular
|
|
15
|
+
* 57 boxes 96 by 80 (the one being set in the primary container, the other in the highest surface container), AM and
|
|
16
|
+
* PM stacked beside them on a 12-hour clock, and the 256dp dial: a 48dp knob in the primary color on a line from the
|
|
17
|
+
* middle, the numbers 101dp out (a 24-hour clock adds 00 and 13–23 69dp out). A tap or a drag on the dial sets the
|
|
18
|
+
* hour, then it turns to the minutes.
|
|
19
|
+
*/
|
|
20
|
+
export declare function TimeDial({ hours, minutes, onChange, hour12, locale, title, hoursLabel, minutesLabel, testID }: TimeDialProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type WheelItem = {
|
|
2
|
+
label: string;
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type WheelColumn = {
|
|
6
|
+
key: string;
|
|
7
|
+
items: WheelItem[];
|
|
8
|
+
/** The item at the band. */
|
|
9
|
+
index: number;
|
|
10
|
+
onChange: (index: number) => void;
|
|
11
|
+
/** The column's width. */
|
|
12
|
+
width: number;
|
|
13
|
+
/** The column's name, read by a screen reader ("Hours"). */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Where its labels stand in the column. @default "center" */
|
|
16
|
+
align?: "start" | "center" | "end";
|
|
17
|
+
/** The labels' inset from the column's side they stand at. @default 4 */
|
|
18
|
+
inset?: number;
|
|
19
|
+
};
|
|
20
|
+
export type WheelsProps = {
|
|
21
|
+
columns: WheelColumn[];
|
|
22
|
+
/** The wheels' height. @default 202 on iOS (a compact time picker's popover), 144 on Android */
|
|
23
|
+
height?: number;
|
|
24
|
+
/** iOS: the band's inset from the wheels' sides. @default 20 */
|
|
25
|
+
bandInset?: number;
|
|
26
|
+
/** Takes no turns, presses or keys. */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
testID?: string;
|
|
29
|
+
};
|
|
30
|
+
/** iOS: a row of UIDatePicker's wheels, 32 apart (the band of iOS 27.2, 32 tall). Android: a NumberPicker's 48dp rows. */
|
|
31
|
+
export declare const IOS_WHEEL_ROW = 32;
|
|
32
|
+
export declare const ANDROID_WHEEL_ROW = 48;
|
|
33
|
+
/**
|
|
34
|
+
* The wheels of a time (or date) picker. On iOS UIDatePicker's `.wheels` as iOS 27.2 draws them in a compact time
|
|
35
|
+
* picker's popover: rows 32 apart in Regular 22, a 32 band of the ink at 7% across the columns 20 in from the sides,
|
|
36
|
+
* the rows on the band in the ink and the others in its 35% gray, turning away like a cylinder's. On Android the
|
|
37
|
+
* spinner mode of its DatePicker and TimePicker: three 48dp rows, the middle one between two lines in the ink, the
|
|
38
|
+
* others faded. A wheel stops on a row; a tap on a row turns it there; VoiceOver and TalkBack turn it one row at a time.
|
|
39
|
+
*/
|
|
40
|
+
export declare function Wheels({ columns, height: heightProp, bandInset, disabled, testID }: WheelsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Date helpers of DatePicker: plain `Date`s in the device's time zone, days compared by their calendar date. */
|
|
2
|
+
export declare function sameDay(a: Date | null | undefined, b: Date | null | undefined): boolean;
|
|
3
|
+
export declare function startOfDay(date: Date): Date;
|
|
4
|
+
/** The first day of the month `offset` months from `date`'s. */
|
|
5
|
+
export declare function monthOf(date: Date, offset?: number): Date;
|
|
6
|
+
/** A day lies outside `min`…`max` (compared by calendar day). */
|
|
7
|
+
export declare function dayOutside(day: Date, min?: Date, max?: Date): boolean;
|
|
8
|
+
/** A moment lies outside `min`…`max` (compared to the minute). */
|
|
9
|
+
export declare function timeOutside(date: Date, min?: Date, max?: Date): boolean;
|
|
10
|
+
/** The date kept inside `min`…`max`. */
|
|
11
|
+
export declare function clampDate(date: Date, min?: Date, max?: Date): Date;
|
|
12
|
+
/** The weeks of a month, each of seven days; days of the months around it are `null`. */
|
|
13
|
+
export declare function monthWeeks(month: Date, weekStartsOn: number): (Date | null)[][];
|
|
14
|
+
/** `value` on `day`: its time kept, the start of the day when there is no value yet. */
|
|
15
|
+
export declare function withDay(value: Date | null, day: Date): Date;
|
|
16
|
+
/** `value` at `hours`:`minutes`, today when there is no value yet. */
|
|
17
|
+
export declare function withTime(value: Date | null, hours: number, minutes: number): Date;
|
|
18
|
+
/** The day a week starts on in the locale (0 Sunday … 6 Saturday), from `Intl.Locale`'s week info; Monday without it. */
|
|
19
|
+
export declare function localeWeekStart(locale?: string): number;
|
|
20
|
+
/** The locale reads time on a 12-hour clock. */
|
|
21
|
+
export declare function localeHour12(locale?: string): boolean;
|
|
22
|
+
/** The date as a compact picker shows it: "13 Nov 2026" (iOS) or "Nov 13, 2026", by the locale. */
|
|
23
|
+
export declare function formatDate(date: Date, locale?: string): string;
|
|
24
|
+
/** The time: "09:00", or "9:00 AM" on a 12-hour clock. */
|
|
25
|
+
export declare function formatTime(date: Date, locale: string | undefined, hour12: boolean): string;
|
|
26
|
+
/** The month's title: "November 2026". */
|
|
27
|
+
export declare function formatMonth(month: Date, locale?: string): string;
|
|
28
|
+
/** Android's dialog headline: "Tue, Nov 24". */
|
|
29
|
+
export declare function formatHeadline(date: Date, locale?: string): string;
|
|
30
|
+
/** A day on a date-and-time wheel: "Wed Nov 25". */
|
|
31
|
+
export declare function formatWheelDay(date: Date, locale?: string): string;
|
|
32
|
+
/** A day read out in full: "Tuesday, 24 November 2026". */
|
|
33
|
+
export declare function formatFullDay(date: Date, locale?: string): string;
|
|
34
|
+
/** The weekdays' labels from `weekStartsOn`: "MON" (`short`, iOS) or "M" (`narrow`, Android). */
|
|
35
|
+
export declare function weekdayLabels(locale: string | undefined, weekStartsOn: number, width: "short" | "narrow"): {
|
|
36
|
+
label: string;
|
|
37
|
+
name: string;
|
|
38
|
+
}[];
|
|
39
|
+
/** The month names of the locale, January first. */
|
|
40
|
+
export declare function monthNames(locale?: string): string[];
|
|
41
|
+
/** The order of day, month and year in the locale's dates, for the date wheels. */
|
|
42
|
+
export declare function dateOrder(locale?: string): ("day" | "month" | "year")[];
|
|
43
|
+
/** The locale's day period labels: ["AM", "PM"]. */
|
|
44
|
+
export declare function periodLabels(locale?: string): [string, string];
|
|
45
|
+
export declare const pad2: (value: number) => string;
|
|
@@ -57,5 +57,23 @@ export type ChoiceDialogProps = {
|
|
|
57
57
|
* Select's picker on Android; not part of the public API.
|
|
58
58
|
*/
|
|
59
59
|
export declare function ChoiceDialog({ open, onClose, title, cancelLabel, okLabel, onOk, children, listProps, testID }: ChoiceDialogProps): import("react").JSX.Element;
|
|
60
|
+
export type PickerDialogProps = {
|
|
61
|
+
open: boolean;
|
|
62
|
+
onClose: () => void;
|
|
63
|
+
/** Applies the choice and closes the dialog. */
|
|
64
|
+
onOk: () => void;
|
|
65
|
+
cancelLabel: string;
|
|
66
|
+
okLabel: string;
|
|
67
|
+
/** The dialog's name for a screen reader. */
|
|
68
|
+
label?: string;
|
|
69
|
+
/** The picker, across the dialog's whole width (its own header in it). */
|
|
70
|
+
children: ReactNode;
|
|
71
|
+
testID?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Android's picker dialog: the dialog's panel holding a picker of its own (Material 3's date picker or time picker
|
|
75
|
+
* dial), Cancel and OK at the end. DatePicker's dialog on Android; not part of the public API.
|
|
76
|
+
*/
|
|
77
|
+
export declare function PickerDialog({ open, onClose, onOk, cancelLabel, okLabel, label, children, testID }: PickerDialogProps): import("react").JSX.Element;
|
|
60
78
|
/** The background of an Android dialog: white, a dark gray in dark mode. */
|
|
61
79
|
export declare const androidDialogBackground: (theme: Theme) => string;
|
|
@@ -23,3 +23,9 @@ export declare const MaterialCheckSymbol: import("./createIcon").IconComponent;
|
|
|
23
23
|
* `abc_ic_ab_back_material` that Settings' toolbar shows); it is mirrored right to left.
|
|
24
24
|
*/
|
|
25
25
|
export declare const MaterialArrowBack: import("./createIcon").IconComponent;
|
|
26
|
+
/** Material Symbols' chevron_left and chevron_right (24, the outlined weight 400): a month's arrows in the date picker. */
|
|
27
|
+
export declare const MaterialChevronLeft: import("./createIcon").IconComponent;
|
|
28
|
+
export declare const MaterialChevronRight: import("./createIcon").IconComponent;
|
|
29
|
+
/** Material Symbols' calendar_today and schedule (24, outlined weight 400): the trailing icons of a date and a time field. */
|
|
30
|
+
export declare const MaterialCalendarToday: import("./createIcon").IconComponent;
|
|
31
|
+
export declare const MaterialSchedule: import("./createIcon").IconComponent;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export { OTPInput, type OTPInputProps } from "./components/OTPInput/OTPInput";
|
|
|
25
25
|
export { Select, type SelectOption, type SelectProps } from "./components/Select/Select";
|
|
26
26
|
export { Menu, type MenuContentProps, type MenuItemProps, type MenuProps } from "./components/Menu/Menu";
|
|
27
27
|
export { ContextMenu, type ContextMenuContentProps, type ContextMenuProps } from "./components/ContextMenu/ContextMenu";
|
|
28
|
+
export { DatePicker, type DatePickerDisplay, type DatePickerMode, type DatePickerProps } from "./components/DatePicker/DatePicker";
|
|
28
29
|
export { ActionSheet, type ActionSheetAction, type ActionSheetProps } from "./components/ActionSheet/ActionSheet";
|
|
29
30
|
export { BottomSheet, type BottomSheetFooterProps, type BottomSheetProps } from "./components/BottomSheet/BottomSheet";
|
|
30
31
|
export { Dialog, type DialogAction, type DialogProps } from "./components/Dialog/Dialog";
|
package/package.json
CHANGED