@plexui/react-native 0.1.0 → 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,410 @@
1
+ import { cloneElement, isValidElement, useState, type ReactElement, type ReactNode } from "react"
2
+ import { Pressable, StyleSheet, View, useWindowDimensions, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
3
+ import Svg, { Path } from "react-native-svg"
4
+ import X from "../../icons/plex/X"
5
+ import { flattenChildren, isRenderable, textOf } from "../../internal/children"
6
+ import { FloatingPanel } from "../../internal/FloatingPanel"
7
+ import { anchorProps, type FloatingAlign, type FloatingSide } from "../../internal/floating"
8
+ import { Glass } from "../../internal/Glass"
9
+ import { accentText, barSurface, controlHighlight, dangerText, elevationShadow } from "../../theme/material"
10
+ import { useTheme } from "../../theme/ThemeProvider"
11
+ import type { Theme } from "../../theme/types"
12
+ import { Button, type ButtonColor, type ButtonProps } from "../Button/Button"
13
+ import { IconDefaultsProvider } from "../Icon/createIcon"
14
+ import { useMenuAnchor } from "../Menu/Menu"
15
+ import { Text, TextColorProvider } from "../Text/Text"
16
+
17
+ /** Material's text button sets its label 12dp in: the row moves out by as much, so the labels line up with the text. */
18
+ const ANDROID_TEXT_BUTTON_INSET = 12
19
+
20
+ /** The edge of an inline tip that points at what it explains. */
21
+ export type TipArrowEdge = "top" | "bottom" | "left" | "right"
22
+
23
+ /** How a tip's actions show on a phone. */
24
+ export type TipMobileActions = "rows" | "buttons"
25
+
26
+ type TipContentProps = {
27
+ /** The tip's title: what the feature is. */
28
+ title: ReactNode
29
+ /** One or two sentences on how to use it. */
30
+ description?: ReactNode
31
+ /** A symbol that leads the message, as a TipKit tip's image. */
32
+ icon?: ReactNode
33
+ /** Buttons for the tip's actions, below the message. */
34
+ actions?: ReactNode
35
+ /**
36
+ * `rows`: each action a row of text in its button's color under a separator, as iOS tips show them (text buttons on
37
+ * Android); `buttons`: each Button as given, a full-width capsule under the message, as an iOS card that asks for a
38
+ * permission. @default "rows"
39
+ */
40
+ mobileActions?: TipMobileActions
41
+ }
42
+
43
+ export type TipProps = TipContentProps & {
44
+ /** Shows the Close button; called when it is pressed. */
45
+ onClose?: () => void
46
+ /** The Close button's label. @default "Close tip" */
47
+ closeLabel?: string
48
+ /** Draws an arrow at this edge, pointing at what the tip explains (TipKit's annotation). */
49
+ arrowEdge?: TipArrowEdge
50
+ testID?: string
51
+ style?: StyleProp<ViewStyle>
52
+ }
53
+
54
+ /** The kit's arrow (47 by 13), pointing down: the same path as the web's clip-path. */
55
+ const ARROW_PATH =
56
+ "M0 0C1.71 0 3.42 -.01 5.14 .01C6.78 .03 8.61 .06 10.21 .66C11.93 1.31 13.07 2.44 14.22 3.78C15.04 4.74 16.67 6.8 17.46 7.79C18.1 8.6 19.37 10.21 20.06 10.98C20.93 11.96 22.01 13 23.5 13C24.99 13 26.07 11.96 26.94 10.98C27.63 10.21 28.9 8.6 29.54 7.79C30.33 6.8 31.96 4.74 32.78 3.78C33.93 2.44 35.07 1.31 36.79 .66C38.39 .06 40.22 .03 41.86 .01C43.58 -.01 45.29 0 47 0Z"
57
+ /** Material 3's rich tooltip caret, 16 by 8, pointing down. */
58
+ const CARET_PATH = "M0 0L8 8L16 0Z"
59
+
60
+ /**
61
+ * The numbers of each platform. iOS: Tip.module.css at 767px and below (TipKit: 26 corners, 14 top and the layout
62
+ * margin across, a 36 symbol 12 from the text, 17/22 semibold over 15/20 secondary, a bare 22 Close in the tertiary
63
+ * label in a 44 target 1 from the top and 6 from the end, rows of 17 regular 46 tall under a separator, capsules of
64
+ * 48 10 apart). Android: a card of the Plex Android look with Material 3's rich tooltip inside (16dp corners, 16dp
65
+ * padding, a 24dp symbol, Title M over Body M, Close 24dp in a 48dp target, text buttons, 40dp capsules).
66
+ */
67
+ function metricsOf(theme: Theme) {
68
+ if (theme.isAndroid) {
69
+ return { radius: 16, top: 16, inline: 16, bottomRows: 8, bottomNone: 16, bottomButtons: 16, gap: 12, gapButtons: 16, iconFrame: 24, icon: 24, iconGap: 16, closeTarget: 48, closeIcon: 24, closeTop: 4, closeEnd: 4, messageEnd: 28, arrow: { width: 16, height: 8, path: CARET_PATH } }
70
+ }
71
+ const inline = theme.length("--mobile-layout-margin", 16)
72
+ const closeSize = 22
73
+ const closeOffset = 17
74
+ return {
75
+ radius: 26,
76
+ top: 14,
77
+ inline,
78
+ bottomRows: 0,
79
+ bottomNone: 14,
80
+ bottomButtons: 16,
81
+ gap: 11,
82
+ gapButtons: 16,
83
+ iconFrame: 36,
84
+ icon: 36,
85
+ iconGap: 12,
86
+ closeTarget: 44,
87
+ closeIcon: 22,
88
+ // The 44 target centers the 22 glyph 12 from the top and 17 from the end
89
+ closeTop: 12 - (44 - closeSize) / 2,
90
+ closeEnd: closeOffset - (44 - closeSize) / 2,
91
+ messageEnd: closeSize + closeOffset - inline + 1,
92
+ arrow: { width: theme.length("--tip-arrow-width", 47), height: theme.length("--tip-arrow-height", 13), path: ARROW_PATH },
93
+ }
94
+ }
95
+
96
+ type TipBodyProps = TipContentProps & {
97
+ onClose?: () => void
98
+ closeLabel: string
99
+ /** The card's fill; transparent over the popover's glass. */
100
+ background?: string
101
+ role?: "note"
102
+ testID?: string
103
+ style?: StyleProp<ViewStyle>
104
+ children?: ReactNode
105
+ }
106
+
107
+ function TipBody({ title, description, icon, actions, mobileActions = "rows", onClose, closeLabel, background, role, testID, style, children }: TipBodyProps) {
108
+ const theme = useTheme()
109
+ const android = theme.isAndroid
110
+ const m = metricsOf(theme)
111
+ const items = flattenChildren(actions).filter(isRenderable)
112
+ const hasActions = items.length > 0
113
+ const buttons = mobileActions === "buttons"
114
+ const hasIcon = isRenderable(icon)
115
+ const closable = onClose != null
116
+ const descriptionColor = android ? theme.colors.textSecondary : theme.color("--tip-description-color", theme.colors.textSecondary)
117
+ const paddingBottom = !hasActions ? m.bottomNone : buttons ? m.bottomButtons : m.bottomRows
118
+ const textStart = hasIcon ? m.iconFrame + m.iconGap : 0
119
+ return (
120
+ <View
121
+ role={role}
122
+ aria-label={role ? textOf(title) || undefined : undefined}
123
+ testID={testID}
124
+ style={[
125
+ styles.tip,
126
+ {
127
+ borderRadius: m.radius,
128
+ paddingTop: m.top,
129
+ paddingHorizontal: m.inline,
130
+ paddingBottom,
131
+ columnGap: m.iconGap,
132
+ rowGap: hasActions && buttons ? m.gapButtons : m.gap,
133
+ backgroundColor: background ?? theme.colors.groupedSurface,
134
+ },
135
+ style,
136
+ ]}
137
+ >
138
+ {children}
139
+ {hasIcon ? (
140
+ <View style={[styles.icon, { width: m.iconFrame, height: m.iconFrame }]}>
141
+ <IconDefaultsProvider size={m.icon} color={descriptionColor}>
142
+ {icon}
143
+ </IconDefaultsProvider>
144
+ </View>
145
+ ) : null}
146
+ <View style={[styles.message, closable ? { paddingEnd: m.messageEnd } : null]}>
147
+ <Text variant="headline">{title}</Text>
148
+ {isRenderable(description) ? (
149
+ <TextColorProvider value={descriptionColor}>
150
+ <Text variant="subheadline" color={descriptionColor} style={android ? styles.androidDescription : null}>
151
+ {description}
152
+ </Text>
153
+ </TextColorProvider>
154
+ ) : null}
155
+ </View>
156
+ {hasActions ? (
157
+ <View
158
+ style={[
159
+ styles.actions,
160
+ buttons ? styles.buttons : android ? [styles.androidActions, { marginStart: textStart - ANDROID_TEXT_BUTTON_INSET }] : { paddingStart: textStart },
161
+ ]}
162
+ >
163
+ {items.map((item, index) => (buttons ? <ActionButton key={index} item={item} /> : <ActionRow key={index} item={item} />))}
164
+ </View>
165
+ ) : null}
166
+ {closable ? (
167
+ <Pressable
168
+ accessibilityRole="button"
169
+ accessibilityLabel={closeLabel}
170
+ onPress={onClose}
171
+ style={[styles.close, { width: m.closeTarget, height: m.closeTarget, top: m.closeTop, end: m.closeEnd, borderRadius: m.closeTarget / 2 }]}
172
+ >
173
+ {({ pressed }) => (
174
+ <View style={[styles.closeGlyph, android && pressed ? { backgroundColor: controlHighlight(theme.scheme), borderRadius: m.closeTarget / 2 } : null]}>
175
+ <X size={m.closeIcon} color={android ? theme.colors.labelSecondary : theme.colors.labelTertiary} style={!android && pressed ? styles.pressed : undefined} />
176
+ </View>
177
+ )}
178
+ </Pressable>
179
+ ) : null}
180
+ </View>
181
+ )
182
+ }
183
+
184
+ /** An action as a capsule across the tip, its Button's color and variant kept: 48 tall on iOS, 40dp on Android. */
185
+ function ActionButton({ item }: { item: ReactNode }) {
186
+ const theme = useTheme()
187
+ if (!isValidElement(item) || item.type !== Button) return <>{item}</>
188
+ const button = item as ReactElement<ButtonProps>
189
+ return cloneElement(button, {
190
+ size: theme.isAndroid ? "lg" : "xl",
191
+ pill: true,
192
+ block: true,
193
+ style: [button.props.style, theme.isAndroid ? null : { minHeight: 48 }],
194
+ })
195
+ }
196
+
197
+ /**
198
+ * An action as a row of text in its Button's color under a separator, 46 tall, as iOS tips list them; on Android a
199
+ * text button in the accent, as Material 3's rich tooltip sets its actions. Other elements stand as given.
200
+ */
201
+ function ActionRow({ item }: { item: ReactNode }) {
202
+ const theme = useTheme()
203
+ if (!isValidElement(item) || item.type !== Button) return <>{item}</>
204
+ const { color = "primary", children, onPress, disabled, accessibilityLabel, testID } = (item as ReactElement<ButtonProps & { color?: ButtonColor }>).props
205
+ if (theme.isAndroid) {
206
+ // Material's text button: 40dp, 12dp in, the label in the accent (red for a danger action), a press layer behind
207
+ const label = disabled ? theme.colors.labelTertiary : color === "danger" ? dangerText(theme) : accentText(theme)
208
+ return (
209
+ <Pressable
210
+ accessibilityRole="button"
211
+ accessibilityLabel={accessibilityLabel}
212
+ accessibilityState={{ disabled: !!disabled }}
213
+ disabled={disabled ?? undefined}
214
+ onPress={onPress as ((event: GestureResponderEvent) => void) | undefined}
215
+ testID={testID}
216
+ style={({ pressed }) => [styles.androidRow, pressed ? { backgroundColor: controlHighlight(theme.scheme) } : null]}
217
+ >
218
+ <Text variant="subheadline" weight="medium" color={label}>
219
+ {children as ReactNode}
220
+ </Text>
221
+ </Pressable>
222
+ )
223
+ }
224
+ const ink = theme.color(`--color-text-${color}-ghost`, theme.colors.text)
225
+ return (
226
+ <Pressable
227
+ accessibilityRole="button"
228
+ accessibilityLabel={accessibilityLabel}
229
+ accessibilityState={{ disabled: !!disabled }}
230
+ disabled={disabled ?? undefined}
231
+ onPress={onPress as ((event: GestureResponderEvent) => void) | undefined}
232
+ testID={testID}
233
+ style={({ pressed }) => [styles.row, { borderTopColor: theme.color("--color-border", theme.colors.border) }, pressed ? { backgroundColor: theme.color("--alpha-05") } : null]}
234
+ >
235
+ <Text variant="body" color={disabled ? theme.colors.labelTertiary : ink}>
236
+ {children as ReactNode}
237
+ </Text>
238
+ </Pressable>
239
+ )
240
+ }
241
+
242
+ /** The arrow of a tip at its edge, in the tip's fill: the kit's 47 by 13 on iOS, Material's 16 by 8 caret on Android. */
243
+ function TipArrow({ edge, color, offset, length }: { edge: TipArrowEdge; color: string; offset?: number; length?: number }) {
244
+ const theme = useTheme()
245
+ const { arrow } = metricsOf(theme)
246
+ const rotate = edge === "bottom" ? "0deg" : edge === "top" ? "180deg" : edge === "left" ? "90deg" : "-90deg"
247
+ // A sideways arrow turns about its own center: it is moved by half its length less half its height
248
+ const shift = (arrow.width - arrow.height) / 2
249
+ const along = offset != null ? offset - arrow.width / 2 : length != null ? (length - arrow.width) / 2 : undefined
250
+ const position: ViewStyle =
251
+ edge === "bottom"
252
+ ? { top: "100%", left: along ?? "50%", marginLeft: along == null ? -arrow.width / 2 : 0 }
253
+ : edge === "top"
254
+ ? { bottom: "100%", left: along ?? "50%", marginLeft: along == null ? -arrow.width / 2 : 0 }
255
+ : edge === "left"
256
+ ? { top: along != null ? along + shift : "50%", marginTop: along == null ? -arrow.height / 2 : 0, right: "100%", marginRight: -shift }
257
+ : { top: along != null ? along + shift : "50%", marginTop: along == null ? -arrow.height / 2 : 0, left: "100%", marginLeft: -shift }
258
+ return (
259
+ <View pointerEvents="none" style={[styles.arrow, position, { width: arrow.width, height: arrow.height, transform: [{ rotate }] }]}>
260
+ <Svg width={arrow.width} height={arrow.height} viewBox={`0 0 ${arrow.width} ${arrow.height}`}>
261
+ <Path d={arrow.path} fill={color} />
262
+ </Svg>
263
+ </View>
264
+ )
265
+ }
266
+
267
+ /**
268
+ * A tip inside the page, as @plexui/ui's Tip on a phone (TipKit's inline tip): a title, a description, an optional
269
+ * symbol, actions and Close, on the card of a grouped list; `arrowEdge` adds TipKit's annotation arrow. On Android the
270
+ * same card in the Plex Android look, laid out as Material 3's rich tooltip.
271
+ */
272
+ export function Tip({ onClose, closeLabel = "Close tip", arrowEdge, testID, style, ...content }: TipProps) {
273
+ const theme = useTheme()
274
+ const { arrow } = metricsOf(theme)
275
+ const fill = theme.colors.groupedSurface
276
+ const room: ViewStyle | null = arrowEdge
277
+ ? { [arrowEdge === "top" ? "marginTop" : arrowEdge === "bottom" ? "marginBottom" : arrowEdge === "left" ? "marginLeft" : "marginRight"]: arrow.height }
278
+ : null
279
+ return (
280
+ <TipBody {...content} onClose={onClose} closeLabel={closeLabel} role="note" testID={testID} background={fill} style={[room, style]}>
281
+ {arrowEdge ? <TipArrow edge={arrowEdge} color={fill} /> : null}
282
+ </TipBody>
283
+ )
284
+ }
285
+
286
+ export type TipPopoverProps = TipContentProps & {
287
+ /** Shows the tip (controlled). */
288
+ open?: boolean
289
+ /** Shows the tip at first (uncontrolled). @default false */
290
+ defaultOpen?: boolean
291
+ /** Called when the tip opens or closes: Close, a tap outside, Android's back or the web's Escape closes it. */
292
+ onOpenChange?: (open: boolean) => void
293
+ /** The control the tip explains: an element that hands its native view to `ref` (a Button, Pressable, View). */
294
+ children: ReactElement
295
+ /** The side of the control the tip shows on. Turned when it does not fit. @default "bottom" */
296
+ side?: FloatingSide
297
+ /** The alignment against the control. @default "center" */
298
+ align?: FloatingAlign
299
+ /** The distance from the control to the arrow's point. @default 4 */
300
+ sideOffset?: number
301
+ /** Shows the Close button. @default true */
302
+ closeButton?: boolean
303
+ /** The Close button's label. @default "Close tip" */
304
+ closeLabel?: string
305
+ testID?: string
306
+ style?: StyleProp<ViewStyle>
307
+ }
308
+
309
+ /**
310
+ * A tip anchored to a control, as @plexui/ui's Tip.Popover on a phone (TipKit's popover tip): the tip's content on the
311
+ * iOS 27 alert's glass with the kit's popover shadow, 300 wide, its arrow pointing at the control; on Android the
312
+ * popup surface of the Plex Android look with Material's caret. It does not take the focus.
313
+ */
314
+ function TipPopover({
315
+ open: controlledOpen,
316
+ defaultOpen = false,
317
+ onOpenChange,
318
+ children,
319
+ side = "bottom",
320
+ align = "center",
321
+ sideOffset = 4,
322
+ closeButton = true,
323
+ closeLabel = "Close tip",
324
+ testID,
325
+ style,
326
+ ...content
327
+ }: TipPopoverProps) {
328
+ const theme = useTheme()
329
+ const window = useWindowDimensions()
330
+ const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen)
331
+ const open = controlledOpen ?? uncontrolledOpen
332
+ const setOpen = (next: boolean) => {
333
+ if (controlledOpen === undefined) setUncontrolledOpen(next)
334
+ onOpenChange?.(next)
335
+ }
336
+ const { anchor, place, setTrigger } = useMenuAnchor(open)
337
+ const android = theme.isAndroid
338
+ const { arrow } = metricsOf(theme)
339
+ const padding = 16
340
+ const width = Math.min(theme.length("--tip-popover-width", 300), window.width - padding * 2)
341
+ const fill = android ? barSurface(theme.material, theme.scheme) : theme.color("--dialog-alert-background", theme.color("--tip-popover-background"))
342
+ const body = (
343
+ <TipBody {...content} onClose={closeButton ? () => setOpen(false) : undefined} closeLabel={closeLabel} background="transparent" />
344
+ )
345
+ return (
346
+ <>
347
+ {/* The control keeps its place in the layout; the tip stands at it and follows it */}
348
+ {isValidElement(children)
349
+ ? cloneElement(children as ReactElement<{ ref?: unknown; onLayout?: (event: never) => void }>, anchorProps((children as ReactElement<{ ref?: unknown; onLayout?: (event: never) => void }>).props, setTrigger as never, open ? () => place() : undefined) as never)
350
+ : children}
351
+ <FloatingPanel
352
+ open={open}
353
+ onDismiss={() => setOpen(false)}
354
+ anchor={anchor}
355
+ side={side}
356
+ align={align}
357
+ // Radix adds the arrow's height to the offset: the distance is to the arrow's point
358
+ sideOffset={sideOffset + arrow.height}
359
+ collisionPadding={padding}
360
+ arrow={{ width: arrow.width, padding: android ? 12 : 26 }}
361
+ glass={!android}
362
+ autoFocus={false}
363
+ role="dialog"
364
+ aria-label={textOf(content.title) || undefined}
365
+ testID={testID}
366
+ style={[{ width }, style]}
367
+ >
368
+ {(placement) => (
369
+ <>
370
+ {android ? (
371
+ <View style={[styles.popupSurface, { backgroundColor: fill, boxShadow: elevationShadow.level2 }]}>{body}</View>
372
+ ) : (
373
+ <Glass
374
+ radius={metricsOf(theme).radius}
375
+ fillToken="--dialog-alert-background"
376
+ filterToken="--dialog-alert-backdrop-filter"
377
+ shadowToken="--tip-popover-shadow"
378
+ >
379
+ {body}
380
+ </Glass>
381
+ )}
382
+ <TipArrow edge={opposite[placement.side]} color={fill} offset={placement.size ? placement.arrow : undefined} />
383
+ </>
384
+ )}
385
+ </FloatingPanel>
386
+ </>
387
+ )
388
+ }
389
+
390
+ /** The tip's edge that faces the control: the arrow points back at it. */
391
+ const opposite: Record<FloatingSide, TipArrowEdge> = { bottom: "top", top: "bottom", left: "right", right: "left" }
392
+
393
+ const styles = StyleSheet.create({
394
+ tip: { position: "relative", flexDirection: "row", flexWrap: "wrap", alignItems: "flex-start", alignSelf: "stretch", borderCurve: "continuous" },
395
+ icon: { flexShrink: 0, alignItems: "center", justifyContent: "center" },
396
+ message: { flex: 1, minWidth: 0 },
397
+ androidDescription: { marginTop: 2 },
398
+ actions: { flexBasis: "100%", flexGrow: 1, flexDirection: "column" },
399
+ buttons: { gap: 10 },
400
+ androidActions: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
401
+ row: { minHeight: 46, paddingVertical: 12, borderTopWidth: 1, justifyContent: "center" },
402
+ androidRow: { alignSelf: "flex-start", minHeight: 40, paddingHorizontal: 12, borderRadius: 20, justifyContent: "center" },
403
+ close: { position: "absolute", alignItems: "center", justifyContent: "center" },
404
+ closeGlyph: { width: "100%", height: "100%", alignItems: "center", justifyContent: "center" },
405
+ pressed: { opacity: 0.5 },
406
+ arrow: { position: "absolute" },
407
+ popupSurface: { borderRadius: 12, borderCurve: "continuous" },
408
+ })
409
+
410
+ Tip.Popover = TipPopover
@@ -15,6 +15,7 @@ import { physicalPadding, useRTL } from "../../internal/direction"
15
15
  import { Glass } from "../../internal/Glass"
