@plexui/react-native 0.1.1 → 0.2.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 (149) hide show
  1. package/README.md +34 -0
  2. package/dist/es/components/ActionSheet/ActionSheet.js +53 -19
  3. package/dist/es/components/Alert/Alert.js +163 -0
  4. package/dist/es/components/Avatar/Avatar.js +20 -8
  5. package/dist/es/components/BottomActions/BottomActions.js +34 -0
  6. package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
  7. package/dist/es/components/Button/Button.js +108 -28
  8. package/dist/es/components/Card/Card.js +16 -8
  9. package/dist/es/components/Checkbox/Checkbox.js +67 -99
  10. package/dist/es/components/Chip/Chip.js +16 -7
  11. package/dist/es/components/Dialog/Dialog.js +38 -24
  12. package/dist/es/components/Field/Field.js +91 -0
  13. package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
  14. package/dist/es/components/Icon/createIcon.js +13 -2
  15. package/dist/es/components/Indicator/CircularProgress.js +80 -0
  16. package/dist/es/components/Indicator/LoadingDots.js +46 -0
  17. package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
  18. package/dist/es/components/Indicator/index.js +3 -0
  19. package/dist/es/components/Input/Input.js +69 -60
  20. package/dist/es/components/InputGroup/InputGroup.js +130 -0
  21. package/dist/es/components/List/List.js +175 -59
  22. package/dist/es/components/Menu/Menu.js +69 -40
  23. package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
  24. package/dist/es/components/OTPInput/OTPInput.js +9 -3
  25. package/dist/es/components/PageControl/PageControl.js +13 -7
  26. package/dist/es/components/Popover/Popover.js +128 -0
  27. package/dist/es/components/Progress/Progress.js +142 -0
  28. package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
  29. package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
  30. package/dist/es/components/Select/Select.js +97 -34
  31. package/dist/es/components/Separator/Separator.js +31 -0
  32. package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
  33. package/dist/es/components/Stepper/Stepper.js +219 -0
  34. package/dist/es/components/Switch/Switch.js +26 -12
  35. package/dist/es/components/TagInput/TagInput.js +121 -0
  36. package/dist/es/components/Text/Text.js +7 -4
  37. package/dist/es/components/TextLink/TextLink.js +42 -0
  38. package/dist/es/components/Textarea/Textarea.js +12 -0
  39. package/dist/es/components/Tip/Tip.js +193 -0
  40. package/dist/es/components/Toolbar/Toolbar.js +6 -2
  41. package/dist/es/components/Tooltip/Tooltip.js +272 -0
  42. package/dist/es/index.js +20 -2
  43. package/dist/es/internal/FloatingPanel.js +111 -0
  44. package/dist/es/internal/fieldStack.js +73 -0
  45. package/dist/es/internal/floating.js +97 -0
  46. package/dist/es/internal/ripple.js +119 -0
  47. package/dist/es/internal/row.js +2 -1
  48. package/dist/es/internal/transition.js +113 -0
  49. package/dist/es/theme/ThemeProvider.js +41 -9
  50. package/dist/es/theme/material.js +37 -7
  51. package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
  52. package/dist/types/components/Alert/Alert.d.ts +51 -0
  53. package/dist/types/components/Avatar/Avatar.d.ts +4 -2
  54. package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
  55. package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
  56. package/dist/types/components/Button/Button.d.ts +20 -5
  57. package/dist/types/components/Card/Card.d.ts +14 -1
  58. package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
  59. package/dist/types/components/Chip/Chip.d.ts +12 -1
  60. package/dist/types/components/Dialog/Dialog.d.ts +9 -5
  61. package/dist/types/components/Field/Field.d.ts +64 -0
  62. package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
  63. package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
  64. package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
  65. package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
  66. package/dist/types/components/Indicator/index.d.ts +3 -0
  67. package/dist/types/components/Input/Input.d.ts +13 -3
  68. package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
  69. package/dist/types/components/List/List.d.ts +57 -14
  70. package/dist/types/components/Menu/Menu.d.ts +4 -0
  71. package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
  72. package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
  73. package/dist/types/components/PageControl/PageControl.d.ts +11 -1
  74. package/dist/types/components/Popover/Popover.d.ts +86 -0
  75. package/dist/types/components/Progress/Progress.d.ts +56 -0
  76. package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
  77. package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
  78. package/dist/types/components/Select/Select.d.ts +36 -8
  79. package/dist/types/components/Separator/Separator.d.ts +19 -0
  80. package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
  81. package/dist/types/components/Stepper/Stepper.d.ts +61 -0
  82. package/dist/types/components/Switch/Switch.d.ts +5 -5
  83. package/dist/types/components/TagInput/TagInput.d.ts +44 -0
  84. package/dist/types/components/TextLink/TextLink.d.ts +30 -0
  85. package/dist/types/components/Textarea/Textarea.d.ts +19 -0
  86. package/dist/types/components/Tip/Tip.d.ts +71 -0
  87. package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
  88. package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
  89. package/dist/types/index.d.ts +20 -2
  90. package/dist/types/internal/FloatingPanel.d.ts +70 -0
  91. package/dist/types/internal/fieldStack.d.ts +48 -0
  92. package/dist/types/internal/floating.d.ts +71 -0
  93. package/dist/types/internal/ripple.d.ts +17 -0
  94. package/dist/types/internal/row.d.ts +15 -3
  95. package/dist/types/internal/transition.d.ts +37 -0
  96. package/dist/types/theme/ThemeProvider.d.ts +28 -4
  97. package/dist/types/theme/material.d.ts +20 -6
  98. package/dist/types/theme/types.d.ts +8 -0
  99. package/package.json +2 -2
  100. package/src/components/ActionSheet/ActionSheet.tsx +107 -38
  101. package/src/components/Alert/Alert.tsx +279 -0
  102. package/src/components/Avatar/Avatar.tsx +21 -9
  103. package/src/components/BottomActions/BottomActions.tsx +54 -0
  104. package/src/components/BottomSheet/BottomSheet.tsx +111 -25
  105. package/src/components/Button/Button.tsx +170 -35
  106. package/src/components/Card/Card.tsx +33 -9
  107. package/src/components/Checkbox/Checkbox.tsx +89 -124
  108. package/src/components/Chip/Chip.tsx +49 -6
  109. package/src/components/Dialog/Dialog.tsx +68 -37
  110. package/src/components/Field/Field.tsx +227 -0
  111. package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
  112. package/src/components/Icon/createIcon.tsx +16 -6
  113. package/src/components/Indicator/CircularProgress.tsx +141 -0
  114. package/src/components/Indicator/LoadingDots.tsx +79 -0
  115. package/src/components/Indicator/LoadingIndicator.tsx +166 -0
  116. package/src/components/Indicator/index.ts +3 -0
  117. package/src/components/Input/Input.tsx +126 -97
  118. package/src/components/InputGroup/InputGroup.tsx +261 -0
  119. package/src/components/List/List.tsx +345 -88
  120. package/src/components/Menu/Menu.tsx +83 -41
  121. package/src/components/NavigationButton/NavigationButton.tsx +35 -5
  122. package/src/components/OTPInput/OTPInput.tsx +21 -2
  123. package/src/components/PageControl/PageControl.tsx +36 -8
  124. package/src/components/Popover/Popover.tsx +261 -0
  125. package/src/components/Progress/Progress.tsx +255 -0
  126. package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
  127. package/src/components/RollingNumber/RollingNumber.tsx +189 -0
  128. package/src/components/Select/Select.tsx +175 -71
  129. package/src/components/Separator/Separator.tsx +51 -0
  130. package/src/components/ShimmerText/ShimmerText.tsx +144 -0
  131. package/src/components/Stepper/Stepper.tsx +386 -0
  132. package/src/components/Switch/Switch.tsx +26 -12
  133. package/src/components/TagInput/TagInput.tsx +227 -0
  134. package/src/components/Text/Text.tsx +8 -4
  135. package/src/components/TextLink/TextLink.tsx +77 -0
  136. package/src/components/Textarea/Textarea.tsx +23 -0
  137. package/src/components/Tip/Tip.tsx +410 -0
  138. package/src/components/Toolbar/Toolbar.tsx +27 -2
  139. package/src/components/Tooltip/Tooltip.tsx +478 -0
  140. package/src/index.ts +36 -2
  141. package/src/internal/FloatingPanel.tsx +199 -0
  142. package/src/internal/fieldStack.tsx +179 -0
  143. package/src/internal/floating.ts +131 -0
  144. package/src/internal/ripple.tsx +132 -0
  145. package/src/internal/row.ts +16 -3
  146. package/src/internal/transition.ts +124 -0
  147. package/src/theme/ThemeProvider.tsx +65 -15
  148. package/src/theme/material.ts +39 -7
  149. package/src/theme/types.ts +8 -0
