@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
@@ -11,10 +11,13 @@ import { lastInputKeyboard, spaceToggles } from "../../internal/a11y";
11
11
  import { textOf } from "../../internal/children";
12
12
  import { isRTL, mirrored } from "../../internal/direction";
13
13
  import { curves } from "../../internal/motion";
14
+ import { useRipple } from "../../internal/ripple";
14
15
  import { RowFrameContext } from "../../internal/row";
15
16
  import { Glass } from "../../internal/Glass";
16
17
  import { ACCELERATE_DECELERATE, canTransformGlass, glassOpacity, Overlay, overlayTiming } from "../../internal/Overlay";
17
- import { barSurface, elevationShadow, withAlpha, dangerText } from "../../theme/material";
18
+ import { androidGray, androidSelector, barSurface, withAlpha, dangerText } from "../../theme/material";
19
+ import { useAndroidGlass } from "../../internal/BarBackdrop";
20
+ import { BarItemContext } from "../Button/Button";
18
21
  import { useTheme } from "../../theme/ThemeProvider";
19
22
  import { IconDefaultsProvider } from "../Icon/createIcon";
20
23
  import { Text } from "../Text/Text";
@@ -93,6 +96,7 @@ function MenuRoot({ children, open: openProp, onOpenChange }) {
93
96
  const open = openProp ?? own;
94
97
  // A menu opened from outside (the controlled `open`) is placed at its trigger too
95
98
  const { anchor, row, place, setTrigger, setRowFrame } = useMenuAnchor(open);
99
+ const [header, setHeader] = useState(false);
96
100
  // Listens for the input from the start, so a menu opened from the keyboard knows it (the web)
97
101
  useEffect(() => {
98
102
  lastInputKeyboard();
@@ -108,7 +112,7 @@ function MenuRoot({ children, open: openProp, onOpenChange }) {
108
112
  else
109
113
  apply();
110
114
  };
111
- return _jsx(MenuContext.Provider, { value: { open, setOpen, anchor, row, setTrigger, setRowFrame, place: () => place() }, children: children });
115
+ return _jsx(MenuContext.Provider, { value: { open, setOpen, anchor, row, header, setHeader, setTrigger, setRowFrame, place: () => place() }, children: children });
112
116
  }
113
117
  MenuRoot.displayName = "Menu";
114
118
  function useMenu(part) {
@@ -119,13 +123,18 @@ function useMenu(part) {
119
123
  }
120
124
  /** The element that opens the menu: a Button or anything with `onPress`. */
121
125
  function MenuTrigger({ children, style }) {
122
- const { open, setOpen, setTrigger, setRowFrame, place } = useMenu("Menu.Trigger");
123
- // A trigger in a List row tells the menu its row
126
+ const { open, setOpen, setTrigger, setRowFrame, setHeader, place } = useMenu("Menu.Trigger");
127
+ // A trigger in a List row tells the menu its row; one in a bar that it is the bar's (Android's header menu)
124
128
  const frame = useContext(RowFrameContext);
129
+ const inBar = useContext(BarItemContext) != null;
125
130
  useLayoutEffect(() => {
126
131
  setRowFrame(frame);
127
132
  return () => setRowFrame(null);
128
133
  }, [frame, setRowFrame]);
134
+ useLayoutEffect(() => {
135
+ setHeader(inBar);
136
+ return () => setHeader(false);
137
+ }, [inBar, setHeader]);
129
138
  const onPress = isValidElement(children) ? children.props.onPress : undefined;
130
139
  const child = isValidElement(children)
131
140
  ? cloneElement(children, {
@@ -145,7 +154,7 @@ MenuTrigger.displayName = "Menu.Trigger";
145
154
  function MenuContent(props) {
146
155
  const menu = useMenu("Menu.Content");
147
156
  // A menu whose items say `checked` (true or false) is a set of options: it keeps the checkmark's column, as Select's
148
- return _jsx(MenuSurface, { ...props, check: hasCheckedItems(props.children), open: menu.open, anchor: menu.anchor, row: menu.row, onClose: () => menu.setOpen(false) });
157
+ return _jsx(MenuSurface, { ...props, check: hasCheckedItems(props.children), open: menu.open, anchor: menu.anchor, row: menu.row, header: menu.header, onClose: () => menu.setOpen(false) });
149
158
  }
150
159
  function hasCheckedItems(children) {
151
160
  return Children.toArray(children).some((child) => isValidElement(child) ? child.props.checked !== undefined || (child.type === Fragment && hasCheckedItems(child.props.children)) : false);
@@ -157,7 +166,7 @@ export function MenuSurface(props) {
157
166
  return theme.isAndroid ? _jsx(AndroidMenuSurface, { ...props }) : _jsx(IOSMenuSurface, { ...props });
158
167
  }
159
168
  /** iOS 26's pop-up menu: glass, a submenu over the menu at its row while the menu steps back. */
160
- function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check = false, cover, children, "aria-label": ariaLabel, testID }) {
169
+ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check = false, multiple = false, cover, children, "aria-label": ariaLabel, testID }) {
161
170
  const theme = useTheme();
162
171
  const insets = useSafeAreaInsets();
163
172
  const window = useWindowDimensions();
@@ -224,7 +233,7 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
224
233
  moveTo(step, 1, true);
225
234
  };
226
235
  const collapse = () => moveTo(step, 0, false, () => setSub(null));
227
- const surface = { close: onClose, check, openSub, subOpen: sub != null };
236
+ const surface = { close: onClose, check, multiple, openSub, subOpen: sub != null };
228
237
  const content = _jsx(SurfaceContext.Provider, { value: surface, children: children });
229
238
  const subItems = sub != null ? _jsx(SurfaceContext.Provider, { value: { close: onClose, check: hasCheckedItems(sub.items) }, children: sub.items }) : null;
230
239
  const scale = !theme.reducedMotion && canTransformGlass;
@@ -384,7 +393,7 @@ function AndroidPage({ children, width, minWidth, maxWidth, maxHeight, onSize, s
384
393
  * width back, shrinks to 0.95 under a dim of up to 25% black, and the popup's size turns into the submenu's; Back, a
385
394
  * drag towards the end or a flick takes it back.
386
395
  */
387
- function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width, check = false, cover, children, "aria-label": ariaLabel, testID }) {
396
+ function AndroidMenuSurface({ open, anchor, row, header = false, onClose, align = "start", width, check = false, multiple = false, cover, children, "aria-label": ariaLabel, testID }) {
388
397
  const theme = useTheme();
389
398
  const insets = useSafeAreaInsets();
390
399
  const window = useWindowDimensions();
@@ -565,9 +574,9 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
565
574
  },
566
575
  });
567
576
  });
568
- const surface = { close: onClose, check, openSub, subOpen: sub != null };
577
+ const surface = { close: onClose, check, multiple, openSub, subOpen: sub != null, header };
569
578
  // The submenu's page: Back, the 8dp band, the items
570
- const subItems = sub != null ? (_jsxs(SurfaceContext.Provider, { value: { close: onClose, check: hasCheckedItems(sub.items) }, children: [_jsx(MenuRow, { icon: _jsx(ArrowLeftLg, {}), stay: collapse, children: sub.backLabel }), _jsx(MenuSeparator, {}), sub.items] })) : null;
579
+ const subItems = sub != null ? (_jsxs(SurfaceContext.Provider, { value: { close: onClose, check: hasCheckedItems(sub.items), header }, children: [_jsx(MenuRow, { icon: _jsx(ArrowLeftLg, {}), stay: collapse, children: sub.backLabel }), _jsx(MenuSeparator, {}), sub.items] })) : null;
571
580
  // The web's keyboard, as the WAI-ARIA menu pattern, over the page in front
572
581
  const panel = useRef(null);
573
582
  const mainPage = useRef(null);
@@ -604,7 +613,16 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
604
613
  const hidden = sub != null && !web ? { importantForAccessibility: "no-hide-descendants", accessibilityElementsHidden: true } : null;
605
614
  // The submenu stands at the popup's start edge
606
615
  const startEdge = rtl && !swapped ? { right: 0 } : { left: 0 };
607
- const background = barSurface(m, theme.scheme);
616
+ // A row's menu (and any other) is the popup's card: white, a raised gray at night (the web's --android-card); a
617
+ // header menu the bar's glass, blurred 36 under it on the web
618
+ const glass = useAndroidGlass("bar");
619
+ const card = theme.scheme === "dark" ? theme.color("--gray-300", barSurface(m, theme.scheme)) : barSurface(m, theme.scheme);
620
+ const background = header ? glass.backgroundColor : card;
621
+ const fillLook = header
622
+ ? { ...glass, borderRadius: 22, ...(web ? { backdropFilter: "blur(36px)", WebkitBackdropFilter: "blur(36px)" } : null) }
623
+ : { backgroundColor: card, borderRadius: 12, boxShadow: theme.scheme === "dark" ? "0 3px 8px rgba(0, 0, 0, 0.4)" : "0 3px 8px rgba(0, 0, 0, 0.14), 0 0 1px rgba(0, 0, 0, 0.12)" };
624
+ // The screen behind it dims: black at 40% (20% at night) around a row's menu and any other, 10% behind a header menu
625
+ const dimAlpha = header ? 0.1 : theme.scheme === "dark" ? 0.2 : 0.4;
608
626
  // From a List row: the popup's fade (and the dim's) over the first 150ms of its 200, and its growth from 0.95
609
627
  const popFade = clock.interpolate({ inputRange: [0, ROW_POP.fade / ROW_POP.scale], outputRange: [0, 1], easing: ACCELERATE_DECELERATE, extrapolate: "clamp" });
610
628
  const popScale = clock.interpolate({ inputRange: [0, 1], outputRange: [0.95, 1], easing: ROW_POP.easing });
@@ -614,7 +632,7 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
614
632
  const shift = reduced ? null : opening ? drop : drop ? Animated.add(drop, lift) : lift;
615
633
  const popIn = popping && opening && !reduced;
616
634
  const opacity = reduced || !opening ? progress : popping ? popFade : 1;
617
- return (_jsxs(_Fragment, { children: [row ? _jsx(RowDim, { row: row, fade: popIn ? popFade : progress, alpha: theme.scheme === "dark" ? 0.2 : 0.4, width: window.width, height: window.height }) : null, _jsxs(Animated.View, { ref: panel, ...(web ? { tabIndex: -1, onKeyDown: (raw) => menuKeyDown(raw, sub ? subPage.current : mainPage.current) } : null), accessibilityRole: "menu", "aria-label": ariaLabel, style: [
635
+ return (_jsxs(_Fragment, { children: [row ? (_jsx(RowDim, { row: row, fade: popIn ? popFade : progress, alpha: dimAlpha, width: window.width, height: window.height })) : (_jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { backgroundColor: `rgba(0, 0, 0, ${dimAlpha})`, opacity: progress }] })), _jsxs(Animated.View, { ref: panel, ...(web ? { tabIndex: -1, onKeyDown: (raw) => menuKeyDown(raw, sub ? subPage.current : mainPage.current) } : null), accessibilityRole: "menu", "aria-label": ariaLabel, style: [
618
636
  styles.surface,
619
637
  horizontal,
620
638
  {
@@ -624,7 +642,7 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
624
642
  transformOrigin: popIn ? (rtl ? "0% 100%" : "100% 100%") : undefined,
625
643
  transform: popIn ? [{ scale: popScale }] : shift ? [{ translateY: shift }] : undefined,
626
644
  },
627
- ], children: [_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidFill, { backgroundColor: background, opacity: unrolling ? reveal([0, 1]) : 1 }] }), _jsxs(Animated.View, { pointerEvents: moving ? "none" : "auto", style: [styles.android, { width: panelWidth, height: panelHeight }], children: [_jsxs(Animated.View, { ref: mainPage, ...hidden, pointerEvents: sub ? "none" : "auto", style: [
645
+ ], children: [_jsx(Animated.View, { pointerEvents: "none", style: [styles.androidFill, fillLook, { opacity: unrolling ? reveal([0, 1]) : 1 }] }), _jsxs(Animated.View, { pointerEvents: moving ? "none" : "auto", style: [styles.android, header ? styles.androidHeaderPanel : null, { width: panelWidth, height: panelHeight }], children: [_jsxs(Animated.View, { ref: mainPage, ...hidden, pointerEvents: sub ? "none" : "auto", style: [
628
646
  styles.androidPageBox,
629
647
  behind ? null : styles.gone,
630
648
  {
@@ -635,9 +653,9 @@ function AndroidMenuSurface({ open, anchor, row, onClose, align = "start", width
635
653
  ? [{ translateY: Animated.multiply(drop, -1) }]
636
654
  : undefined,
637
655
  },
638
- ], children: [_jsx(CascadeContext.Provider, { value: cascade, children: _jsx(AndroidPage, { width: morphing ? size.width : width, minWidth: minWidth, maxWidth: maxWidth, maxHeight: maxHeight, onSize: (measured) => setSize(sameSize(measured)), children: _jsx(SurfaceContext.Provider, { value: surface, children: children }) }) }), sub ? _jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { backgroundColor: "#000000", opacity: swipe.interpolate({ inputRange: [0, 1], outputRange: [0, 0.25] }) }] }) : null] }), sub ? (
656
+ ], children: [_jsx(CascadeContext.Provider, { value: cascade, children: _jsx(AndroidPage, { width: morphing ? size.width : width, minWidth: minWidth, maxWidth: maxWidth, maxHeight: maxHeight, onSize: (measured) => setSize(sameSize(measured)), style: header ? styles.androidHeaderPage : undefined, children: _jsx(SurfaceContext.Provider, { value: surface, children: children }) }) }), sub ? _jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { backgroundColor: "#000000", opacity: swipe.interpolate({ inputRange: [0, 1], outputRange: [0, 0.25] }) }] }) : null] }), sub ? (
639
657
  // As wide as the widest page may be, so the submenu takes its own width, not the menu's
640
- _jsx(Animated.View, { ref: subPage, ...swipeBack.responder.panHandlers, pointerEvents: "box-none", style: [styles.androidSubPage, startEdge, { width: maxWidth, transform: [{ translateX: swipe.interpolate({ inputRange: [0, 1], outputRange: [span || window.width, 0] }) }] }], children: _jsx(AndroidPage, { width: width, minWidth: minWidth, maxWidth: maxWidth, maxHeight: maxHeight, onSize: onSubSize, style: { backgroundColor: background }, children: subItems }) })) : null] })] })] }));
658
+ _jsx(Animated.View, { ref: subPage, ...swipeBack.responder.panHandlers, pointerEvents: "box-none", style: [styles.androidSubPage, startEdge, { width: maxWidth, transform: [{ translateX: swipe.interpolate({ inputRange: [0, 1], outputRange: [span || window.width, 0] }) }] }], children: _jsx(AndroidPage, { width: width, minWidth: minWidth, maxWidth: maxWidth, maxHeight: maxHeight, onSize: onSubSize, style: [{ backgroundColor: background }, header ? styles.androidHeaderPage : null], children: subItems }) })) : null] })] })] }));
641
659
  } }));
