@plexui/react-native 0.3.0 → 0.5.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.
- package/dist/es/components/ActionSheet/ActionSheet.js +1 -1
- package/dist/es/components/BottomSheet/BottomSheet.js +87 -17
- package/dist/es/components/Button/Button.js +21 -4
- package/dist/es/components/ContextMenu/ContextMenu.js +16 -16
- package/dist/es/components/Input/Input.js +3 -1
- package/dist/es/components/List/List.js +15 -1
- package/dist/es/components/Menu/Menu.js +26 -11
- package/dist/es/components/Tip/Tip.js +29 -12
- package/dist/es/internal/Glass.js +15 -8
- package/dist/types/components/BottomSheet/BottomSheet.d.ts +22 -1
- package/dist/types/components/Button/Button.d.ts +6 -2
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +17 -2
- package/dist/types/components/Menu/Menu.d.ts +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/internal/Glass.d.ts +7 -1
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +1 -0
- package/src/components/BottomSheet/BottomSheet.tsx +153 -25
- package/src/components/Button/Button.tsx +26 -6
- package/src/components/ContextMenu/ContextMenu.tsx +42 -12
- package/src/components/Input/Input.tsx +3 -1
- package/src/components/List/List.tsx +13 -1
- package/src/components/Menu/Menu.tsx +27 -12
- package/src/components/Tip/Tip.tsx +68 -12
- package/src/index.ts +2 -2
- package/src/internal/Glass.tsx +22 -8
|
@@ -36,8 +36,12 @@ export type ButtonProps = Omit<PressableProps, "children" | "style"> & {
|
|
|
36
36
|
pill?: boolean
|
|
37
37
|
/** The shape on Android: a pill (default), as newer Android screens draw a button, or 8dp corners. */
|
|
38
38
|
shape?: "round" | "square"
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The glass of iOS 26 for a neutral soft or ghost button, or its clear glass over a photo, a video or a color (a
|
|
41
|
+
* light frost and a #f5f5f5 label, in both themes). Android has no glass: a clear button there is a translucent
|
|
42
|
+
* gray with the same label.
|
|
43
|
+
*/
|
|
44
|
+
mobileMaterial?: "glass" | "flat" | "clear"
|
|
41
45
|
/** A button as wide and tall: an icon alone. */
|
|
42
46
|
uniform?: boolean
|
|
43
47
|
/** Takes the whole width. */
|
|
@@ -591,22 +595,38 @@ function ButtonBody({
|
|
|
591
595
|
// its buttons on glass and its plain ones; the token alone gives the Regular of the plain button
|
|
592
596
|
weight: theme.isIOS && variant !== "ghost" ? "medium" : base.weight,
|
|
593
597
|
}
|
|
594
|
-
const
|
|
598
|
+
const barred = barColors(theme, buttonColors(theme, color, variant, disabled, selected), { bar, prominent: accentAction, neutral, disabled, selected, flat: mobileMaterial === "flat" })
|
|
599
|
+
// Clear glass over a photo, a video or a color: the kit's #f5f5f5 label in both themes, on iOS clear glass and on
|
|
600
|
+
// Android (no glass) its gray at 17%, a little more when pressed
|
|
601
|
+
const clear = mobileMaterial === "clear" && neutral && !bar
|
|
602
|
+
const clearLabel = clear ? theme.color("--mobile-glass-clear-label", "#f5f5f5") : ""
|
|
603
|
+
const colors: typeof barred = clear
|
|
604
|
+
? {
|
|
605
|
+
...barred,
|
|
606
|
+
text: disabled ? withAlpha(clearLabel, 0.4) : clearLabel,
|
|
607
|
+
pressedText: undefined,
|
|
608
|
+
background: theme.color("--mobile-glass-clear-background", "rgba(153, 153, 153, 0.17)"),
|
|
609
|
+
pressed: theme.color("--mobile-glass-clear-background-active", "rgba(153, 153, 153, 0.28)"),
|
|
610
|
+
border: undefined,
|
|
611
|
+
}
|
|
612
|
+
: barred
|
|
595
613
|
// In a bar every neutral soft or ghost button is glass, as on iOS 26, unless it asks to stay flat or is selected.
|
|
596
614
|
// A disabled glass button keeps its glass, as the phone CSS's
|
|
597
615
|
const wantsGlass = bar ? mobileMaterial !== "flat" && neutral && !selected && !bar.inGroup : mobileMaterial === "glass" && neutral
|
|
598
|
-
const glass = theme.isIOS && wantsGlass
|
|
616
|
+
const glass = theme.isIOS && (wantsGlass || clear)
|
|
599
617
|
// On Android the same button stands on a glass of its own, as the Android bar circles: a see-through card with a
|
|
600
618
|
// rim and a soft shadow (the glass of a plain bar)
|
|
601
619
|
const card = theme.isAndroid && !!bar && !bar.plain && (wantsGlass || (accentAction && disabled && !bar.inGroup))
|
|
602
620
|
const androidGlass = useAndroidGlass("bar", bar?.canvas)
|
|
603
621
|
if (glass && !bar) {
|
|
604
|
-
// The Liquid Glass text button of the iOS 27 kit: Medium (`--button-glass-font-weight`), 17/22 at md and lg
|
|
622
|
+
// The Liquid Glass text button of the iOS 27 kit: Medium (`--button-glass-font-weight`), 17/22 at md and lg, 12 a side
|
|
605
623
|
const glassWeight = theme.length("--button-glass-font-weight", 510)
|
|
606
624
|
metrics.weight = glassWeight >= 590 ? "semibold" : glassWeight >= 500 ? "medium" : "regular"
|
|
607
625
|
if (size === "md" || size === "lg") {
|
|
608
626
|
metrics.fontSize = theme.length("--button-glass-font-size", metrics.fontSize)
|
|
609
627
|
metrics.lineHeight = theme.length("--button-glass-line-height", metrics.lineHeight)
|
|
628
|
+
// 12 each side, where a bordered medium button's Subheadline label takes 14
|
|
629
|
+
if (!gutterSize) metrics.gutter = theme.length("--button-glass-gutter", metrics.gutter)
|
|
610
630
|
}
|
|
611
631
|
}
|
|
612
632
|
const nativeRipple = useMaterialPress(theme)
|
|
@@ -771,7 +791,7 @@ function ButtonBody({
|
|
|
771
791
|
if (glass) {
|
|
772
792
|
return (
|
|
773
793
|
<Pressable {...pressable} style={[{ alignSelf: block ? "stretch" : "flex-start" }, style]}>
|
|
774
|
-
<Glass interactive={!inert} elevation={bar?.raised ? "raised" : "regular"} radius={metrics.radius} fillToken={pressed && !inert ? "--mobile-glass-background-active" : undefined} style={[body, { borderRadius: metrics.radius }]}>
|
|
794
|
+
<Glass interactive={!inert} clear={clear} elevation={bar?.raised ? "raised" : "regular"} radius={metrics.radius} fillToken={pressed && !inert ? (clear ? "--mobile-glass-clear-background-active" : "--mobile-glass-background-active") : undefined} style={[body, { borderRadius: metrics.radius }]}>
|
|
775
795
|
{content}
|
|
776
796
|
</Glass>
|
|
777
797
|
</Pressable>
|
|
@@ -11,9 +11,22 @@ type ContextMenuState = {
|
|
|
11
11
|
setOpen: (next: boolean) => void
|
|
12
12
|
anchor: MenuAnchor | null
|
|
13
13
|
preview: ReactNode
|
|
14
|
-
|
|
14
|
+
look: PreviewLook
|
|
15
|
+
setTarget: (node: Measurable | null, preview: ReactNode, look: PreviewLook) => void
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/** How the held element lifts: its own corner radius, and whether it stands on the preview's card or on its own. */
|
|
19
|
+
type PreviewLook = { radius?: number; shape: ContextMenuPreviewShape }
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* `card`: the element on the preview's card (a grouped surface, clipped to the kit's 30 or half the element's height).
|
|
23
|
+
* `element`: an element that draws its own shape, such as a chat bubble, lifts as it is, with no card and no clip,
|
|
24
|
+
* its shadow following its `radius` (UIKit's UITargetedPreview with a clear background and a visible path).
|
|
25
|
+
*/
|
|
26
|
+
export type ContextMenuPreviewShape = "card" | "element"
|
|
27
|
+
|
|
28
|
+
const CARD: PreviewLook = { shape: "card" }
|
|
29
|
+
|
|
17
30
|
const ContextMenuContext = createContext<ContextMenuState | null>(null)
|
|
18
31
|
|
|
19
32
|
function useContextMenu(part: string) {
|
|
@@ -40,8 +53,9 @@ function ContextMenuRoot({ children, open: openProp, onOpenChange }: ContextMenu
|
|
|
40
53
|
const [own, setOwn] = useState(false)
|
|
41
54
|
const open = openProp ?? own
|
|
42
55
|
const [anchor, setAnchor] = useState<MenuAnchor | null>(null)
|
|
43
|
-
const target = useRef<{ node: Measurable | null; preview: ReactNode }>({ node: null, preview: null })
|
|
56
|
+
const target = useRef<{ node: Measurable | null; preview: ReactNode; look: PreviewLook }>({ node: null, preview: null, look: CARD })
|
|
44
57
|
const [preview, setPreview] = useState<ReactNode>(null)
|
|
58
|
+
const [look, setLook] = useState<PreviewLook>(CARD)
|
|
45
59
|
const apply = useCallback(
|
|
46
60
|
(next: boolean) => {
|
|
47
61
|
if (openProp === undefined) setOwn(next)
|
|
@@ -64,6 +78,7 @@ function ContextMenuRoot({ children, open: openProp, onOpenChange }: ContextMenu
|
|
|
64
78
|
if (!live) return
|
|
65
79
|
setAnchor(box)
|
|
66
80
|
setPreview(target.current.preview)
|
|
81
|
+
setLook(target.current.look)
|
|
67
82
|
})
|
|
68
83
|
// A turn of the screen moves the element: the menu closes, as iOS dismisses a context menu on rotation
|
|
69
84
|
const sub = Dimensions.addEventListener("change", () => applyRef.current(false))
|
|
@@ -72,10 +87,10 @@ function ContextMenuRoot({ children, open: openProp, onOpenChange }: ContextMenu
|
|
|
72
87
|
sub.remove()
|
|
73
88
|
}
|
|
74
89
|
}, [open])
|
|
75
|
-
const setTarget = useCallback((node: Measurable | null, next: ReactNode) => {
|
|
76
|
-
target.current = { node, preview: next }
|
|
90
|
+
const setTarget = useCallback((node: Measurable | null, next: ReactNode, nextLook: PreviewLook) => {
|
|
91
|
+
target.current = { node, preview: next, look: nextLook }
|
|
77
92
|
}, [])
|
|
78
|
-
return <ContextMenuContext.Provider value={{ open, setOpen, anchor, preview, setTarget }}>{children}</ContextMenuContext.Provider>
|
|
93
|
+
return <ContextMenuContext.Provider value={{ open, setOpen, anchor, preview, look, setTarget }}>{children}</ContextMenuContext.Provider>
|
|
79
94
|
}
|
|
80
95
|
ContextMenuRoot.displayName = "ContextMenu"
|
|
81
96
|
|
|
@@ -91,7 +106,20 @@ type Holdable = {
|
|
|
91
106
|
* runs; a touch and hold opens the menu, and so does a right click on the web. The lifted preview on iOS is the
|
|
92
107
|
* element drawn again from its props, so state the element keeps inside itself is not in it.
|
|
93
108
|
*/
|
|
94
|
-
|
|
109
|
+
export type ContextMenuTriggerProps = {
|
|
110
|
+
children: ReactElement<Holdable>
|
|
111
|
+
style?: StyleProp<ViewStyle>
|
|
112
|
+
/**
|
|
113
|
+
* The element's own corner radius. On iOS the lifted preview keeps these corners (and with `shape="element"` its
|
|
114
|
+
* shadow follows them); on Android the dimming is cut around the element at them. Unset: a card at the kit's 30
|
|
115
|
+
* (half the element's height at most) on iOS, square on Android.
|
|
116
|
+
*/
|
|
117
|
+
radius?: number
|
|
118
|
+
/** `card` (default) lifts the element on the preview's card; `element` lifts an element that draws its own shape as it is. */
|
|
119
|
+
shape?: ContextMenuPreviewShape
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function ContextMenuTrigger({ children, style, radius, shape = "card" }: ContextMenuTriggerProps) {
|
|
95
123
|
const theme = useTheme()
|
|
96
124
|
const { setOpen, setTarget, open, anchor } = useContextMenu("ContextMenu.Trigger")
|
|
97
125
|
const child = isValidElement<Holdable>(children) ? children : null
|
|
@@ -117,7 +145,7 @@ function ContextMenuTrigger({ children, style }: { children: ReactElement<Holdab
|
|
|
117
145
|
const web = Platform.OS === "web"
|
|
118
146
|
return (
|
|
119
147
|
<View
|
|
120
|
-
ref={(next: unknown) => setTarget(next as Measurable | null, preview)}
|
|
148
|
+
ref={(next: unknown) => setTarget(next as Measurable | null, preview, { radius, shape })}
|
|
121
149
|
collapsable={false}
|
|
122
150
|
// On iOS the element hides under its lifted preview while the menu is open, so it is not drawn twice; Android
|
|
123
151
|
// keeps it lit in its place
|
|
@@ -142,16 +170,18 @@ export type ContextMenuContentProps = Omit<MenuContentProps, "align">
|
|
|
142
170
|
/** The menu: Menu's items, 250 wide on iOS. */
|
|
143
171
|
function ContextMenuContent(props: ContextMenuContentProps) {
|
|
144
172
|
const theme = useTheme()
|
|
145
|
-
const { open, setOpen, anchor, preview } = useContextMenu("ContextMenu.Content")
|
|
146
|
-
// The preview keeps a row's corners to half its height, else the kit's 30 (--context-menu-preview-radius)
|
|
173
|
+
const { open, setOpen, anchor, preview, look } = useContextMenu("ContextMenu.Content")
|
|
174
|
+
// The preview keeps a row's corners to half its height, else the kit's 30 (--context-menu-preview-radius); a
|
|
175
|
+
// Trigger's `radius` is the element's own corners
|
|
147
176
|
// Items that say `checked` make a set of options, with the checkmark's column, as in Menu
|
|
148
177
|
const check = hasCheckedItems(props.children)
|
|
149
|
-
const
|
|
178
|
+
const half = (anchor?.height ?? 60) / 2
|
|
179
|
+
const radius = Math.min(look.radius ?? theme.length("--context-menu-preview-radius", 30), half)
|
|
150
180
|
if (theme.isAndroid) {
|
|
151
181
|
// Android: Material's popup under the element at its end, the screen dimmed around it
|
|
152
|
-
return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} row={anchor ? { box: anchor, radius: { top: 0, bottom: 0 } } : null} cover={false} onClose={() => setOpen(false)} />
|
|
182
|
+
return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} row={anchor ? { box: anchor, radius: { top: look.radius ?? 0, bottom: look.radius ?? 0 } } : null} cover={false} onClose={() => setOpen(false)} />
|
|
153
183
|
}
|
|
154
|
-
return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} context={{ preview, radius }} onClose={() => setOpen(false)} />
|
|
184
|
+
return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} context={{ preview, radius, bare: look.shape === "element" }} onClose={() => setOpen(false)} />
|
|
155
185
|
}
|
|
156
186
|
ContextMenuContent.displayName = "ContextMenu.Content"
|
|
157
187
|
|
|
@@ -267,7 +267,9 @@ export function fieldLook(
|
|
|
267
267
|
const row = IOS_FIELD[size] ?? IOS_FIELD.md
|
|
268
268
|
const height = theme.length(`--control-size-${row.height}`, 44)
|
|
269
269
|
const radius = pill ? height / 2 : theme.length(`--control-radius-${row.radius}`, IOS_RADIUS[row.radius])
|
|
270
|
-
|
|
270
|
+
// A tall capsule (50 and up) sets its text 20 in, as iOS 26's own (Mail's Add Account, Apple Account's Add Email
|
|
271
|
+
// Address); a smaller field keeps 14
|
|
272
|
+
const gutter = startAdornment ? 11 : pill && height >= 48 ? 20 : 14
|
|
271
273
|
const border =
|
|
272
274
|
variant === "outline"
|
|
273
275
|
? state.invalid
|
|
@@ -928,6 +928,9 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
928
928
|
// A picture wider than the tile (a photo, an avatar) keeps its own size: it starts at the row's inset, where the
|
|
929
929
|
// header and the footer stand, and the text follows 14 past it, as UIKit's image to text padding
|
|
930
930
|
const [wide, setWide] = useState(false)
|
|
931
|
+
// A picture taller than the tile (a 40 photo) keeps the cell's margins over and under it, 10 as UIKit's content
|
|
932
|
+
// configuration keeps them: a 40 photo makes a 60 row
|
|
933
|
+
const [tall, setTall] = useState(false)
|
|
931
934
|
// In a List with `columns` a field's value starts at one column, 40% into the row (`--field-row-column-width`)
|
|
932
935
|
// A switch, a checkbox and a radio stay at the row's edge
|
|
933
936
|
const columns = useContext(ListOptionsContext)?.columns === true && trailing != null
|
|
@@ -950,11 +953,14 @@ function IOSContent({ handPress, valueColor, theme, label, description, descript
|
|
|
950
953
|
style={[
|
|
951
954
|
styles.tile,
|
|
952
955
|
{ minWidth: tile, minHeight: tile, marginStart: wide ? 0 : theme.length("--field-row-icon-offset", -2), marginEnd: theme.length("--field-row-icon-gap", 14) },
|
|
956
|
+
tall ? { marginVertical: theme.length("--field-row-picture-margin-block", 10) } : null,
|
|
953
957
|
leadingColor ? { backgroundColor: leadingColor, borderRadius: theme.length("--field-row-icon-radius", 7) } : null,
|
|
954
958
|
]}
|
|
955
959
|
onLayout={(event) => {
|
|
956
960
|
const next = event.nativeEvent.layout.width > tile + 0.5
|
|
957
961
|
if (next !== wide) setWide(next)
|
|
962
|
+
const taller = event.nativeEvent.layout.height > tile + 0.5
|
|
963
|
+
if (taller !== tall) setTall(taller)
|
|
958
964
|
}}
|
|
959
965
|
>
|
|
960
966
|
<IconDefaultsProvider size={leadingColor ? 20 : theme.length("--field-row-icon-symbol-size", 24)} color={leadingColor ? "#ffffff" : disabled ? theme.colors.labelTertiary : theme.colors.accent}>
|
|
@@ -1070,6 +1076,9 @@ function AndroidContent({
|
|
|
1070
1076
|
// A picture wider than the symbol's 24 (a photo, an avatar) keeps its own size from the rows' inset (21, where the
|
|
1071
1077
|
// header and the footer stand), the text 16 past it, as Material's list item with a leading avatar; 0 for a symbol
|
|
1072
1078
|
const [wide, setWide] = useState(0)
|
|
1079
|
+
// A picture taller than the symbol's 24 (a 40 avatar) keeps 8 over and under it, Material's list item with a leading
|
|
1080
|
+
// avatar: a 40 photo makes a 56 row
|
|
1081
|
+
const [tall, setTall] = useState(false)
|
|
1073
1082
|
// The text (and the divider) 21 in, or 64 after a symbol, a tile or a choice's mark (its 20dp circle 22 in)
|
|
1074
1083
|
const textStart = leading == null ? ANDROID_INSET : wide > 0 && !tile && !leadingMark ? ANDROID_INSET + wide + 16 : 64
|
|
1075
1084
|
// A value that ends the row stands 17 from the end (a value row), 20 in a row with a tile (a tiled row)
|
|
@@ -1090,7 +1099,7 @@ function AndroidContent({
|
|
|
1090
1099
|
<View style={styles.androidMark}>{leading}</View>
|
|
1091
1100
|
) : (
|
|
1092
1101
|
<View
|
|
1093
|
-
style={tile ? [styles.androidTile, { backgroundColor: leadingColor, opacity: disabled ? 0.5 : 1 }] : [styles.androidIcon, wide > 0 ? styles.androidWide : null]}
|
|
1102
|
+
style={tile ? [styles.androidTile, { backgroundColor: leadingColor, opacity: disabled ? 0.5 : 1 }] : [styles.androidIcon, wide > 0 ? styles.androidWide : null, tall ? styles.androidTall : null]}
|
|
1094
1103
|
onLayout={
|
|
1095
1104
|
tile
|
|
1096
1105
|
? undefined
|
|
@@ -1098,6 +1107,8 @@ function AndroidContent({
|
|
|
1098
1107
|
const width = event.nativeEvent.layout.width
|
|
1099
1108
|
const next = width > 24.5 ? width : 0
|
|
1100
1109
|
if (Math.abs(next - wide) > 0.5) setWide(next)
|
|
1110
|
+
const taller = event.nativeEvent.layout.height > 24.5
|
|
1111
|
+
if (taller !== tall) setTall(taller)
|
|
1101
1112
|
}
|
|
1102
1113
|
}
|
|
1103
1114
|
>
|
|
@@ -1198,6 +1209,7 @@ const styles = StyleSheet.create({
|
|
|
1198
1209
|
androidFooterPlain: { paddingHorizontal: ANDROID_INSET },
|
|
1199
1210
|
androidRow: { flexDirection: "row", alignItems: "center", minHeight: 50, paddingStart: ANDROID_INSET, paddingEnd: ANDROID_INSET },
|
|
1200
1211
|
// A 24dp symbol at 20, a 28dp tile at 18 with a 24dp symbol, or a choice's 20dp mark at 22: the text at 64
|
|
1212
|
+
androidTall: { marginVertical: 8 },
|
|
1201
1213
|
androidIcon: { minWidth: 24, minHeight: 24, alignItems: "center", justifyContent: "center", marginStart: -1, marginEnd: 20 },
|
|
1202
1214
|
androidWide: { marginStart: 0, marginEnd: 16 },
|
|
1203
1215
|
androidMark: { width: 20, alignItems: "center", justifyContent: "center", marginStart: 1, marginEnd: 22 },
|
|
@@ -230,7 +230,7 @@ type SurfaceProps = MenuContentProps & {
|
|
|
230
230
|
* A context menu's touch and hold (ContextMenu): on iOS the screen dims and blurs but the element, drawn again
|
|
231
231
|
* over the dimming as its lifted `preview`, and the menu stands 16 from it, by the third of the screen it is in.
|
|
232
232
|
*/
|
|
233
|
-
context?: { preview: ReactNode; radius: number }
|
|
233
|
+
context?: { preview: ReactNode; radius: number; bare?: boolean }
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
/** The floating panel of a menu, placed under its anchor (over it when the screen ends first). */
|
|
@@ -286,26 +286,38 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
|
|
|
286
286
|
const fitsBelow = below + height <= window.height - bottomEdge
|
|
287
287
|
const above = over ? box.y + box.height - height : box.y - gap - height
|
|
288
288
|
let top = size == null ? -window.height - 1000 : fitsBelow ? below : Math.max(topEdge, above)
|
|
289
|
-
|
|
289
|
+
// A preview wider than the screen less 16 a side is scaled down about its middle to fit, as iOS 27.2 shrinks a
|
|
290
|
+
// lifted cell or card, and one that would cross the 16 is moved in: `seen` is where it shows
|
|
291
|
+
const fit = 16
|
|
292
|
+
const fitScale = context && box.width > window.width - fit * 2 ? (window.width - fit * 2) / box.width : 1
|
|
293
|
+
const seenWidth = box.width * fitScale
|
|
294
|
+
const seenHeight = box.height * fitScale
|
|
295
|
+
const seen = {
|
|
296
|
+
x: context && box.width > 0 ? Math.max(fit, Math.min(box.x + (box.width - seenWidth) / 2, window.width - fit - seenWidth)) : box.x,
|
|
297
|
+
y: box.y + (box.height - seenHeight) / 2,
|
|
298
|
+
width: seenWidth,
|
|
299
|
+
height: seenHeight,
|
|
300
|
+
}
|
|
301
|
+
let previewTop = seen.y
|
|
290
302
|
if (context) {
|
|
291
303
|
// iOS 27.2 places a context menu by where the element stands (ref-app menus-context): in the left third at its
|
|
292
304
|
// left edge, in the right third at its right edge, else at its centre; 16 under it, or over it when the element
|
|
293
305
|
// is in the lower half and the menu fits there (the web's ContextMenu, contextMenuPreview)
|
|
294
|
-
const centre =
|
|
295
|
-
left = centre < window.width / 3 ?
|
|
306
|
+
const centre = seen.x + seen.width / 2
|
|
307
|
+
left = centre < window.width / 3 ? seen.x : centre > (window.width * 2) / 3 ? seen.x + seen.width - measured : centre - measured / 2
|
|
296
308
|
left = Math.max(margin, Math.min(left, window.width - measured - margin))
|
|
297
309
|
const lift = 16
|
|
298
|
-
const overIt =
|
|
299
|
-
const underIt =
|
|
300
|
-
const lower =
|
|
310
|
+
const overIt = seen.y - lift - height
|
|
311
|
+
const underIt = seen.y + seen.height + lift
|
|
312
|
+
const lower = seen.y + seen.height / 2 > window.height / 2
|
|
301
313
|
if (size != null) {
|
|
302
314
|
if (lower && overIt >= topEdge) top = overIt
|
|
303
315
|
else {
|
|
304
316
|
// Where the menu does not fit under the element it lifts the element up with it, as iOS moves the preview, so
|
|
305
317
|
// the menu never covers it
|
|
306
318
|
const overflow = underIt + height - (window.height - bottomEdge)
|
|
307
|
-
previewTop = overflow > 0 ? Math.max(topEdge,
|
|
308
|
-
top = Math.max(topEdge, Math.min(previewTop +
|
|
319
|
+
previewTop = overflow > 0 ? Math.max(topEdge, seen.y - overflow) : seen.y
|
|
320
|
+
top = Math.max(topEdge, Math.min(previewTop + seen.height + lift, window.height - bottomEdge - height))
|
|
309
321
|
}
|
|
310
322
|
}
|
|
311
323
|
}
|
|
@@ -404,13 +416,16 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
|
|
|
404
416
|
pointerEvents="none"
|
|
405
417
|
style={[
|
|
406
418
|
styles.preview,
|
|
407
|
-
|
|
419
|
+
// Drawn at its own size and scaled about its middle onto where it is seen
|
|
420
|
+
swap ? { right: seen.x + (seen.width - box.width) / 2 } : { left: seen.x + (seen.width - box.width) / 2 },
|
|
408
421
|
{
|
|
409
|
-
top: previewTop,
|
|
422
|
+
top: previewTop + (seen.height - box.height) / 2,
|
|
410
423
|
width: box.width,
|
|
411
424
|
height: box.height,
|
|
425
|
+
transform: fitScale < 1 ? [{ scale: fitScale }] : undefined,
|
|
412
426
|
borderRadius: context.radius,
|
|
413
|
-
|
|
427
|
+
// An element that draws its own shape lifts as it is: no card behind it and no clip of its own
|
|
428
|
+
...(context.bare ? { overflow: "visible" as const } : { backgroundColor: theme.colors.groupedSurface }),
|
|
414
429
|
boxShadow: String(theme.token("--context-menu-preview-shadow") ?? "0 0 32px rgba(0, 0, 0, 0.2)"),
|
|
415
430
|
},
|
|
416
431
|
]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cloneElement, isValidElement, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import { StyleSheet, View, useWindowDimensions, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
2
|
+
import { ActivityIndicator, StyleSheet, View, useWindowDimensions, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
3
|
import { Pressable } from "../../internal/Pressable"
|
|
4
4
|
import Svg, { Path } from "react-native-svg"
|
|
5
5
|
import X from "../../icons/plex/X"
|
|
@@ -7,7 +7,7 @@ import { flattenChildren, isRenderable, textOf } from "../../internal/children"
|
|
|
7
7
|
import { FloatingPanel } from "../../internal/FloatingPanel"
|
|
8
8
|
import { anchorProps, type FloatingAlign, type FloatingSide } from "../../internal/floating"
|
|
9
9
|
import { Glass } from "../../internal/Glass"
|
|
10
|
-
import { accentText, barSurface, controlHighlight, dangerText, elevationShadow } from "../../theme/material"
|
|
10
|
+
import { accentText, barSurface, controlHighlight, dangerText, elevationShadow, withAlpha } from "../../theme/material"
|
|
11
11
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
12
12
|
import type { Theme } from "../../theme/types"
|
|
13
13
|
import { Button, type ButtonColor, type ButtonProps } from "../Button/Button"
|
|
@@ -116,6 +116,9 @@ function TipBody({ title, description, icon, actions, mobileActions = "rows", on
|
|
|
116
116
|
const closable = onClose != null
|
|
117
117
|
const descriptionColor = android ? theme.colors.textSecondary : theme.color("--tip-description-color", theme.colors.textSecondary)
|
|
118
118
|
const paddingBottom = !hasActions ? m.bottomNone : buttons ? m.bottomButtons : m.bottomRows
|
|
119
|
+
// iOS's tip with button actions is TipKit's mini tip (its kit's Hint View): 22 over the title, 4 between the title
|
|
120
|
+
// and the message, 22 from the words to the action and 16 under it
|
|
121
|
+
const miniTip = !android && hasActions && buttons
|
|
119
122
|
const textStart = hasIcon ? m.iconFrame + m.iconGap : 0
|
|
120
123
|
return (
|
|
121
124
|
<View
|
|
@@ -126,11 +129,11 @@ function TipBody({ title, description, icon, actions, mobileActions = "rows", on
|
|
|
126
129
|
styles.tip,
|
|
127
130
|
{
|
|
128
131
|
borderRadius: m.radius,
|
|
129
|
-
paddingTop: m.top,
|
|
132
|
+
paddingTop: miniTip ? 22 : m.top,
|
|
130
133
|
paddingHorizontal: m.inline,
|
|
131
134
|
paddingBottom,
|
|
132
135
|
columnGap: m.iconGap,
|
|
133
|
-
rowGap: hasActions && buttons ? m.gapButtons : m.gap,
|
|
136
|
+
rowGap: miniTip ? 22 : hasActions && buttons ? m.gapButtons : m.gap,
|
|
134
137
|
backgroundColor: background ?? theme.colors.groupedSurface,
|
|
135
138
|
},
|
|
136
139
|
style,
|
|
@@ -148,7 +151,7 @@ function TipBody({ title, description, icon, actions, mobileActions = "rows", on
|
|
|
148
151
|
<Text variant="headline">{title}</Text>
|
|
149
152
|
{isRenderable(description) ? (
|
|
150
153
|
<TextColorProvider value={descriptionColor}>
|
|
151
|
-
<Text variant="subheadline" color={descriptionColor} style={android ? styles.androidDescription : null}>
|
|
154
|
+
<Text variant="subheadline" color={descriptionColor} style={android ? styles.androidDescription : miniTip ? styles.miniDescription : null}>
|
|
152
155
|
{description}
|
|
153
156
|
</Text>
|
|
154
157
|
</TextColorProvider>
|
|
@@ -182,19 +185,68 @@ function TipBody({ title, description, icon, actions, mobileActions = "rows", on
|
|
|
182
185
|
)
|
|
183
186
|
}
|
|
184
187
|
|
|
185
|
-
/**
|
|
188
|
+
/**
|
|
189
|
+
* An action as a capsule across the tip. On iOS it is TipKit's action (the kit's Hint View): 50 tall, a 17 Semibold
|
|
190
|
+
* label in the action's color (the accent for a primary one) on that color at 8% over the gray fill at 8%. On Android
|
|
191
|
+
* the Button keeps its color and variant, a 40dp capsule.
|
|
192
|
+
*/
|
|
186
193
|
function ActionButton({ item }: { item: ReactNode }) {
|
|
187
194
|
const theme = useTheme()
|
|
188
195
|
if (!isValidElement(item) || item.type !== Button) return <>{item}</>
|
|
189
196
|
const button = item as ReactElement<ButtonProps>
|
|
190
|
-
return cloneElement(button, {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
197
|
+
if (theme.isAndroid) return cloneElement(button, { size: "lg", pill: true, block: true })
|
|
198
|
+
// The Button's look props stay here; its handlers, ref and accessibility props pass on to the capsule
|
|
199
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
200
|
+
const {
|
|
201
|
+
color = "primary",
|
|
202
|
+
children,
|
|
203
|
+
disabled = false,
|
|
204
|
+
loading = false,
|
|
205
|
+
inert: inertProp = loading,
|
|
206
|
+
variant,
|
|
207
|
+
size,
|
|
208
|
+
pill,
|
|
209
|
+
shape,
|
|
210
|
+
mobileMaterial,
|
|
211
|
+
uniform,
|
|
212
|
+
block,
|
|
213
|
+
labelLines,
|
|
214
|
+
selected,
|
|
215
|
+
iconSize,
|
|
216
|
+
gutterSize,
|
|
217
|
+
opticallyAlign,
|
|
218
|
+
style,
|
|
219
|
+
accessibilityState,
|
|
220
|
+
...pressable
|
|
221
|
+
} = button.props
|
|
222
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
223
|
+
// As the Button: a loading or inert action takes no presses and keeps its look; a disabled one dims
|
|
224
|
+
const inert = disabled || inertProp
|
|
225
|
+
const ink = color === "primary" ? theme.colors.accent : theme.color(`--color-text-${color}-ghost`, theme.colors.accent)
|
|
226
|
+
return (
|
|
227
|
+
<Pressable
|
|
228
|
+
accessibilityRole="button"
|
|
229
|
+
{...pressable}
|
|
230
|
+
accessibilityState={{ ...accessibilityState, disabled: inert, busy: loading }}
|
|
231
|
+
aria-busy={loading}
|
|
232
|
+
disabled={inert}
|
|
233
|
+
style={({ pressed }) => [styles.miniAction, { backgroundColor: MINI_GRAY, opacity: disabled ? 0.4 : 1 }, pressed && !inert ? styles.pressed : null]}
|
|
234
|
+
>
|
|
235
|
+
<View pointerEvents="none" style={[StyleSheet.absoluteFill, styles.miniActionTint, { backgroundColor: withAlpha(ink, 0.08) }]} />
|
|
236
|
+
{loading ? (
|
|
237
|
+
<ActivityIndicator color={ink} />
|
|
238
|
+
) : (
|
|
239
|
+
<Text variant="body" weight="semibold" numberOfLines={2} style={styles.miniLabel} color={ink}>
|
|
240
|
+
{children as ReactNode}
|
|
241
|
+
</Text>
|
|
242
|
+
)}
|
|
243
|
+
</Pressable>
|
|
244
|
+
)
|
|
196
245
|
}
|
|
197
246
|
|
|
247
|
+
/** The gray under a TipKit action's tint: the kit's rgba(116, 116, 128, 0.08). */
|
|
248
|
+
const MINI_GRAY = "rgba(116, 116, 128, 0.08)"
|
|
249
|
+
|
|
198
250
|
/**
|
|
199
251
|
* 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
|
|
200
252
|
* text button in the accent, as Material 3's rich tooltip sets its actions. Other elements stand as given.
|
|
@@ -398,6 +450,10 @@ const styles = StyleSheet.create({
|
|
|
398
450
|
androidDescription: { marginTop: 2 },
|
|
399
451
|
actions: { flexBasis: "100%", flexGrow: 1, flexDirection: "column" },
|
|
400
452
|
buttons: { gap: 10 },
|
|
453
|
+
miniDescription: { marginTop: 4 },
|
|
454
|
+
miniAction: { minHeight: 50, paddingHorizontal: 20, paddingVertical: 14, borderRadius: 25, borderCurve: "continuous", alignItems: "center", justifyContent: "center", overflow: "hidden" },
|
|
455
|
+
miniActionTint: { borderRadius: 25 },
|
|
456
|
+
miniLabel: { lineHeight: 18, textAlign: "center" },
|
|
401
457
|
androidActions: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
|
402
458
|
row: { minHeight: 46, paddingVertical: 12, borderTopWidth: 1, justifyContent: "center" },
|
|
403
459
|
androidRow: { alignSelf: "flex-start", minHeight: 40, paddingHorizontal: 12, borderRadius: 20, justifyContent: "center" },
|
package/src/index.ts
CHANGED
|
@@ -83,11 +83,11 @@ export { OTPInput, type OTPInputProps } from "./components/OTPInput/OTPInput"
|
|
|
83
83
|
export { PhoneInput, type CountryCode, type PhoneDetails, type PhoneInputProps } from "./components/PhoneInput/PhoneInput"
|
|
84
84
|
export { Select, type SelectOption, type SelectProps } from "./components/Select/Select"
|
|
85
85
|
export { Menu, type MenuContentProps, type MenuItemProps, type MenuProps } from "./components/Menu/Menu"
|
|
86
|
-
export { ContextMenu, type ContextMenuContentProps, type ContextMenuProps } from "./components/ContextMenu/ContextMenu"
|
|
86
|
+
export { ContextMenu, type ContextMenuContentProps, type ContextMenuPreviewShape, type ContextMenuProps, type ContextMenuTriggerProps } from "./components/ContextMenu/ContextMenu"
|
|
87
87
|
export { ScrollEdge, type ScrollEdgeProps } from "./components/ScrollEdge/ScrollEdge"
|
|
88
88
|
export { DatePicker, type DatePickerDisplay, type DatePickerMode, type DatePickerProps } from "./components/DatePicker/DatePicker"
|
|
89
89
|
export { ActionSheet, type ActionSheetAction, type ActionSheetProps } from "./components/ActionSheet/ActionSheet"
|
|
90
|
-
export { BottomSheet, type BottomSheetFooterProps, type BottomSheetProps } from "./components/BottomSheet/BottomSheet"
|
|
90
|
+
export { BottomSheet, type BottomSheetFooterProps, type BottomSheetHero, type BottomSheetHeroTone, type BottomSheetProps } from "./components/BottomSheet/BottomSheet"
|
|
91
91
|
export { Dialog, type DialogAction, type DialogProps } from "./components/Dialog/Dialog"
|
|
92
92
|
export { Toaster, toast, type ToasterProps, type ToastId, type ToastOptions, type ToastT, type ToastType } from "./components/Toast/Toast"
|
|
93
93
|
|
package/src/internal/Glass.tsx
CHANGED
|
@@ -13,6 +13,12 @@ export type GlassProps = ViewProps & {
|
|
|
13
13
|
tint?: string
|
|
14
14
|
/** Native glass reacts to touches (iOS 26 interactive glass). */
|
|
15
15
|
interactive?: boolean
|
|
16
|
+
/**
|
|
17
|
+
* iOS 26's clear glass, for controls over a photo, a video or a color: native `.clear` glass on iOS 26, elsewhere
|
|
18
|
+
* the kit's clear fill (`--mobile-glass-clear-background`, gray 153 at 17%) with a light blur, a 0.5 rim and a
|
|
19
|
+
* faint shadow (`--mobile-glass-clear-*`), the same in light and dark: what is under it decides how it reads.
|
|
20
|
+
*/
|
|
21
|
+
clear?: boolean
|
|
16
22
|
/** A fill token for the glass instead of `--mobile-glass-background` (menus, alerts and toasts set their own). */
|
|
17
23
|
fillToken?: string
|
|
18
24
|
/**
|
|
@@ -116,6 +122,12 @@ const lensMask = (width: number, height: number, radius: number) => {
|
|
|
116
122
|
return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`
|
|
117
123
|
}
|
|
118
124
|
|
|
125
|
+
/** The clear glass where its tokens are not set: the kit's gray 153 at 17% over a light blur. */
|
|
126
|
+
const CLEAR_FILL = "rgba(153, 153, 153, 0.17)"
|
|
127
|
+
const CLEAR_FILTER = "blur(4px) brightness(1.08)"
|
|
128
|
+
/** Clear glass with no blur (Reduce Transparency, no blur module): a dark gray, as the clear glass over a dark photo. */
|
|
129
|
+
const CLEAR_OPAQUE = "#3a3a3c"
|
|
130
|
+
|
|
119
131
|
/** The filter and the shadow of the glass surfaces of the phone layer, by their fill (mobile-materials.css, touch.css). */
|
|
120
132
|
const SURFACES: Record<string, { filter: string; shadow: string }> = {
|
|
121
133
|
"--menu-mobile-background": { filter: "--menu-mobile-backdrop-filter", shadow: "--menu-shadow" },
|
|
@@ -141,6 +153,7 @@ export function Glass({
|
|
|
141
153
|
elevation = "regular",
|
|
142
154
|
tint,
|
|
143
155
|
interactive,
|
|
156
|
+
clear = false,
|
|
144
157
|
fillToken,
|
|
145
158
|
filterToken,
|
|
146
159
|
shadowToken,
|
|
@@ -156,7 +169,7 @@ export function Glass({
|
|
|
156
169
|
const overrides = useThemeOverrides()
|
|
157
170
|
const shape: ViewStyle = { borderRadius: radius, borderCurve: "continuous" }
|
|
158
171
|
const surface = fillToken ? SURFACES[fillToken] : undefined
|
|
159
|
-
const shadow = theme.token(shadowToken ?? surface?.shadow ?? (elevation === "raised" ? "--mobile-glass-shadow-raised" : "--mobile-glass-shadow"))
|
|
172
|
+
const shadow = theme.token(shadowToken ?? surface?.shadow ?? (clear ? "--mobile-glass-clear-shadow" : elevation === "raised" ? "--mobile-glass-shadow-raised" : "--mobile-glass-shadow"))
|
|
160
173
|
const boxShadow = typeof shadow === "string" ? shadow : undefined
|
|
161
174
|
const native = liquidGlassModule()
|
|
162
175
|
// iOS 26's own glass turns frostier by itself with Reduce Transparency
|
|
@@ -165,7 +178,7 @@ export function Glass({
|
|
|
165
178
|
return (
|
|
166
179
|
<GlassView
|
|
167
180
|
{...rest}
|
|
168
|
-
glassEffectStyle="regular"
|
|
181
|
+
glassEffectStyle={clear ? "clear" : "regular"}
|
|
169
182
|
colorScheme={theme.scheme}
|
|
170
183
|
tintColor={tint}
|
|
171
184
|
isInteractive={interactive}
|
|
@@ -176,8 +189,8 @@ export function Glass({
|
|
|
176
189
|
)
|
|
177
190
|
}
|
|
178
191
|
const web = Platform.OS === "web"
|
|
179
|
-
const fillName = fillToken ?? "--mobile-glass-background"
|
|
180
|
-
const filterName = filterToken ?? surface?.filter ?? "--mobile-glass-backdrop-filter"
|
|
192
|
+
const fillName = fillToken ?? (clear ? "--mobile-glass-clear-background" : "--mobile-glass-background")
|
|
193
|
+
const filterName = filterToken ?? surface?.filter ?? (clear ? "--mobile-glass-clear-backdrop-filter" : "--mobile-glass-backdrop-filter")
|
|
181
194
|
const dense = web && !theme.isAndroid ? WEB_DENSE[fillName] : undefined
|
|
182
195
|
const denseFill = dense != null && tint == null && overrides?.[fillName] == null
|
|
183
196
|
// Glass with a fill of its own and the plain glass's filter (the large segmented control) blurs as the plain glass
|
|
@@ -185,9 +198,9 @@ export function Glass({
|
|
|
185
198
|
const plainFilter = web && !theme.isAndroid && dense == null && filterToken == null && filterName === "--mobile-glass-backdrop-filter" && overrides?.[filterName] == null
|
|
186
199
|
const denseFilter = (dense != null && filterToken == null && overrides?.[filterName] == null) || plainFilter
|
|
187
200
|
const webFilter = dense ?? WEB_DENSE["--mobile-glass-background"]
|
|
188
|
-
const fill = tint ?? (denseFill ? theme.color(dense.fill, theme.scheme === "dark" ? dense.dark : dense.light) : theme.color(fillName))
|
|
201
|
+
const fill = tint ?? (denseFill ? theme.color(dense.fill, theme.scheme === "dark" ? dense.dark : dense.light) : theme.color(fillName, clear ? CLEAR_FILL : undefined))
|
|
189
202
|
const filterValue = denseFilter ? (theme.token(webFilter.filter) ?? webFilter.blur) : theme.token(filterName)
|
|
190
|
-
const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : "blur(12px)"
|
|
203
|
+
const filter = blur != null ? `blur(${blur}px)` : typeof filterValue === "string" ? filterValue : clear ? CLEAR_FILTER : "blur(12px)"
|
|
191
204
|
const module = web || Platform.OS !== "ios" ? null : blurModule()
|
|
192
205
|
const opaque = reduceTransparency || (!web && module == null)
|
|
193
206
|
if (web && !opaque) {
|
|
@@ -243,11 +256,12 @@ export function Glass({
|
|
|
243
256
|
<View {...rest} style={[shape, { boxShadow }, style]}>
|
|
244
257
|
<View style={[StyleSheet.absoluteFill, shape, { overflow: "hidden" }]} pointerEvents="none">
|
|
245
258
|
{opaque ? (
|
|
246
|
-
|
|
259
|
+
// Clear glass carries a light label over a photo or a color: opaque, it stands on a dark gray so the label reads
|
|
260
|
+
<View style={[StyleSheet.absoluteFill, { backgroundColor: clear ? theme.color("--mobile-glass-clear-opaque-background", CLEAR_OPAQUE) : theme.color("--mobile-surface-elevated-plain-primary", theme.colors.surfaceElevated) }]} />
|
|
247
261
|
) : module ? (
|
|
248
262
|
<module.BlurView
|
|
249
263
|
intensity={intensityOf(radiusPx)}
|
|
250
|
-
tint={theme.scheme === "dark" ? "systemChromeMaterialDark" : "systemChromeMaterialLight"}
|
|
264
|
+
tint={clear ? "systemUltraThinMaterial" : theme.scheme === "dark" ? "systemChromeMaterialDark" : "systemChromeMaterialLight"}
|
|
251
265
|
style={StyleSheet.absoluteFill}
|
|
252
266
|
/>
|
|
253
267
|
) : null}
|