@@ -0,0 +1,142 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useState } from "react";
3
+ import { Animated, Easing, Platform, StyleSheet, View } from "react-native";
4
+ import { isRTL } from "../../internal/direction";
5
+ import { curves } from "../../internal/motion";
6
+ import { cssEase, useLoopClock, useTransitionValue } from "../../internal/transition";
7
+ import { withAlpha } from "../../theme/material";
8
+ import { useTheme } from "../../theme/ThemeProvider";
9
+ /** The parts of a segmented bar, each clamped so their sum stays within `max`, and their sum. */
10
+ export const progressSegments = (segments, max) => {
11
+ let total = 0;
12
+ const parts = segments.map((segment) => {
13
+ const value = Math.max(0, Math.min(max - total, segment.value || 0));
14
+ total += value;
15
+ return { ...segment, value };
16
+ });
17
+ return { parts, total };
18
+ };
19
+ const segmentsLabel = (parts, max) => parts.map((part) => `${part.label ? `${part.label} ` : ""}${Math.round((part.value / max) * 100)}%`).join(", ");
20
+ const defaultValueLabel = (value, max) => `${Math.round((value / max) * 100)}%`;
21
+ /** The fill of a color: the Plex ink for primary (the accent on Android, as its progress bars), else the solid one. */
22
+ function fillColor(theme, color) {
23
+ if (color === "primary")
24
+ return theme.isAndroid ? theme.material.primary : theme.color("--progress-indicator-color", theme.colors.text);
25
+ return theme.color(`--color-background-${color}-solid`);
26
+ }
27
+ /** The track: `--progress-track-color` on iOS; on Android the slider's track, the ink at 8% (16% at night). */
28
+ const trackColor = (theme) => theme.isAndroid ? withAlpha(theme.material.onSurface, theme.scheme === "dark" ? 0.16 : 0.08) : theme.color("--progress-track-color");
29
+ const height = (theme, size) => size === "md" ? theme.length("--progress-height-md", 6) : size === "lg" ? theme.length("--progress-height-lg", 8) : theme.length("--progress-height", 4);
30
+ /** How a new value moves the fill: the CSS transition on iOS; Android's line progress, 300ms decelerating. */
31
+ function valueMotion(theme) {
32
+ return theme.isAndroid
33
+ ? { duration: 300, easing: curves.decelerate }
34
+ : { duration: theme.duration("--progress-transition-duration", 120), easing: cssEase };
35
+ }
36
+ /**
37
+ * A horizontal bar of a task's progress, or a sweep while its length is unknown, as @plexui/ui's Progress. iOS:
38
+ * the phone layer's tokens (`--progress-height` 4, 6, 8; `--progress-track-color`; the ink fill); a new value moves
39
+ * the fill in `--progress-transition-duration` (120ms, ease); the indeterminate sweep is 40% of the track, there and
40
+ * back in `--progress-indeterminate-duration` (1.5s, ease-in-out). Android: the Plex Android look's line progress,
41
+ * the accent on the ink at 8%, a new value in 300ms decelerating, and Material's indeterminate pair of lines (1750ms).
42
+ * A segmented bar puts its parts side by side with `--progress-segment-gap` (2) of track between them. With reduced
43
+ * motion a value lands at once and the sweep stands still in the middle.
44
+ */
45
+ export function Progress({ value = null, max = 100, segments, size = "sm", color = "primary", getValueLabel = defaultValueLabel, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, accessibilityLabel, testID, style, }) {
46
+ const theme = useTheme();
47
+ const [width, setWidth] = useState(0);
48
+ const [rtl, setRTL] = useState(false);
49
+ const onLayout = (event) => {
50
+ const next = event.nativeEvent.layout.width;
51
+ setWidth((old) => (old === next ? old : next));
52
+ const direction = isRTL(event.currentTarget);
53
+ setRTL((old) => (old === direction ? old : direction));
54
+ };
55
+ const rootMax = typeof max === "number" && max > 0 && !Number.isNaN(max) ? max : 100;
56
+ const thickness = height(theme, size);
57
+ const name = accessibilityLabel ?? ariaLabel;
58
+ let content;
59
+ let now;
60
+ let text;
61
+ if (segments) {
62
+ const { parts, total } = progressSegments(segments, rootMax);
63
+ now = total;
64
+ text = segmentsLabel(parts, rootMax);
65
+ content = (_jsx(View, { style: [styles.segments, { gap: theme.length("--progress-segment-gap", 2) }], children: parts.map((part, index) => (part.value > 0 ? _jsx(Segment, { share: part.value / rootMax, color: fillColor(theme, part.color ?? "primary"), theme: theme }, index) : null)) }));
66
+ }
67
+ else {
68
+ const resolved = value == null ? null : Math.max(0, Math.min(rootMax, value));
69
+ now = resolved ?? undefined;
70
+ text = resolved == null ? undefined : getValueLabel(resolved, rootMax);
71
+ const fill = fillColor(theme, color);
72
+ content =
73
+ resolved == null ? (theme.isAndroid ? (_jsx(AndroidSweep, { width: width, color: fill, theme: theme })) : (_jsx(Sweep, { width: width, rtl: rtl, color: fill, theme: theme }))) : (_jsx(Fill, { fraction: resolved / rootMax, width: width, rtl: rtl, color: fill, theme: theme }));
74
+ }
75
+ return (_jsx(View, { accessible: true, accessibilityRole: "progressbar", accessibilityLabel: name, accessibilityValue: now == null ? undefined : { min: 0, max: rootMax, now, text }, accessibilityState: now == null ? { busy: true } : undefined, "aria-labelledby": ariaLabelledBy, ...(Platform.OS === "web" ? { "aria-valuemin": 0, "aria-valuemax": rootMax, "aria-valuenow": now, "aria-valuetext": text } : null), testID: testID, onLayout: onLayout, style: [styles.root, { height: thickness, borderRadius: thickness / 2, backgroundColor: trackColor(theme) }, style], children: content }));
76
+ }
77
+ /** The filled part: the whole track's width, moved back by what is left (rounded at its leading end). */
78
+ function Fill({ fraction, width, rtl, color, theme }) {
79
+ const motion = valueMotion(theme);
80
+ const shown = useTransitionValue(fraction, { ...motion, native: true, reducedMotion: theme.reducedMotion });
81
+ const [span] = useState(() => new Animated.Value(width));
82
+ useEffect(() => span.setValue(width), [span, width]);
83
+ const translateX = Animated.multiply(shown.interpolate({ inputRange: [0, 1], outputRange: rtl ? [1, 0] : [-1, 0] }), span);
84
+ return (_jsx(Animated.View, { pointerEvents: "none",
85
+ // Until the track is measured the fill waits, so a first frame does not show it full
86
+ style: [StyleSheet.absoluteFill, styles.rounded, { backgroundColor: color, opacity: width > 0 ? 1 : 0, transform: [{ translateX }] }] }));
87
+ }
88
+ /** iOS's sweep: 40% of the track goes from just before its start to past its end and back, ease-in-out each way. */
89
+ function Sweep({ width, rtl, color, theme }) {
90
+ const period = theme.duration("--progress-indeterminate-duration", 1500);
91
+ const moving = !theme.reducedMotion && width > 0;
92
+ const clock = useLoopClock(period, moving, true);
93
+ const [span] = useState(() => new Animated.Value(width));
94
+ useEffect(() => span.setValue(width), [span, width]);
95
+ const half = period / 2;
96
+ // translateX of the 40% bar in its own widths: -100% → 150% → -100% (keyframes 0, 50%, 100%)
97
+ const phase = clock.interpolate({
98
+ inputRange: [0, half, period],
99
+ outputRange: [-1, 1.5, -1],
100
+ easing: curves.easeInOut,
101
+ });
102
+ const share = 0.4;
103
+ const translateX = moving ? Animated.multiply(Animated.multiply(phase, rtl ? -share : share), span) : (rtl ? -0.3 : 0.3) * width;
104
+ // With reduced motion the bar stands still in the middle
105
+ return (_jsx(Animated.View, { pointerEvents: "none", style: [styles.sweep, styles.rounded, { width: `${share * 100}%`, backgroundColor: color, opacity: width > 0 ? 1 : 0, transform: [{ translateX }] }] }));
106
+ }
107
+ /** Material's indeterminate line progress: two lines run along the track in 1750ms (Compose's keyframes). */
108
+ const LINES = [
109
+ { head: [0, 1000], tail: [250, 1000] },
110
+ { head: [650, 850], tail: [900, 850] },
111
+ ];
112
+ const LINE_PERIOD = 1750;
113
+ /** Material's emphasized accelerate curve, on which each end of a line runs. */
114
+ const emphasizedAccelerate = Easing.bezier(0.3, 0, 0.8, 0.15);
115
+ function AndroidSweep({ width, color, theme }) {
116
+ const moving = !theme.reducedMotion && width > 0;
117
+ // The lines' ends move the layout (left, width), which the native driver cannot run
118
+ const clock = useLoopClock(LINE_PERIOD, moving, false);
119
+ if (!moving) {
120
+ // With reduced motion a line stands still in the middle
121
+ return _jsx(View, { pointerEvents: "none", style: [styles.sweep, styles.rounded, { start: "30%", width: "40%", backgroundColor: color, opacity: width > 0 ? 1 : 0 }] });
122
+ }
123
+ const end = ([delay, duration]) => clock.interpolate({ inputRange: [delay, delay + duration], outputRange: [0, width], easing: emphasizedAccelerate, extrapolate: "clamp" });
124
+ return (_jsx(_Fragment, { children: LINES.map((line, index) => {
125
+ const head = end(line.head);
126
+ const tail = end(line.tail);
127
+ return _jsx(Animated.View, { pointerEvents: "none", style: [styles.sweep, styles.rounded, { start: tail, width: Animated.subtract(head, tail), backgroundColor: color }] }, index);
128
+ }) }));
129
+ }
130
+ /** A part of a segmented bar: its share of the track, which a change moves as the CSS transition of its width. */
131
+ function Segment({ share, color, theme }) {
132
+ const shown = useTransitionValue(share, { ...valueMotion(theme), reducedMotion: theme.reducedMotion });
133
+ return (_jsx(Animated.View, { pointerEvents: "none", style: [styles.segment, { width: shown.interpolate({ inputRange: [0, 1], outputRange: ["0%", "100%"] }), backgroundColor: color }] }));
134
+ }
135
+ const styles = StyleSheet.create({
136
+ root: { width: "100%", overflow: "hidden" },
137
+ rounded: { borderRadius: 9999 },
138
+ sweep: { position: "absolute", top: 0, bottom: 0, start: 0 },
139
+ segments: { flex: 1, flexDirection: "row" },
140
+ // A full bar's parts give the gaps back in proportion, so the last one is not cut off at the end
141
+ segment: { flexShrink: 1, minWidth: 0, height: "100%" },
142
+ });
@@ -0,0 +1,207 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cloneElement, createContext, isValidElement, useContext, useMemo, useState } from "react";
3
+ import { Animated, Platform, StyleSheet, View } from "react-native";
4
+ import CheckMd from "../../icons/plex/CheckMd";
5
+ import { flattenChildren, textOf } from "../../internal/children";
6
+ import { cssEasing, useColorTransition } from "../../internal/transition";
7
+ import { useTheme } from "../../theme/ThemeProvider";
8
+ import { IconDefaultsProvider } from "../Icon";
9
+ import { Text } from "../Text/Text";
10
+ const StepsContext = createContext(null);
11
+ const StepContext = createContext(null);
12
+ const useSteps = () => {
13
+ const context = useContext(StepsContext);
14
+ if (!context)
15
+ throw new Error("ProgressSteps components must be wrapped in <ProgressSteps />");
16
+ return context;
17
+ };
18
+ const metricsOf = (theme, size) => ({
19
+ indicator: theme.length(`--progress-steps-indicator-size-${size}`, { sm: 24, md: 32, lg: 40 }[size]),
20
+ rowGap: theme.length(`--progress-steps-row-gap-${size}`, { sm: 16, md: 24, lg: 32 }[size]),
21
+ contentGap: theme.length(`--progress-steps-content-gap-${size}`, { sm: 10, md: 12, lg: 16 }[size]),
22
+ font: theme.length(`--progress-steps-font-size-${size}`, { sm: 12, md: 14, lg: 16 }[size]),
23
+ icon: theme.length(`--progress-steps-icon-size-${size}`, { sm: 14, md: 16, lg: 18 }[size]),
24
+ line: theme.length("--font-text-sm-line-height", 20),
25
+ });
26
+ /**
27
+ * The colors of the steps. iOS: the tokens (the ink for completed and active steps, `--gray-100` ahead). Android: the
28
+ * Plex Android look's accent for completed and active steps on `surfaceContainerHighest`, as Material draws a filled
29
+ * selection. `color="success"` takes the solid success colors on both.
30
+ */
31
+ function colorsOf(theme, color) {
32
+ const m = theme.material;
33
+ const success = color === "success";
34
+ const successFill = theme.color("--color-background-success-solid");
35
+ const successText = theme.color("--color-text-success-solid", "#FFFFFF");
36
+ if (theme.isAndroid) {
37
+ const fill = success ? successFill : m.primary;
38
+ const onFill = success ? successText : m.onPrimary;
39
+ return {
40
+ indicator: { completed: fill, active: fill, inactive: m.surfaceContainerHighest },
41
+ indicatorText: { completed: onFill, active: onFill, inactive: m.onSurfaceVariant },
42
+ connector: m.surfaceContainerHighest,
43
+ connectorCompleted: fill,
44
+ title: m.onSurface,
45
+ titleInactive: m.onSurfaceVariant,
46
+ description: m.onSurfaceVariant,
47
+ descriptionInactive: m.onSurfaceVariant,
48
+ minimalUpcoming: m.surfaceContainerHighest,
49
+ minimalCompleted: fill,
50
+ };
51
+ }
52
+ return {
53
+ indicator: {
54
+ completed: success ? successFill : theme.color("--progress-steps-indicator-background-completed"),
55
+ active: success ? successFill : theme.color("--progress-steps-indicator-background-active"),
56
+ inactive: theme.color("--progress-steps-indicator-background"),
57
+ },
58
+ indicatorText: {
59
+ completed: success ? successText : theme.color("--progress-steps-indicator-text-completed"),
60
+ active: success ? successText : theme.color("--progress-steps-indicator-text-active"),
61
+ inactive: theme.color("--progress-steps-indicator-text"),
62
+ },
63
+ connector: theme.color("--progress-steps-connector-color"),
64
+ connectorCompleted: success ? successFill : theme.color("--progress-steps-connector-color-completed"),
65
+ title: theme.color("--progress-steps-title-color", theme.colors.text),
66
+ titleInactive: theme.color("--progress-steps-title-color-inactive"),
67
+ description: theme.color("--progress-steps-description-color"),
68
+ descriptionInactive: theme.color("--progress-steps-description-color-inactive"),
69
+ minimalUpcoming: theme.color("--progress-steps-minimal-color-upcoming"),
70
+ minimalCompleted: success ? successFill : theme.color("--progress-steps-minimal-color-completed"),
71
+ };
72
+ }
73
+ const web = Platform.OS === "web";
74
+ /**
75
+ * The steps of a multi-step flow, such as a checkout or onboarding, and the current one, as @plexui/ui's
76
+ * ProgressSteps: a numbered indicator per step (a check once completed), the connectors between them and each step's
77
+ * title and description, in a row or a column; or, with `variant="minimal"`, a bar of short segments. Neither
78
+ * platform has a control of its own, so both draw the Plex steps: iOS in the tokens (indicators 24, 32, 40; the ink
79
+ * for completed and active steps), Android in the Plex Android look's accent. A change of step fades the colors in
80
+ * `--transition-duration-basic` (120ms, ease), at once with reduced motion.
81
+ */
82
+ export function ProgressSteps({ current, total, variant = "default", color = "default", orientation = "horizontal", size = "md", connectorStyle = "solid", testID, style, children, }) {
83
+ const theme = useTheme();
84
+ const steps = flattenChildren(children).filter(isValidElement);
85
+ const minimal = variant === "minimal";
86
+ const count = minimal ? Math.max(0, total ?? 0) : steps.length;
87
+ const motion = useMemo(() => ({
88
+ duration: theme.duration("--transition-duration-basic", 120),
89
+ easing: cssEasing(theme.token("--transition-ease-basic")),
90
+ reducedMotion: theme.reducedMotion,
91
+ }), [theme]);
92
+ const colors = colorsOf(theme, color);
93
+ if (minimal) {
94
+ const key = size === "lg" ? "lg" : size === "sm" ? "sm" : "md";
95
+ const width = theme.length(`--progress-steps-minimal-width-${key}`, key === "lg" ? 32 : 24);
96
+ const height = theme.length(`--progress-steps-minimal-height-${key}`, key === "lg" ? 4 : 3);
97
+ const gap = theme.length(`--progress-steps-minimal-gap-${key}`, key === "lg" ? 6 : 4);
98
+ return (_jsx(View, { accessible: true, accessibilityRole: "progressbar", accessibilityLabel: "Progress", accessibilityValue: { min: 1, max: count, now: current }, ...(web ? { "aria-valuemin": 1, "aria-valuemax": count, "aria-valuenow": current } : null), testID: testID, style: [styles.minimal, { gap }, style], children: Array.from({ length: count }, (_, index) => (_jsx(MinimalSegment, { color: index < current ? colors.minimalCompleted : colors.minimalUpcoming, width: width, height: height, radius: theme.length("--progress-steps-minimal-radius", 9999), motion: motion }, index))) }));
99
+ }
100
+ const context = {
101
+ current,
102
+ orientation,
103
+ connectorStyle,
104
+ total: count,
105
+ metrics: metricsOf(theme, size),
106
+ colors,
107
+ connectorWidth: theme.length("--progress-steps-connector-width", 2),
108
+ dash: theme.length("--progress-steps-connector-dash-length", 4),
109
+ gap: theme.length("--progress-steps-connector-dash-gap", 4),
110
+ motion,
111
+ };
112
+ const horizontal = orientation === "horizontal";
113
+ return (_jsx(StepsContext.Provider, { value: context, children: _jsx(View, { ...(web ? { role: "navigation", "aria-label": "Progress" } : null), testID: testID, style: [styles.root, style], children: _jsx(View, { accessibilityRole: "list", style: horizontal ? [styles.row, { gap: context.metrics.rowGap }] : styles.column, children: steps.map((step, index) => cloneElement(step, { _index: index })) }) }) }));
114
+ }
115
+ function MinimalSegment({ color, width, height, radius, motion }) {
116
+ const backgroundColor = useColorTransition(color, motion);
117
+ return _jsx(Animated.View, { style: { width, height, borderRadius: Math.min(radius, height / 2), backgroundColor } });
118
+ }
119
+ /** A step: its indicator, the connector to the next step, and its title and description. */
120
+ function Step({ icon, children, _index = 0 }) {
121
+ const context = useSteps();
122
+ const { current, orientation, total, metrics, colors, motion } = context;
123
+ const state = _index < current - 1 ? "completed" : _index === current - 1 ? "active" : "inactive";
124
+ const horizontal = orientation === "horizontal";
125
+ const [width, setWidth] = useState(0);
126
+ const onLayout = horizontal ? (event) => setWidth(event.nativeEvent.layout.width) : undefined;
127
+ const background = useColorTransition(colors.indicator[state], motion);
128
+ const ink = colors.indicatorText[state];
129
+ const parts = flattenChildren(children);
130
+ const shown = parts.filter((part) => !(isValidElement(part) && part.type === Title && part.props.visuallyHidden));
131
+ const name = parts.map(textOf).filter(Boolean).join(", ");
132
+ const last = _index === total - 1;
133
+ return (_jsxs(View
134
+ // On a phone a step is read as one: its title and description; the current one as selected
135
+ , {
136
+ // On a phone a step is read as one: its title and description; the current one as selected
137
+ accessible: !web, accessibilityLabel: web ? undefined : name || String(_index + 1), accessibilityState: web ? undefined : { selected: state === "active" }, ...(web ? { role: "listitem", "aria-current": state === "active" ? "step" : undefined } : null), onLayout: onLayout, style: [
138
+ horizontal ? styles.stepHorizontal : styles.stepVertical,
139
+ { gap: metrics.contentGap, minHeight: metrics.indicator + metrics.rowGap },
140
+ ], children: [_jsx(Animated.View, { style: [styles.indicator, { width: metrics.indicator, height: metrics.indicator, borderRadius: metrics.indicator / 2, backgroundColor: background }], children: state === "completed" ? (_jsx(CheckMd, { size: metrics.font, color: ink })) : icon != null ? (_jsx(IconDefaultsProvider, { size: metrics.icon, color: ink, children: icon })) : (_jsx(Text, { weight: "medium", color: ink, style: { fontSize: metrics.font, lineHeight: Math.round(metrics.font * 1.43) }, children: _index + 1 })) }), last ? null : _jsx(Connector, { completed: state === "completed", width: width }), parts.length === 0 ? null : (_jsx(View, { style: shown.length === 0
141
+ ? styles.hidden
142
+ : horizontal
143
+ ? styles.contentHorizontal
144
+ : [styles.contentVertical, { paddingBottom: metrics.rowGap }], children: _jsx(StepContext.Provider, { value: { state, first: shown[0] }, children: parts }) }))] }));
145
+ }
146
+ /** The line from a step to the next: under the next indicator's edge, solid once completed, else as `connectorStyle`. */
147
+ function Connector({ completed, width }) {
148
+ const { orientation, connectorStyle, metrics, colors, connectorWidth, dash, gap, motion } = useSteps();
149
+ const horizontal = orientation === "horizontal";
150
+ const color = useColorTransition(completed ? colors.connectorCompleted : colors.connector, motion);
151
+ const [length, setLength] = useState(0);
152
+ const dashed = connectorStyle === "dashed" && !completed;
153
+ const place = horizontal
154
+ ? {
155
+ top: metrics.indicator / 2 - connectorWidth / 2,
156
+ start: "50%",
157
+ marginStart: metrics.indicator / 2,
158
+ width: Math.max(0, width + metrics.rowGap - metrics.indicator),
159
+ height: connectorWidth,
160
+ }
161
+ : { top: metrics.indicator, start: metrics.indicator / 2 - connectorWidth / 2, width: connectorWidth, bottom: -metrics.rowGap };
162
+ return (_jsx(Animated.View, { pointerEvents: "none", onLayout: dashed ? (event) => setLength(horizontal ? event.nativeEvent.layout.width : event.nativeEvent.layout.height) : undefined, style: [styles.connector, place, { borderRadius: connectorWidth / 2 }, dashed ? null : { backgroundColor: color }], children: dashed
163
+ ? Array.from({ length: Math.ceil(length / (dash + gap)) }, (_, index) => (_jsx(View, { style: [
164
+ styles.dash,
165
+ horizontal ? { start: index * (dash + gap), width: dash, height: connectorWidth } : { top: index * (dash + gap), height: dash, width: connectorWidth },
166
+ { backgroundColor: colors.connector },
167
+ ] }, index)))
168
+ : null }));
169
+ }
170
+ /** The title of a step: 14/20 medium, beside the indicator's middle in a column, under it in a row. */
171
+ function Title({ children, visuallyHidden = false }) {
172
+ const { orientation, metrics, colors } = useSteps();
173
+ const step = useContext(StepContext);
174
+ if (visuallyHidden) {
175
+ // On a phone the step reads its title; on the web it stays in the page for screen readers
176
+ return web ? (_jsx(View, { style: styles.visuallyHidden, children: _jsx(Text, { size: "sm", children: children }) })) : null;
177
+ }
178
+ const inactive = step?.state === "inactive";
179
+ return (_jsx(Text, { size: "sm", weight: "medium", color: inactive ? colors.titleInactive : colors.title, align: orientation === "horizontal" ? "center" : undefined, style: orientation === "horizontal" ? null : { paddingTop: (metrics.indicator - metrics.line) / 2 }, children: children }));
180
+ }
181
+ /** The description of a step: 14/20, 2 below the title (beside the indicator's middle when it stands alone). */
182
+ function Description({ children }) {
183
+ const { orientation, metrics, colors } = useSteps();
184
+ const step = useContext(StepContext);
185
+ const inactive = step?.state === "inactive";
186
+ const first = isValidElement(step?.first) && step.first.type === Description;
187
+ const horizontal = orientation === "horizontal";
188
+ return (_jsx(Text, { size: "sm", color: inactive ? colors.descriptionInactive : colors.description, align: horizontal ? "center" : undefined, style: first ? { paddingTop: horizontal ? 0 : (metrics.indicator - metrics.line) / 2 } : { marginTop: 2 }, children: children }));
189
+ }
190
+ ProgressSteps.Step = Step;
191
+ ProgressSteps.Title = Title;
192
+ ProgressSteps.Description = Description;
193
+ const styles = StyleSheet.create({
194
+ root: { width: "100%" },
195
+ row: { flexDirection: "row", width: "100%" },
196
+ column: { flexDirection: "column", width: "100%" },
197
+ stepVertical: { flexDirection: "row", alignItems: "flex-start" },
198
+ stepHorizontal: { flex: 1, flexBasis: 0, minWidth: 0, flexDirection: "column", alignItems: "center" },
199
+ indicator: { zIndex: 1, alignItems: "center", justifyContent: "center", flexShrink: 0 },
200
+ connector: { position: "absolute", overflow: "hidden" },
201
+ dash: { position: "absolute" },
202
+ contentVertical: { flex: 1, minWidth: 0 },
203
+ contentHorizontal: { width: "100%", paddingTop: 8 },
204
+ hidden: { position: "absolute", width: 1, height: 1, overflow: "hidden", opacity: 0 },
205
+ visuallyHidden: { position: "absolute", width: 1, height: 1, margin: -1, overflow: "hidden", opacity: 0 },
206
+ minimal: { flexDirection: "row" },
207
+ });
@@ -0,0 +1,125 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useLayoutEffect, useState } from "react";
3
+ import { Animated, Platform, StyleSheet, View } from "react-native";
4
+ import { curves } from "../../internal/motion";
5
+ import { cssEasing, nativeDriver, useTransitionValue } from "../../internal/transition";
6
+ import { useTheme } from "../../theme/ThemeProvider";
7
+ import { Text, textStyle } from "../Text/Text";
8
+ /** The parts of a written number, or, where the engine has no `formatToParts`, its characters read as one integer. */
9
+ function partsOf(formatter, value, glyphs) {
10
+ if (typeof formatter.formatToParts === "function")
11
+ return formatter.formatToParts(value);
12
+ return Array.from(formatter.format(value)).map((character) => ({ type: glyphs.includes(character) ? "integer" : "literal", value: character }));
13
+ }
14
+ /**
15
+ * A written number's characters, each keyed by its place around the decimal separator, so a digit keeps its reel
16
+ * when the number grows or its fraction gets longer; digits are the locale's own (Arabic-Indic, Bengali…).
17
+ */
18
+ export const rollingNumberParts = (value, locales = "en-US", format) => {
19
+ const formatter = new Intl.NumberFormat(locales, format);
20
+ const { locale, numberingSystem } = formatter.resolvedOptions();
21
+ const digitFormatter = new Intl.NumberFormat(locale, { numberingSystem, useGrouping: false });
22
+ const glyphs = Array.from({ length: 10 }, (_, digit) => digitFormatter.format(digit));
23
+ const parts = partsOf(formatter, value, glyphs);
24
+ let integers = parts.reduce((count, part) => count + (part.type === "integer" ? Array.from(part.value).length : 0), 0);
25
+ let fractions = 0;
26
+ const seen = {};
27
+ const characters = parts.flatMap((part) => Array.from(part.value).map((character) => {
28
+ const glyph = glyphs.indexOf(character);
29
+ const digit = (part.type === "integer" || part.type === "fraction") && glyph >= 0 ? glyph : null;
30
+ let key;
31
+ if (part.type === "integer")
32
+ key = `i${integers--}`;
33
+ else if (part.type === "fraction")
34
+ key = `f${++fractions}`;
35
+ else if (part.type === "group")
36
+ key = `g${integers}`;
37
+ else {
38
+ seen[part.type] = (seen[part.type] ?? 0) + 1;
39
+ key = `${part.type}${seen[part.type]}-${character}`;
40
+ }
41
+ return { character, digit, key };
42
+ }));
43
+ return { text: parts.map((part) => part.value).join(""), glyphs, characters };
44
+ };
45
+ /**
46
+ * A number whose digits roll to a new value, as an odometer, and @plexui/ui's RollingNumber: for a total, a balance, a
47
+ * count or a KPI that changes while it is watched. It takes the props of `Text` for its type and color, in tabular
48
+ * figures. iOS, as the web: each changed digit's reel of 0 to 9 turns to it in `--rolling-number-duration` (600ms) on
49
+ * `--rolling-number-ease`. Android, the Plex Android look's animated text: a changed character fades out and away by
50
+ * 0.3 of the font size while the new one comes in, in 320ms (ease-out quint), up for a larger number. With reduced
51
+ * motion it changes at once. A screen reader reads the written number.
52
+ */
53
+ export function RollingNumber({ value, locales, format, containerStyle, style, size, variant, weight, mono, testID, accessibilityLabel, ...text }) {
54
+ const theme = useTheme();
55
+ const { text: written, glyphs, characters } = rollingNumberParts(value, locales, format);
56
+ const flat = StyleSheet.flatten(style);
57
+ const base = textStyle(theme, { variant, size, weight, mono });
58
+ const lineHeight = flat?.lineHeight ?? base.lineHeight ?? 20;
59
+ const fontSize = flat?.fontSize ?? base.fontSize ?? 16;
60
+ // The direction a change moves on Android: up for a larger number
61
+ const [last, setLast] = useState({ value, up: true });
62
+ if (last.value !== value)
63
+ setLast({ value, up: value > last.value });
64
+ const glyphProps = { ...text, size, variant, weight, mono, tabularNums: true, style };
65
+ return (_jsx(View, { accessible: true, accessibilityRole: "text", accessibilityLabel: accessibilityLabel ?? written, testID: testID, ...(Platform.OS === "web" ? { dir: "ltr" } : null), style: [styles.row, styles.ltr, containerStyle], children: characters.map(({ character, digit, key }) => theme.isAndroid ? (_jsx(Changing, { character: character, up: last.up, lift: 0.3 * fontSize, reduced: theme.reducedMotion, text: glyphProps }, key)) : digit === null ? (_jsx(Text, { ...glyphProps, children: character }, key)) : (_jsx(Reel, { digit: digit, character: character, glyphs: glyphs, lineHeight: lineHeight, text: glyphProps }, key))) }));
66
+ }
67
+ /** iOS's reel: the digit itself, hidden, keeps the width and height; a column of 0 to 9 turns over it. */
68
+ function Reel({ digit, character, glyphs, lineHeight, text }) {
69
+ const theme = useTheme();
70
+ const [line, setLine] = useState(lineHeight);
71
+ const position = useTransitionValue(digit, {
72
+ duration: theme.duration("--rolling-number-duration", 600),
73
+ easing: cssEasing(theme.token("--rolling-number-ease"), curves.easeInOut),
74
+ native: true,
75
+ reducedMotion: theme.reducedMotion,
76
+ });
77
+ const onLayout = (event) => {
78
+ const next = event.nativeEvent.layout.height;
79
+ if (next > 0)
80
+ setLine((old) => (old === next ? old : next));
81
+ };
82
+ return (_jsxs(View, { style: styles.digit, children: [_jsx(Text, { ...text, onLayout: onLayout, style: [text.style, styles.ghost], children: character }), _jsx(Animated.View, { style: [styles.reel, { transform: [{ translateY: position.interpolate({ inputRange: [0, 9], outputRange: [0, -9 * line] }) }] }], children: glyphs.map((glyph) => (_jsx(Text, { ...text, style: [text.style, { height: line }], children: glyph }, glyph))) })] }));
83
+ }
84
+ /** Android's animated text: a new character comes in as the old one leaves, both fading and moving by `lift`. */
85
+ function Changing({ character, up, lift, reduced, text }) {
86
+ const [pair, setPair] = useState({ old: null, now: character, up });
87
+ if (pair.now !== character)
88
+ setPair({ old: pair.now, now: character, up });
89
+ const [progress] = useState(() => new Animated.Value(1));
90
+ useLayoutEffect(() => {
91
+ if (pair.old == null)
92
+ return;
93
+ progress.setValue(reduced ? 1 : 0);
94
+ }, [pair, progress, reduced]);
95
+ useEffect(() => {
96
+ if (pair.old == null || reduced)
97
+ return;
98
+ const animation = Animated.timing(progress, { toValue: 1, duration: 320, easing: curves.easeOutQuint, useNativeDriver: nativeDriver, isInteraction: false });
99
+ animation.start(({ finished }) => {
100
+ if (finished)
101
+ setPair((current) => (current === pair ? { ...current, old: null } : current));
102
+ });
103
+ return () => animation.stop();
104
+ }, [pair, progress, reduced]);
105
+ const direction = pair.up ? 1 : -1;
106
+ return (_jsxs(View, { children: [_jsx(Animated.View, { style: pair.old == null
107
+ ? null
108
+ : { opacity: progress, transform: [{ translateY: progress.interpolate({ inputRange: [0, 1], outputRange: [direction * lift, 0] }) }] }, children: _jsx(Text, { ...text, children: pair.now }) }), pair.old == null || reduced ? null : (_jsx(Animated.View, { style: [
109
+ styles.leaving,
110
+ {
111
+ opacity: progress.interpolate({ inputRange: [0, 1], outputRange: [1, 0] }),
112
+ transform: [{ translateY: progress.interpolate({ inputRange: [0, 1], outputRange: [0, -direction * lift] }) }],
113
+ },
114
+ ], children: _jsx(Text, { ...text, children: pair.old }) }))] }));
115
+ }
116
+ const styles = StyleSheet.create({
117
+ row: { flexDirection: "row", alignItems: "flex-start" },
118
+ // The web takes dir="ltr" (react-native-web has no direction style, and checks every style it is given here)
119
+ ltr: Platform.OS === "web" ? {} : { direction: "ltr" },
120
+ // Clips the reel to one line
121
+ digit: { overflow: "hidden" },
122
+ ghost: { opacity: 0 },
123
+ reel: { position: "absolute", top: 0, start: 0, end: 0, alignItems: "center" },
124
+ leaving: { position: "absolute", top: 0, start: 0 },
125
+ });