16
16
  import { curves } from "../../internal/motion"
17
17
  import { divider, withAlpha } from "../../theme/material"
18
+ import { textOf } from "../../internal/children"
18
19
  import { useTheme } from "../../theme/ThemeProvider"
19
20
  import type { Theme } from "../../theme/types"
20
21
  import { flattenChildren } from "../../internal/children"
@@ -201,9 +202,17 @@ function ToolbarGroup({ children, style, ...rest }: ViewProps) {
201
202
  ToolbarGroup.displayName = "Toolbar.Group"
202
203
 
203
204
  export type ToolbarTitleProps = {
204
- children: ReactNode
205
+ /** The title's text. With `image` it may be left out. */
206
+ children?: ReactNode
205
207
  subtitle?: ReactNode
206
208
  numberOfLines?: number
209
+ /**
210
+ * A picture in the title's place: a logo (an Image, an svg). It stays the bar's header for a screen reader, named by
211
+ * `accessibilityLabel` (or the text in `children`, which is then not drawn).
212
+ */
213
+ image?: ReactNode
214
+ /** The header's name, for an `image` title. */
215
+ accessibilityLabel?: string
207
216
  }
208
217
 
209
218
  /** The title of the bar, and an optional subtitle under it. Announced as a header. */
@@ -248,7 +257,7 @@ function barItem(theme: Theme, placement: ToolbarPlacement, plain: boolean): Bar
248
257
  // Android's opaque bar: 24dp glyphs plain in 48dp targets, a label (Save) Medium 15 12 in from the ends of its press
249
258
  if (theme.isAndroid && plain) return { height: 48, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 12, plain: true }
250
259
  // Android: 46dp circles with 24dp glyphs; a label (Save) Medium 15 in a capsule 16 in from its ends
251
- if (theme.isAndroid) return { height: 46, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 16 }
260
+ if (theme.isAndroid) return { height: 46, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 16, bottom: placement === "bottom" }
252
261
  const bottom = placement === "bottom"
253
262
  const weight = (name: string, fallback: number) => {
254
263
  const value = theme.length(name, fallback)
@@ -331,8 +340,22 @@ function BarTitle({
331
340
  android && start && !large ? { marginStart: plain ? (afterLeading ? 20 : 14) : 18 } : null,
332
341
  ]}
333
342
  >
343
+ {title.image != null ? (
344
+ // A logo is the header: one element named for a screen reader, the picture itself hidden from it
345
+ <View
346
+ accessible
347
+ accessibilityRole="header"
348
+ accessibilityLabel={title.accessibilityLabel ?? (textOf(title.children) || undefined)}
349
+ style={styles.titleImage}
350
+ >
351
+ <View importantForAccessibility="no-hide-descendants" accessibilityElementsHidden aria-hidden>
352
+ {title.image}
353
+ </View>
354
+ </View>
355
+ ) : (
334
356
  <Text
335
357
  accessibilityRole="header"
358
+ accessibilityLabel={title.accessibilityLabel}
336
359
  numberOfLines={title.numberOfLines ?? 1}
337
360
  weight={android ? "medium" : large ? "bold" : "semibold"}
338
361
  align={start || large ? "auto" : "center"}
@@ -340,6 +363,7 @@ function BarTitle({
340
363
  >
341
364
  {title.children}
342
365
  </Text>
366
+ )}
343
367
  {subtitle ? (
344
368
  <Text
345
369
  numberOfLines={1}
@@ -661,6 +685,7 @@ export const Toolbar = Object.assign(ToolbarRoot, {
661
685
  })
662
686
 
663
687
  const styles = StyleSheet.create({
688
+ titleImage: { flexDirection: "row", alignItems: "center" },
664
689
  slot: { flexDirection: "row", alignItems: "center" },
665
690
  trailing: { justifyContent: "flex-end" },
666
691
  content: { justifyContent: "center" },