@plexui/react-native 0.2.4 → 0.2.6

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 (40) hide show
  1. package/dist/es/components/Badge/Badge.js +10 -0
  2. package/dist/es/components/DatePicker/Calendar.js +112 -0
  3. package/dist/es/components/DatePicker/DatePicker.js +335 -0
  4. package/dist/es/components/DatePicker/TimeDial.js +123 -0
  5. package/dist/es/components/DatePicker/Wheel.js +164 -0
  6. package/dist/es/components/DatePicker/dates.js +147 -0
  7. package/dist/es/components/Dialog/Dialog.js +21 -0
  8. package/dist/es/components/Icon/material.js +16 -0
  9. package/dist/es/components/PageControl/PageControl.js +49 -22
  10. package/dist/es/components/ScrollEdge/ScrollEdge.js +27 -0
  11. package/dist/es/components/TabBar/TabBar.js +16 -13
  12. package/dist/es/index.js +2 -0
  13. package/dist/es/internal/BarBackdrop.js +54 -0
  14. package/dist/types/components/Badge/Badge.d.ts +1 -1
  15. package/dist/types/components/DatePicker/Calendar.d.ts +29 -0
  16. package/dist/types/components/DatePicker/DatePicker.d.ts +57 -0
  17. package/dist/types/components/DatePicker/TimeDial.d.ts +20 -0
  18. package/dist/types/components/DatePicker/Wheel.d.ts +40 -0
  19. package/dist/types/components/DatePicker/dates.d.ts +45 -0
  20. package/dist/types/components/Dialog/Dialog.d.ts +18 -0
  21. package/dist/types/components/Icon/material.d.ts +6 -0
  22. package/dist/types/components/PageControl/PageControl.d.ts +12 -1
  23. package/dist/types/components/ScrollEdge/ScrollEdge.d.ts +19 -0
  24. package/dist/types/components/TabBar/TabBar.d.ts +14 -4
  25. package/dist/types/index.d.ts +3 -1
  26. package/dist/types/internal/BarBackdrop.d.ts +9 -0
  27. package/package.json +1 -1
  28. package/src/components/Badge/Badge.tsx +9 -1
  29. package/src/components/DatePicker/Calendar.tsx +227 -0
  30. package/src/components/DatePicker/DatePicker.tsx +608 -0
  31. package/src/components/DatePicker/TimeDial.tsx +201 -0
  32. package/src/components/DatePicker/Wheel.tsx +247 -0
  33. package/src/components/DatePicker/dates.ts +161 -0
  34. package/src/components/Dialog/Dialog.tsx +46 -0
  35. package/src/components/Icon/material.ts +18 -0
  36. package/src/components/PageControl/PageControl.tsx +71 -24
  37. package/src/components/ScrollEdge/ScrollEdge.tsx +48 -0
  38. package/src/components/TabBar/TabBar.tsx +33 -15
  39. package/src/index.ts +3 -0
  40. package/src/internal/BarBackdrop.tsx +73 -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
+ ]);
@@ -46,7 +46,7 @@ const SCRUB_THRESHOLD = 8;
46
46
  * page and back as it moves), in a 48dp target, with no capsule at all. For a screen reader it is adjustable: swipe
47
47
  * up or down for the next or previous page.
48
48
  */