642
660
  }
643
661
  /** The space between a List row and the popup opened from it. */
@@ -662,7 +680,7 @@ function RowDim({ row, fade, alpha, width, height }) {
662
680
  }
663
681
  /** The enabled items of a menu's panel on the web, in their order. */
664
682
  function menuItems(node) {
665
- const found = node?.querySelectorAll?.('[role="menuitem"], [role="menuitemradio"]');
683
+ const found = node?.querySelectorAll?.('[role="menuitem"], [role="menuitemradio"], [role="menuitemcheckbox"]');
666
684
  return found ? Array.from(found).filter((item) => item.getAttribute("aria-disabled") !== "true") : [];
667
685
  }
668
686
  /**
@@ -721,42 +739,50 @@ function MenuRow({ children, icon, description, danger = false, disabled = false
721
739
  const surface = useContext(SurfaceContext);
722
740
  const own = useRef(null);
723
741
  const node = rowRef ?? own;
742
+ // An item that says `checked` in a menu of options is a radio item (a checkbox item when several can be chosen): the
743
+ // web names it so, and a phone reads its state
744
+ const option = surface.check && checked !== undefined && !stay;
724
745
  const select = () => {
725
746
  if (disabled)
726
747
  return;
727
748
  if (stay)
728
749
  return stay();
729
750
  onSelect?.();
730
- surface.close();
751
+ // An option of a multiple choice checks or unchecks itself and the menu stays open
752
+ if (!(surface.multiple && option))
753
+ surface.close();
731
754
  };
732
- // An item that says `checked` in a menu of options is a radio item: the web names it so, and a phone reads its state
733
- const option = surface.check && checked !== undefined && !stay;
734
755
  const semantics = {
735
- ...(Platform.OS === "web" ? { role: (option ? "menuitemradio" : "menuitem") } : { accessibilityRole: "menuitem" }),
756
+ ...(Platform.OS === "web"
757
+ ? { role: (option ? (surface.multiple ? "menuitemcheckbox" : "menuitemradio") : "menuitem"), "aria-checked": option ? !!checked : undefined }
758
+ : { accessibilityRole: "menuitem" }),
736
759
  accessibilityState: { disabled, checked: option ? !!checked : undefined, expanded: opens ? !!expanded : undefined },
737
760
  ...(opens ? { "aria-haspopup": "menu", "aria-expanded": !!expanded } : null),
738
761
  // React Native Web's Pressable takes Space only for a button
739
762
  ...spaceToggles(select),
740
763
  };
741
764
  const rtl = isRTL();
765
+ // Android's press: the item's ripple from the touch point in the dialog button selector, clipped to the item and the
766
+ // popup's corners at the first and the last; the platform's on a device, drawn here on the web
767
+ const nativeRipple = theme.isAndroid && Platform.OS === "android";
768
+ const ripple = useRipple(androidSelector(theme.scheme), theme.isAndroid && !nativeRipple, theme.reducedMotion);
742
769
  if (theme.isAndroid) {
743
- // Android's popup item: 48dp, 18 in, Regular 16 in the text color, a 24dp icon at 18 with the text 43 past it, a
744
- // 13 gray description; red for a destructive item. A chosen option shows the bare check at the leading edge, the
745
- // text 34 past it (at the end after an icon); a row that opens a submenu shows its arrow 8 after the text. The
746
- // press is the text color at 12%
770
+ // Android's popup item: 48dp, 18 in, Regular 16 in the text color, a 24dp icon at 18 with the text 20 past it (62
771
+ // in), a 13 gray description; red for a destructive item. A chosen option shows the bare check at the end, 18
772
+ // after the text; a row that opens a submenu shows its arrow 8 after the text. Keyboard focus shows as the text
773
+ // color at 12%
747
774
  const m = theme.material;
748
775
  const chosen = surface.check && !!checked && !stay;
749
776
  const color = danger ? dangerText(theme) : m.onSurface;
750
- const leadCheck = surface.check && !icon;
751
- const trailCheck = surface.check && !!icon && !opens && !stay;
752
- return (_jsx(CascadeRow, { children: _jsxs(Pressable, { ...semantics, ref: node, disabled: disabled, onPress: select, testID: testID,
753
- // The web's keyboard focus shows as the press does (React Native Web passes `focused`), in place of the
754
- // browser's square ring, which the popup's round corners would cut
777
+ const trailCheck = surface.check && !opens && !stay;
778
+ return (_jsx(CascadeRow, { children: _jsxs(Pressable, { ...semantics, ref: node, disabled: disabled, onPress: select, onPressIn: nativeRipple ? undefined : ripple.start, onPressOut: nativeRipple ? undefined : ripple.end, android_ripple: nativeRipple ? { color: androidSelector(theme.scheme), foreground: true } : undefined, testID: testID,
779
+ // The web's keyboard focus shows as a layer (React Native Web passes `focused`), in place of the browser's
780
+ // square ring, which the popup's round corners would cut
755
781
  style: (state) => [
756
782
  styles.androidItem,
757
783
  { opacity: disabled ? 0.5 : 1 },
758
- state.pressed || (state.focused && focusVisible(node.current)) ? { backgroundColor: withAlpha(color, 0.12) } : null,
759
- ], children: [leadCheck ? _jsx(View, { style: styles.androidLeadCheck, children: chosen ? _jsx(PopupCheck, { color: color }) : null }) : null, icon ? (_jsx(View, { style: [styles.androidIcon, mirrored(rtl && stay != null && !opens)], children: _jsx(IconDefaultsProvider, { size: 24, color: color, children: icon }) })) : null, _jsxs(View, { style: styles.text, children: [_jsx(Text, { color: color, numberOfLines: 1, style: { fontSize: 16, lineHeight: 20 }, children: children }), description != null ? (
784
+ state.focused && focusVisible(node.current) ? { backgroundColor: withAlpha(color, 0.12) } : null,
785
+ ], children: [ripple.layer, icon ? (_jsx(View, { style: [styles.androidIcon, mirrored(rtl && stay != null && !opens)], children: _jsx(IconDefaultsProvider, { size: 24, color: color, children: icon }) })) : null, _jsxs(View, { style: styles.text, children: [_jsx(Text, { color: color, numberOfLines: 1, style: { fontSize: 16, lineHeight: 20 }, children: children }), description != null ? (
760
786
  // The secondary text gray of the Android look
761
787
  _jsx(Text, { color: theme.colors.labelSecondary, style: { fontSize: 13, lineHeight: 16 }, children: description })) : null] }), opens ? (_jsx(View, { style: [styles.androidArrow, mirrored(rtl)], children: _jsx(ChevronRightMd, { size: 24, color: color }) })) : trailCheck ? (_jsx(View, { style: styles.androidTrailCheck, children: chosen ? _jsx(PopupCheck, { color: color }) : null })) : null] }) }));
762
788
  }
@@ -826,10 +852,11 @@ const MenuSubContent = () => null;
826
852
  MenuSubContent.displayName = "Menu.SubContent";
827
853
  function MenuSeparator() {
828
854
  const theme = useTheme();
829
- // Android parts a popup's groups with an 8dp band (the text at 4.5% on the popup, a shade darker than it in dark
830
- // mode)
855
+ const surface = useContext(SurfaceContext);
856
+ // Android parts a popup's groups with an 8dp band: a light gray (#F5F5F5, #262626 at night) in a row's menu, the text
857
+ // at 6% in a header menu
831
858
  if (theme.isAndroid)
832
- return (_jsx(CascadeRow, { children: _jsx(View, { style: [styles.androidSeparator, { backgroundColor: theme.scheme === "dark" ? "rgba(0, 0, 0, 0.25)" : withAlpha(theme.material.onSurface, 0.045) }] }) }));
859
+ return (_jsx(CascadeRow, { children: _jsx(View, { style: [styles.androidSeparator, { backgroundColor: androidGray(theme, surface.header ? "menuBand" : "popupGap") }] }) }));
833
860
  // The phone layer's separator: 1 tall in `--menu-separator-background-color`, `--menu-separator-gutter` around it
834
861
  const gutter = cssBox(theme, "--menu-separator-gutter", [10, 8, 10, 8]);
835
862
  return (_jsx(View, { style: {
@@ -884,18 +911,20 @@ const styles = StyleSheet.create({
884
911
  scroll: { flexGrow: 0 },
885
912
  // Android's popup: 12dp corners, the items flush with its edges, a soft shadow
886
913
  android: { borderRadius: 12, overflow: "hidden" },
887
- androidFill: { position: "absolute", top: 0, bottom: 0, start: 0, end: 0, borderRadius: 12, boxShadow: elevationShadow.level2 },
914
+ androidFill: { position: "absolute", top: 0, bottom: 0, start: 0, end: 0 },
915
+ // A header menu: 22dp corners, 5 above and under its rows
916
+ androidHeaderPanel: { borderRadius: 22 },
917
+ androidHeaderPage: { paddingVertical: 5 },
888
918
  // A page keeps its own size while the popup's changes around it
889
919
  androidPageBox: { alignSelf: "flex-start", flexShrink: 0 },
890
920
  androidPage: { flexShrink: 0, flexGrow: 0 },
891
921
  androidSubPage: { position: "absolute", top: 0, alignItems: "flex-start" },
892
922
  gone: { opacity: 0 },
893
923
  androidItem: { minHeight: 48, flexDirection: "row", alignItems: "center", paddingHorizontal: 18, paddingVertical: 6, outlineWidth: 0, outlineStyle: "none" },
894
- // The 24dp icon at 18, the text 43 past the item's padding: 19 after the icon
895
- androidIcon: { width: 24, marginEnd: 19, alignItems: "center" },
896
- // The check's 26dp box at the leading edge, the text 34 past the item's padding; at the end after an icon
897
- androidLeadCheck: { width: 26, marginEnd: 8, alignItems: "center" },
898
- androidTrailCheck: { width: 26, marginStart: 8, alignItems: "center" },
924
+ // The 24dp icon at 18, the text 20 after it (62 in)
925
+ androidIcon: { width: 24, marginEnd: 20, alignItems: "center" },
926
+ // A chosen option's check at the end: a 24dp column 18 after the text (the 26 glyph box centered on it)
927
+ androidTrailCheck: { width: 24, marginStart: 18, alignItems: "center", justifyContent: "center" },
899
928
  // The submenu arrow: 24dp at the end, the text 8 before it
900
929
  androidArrow: { width: 24, marginStart: 8, alignItems: "center" },
901
930
  androidSeparator: { height: 8 },
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useContext } from "react";
3
- import { View } from "react-native";
3
+ import { StyleSheet, View } from "react-native";
4
4
  import { useTheme } from "../../theme/ThemeProvider";
5
5
  import CheckMd from "../../icons/plex/CheckMd";
6
6
  import ChevronLeftMd from "../../icons/plex/ChevronLeftMd";
@@ -8,6 +8,7 @@ import { mirrored, useRTL } from "../../internal/direction";
8
8
  import { BarItemContext, Button } from "../Button/Button";
9
9
  import { createIcon } from "../Icon/createIcon";
10
10
  import { MaterialArrowBack, MaterialCheckSymbol, MaterialClose } from "../Icon/material";
11
+ import { Text } from "../Text/Text";
11
12
  /** The close glyph of the kit (packages/ui NavigationGlyph), on a 20 grid. */
12
13
  const Close = createIcon("Close", "0 0 20 20", [
13
14
  [
@@ -22,11 +23,13 @@ const LABELS = { back: "Back", close: "Close", confirm: "Confirm" };
22
23
  /**
23
24
  * Back, close and confirm: on iOS the 44pt circle of a bar, glass for back and close and the accent for confirm (in a
24
25
  * Toolbar), with the kit's glyphs at their sizes (`--navigation-button-*`); on Android Material's glyphs (`arrow_back`,
25
- * `close`, `check`) at 24dp: in a bar back and close take Android's 46dp glass circle and confirm the accent one,
26
- * outside a bar they are plain icon buttons.
26
+ * `close`, `check`) at 24dp: in a bar back and close take Android's 46dp glass circle, outside a bar they are plain icon
27
+ * buttons. Confirm on Android is the glass text pill of a top bar (outside a bar too): a short word, its `label` (Done
28
+ * by default), 15/20 Bold in the text color, 16 in from its ends and cut short past 160; in a bottom bar it keeps the
29
+ * accent circle.
27
30
  * Back points the way the screen reads: right to left it turns over.
28
31
  */
29
- export function NavigationButton({ action, color, variant, mobileMaterial, size = "lg", accessibilityLabel, ...rest }) {
32
+ export function NavigationButton({ action, color, variant, mobileMaterial, size = "lg", accessibilityLabel, label, ...rest }) {
30
33
  const theme = useTheme();
31
34
  const bar = useContext(BarItemContext);
32
35
  const confirm = action === "confirm";
@@ -43,6 +46,14 @@ export function NavigationButton({ action, color, variant, mobileMaterial, size
43
46
  ? CheckMd
44
47
  : ChevronLeftMd;
45
48
  const { ref, rtl } = useRTL();
49
+ if (theme.isAndroid && confirm && !bar?.bottom) {
50
+ // The pill draws a short word, never the name; with no name of its own the button is named by its word
51
+ const word = label ?? "Done";
52
+ const name = accessibilityLabel ?? word;
53
+ // A neutral ghost Button in a bar stands on the bar's glass, its label dimmed to 38% when disabled
54
+ const pill = (_jsx(Button, { ...rest, color: color ?? "primary", variant: variant ?? "ghost", mobileMaterial: mobileMaterial, size: size, accessibilityLabel: name, children: _jsx(Text, { weight: "bold", numberOfLines: 1, style: styles.androidConfirm, children: word }) }));
55
+ return bar ? pill : _jsx(BarItemContext.Provider, { value: ANDROID_BAR_ITEM, children: pill });
56
+ }
46
57
  const button = (_jsx(Button, { ...rest, uniform: true, color: color ?? (confirm ? "primary" : theme.isAndroid ? "primary" : "secondary"), variant: variant ?? (confirm ? "solid" : theme.isAndroid ? "ghost" : "soft"), mobileMaterial: mobileMaterial ?? (confirm ? undefined : "glass"), size: size, accessibilityLabel: accessibilityLabel ?? LABELS[action], children: _jsx(View, { ref: ref, style: action === "back" ? mirrored(rtl) : null, children: _jsx(Glyph, { size: iconSize }) }) }));
47
58
  if (bar || theme.isAndroid)
48
59
  return button;
@@ -50,3 +61,8 @@ export function NavigationButton({ action, color, variant, mobileMaterial, size
50
61
  const height = theme.length("--navigation-button-size", 44);
51
62
  return (_jsx(BarItemContext.Provider, { value: { height, fontSize: 17, lineHeight: 22, weight: "medium", prominentWeight: "semibold", iconSize, gutter: 16, prominent: false }, children: button }));
52
63
  }
64
+ /** An Android top bar's item, for a confirm outside a bar: the 46dp glass, 16 in from its ends. */
65
+ const ANDROID_BAR_ITEM = { height: 46, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 16 };
66
+ const styles = StyleSheet.create({
67
+ androidConfirm: { fontSize: 15, lineHeight: 20, maxWidth: 160 },
68
+ });
@@ -165,7 +165,7 @@ const ONE_TIME_CODE = Platform.OS === "android" ? "sms-otp" : "one-time-code";
165
165
  * cells (44 by 52pt capsules); Android outlined code boxes with the accent on the box with focus, whose digits slide
166
166
  * or grow in and shrink away, and whose row shakes when an error appears.
167
167
  */
168
- export function OTPInput({ length: lengthProp = 6, value, onChange, onComplete, grouping, invalid = false, errorMessage, disabled = false, autoFocus = false, testID, style, }) {
168
+ export function OTPInput({ length: lengthProp = 6, value, onChange, onComplete, grouping, invalid = false, errorMessage, disabled = false, autoFocus = false, "aria-label": ariaLabel, label, digitLabel, testID, style, }) {
169
169
  const theme = useTheme();
170
170
  const length = Math.max(1, Math.floor(lengthProp));
171
171
  const controlledValue = useMemo(() => sanitizeDigits(value ?? "", length), [value, length]);
@@ -309,7 +309,13 @@ export function OTPInput({ length: lengthProp = 6, value, onChange, onComplete,
309
309
  shake.setValue(0);
310
310
  Animated.spring(shake, { toValue: 0, velocity: -1000, ...stiffSpring(600, 0.5), useNativeDriver: false }).start();
311
311
  }, [failing, shake, theme.isAndroid, theme.reducedMotion]);
312
- return (_jsxs(View, { style: style, testID: testID, children: [_jsx(Animated.View, { style: [styles.cells, { gap }, theme.isAndroid ? { transform: [{ translateX: shake }] } : null], children: Array.from({ length }, (_, index) => {
312
+ const name = ariaLabel ?? label;
313
+ const cellName = (index) => {
314
+ const own = digitLabel ? digitLabel(index, length) : name ? `${Platform.OS === "web" ? "Digit" : "digit"} ${index + 1} of ${length}` : `Digit ${index + 1}`;
315
+ // The web names the group; a native screen reader hears the code's name on each cell instead
316
+ return name && Platform.OS !== "web" ? `${name}, ${own}` : own;
317
+ };
318
+ return (_jsxs(View, { style: style, testID: testID, role: name ? "group" : undefined, "aria-label": Platform.OS === "web" ? name : undefined, children: [_jsx(Animated.View, { style: [styles.cells, { gap }, theme.isAndroid ? { transform: [{ translateX: shake }] } : null], children: Array.from({ length }, (_, index) => {
313
319
  const isGroupGap = grouping ? shouldShowGap(index, grouping) : false;
314
320
  const focused = focusedIndex === index;
315
321
  const look = cellLook(theme, { focused, filled: !!digits[index], disabled, invalid });
@@ -318,7 +324,7 @@ export function OTPInput({ length: lengthProp = 6, value, onChange, onComplete,
318
324
  }, ...described.props, ...(Platform.OS === "web" ? { disabled } : null), value: digits[index], onChangeText: (text) => handleChangeText(index, text), onKeyPress: (event) => handleKeyPress(index, event), onFocus: () => {
319
325
  if (!disabled)
320
326
  setFocusedIndex(index);
321
- }, onBlur: handleBlur, editable: !disabled, readOnly: disabled, inputMode: "numeric", autoComplete: index === 0 ? ONE_TIME_CODE : "off", autoCorrect: false, spellCheck: false, accessibilityLabel: `Digit ${index + 1}`, "aria-invalid": invalid || undefined, "aria-disabled": disabled || undefined, selectionColor: look.caret, cursorColor: look.caret, underlineColorAndroid: "transparent", testID: testID ? `${testID}-digit-${index + 1}` : undefined,
327
+ }, onBlur: handleBlur, editable: !disabled, readOnly: disabled, inputMode: "numeric", autoComplete: index === 0 ? ONE_TIME_CODE : "off", autoCorrect: false, spellCheck: false, accessibilityLabel: cellName(index), "aria-invalid": invalid || undefined, "aria-disabled": disabled || undefined, selectionColor: look.caret, cursorColor: look.caret, underlineColorAndroid: "transparent", testID: testID ? `${testID}-digit-${index + 1}` : undefined,
322
328
  // Android's box draws the digit itself: the field's text is clear, its caret keeps its color (the
323
329
  // web's caret is otherwise the text's)
324
330
  style: [styles.input, look.text, theme.isAndroid ? { color: "transparent", ...(Platform.OS === "web" ? { caretColor: look.caret } : null) } : null] }));
@@ -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", valueText = defaultValueText, "aria-label": ariaLabel = "Pages", testID, style }) {
49
+ export function PageControl({ count, value: valueProp, defaultValue = 0, onChange, background = "automatic", indicator = "dots", tone = "default", 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);
@@ -69,6 +69,9 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
69
69
  // Android draws every page's dot at full size; the iOS kit shrinks the ends from seven pages
70
70
  const sizes = android ? Array.from({ length: Math.max(0, count) }, () => "full") : pageControlDots(count, current);
71
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);
72
+ 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));
72
75
  // The center of the current dot, for a tap on either side of it
73
76
  let x = padding;
74
77
  let currentCenter = padding;
@@ -76,12 +79,15 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
76
79
  if (size === "hidden")
77
80
  return;
78
81
  if (index === current)
79
- currentCenter = x + dotSize(size) / 2;
80
- x += dotSize(size) + gap;
82
+ currentCenter = x + dotWidth(size, index) / 2;
83
+ x += dotWidth(size, index) + gap;
81
84
  });
82
- const on = android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text);
85
+ const onColor = tone === "onColor";
86
+ const on = onColor ? "#FFFFFF" : android ? theme.material.primary : theme.color("--page-control-dot-color-current", theme.colors.text);
83
87
  // Android's page dots: #BBBBBB, #555555 in a dark theme
84
- const off = android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary);
88
+ const off = onColor ? "rgba(255, 255, 255, 0.4)" : android ? (theme.scheme === "dark" ? "#555555" : "#BBBBBB") : theme.color("--page-control-dot-color", theme.colors.labelTertiary);
89
+ // Android's current dot is drawn over the gray ones (it stretches between pages); a pill is a dot of its own
90
+ const worm = android && !pill;
85
91
  // Android draws no capsule, not even for `prominent`
86
92
  const capsuleHeight = theme.length("--page-control-height", 24);
87
93
  const target = android ? 48 : theme.length("--page-control-target-size", 44);
@@ -126,8 +132,8 @@ export function PageControl({ count, value: valueProp, defaultValue = 0, onChang
126
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: [
127
133
  styles.capsule,
128
134
  { height: capsuleHeight, paddingHorizontal: padding, gap, borderRadius: capsuleHeight / 2 },
129
- showBackground ? { backgroundColor: theme.color("--page-control-background") } : null,
130
- ], children: [sizes.map((size, index) => size === "hidden" ? null : (_jsx(View, { style: { width: dotSize(size), height: dotSize(size), borderRadius: dot / 2, backgroundColor: index === current && !android ? on : off } }, index))), android ? _jsx(AndroidCurrent, { start: currentCenter - dot / 2, color: on, reduced: theme.reducedMotion }) : null] }) }));
135
+ 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] }) }));
131
137
  }
132
138
  /** Android's page dots: 5dp, 11dp from one to the next. */
133
139
  const ANDROID_DOT = 5;
@@ -0,0 +1,128 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cloneElement, createContext, isValidElement, useCallback, useContext, useMemo, useRef, useState } from "react";
3
+ import { Animated, Easing, StyleSheet, View, useWindowDimensions } from "react-native";
4
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
5
+ import { FloatingPanel, paddingOf } from "../../internal/FloatingPanel";
6
+ import { anchorProps } from "../../internal/floating";
7
+ import { Glass } from "../../internal/Glass";
8
+ import { barSurface, elevationShadow } from "../../theme/material";
9
+ import { useTheme } from "../../theme/ThemeProvider";
10
+ import { useMenuAnchor } from "../Menu/Menu";
11
+ const PopoverContext = createContext(null);
12
+ const ControllerContext = createContext(null);
13
+ /**
14
+ * A floating panel for contextual UI at its trigger, as @plexui/ui's Popover on a phone: a tap on the trigger opens it,
15
+ * a tap anywhere else closes it. On iOS it is the compact glass panel an iPhone presents a popover as (the menus'
16
+ * glass, `--popover-radius` 34, `--menu-shadow`), placed under its trigger and centered by default; on Android a
17
+ * popup of the Plex Android look (its surface, 12dp corners, level 2 shadow) that pops from the trigger. Parts:
18
+ * `Popover.Trigger` and `Popover.Content`; `usePopoverController()` inside the content closes or shakes it.
19
+ */
20
+ export function Popover({ children, open: openProp, onOpenChange }) {
21
+ const [own, setOwn] = useState(false);
22
+ const open = openProp ?? own;
23
+ const { anchor, place, setTrigger } = useMenuAnchor(open);
24
+ const setOpen = useCallback((next) => {
25
+ const apply = () => {
26
+ if (openProp === undefined)
27
+ setOwn(next);
28
+ onOpenChange?.(next);
29
+ };
30
+ // The trigger is measured before the panel opens at it
31
+ if (next)
32
+ place(apply);
33
+ else
34
+ apply();
35
+ }, [openProp, onOpenChange, place]);
36
+ const value = useMemo(() => ({ open, setOpen, anchor, setTrigger, place: () => place() }), [open, setOpen, anchor, setTrigger, place]);
37
+ return _jsx(PopoverContext.Provider, { value: value, children: children });
38
+ }
39
+ Popover.displayName = "Popover";
40
+ function usePopover(part) {
41
+ const context = useContext(PopoverContext);
42
+ if (!context)
43
+ throw new Error(`${part} must be inside a Popover`);
44
+ return context;
45
+ }
46
+ /** The element that toggles the popover; the panel opens at it, and follows it when it moves. */
47
+ function PopoverTrigger({ children }) {
48
+ const { open, setOpen, setTrigger, place } = usePopover("Popover.Trigger");
49
+ if (!isValidElement(children))
50
+ return children;
51
+ const { onPress } = children.props;
52
+ return cloneElement(children, {
53
+ ...anchorProps(children.props, setTrigger, open ? place : undefined),
54
+ onPress: (event) => {
55
+ onPress?.(event);
56
+ setOpen(!open);
57
+ },
58
+ "aria-haspopup": "dialog",
59
+ "aria-expanded": open,
60
+ });
61
+ }
62
+ PopoverTrigger.displayName = "Popover.Trigger";
63
+ /** The panel: on iOS the glass of an iPhone popover, on Android the popup surface of the Plex Android look. */
64
+ function PopoverContent({ children, width = "auto", minWidth = 300, maxWidth = 700, side = "bottom", align = "center", sideOffset = 8, alignOffset, avoidCollisions = true, collisionPadding = 20, translucent = false, autoFocus = true, "aria-labelledby": ariaLabelledBy, "aria-label": ariaLabel, testID, style, }) {
65
+ const theme = useTheme();
66
+ const popover = usePopover("Popover.Content");
67
+ const window = useWindowDimensions();
68
+ const insets = useSafeAreaInsets();
69
+ const [shakeX] = useState(() => new Animated.Value(0));
70
+ const shaking = useRef(null);
71
+ const close = useCallback(() => popover.setOpen(false), [popover]);
72
+ const shake = useCallback(() => {
73
+ shaking.current?.stop();
74
+ shakeX.setValue(0);
75
+ // With reduced motion the panel stays still
76
+ if (theme.reducedMotion)
77
+ return;
78
+ // The web's keyframes: 5 to each side twice over 400ms on `ease`
79
+ shaking.current = Animated.timing(shakeX, { toValue: 1, duration: 400, easing: Easing.ease, useNativeDriver: false });
80
+ shaking.current.start();
81
+ }, [shakeX, theme.reducedMotion]);
82
+ const controller = useMemo(() => ({ close, shake }), [close, shake]);
83
+ const translateX = shakeX.interpolate({ inputRange: [0, 0.2, 0.4, 0.6, 0.8, 1], outputRange: [0, -5, 5, -5, 5, 0] });
84
+ const pad = paddingOf(collisionPadding);
85
+ // The room across the window, as Radix's available width caps `maxWidth`
86
+ const available = window.width - Math.max(pad.left, insets.left) - Math.max(pad.right, insets.right);
87
+ const sizing = {
88
+ width: width === "auto" ? undefined : Math.min(width, available),
89
+ minWidth: minWidth === "auto" ? undefined : Math.min(minWidth, available),
90
+ maxWidth: Math.min(maxWidth, available),
91
+ maxHeight: window.height - Math.max(pad.top, insets.top) - Math.max(pad.bottom, insets.bottom),
92
+ };
93
+ const android = theme.isAndroid;
94
+ const radius = android ? ANDROID_RADIUS : theme.length("--popover-radius", 34);
95
+ const content = _jsx(ControllerContext.Provider, { value: controller, children: children });
96
+ const glass = !android && !translucent;
97
+ return (_jsx(FloatingPanel, { open: popover.open, onDismiss: close, anchor: popover.anchor, side: side, align: align, sideOffset: sideOffset, alignOffset: alignOffset ?? (align === "center" ? 0 : -5), avoidCollisions: avoidCollisions, collisionPadding: collisionPadding, glass: glass, autoFocus: autoFocus, role: "dialog", "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, testID: testID, style: sizing, translateX: translateX, children: () => android ? (
98
+ // Material has no translucent surface: the popup's own
99
+ _jsx(View, { style: [styles.surface, { borderRadius: radius, backgroundColor: barSurface(theme.material, theme.scheme), boxShadow: elevationShadow.level2 }, style], children: content })) : translucent ? (_jsx(TranslucentSurface, { radius: radius, style: style, children: content })) : (_jsx(Glass, { radius: radius, elevation: "raised", fillToken: "--popover-mobile-background", filterToken: "--popover-mobile-backdrop-filter", shadowToken: "--menu-shadow", style: [styles.surface, style], children: content })) }));
100
+ }
101
+ PopoverContent.displayName = "Popover.Content";
102
+ /**
103
+ * The translucent panel, kept on a phone as on the web: a frosted gradient (light gray from half to whole up the
104
+ * panel, a blue-gray at night) over a 16px blur, with the desktop panel's shadow and hairline.
105
+ */
106
+ function TranslucentSurface({ radius, style, children }) {
107
+ const theme = useTheme();
108
+ const dark = theme.scheme === "dark";
109
+ const gradient = dark
110
+ ? "linear-gradient(360deg, rgba(86, 88, 105, 0.25) 0%, rgba(86, 88, 105, 0.49) 100%)"
111
+ : "linear-gradient(360deg, rgba(247, 247, 248, 0.5) 0%, rgba(247, 247, 248, 1) 100%)";
112
+ const shadow = [theme.token("--shadow"), theme.token("--shadow-hairline")].filter((part) => typeof part === "string").join(", ");
113
+ return (_jsxs(Glass, { radius: radius, blur: 16, tint: "transparent", style: [styles.surface, { boxShadow: shadow }, style], children: [_jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { borderRadius: radius, borderCurve: "continuous", backgroundImage: gradient }] }), children] }));
114
+ }
115
+ /** `close()` and `shake()` of the popover around: for the content of `Popover.Content`. */
116
+ export function usePopoverController() {
117
+ const controller = useContext(ControllerContext);
118
+ if (!controller)
119
+ throw new Error("usePopoverController must be inside Popover.Content");
120
+ return controller;
121
+ }
122
+ /** The corner of Android's popups in the Plex Android look. */
123
+ const ANDROID_RADIUS = 12;
124
+ const styles = StyleSheet.create({
125
+ surface: { borderCurve: "continuous" },
126
+ });
127
+ Popover.Trigger = PopoverTrigger;
128
+ Popover.Content = PopoverContent;