49
- export function PageControl({ count, value: valueProp, defaultValue = 0, onChange, background = "automatic", indicator = "dots", tone = "default", valueText = defaultValueText, "aria-label": ariaLabel = "Pages", testID, style, }) {
49
+ export function PageControl({ count, value: valueProp, defaultValue = 0, onChange, background = "automatic", indicator = "dots", tone = "default", direction = "horizontal", size = "md", valueText = defaultValueText, "aria-label": ariaLabel = "Pages", testID, style, }) {
50
50
  const theme = useTheme();
51
51
  const [own, setOwn] = useState(defaultValue);
52
52
  const current = clampIndex(valueProp ?? own, count);
@@ -62,25 +62,32 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
62
62
  onChange?.(next, { scrubbing });
63
63
  };
64
64
  const android = theme.isAndroid;
65
- const dot = android ? ANDROID_DOT : theme.length("--page-control-dot-size", 8);
66
- const gap = android ? ANDROID_GAP : theme.length("--page-control-gap", 8);
67
- const padding = theme.length("--page-control-padding-inline", 12);
65
+ const small = size === "sm";
66
+ const vertical = direction === "vertical";
67
+ const dot = small ? (android ? 4 : 5) : android ? ANDROID_DOT : theme.length("--page-control-dot-size", 8);
68
+ const gap = small ? 4 : android ? ANDROID_GAP : theme.length("--page-control-gap", 8);
69
+ const padding = small ? 6 : theme.length("--page-control-padding-inline", 12);
68
70
  const pitch = dot + gap;
69
71
  // Android draws every page's dot at full size; the iOS kit shrinks the ends from seven pages
70
72
  const sizes = android ? Array.from({ length: Math.max(0, count) }, () => "full") : pageControlDots(count, current);
71
- const dotSize = (size) => size === "full" ? dot : android ? (size === "small" ? 4 : 3) : size === "small" ? theme.length("--page-control-dot-size-small", 6) : theme.length("--page-control-dot-size-smaller", 4);
73
+ // The small and smaller ends keep their share of a full dot (6 and 4 of 8 on iOS)
74
+ const dotSize = (kind) => kind === "full"
75
+ ? dot
76
+ : android
77
+ ? Math.max(2, dot - (kind === "small" ? 1 : 2))
78
+ : (dot / 8) * (kind === "small" ? theme.length("--page-control-dot-size-small", 6) : theme.length("--page-control-dot-size-smaller", 4));
72
79
  const pill = indicator === "pill";
73
- // A pill: the current page two and a half dots wide
74
- const dotWidth = (size, index) => (pill && index === current ? dot * 2.5 : dotSize(size));
80
+ // A pill: the current page two and a half dots long (18 at `sm`), along the direction
81
+ const dotWidth = (kind, index) => (pill && index === current ? (small ? 14 : dot * 2.5) : dotSize(kind));
75
82
  // The center of the current dot, for a tap on either side of it
76
83
  let x = padding;
77
84
  let currentCenter = padding;
78
- sizes.forEach((size, index) => {
79
- if (size === "hidden")
85
+ sizes.forEach((kind, index) => {
86
+ if (kind === "hidden")
80
87
  return;
81
88
  if (index === current)
82
- currentCenter = x + dotWidth(size, index) / 2;
83
- x += dotWidth(size, index) + gap;
89
+ currentCenter = x + dotWidth(kind, index) / 2;
90
+ x += dotWidth(kind, index) + gap;
84
91
  });
85
92
  const onColor = tone === "onColor";
86
93
  const on = onColor ? "#FFFFFF" : android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text);
@@ -89,7 +96,7 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
89
96
  // Android's current dot is drawn over the gray ones (it stretches between pages); a pill is a dot of its own
90
97
  const worm = android && !pill;
91
98
  // Android draws no capsule, not even for `prominent`
92
- const capsuleHeight = theme.length("--page-control-height", 24);
99
+ const capsuleHeight = small ? 16 : theme.length("--page-control-height", 24);
93
100
  const target = android ? 48 : theme.length("--page-control-target-size", 44);
94
101
  const showBackground = !android && (background === "prominent" || (background === "automatic" && press != null));
95
102
  const text = valueText(current, count);
@@ -99,7 +106,7 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
99
106
  onKeyDown: (raw) => {
100
107
  const event = raw;
101
108
  // The dots run from the right in a right-to-left row: the left arrow goes on to the next page
102
- const ahead = isRTL(event.currentTarget) ? -1 : 1;
109
+ const ahead = !vertical && isRTL(event.currentTarget) ? -1 : 1;
103
110
  const to = { ArrowRight: current + ahead, ArrowDown: current + 1, ArrowLeft: current - ahead, ArrowUp: current - 1, Home: 0, End: count - 1 };
104
111
  if (!(event.key in to))
105
112
  return;
@@ -111,29 +118,46 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
111
118
  const onMove = (event) => {
112
119
  if (!press || background === "minimal")
113
120
  return;
114
- const dx = (event.nativeEvent.locationX - press.startX) * (press.rtl ? -1 : 1);
121
+ const dx = ((vertical ? event.nativeEvent.locationY : event.nativeEvent.locationX) - press.startX) * (press.rtl ? -1 : 1);
115
122
  if (!press.scrubbing && Math.abs(dx) < SCRUB_THRESHOLD)
116
123
  return;
117
124
  if (!press.scrubbing)
118
125
  setPress({ ...press, scrubbing: true });
119
126
  go(press.startIndex + Math.round(dx / pitch), true);
120
127
  };
121
- return (_jsx(View, { ...keys, accessible: true, accessibilityRole: "adjustable", accessibilityLabel: ariaLabel, accessibilityValue: { min: 1, max: count, now: current + 1, text }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => go(current + (event.nativeEvent.actionName === "increment" ? 1 : -1)), "aria-valuemin": 1, "aria-valuemax": count, "aria-valuenow": current + 1, "aria-valuetext": text, onStartShouldSetResponder: () => count > 1, onResponderTerminationRequest: () => !press?.scrubbing, onResponderGrant: (event) => setPress({ startX: event.nativeEvent.locationX, startIndex: current, scrubbing: false, rtl: isRTL(event.currentTarget) }), onResponderMove: onMove, onResponderRelease: (event) => {
128
+ return (_jsx(View, { ...keys, accessible: true, accessibilityRole: "adjustable", accessibilityLabel: ariaLabel, accessibilityValue: { min: 1, max: count, now: current + 1, text }, accessibilityActions: [{ name: "increment" }, { name: "decrement" }], onAccessibilityAction: (event) => go(current + (event.nativeEvent.actionName === "increment" ? 1 : -1)), "aria-valuemin": 1, "aria-valuemax": count, "aria-valuenow": current + 1, "aria-valuetext": text, onStartShouldSetResponder: () => count > 1, onResponderTerminationRequest: () => !press?.scrubbing, onResponderGrant: (event) => setPress({ startX: vertical ? event.nativeEvent.locationY : event.nativeEvent.locationX, startIndex: current, scrubbing: false, rtl: !vertical && isRTL(event.currentTarget) }), onResponderMove: onMove, onResponderRelease: (event) => {
122
129
  // A tap on the leading side of the current dot goes back, on the trailing side forward; the dots are laid
123
130
  // from the capsule's start, its right edge in a right-to-left row
124
- const x = event.nativeEvent.locationX;
131
+ const x = vertical ? event.nativeEvent.locationY : event.nativeEvent.locationX;
125
132
  const fromStart = press?.rtl ? capsule.x + capsule.width - x : x - capsule.x;
126
133
  if (press && !press.scrubbing)
127
134
  go(current + (fromStart < currentCenter ? -1 : 1));
128
135
  setPress(null);
129
136
  }, onResponderTerminate: () => setPress(null), testID: testID,
130
137
  // The target (44pt, 48dp on Android) reaches past the 24pt capsule without taking room, as the web's control
131
- // lays out at the capsule's height
132
- style: [styles.target, { minHeight: target, marginVertical: -(target - capsuleHeight) / 2 }, style], children: _jsxs(View, { pointerEvents: "none", onLayout: (event) => setCapsule({ x: event.nativeEvent.layout.x, width: event.nativeEvent.layout.width }), style: [
138
+ // lays out at the capsule's height,
139
+ style: [
140
+ styles.target,
141
+ // and is never shorter than that along the dots either (two small dots), the capsule centred in it
142
+ vertical
143
+ ? { minWidth: target, minHeight: target, justifyContent: "center", marginHorizontal: -(target - capsuleHeight) / 2 }
144
+ : { minHeight: target, minWidth: target, justifyContent: "center", marginVertical: -(target - capsuleHeight) / 2 },
145
+ style,
146
+ ], children: _jsxs(View, { pointerEvents: "none", onLayout: (event) => {
147
+ const { x: left, y: top, width, height } = event.nativeEvent.layout;
148
+ setCapsule(vertical ? { x: top, width: height } : { x: left, width });
149
+ }, style: [
133
150
  styles.capsule,
134
- { height: capsuleHeight, paddingHorizontal: padding, gap, borderRadius: capsuleHeight / 2 },
151
+ vertical
152
+ ? { flexDirection: "column", width: capsuleHeight, paddingVertical: padding, gap, borderRadius: capsuleHeight / 2 }
153
+ : { height: capsuleHeight, paddingHorizontal: padding, gap, borderRadius: capsuleHeight / 2 },
135
154
  showBackground ? { backgroundColor: onColor ? "rgba(255, 255, 255, 0.2)" : theme.color("--page-control-background") } : null,
136
- ], children: [sizes.map((size, index) => size === "hidden" ? null : (_jsx(View, { style: { width: dotWidth(size, index), height: dotSize(size), borderRadius: dot / 2, backgroundColor: index === current && !worm ? on : off } }, index))), worm ? _jsx(AndroidCurrent, { start: currentCenter - dot / 2, color: on, reduced: theme.reducedMotion }) : null] }) }));
155
+ ], children: [sizes.map((size, index) => size === "hidden" ? null : (_jsx(View, { style: {
156
+ width: vertical ? dotSize(size) : dotWidth(size, index),
157
+ height: vertical ? dotWidth(size, index) : dotSize(size),
158
+ borderRadius: dot / 2,
159
+ backgroundColor: index === current && !worm ? on : off,
160
+ } }, index))), worm ? _jsx(AndroidCurrent, { start: currentCenter - dot / 2, color: on, reduced: theme.reducedMotion, dot: dot, vertical: vertical }) : null] }) }));
137
161
  }
138
162
  /** Android's page dots: 5dp, 11dp from one to the next. */
139
163
  const ANDROID_DOT = 5;
@@ -148,7 +172,7 @@ const WORM_SETTLE = { duration: 200, easing: curves.easeOutQuint };
148
172
  * one. On a change the far edge is on the new page at once and the near edge follows it through the settle, as when
149
173
  * the pages' scroll draws the dot.
150
174
  */
151
- function AndroidCurrent({ start, color, reduced }) {
175
+ function AndroidCurrent({ start, color, reduced, dot, vertical }) {
152
176
  const [head] = useState(() => new Animated.Value(start));
153
177
  const [tail] = useState(() => new Animated.Value(start));
154
178
  const first = useRef(true);
@@ -168,7 +192,10 @@ function AndroidCurrent({ start, color, reduced }) {
168
192
  // `start` keeps it on the dots' side in a right-to-left row
169
193
  const span = Animated.subtract(head, tail).interpolate({ inputRange: [-1000, 0, 1000], outputRange: [1000, 0, 1000] });
170
194
  const left = Animated.multiply(Animated.subtract(Animated.add(head, tail), span), 0.5);
171
- return (_jsx(Animated.View, { style: { position: "absolute", top: "50%", marginTop: -ANDROID_DOT / 2, start: left, height: ANDROID_DOT, borderRadius: ANDROID_DOT / 2, backgroundColor: color, width: Animated.add(span, ANDROID_DOT) } }));
195
+ const length = Animated.add(span, dot);
196
+ return (_jsx(Animated.View, { style: vertical
197
+ ? { position: "absolute", left: "50%", marginLeft: -dot / 2, top: left, width: dot, borderRadius: dot / 2, backgroundColor: color, height: length }
198
+ : { position: "absolute", top: "50%", marginTop: -dot / 2, start: left, height: dot, borderRadius: dot / 2, backgroundColor: color, width: length } }));
172
199
  }
173
200
  const styles = StyleSheet.create({
174
201
  target: { alignSelf: "center", alignItems: "center", justifyContent: "center" },
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Platform, View } from "react-native";
3
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
4
+ import { SoftBottomVeil, SoftTopEdge } from "../../internal/BarBackdrop";
5
+ import { useTheme } from "../../theme/ThemeProvider";
6
+ /**
7
+ * The soft scroll edge of a screen with no bar at that edge: content that scrolls up under the clock and the status
8
+ * icons, or down to the screen's bottom, is muted there. On iOS it is iOS 27.2's soft edge of a bottom bar (as
9
+ * TabBar's `fade`), turned over at the top: from the safe area's edge 34pt further in, a 10pt blur under a veil of
10
+ * the screen's color that grows to 46% at the screen's edge. On Android the top edge is the soft edge of its top bar
11
+ * over the status bar alone, the bottom one draws nothing. Lay it over the screen, after the scroll view.
12
+ */
13
+ export function ScrollEdge({ edge = "top", scrolled = false, canvasColor, testID, style }) {
14
+ const theme = useTheme();
15
+ const insets = useSafeAreaInsets();
16
+ const canvas = canvasColor ?? theme.colors.background;
17
+ const top = edge === "top";
18
+ if (top && !scrolled)
19
+ return null;
20
+ if (theme.isAndroid) {
21
+ if (!top)
22
+ return null;
23
+ return (_jsx(View, { pointerEvents: "none", testID: testID, style: [{ position: "absolute", top: 0, left: 0, right: 0, height: insets.top }, style], children: _jsx(SoftTopEdge, { fill: canvas, blur: Platform.OS === "web" ? 6 : 0 }) }));
24
+ }
25
+ // The safe area at that edge; the veil reaches 34 past it, into the screen
26
+ return (_jsx(View, { pointerEvents: "none", testID: testID, style: [{ position: "absolute", left: 0, right: 0 }, top ? { top: 0, height: insets.top } : { bottom: 0, height: insets.bottom }, style], children: top ? _jsx(SoftBottomVeil, { fill: canvas, bottom: insets.top }) : _jsx(SoftBottomVeil, { fill: canvas, top: 0 }) }));
27
+ }