@plexui/react-native 0.1.1 → 0.2.1
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/README.md +34 -0
- package/dist/es/components/ActionSheet/ActionSheet.js +67 -19
- package/dist/es/components/Alert/Alert.js +163 -0
- package/dist/es/components/Avatar/Avatar.js +20 -8
- package/dist/es/components/BottomActions/BottomActions.js +34 -0
- package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
- package/dist/es/components/Button/Button.js +108 -28
- package/dist/es/components/Card/Card.js +16 -8
- package/dist/es/components/Checkbox/Checkbox.js +67 -99
- package/dist/es/components/Chip/Chip.js +39 -19
- package/dist/es/components/Dialog/Dialog.js +38 -24
- package/dist/es/components/Field/Field.js +91 -0
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
- package/dist/es/components/Icon/createIcon.js +13 -2
- package/dist/es/components/Indicator/CircularProgress.js +80 -0
- package/dist/es/components/Indicator/LoadingDots.js +46 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
- package/dist/es/components/Indicator/index.js +3 -0
- package/dist/es/components/Input/Input.js +69 -60
- package/dist/es/components/InputGroup/InputGroup.js +130 -0
- package/dist/es/components/List/List.js +175 -59
- package/dist/es/components/Menu/Menu.js +69 -40
- package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
- package/dist/es/components/OTPInput/OTPInput.js +9 -3
- package/dist/es/components/PageControl/PageControl.js +13 -7
- package/dist/es/components/Popover/Popover.js +128 -0
- package/dist/es/components/Progress/Progress.js +142 -0
- package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
- package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
- package/dist/es/components/Select/Select.js +97 -34
- package/dist/es/components/Separator/Separator.js +31 -0
- package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
- package/dist/es/components/Stepper/Stepper.js +219 -0
- package/dist/es/components/Switch/Switch.js +26 -12
- package/dist/es/components/TagInput/TagInput.js +121 -0
- package/dist/es/components/Text/Text.js +7 -4
- package/dist/es/components/TextLink/TextLink.js +42 -0
- package/dist/es/components/Textarea/Textarea.js +12 -0
- package/dist/es/components/Tip/Tip.js +193 -0
- package/dist/es/components/Toolbar/Toolbar.js +6 -2
- package/dist/es/components/Tooltip/Tooltip.js +272 -0
- package/dist/es/index.js +20 -2
- package/dist/es/internal/FloatingPanel.js +111 -0
- package/dist/es/internal/fieldStack.js +73 -0
- package/dist/es/internal/floating.js +97 -0
- package/dist/es/internal/ripple.js +119 -0
- package/dist/es/internal/row.js +2 -1
- package/dist/es/internal/transition.js +113 -0
- package/dist/es/theme/ThemeProvider.js +41 -9
- package/dist/es/theme/material.js +37 -7
- package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
- package/dist/types/components/Alert/Alert.d.ts +51 -0
- package/dist/types/components/Avatar/Avatar.d.ts +4 -2
- package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
- package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
- package/dist/types/components/Button/Button.d.ts +20 -5
- package/dist/types/components/Card/Card.d.ts +14 -1
- package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
- package/dist/types/components/Chip/Chip.d.ts +23 -4
- package/dist/types/components/Dialog/Dialog.d.ts +9 -5
- package/dist/types/components/Field/Field.d.ts +64 -0
- package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
- package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
- package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
- package/dist/types/components/Indicator/index.d.ts +3 -0
- package/dist/types/components/Input/Input.d.ts +13 -3
- package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
- package/dist/types/components/List/List.d.ts +57 -14
- package/dist/types/components/Menu/Menu.d.ts +4 -0
- package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
- package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
- package/dist/types/components/PageControl/PageControl.d.ts +11 -1
- package/dist/types/components/Popover/Popover.d.ts +86 -0
- package/dist/types/components/Progress/Progress.d.ts +56 -0
- package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
- package/dist/types/components/Select/Select.d.ts +36 -8
- package/dist/types/components/Separator/Separator.d.ts +19 -0
- package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
- package/dist/types/components/Stepper/Stepper.d.ts +61 -0
- package/dist/types/components/Switch/Switch.d.ts +5 -5
- package/dist/types/components/TagInput/TagInput.d.ts +44 -0
- package/dist/types/components/TextLink/TextLink.d.ts +30 -0
- package/dist/types/components/Textarea/Textarea.d.ts +19 -0
- package/dist/types/components/Tip/Tip.d.ts +71 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
- package/dist/types/index.d.ts +20 -2
- package/dist/types/internal/FloatingPanel.d.ts +70 -0
- package/dist/types/internal/fieldStack.d.ts +48 -0
- package/dist/types/internal/floating.d.ts +71 -0
- package/dist/types/internal/ripple.d.ts +17 -0
- package/dist/types/internal/row.d.ts +15 -3
- package/dist/types/internal/transition.d.ts +37 -0
- package/dist/types/theme/ThemeProvider.d.ts +28 -4
- package/dist/types/theme/material.d.ts +20 -6
- package/dist/types/theme/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +123 -38
- package/src/components/Alert/Alert.tsx +279 -0
- package/src/components/Avatar/Avatar.tsx +21 -9
- package/src/components/BottomActions/BottomActions.tsx +54 -0
- package/src/components/BottomSheet/BottomSheet.tsx +111 -25
- package/src/components/Button/Button.tsx +170 -35
- package/src/components/Card/Card.tsx +33 -9
- package/src/components/Checkbox/Checkbox.tsx +89 -124
- package/src/components/Chip/Chip.tsx +83 -20
- package/src/components/Dialog/Dialog.tsx +68 -37
- package/src/components/Field/Field.tsx +227 -0
- package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
- package/src/components/Icon/createIcon.tsx +16 -6
- package/src/components/Indicator/CircularProgress.tsx +141 -0
- package/src/components/Indicator/LoadingDots.tsx +79 -0
- package/src/components/Indicator/LoadingIndicator.tsx +166 -0
- package/src/components/Indicator/index.ts +3 -0
- package/src/components/Input/Input.tsx +126 -97
- package/src/components/InputGroup/InputGroup.tsx +261 -0
- package/src/components/List/List.tsx +345 -88
- package/src/components/Menu/Menu.tsx +83 -41
- package/src/components/NavigationButton/NavigationButton.tsx +35 -5
- package/src/components/OTPInput/OTPInput.tsx +21 -2
- package/src/components/PageControl/PageControl.tsx +36 -8
- package/src/components/Popover/Popover.tsx +261 -0
- package/src/components/Progress/Progress.tsx +255 -0
- package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
- package/src/components/RollingNumber/RollingNumber.tsx +189 -0
- package/src/components/Select/Select.tsx +175 -71
- package/src/components/Separator/Separator.tsx +51 -0
- package/src/components/ShimmerText/ShimmerText.tsx +144 -0
- package/src/components/Stepper/Stepper.tsx +386 -0
- package/src/components/Switch/Switch.tsx +26 -12
- package/src/components/TagInput/TagInput.tsx +227 -0
- package/src/components/Text/Text.tsx +8 -4
- package/src/components/TextLink/TextLink.tsx +77 -0
- package/src/components/Textarea/Textarea.tsx +23 -0
- package/src/components/Tip/Tip.tsx +410 -0
- package/src/components/Toolbar/Toolbar.tsx +27 -2
- package/src/components/Tooltip/Tooltip.tsx +478 -0
- package/src/index.ts +36 -2
- package/src/internal/FloatingPanel.tsx +199 -0
- package/src/internal/fieldStack.tsx +179 -0
- package/src/internal/floating.ts +131 -0
- package/src/internal/ripple.tsx +132 -0
- package/src/internal/row.ts +16 -3
- package/src/internal/transition.ts +124 -0
- package/src/theme/ThemeProvider.tsx +65 -15
- package/src/theme/material.ts +39 -7
- package/src/theme/types.ts +8 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useContext, useEffect, useState, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
2
|
+
import { Animated, Easing, Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
3
3
|
import Svg, { Path } from "react-native-svg"
|
|
4
4
|
import CheckMd from "../../icons/plex/CheckMd"
|
|
5
5
|
import Minus from "../../icons/plex/Minus"
|
|
6
6
|
import { spaceToggles, useDescription } from "../../internal/a11y"
|
|
7
7
|
import { ControlLabel, controlLabelLine } from "../../internal/ControlLabel"
|
|
8
|
-
import { RowEndContext, RowHoldContext, rowHold } from "../../internal/row"
|
|
9
|
-
import {
|
|
8
|
+
import { RowEndContext, RowHoldContext, RowStartContext, rowHold } from "../../internal/row"
|
|
9
|
+
import { androidGray, withAlpha } from "../../theme/material"
|
|
10
10
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
11
|
-
import { ANDROID_ROW_END,
|
|
11
|
+
import { ANDROID_ROW_END, iosCheckmarkColor, selectionColor } from "../Switch/Switch"
|
|
12
12
|
|
|
13
13
|
export type CheckboxProps = {
|
|
14
14
|
checked?: boolean | "indeterminate"
|
|
@@ -20,7 +20,7 @@ export type CheckboxProps = {
|
|
|
20
20
|
orientation?: "left" | "right"
|
|
21
21
|
/** `ghost`: the checkmark alone, as an iOS list row draws it. @default "solid" */
|
|
22
22
|
variant?: "solid" | "ghost"
|
|
23
|
-
/** Kept for the API of @plexui/ui: the phone box is a circle on
|
|
23
|
+
/** Kept for the API of @plexui/ui: the phone box is a circle on both platforms. */
|
|
24
24
|
pill?: boolean
|
|
25
25
|
invalid?: boolean
|
|
26
26
|
disabled?: boolean
|
|
@@ -29,18 +29,23 @@ export type CheckboxProps = {
|
|
|
29
29
|
style?: StyleProp<ViewStyle>
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/** Android's
|
|
33
|
-
const ANDROID_BOX =
|
|
32
|
+
/** Android's round check: a 20dp circle (the reference's 19.8), in a 48dp target that reaches 14dp past it. */
|
|
33
|
+
const ANDROID_BOX = 20
|
|
34
34
|
const ANDROID_REACH = (48 - ANDROID_BOX) / 2
|
|
35
|
-
/** A checkbox
|
|
35
|
+
/** A checkbox with a label: the text starts 11dp after the circle (the web's -3 margin and 14 of the target). */
|
|
36
36
|
const ANDROID_LABEL_GAP = 11
|
|
37
|
-
/** A checkbox row's
|
|
37
|
+
/** A checkbox at a List row's end stands 21dp in from the row's edge. */
|
|
38
38
|
const ANDROID_ROW_INSET = 21
|
|
39
|
+
/** The ring of an empty circle, 1.5dp. */
|
|
40
|
+
const ANDROID_RING = 1.5
|
|
41
|
+
/** Android's check eases both ways on cubic-bezier(0.37, 0, 0.63, 1) (the web's `--android-checkbox-ease`). */
|
|
42
|
+
const androidCheckEase = Easing.bezier(0.37, 0, 0.63, 1)
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* A checkbox: on iOS the 22pt circle of the phone layer (`--checkbox-*`: a 1.5pt ring, filled in the primary with a
|
|
42
|
-
* check), on Android
|
|
43
|
-
* color with a round-capped check) in a 48dp target.
|
|
46
|
+
* check), on Android the reference's round check (a 20dp circle, a 1.5dp ring in a light gray, filled in the
|
|
47
|
+
* selection color with a white round-capped check) in a 48dp target. As the first control of a List row (`RowStart`)
|
|
48
|
+
* it leads the row, 22 in.
|
|
44
49
|
*/
|
|
45
50
|
export function Checkbox({
|
|
46
51
|
checked: checkedProp,
|
|
@@ -57,27 +62,39 @@ export function Checkbox({
|
|
|
57
62
|
style,
|
|
58
63
|
}: CheckboxProps) {
|
|
59
64
|
const theme = useTheme()
|
|
60
|
-
// At a List row's end with no text of its own: the row is its label
|
|
61
|
-
|
|
65
|
+
// At a List row's end with no text of its own: the row is its label. Leading the row (Android's multi-select row),
|
|
66
|
+
// the row sets its place
|
|
67
|
+
const atRowStart = useContext(RowStartContext) && label == null && description == null
|
|
68
|
+
const inRow = useContext(RowEndContext) != null && label == null && description == null && !atRowStart
|
|
62
69
|
const hold = useContext(RowHoldContext)
|
|
63
70
|
const [own, setOwn] = useState(defaultChecked)
|
|
64
71
|
const state = checkedProp ?? own
|
|
65
72
|
const on = state !== false
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
|
|
73
|
+
// Android's round check, as the web's: the ring and the fill turn in 150ms, then the mark is drawn from its start
|
|
74
|
+
// in 150ms; unchecking fades the mark out in 150ms as the fill goes. Android only: iOS shows a list row's
|
|
75
|
+
// checkmark, which does not animate
|
|
76
|
+
const [fillIn] = useState(() => new Animated.Value(on ? 1 : 0))
|
|
77
|
+
const [draw] = useState(() => new Animated.Value(on ? 1 : 0))
|
|
78
|
+
const [markIn] = useState(() => new Animated.Value(on ? 1 : 0))
|
|
69
79
|
const animate = theme.isAndroid && !disabled
|
|
70
80
|
useEffect(() => {
|
|
81
|
+
const values = [fillIn, draw, markIn]
|
|
71
82
|
// A disabled box snaps: no motion between enabled and disabled
|
|
72
83
|
if (theme.reducedMotion || !animate) {
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
values.forEach((value) => {
|
|
85
|
+
value.stopAnimation()
|
|
86
|
+
value.setValue(on ? 1 : 0)
|
|
87
|
+
})
|
|
75
88
|
return
|
|
76
89
|
}
|
|
77
|
-
const
|
|
90
|
+
const timing = (value: Animated.Value, toValue: number, delay = 0) =>
|
|
91
|
+
Animated.timing(value, { toValue, duration: 150, delay, easing: androidCheckEase, useNativeDriver: false })
|
|
92
|
+
const animation = on
|
|
93
|
+
? Animated.parallel([timing(fillIn, 1), Animated.sequence([Animated.timing(markIn, { toValue: 1, duration: 0, useNativeDriver: false }), timing(draw, 1, 150)])])
|
|
94
|
+
: Animated.parallel([timing(fillIn, 0), Animated.sequence([timing(markIn, 0), Animated.timing(draw, { toValue: 0, duration: 0, useNativeDriver: false })])])
|
|
78
95
|
animation.start()
|
|
79
96
|
return () => animation.stop()
|
|
80
|
-
}, [on, animate, theme.reducedMotion,
|
|
97
|
+
}, [on, animate, theme.reducedMotion, fillIn, draw, markIn])
|
|
81
98
|
const toggle = () => {
|
|
82
99
|
if (disabled) return
|
|
83
100
|
// An indeterminate box checks on a press, as Radix does on the web
|
|
@@ -89,25 +106,29 @@ export function Checkbox({
|
|
|
89
106
|
let box: ReactNode
|
|
90
107
|
const hasText = label != null || description != null
|
|
91
108
|
if (theme.isAndroid) {
|
|
92
|
-
// The
|
|
93
|
-
//
|
|
94
|
-
// the near-white primary at night
|
|
109
|
+
// The ring a light gray (#B0B9C2, --gray-500 at night), the fill the selection color, the error when invalid
|
|
110
|
+
// (in a List row the error is the row's line: the circle keeps its colors). The mark is the fill's own text
|
|
111
|
+
// color: white on the accent and on the ink of a light theme, dark on the near-white primary at night
|
|
95
112
|
const m = theme.material
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
113
|
+
const red = invalid && !inRow && !atRowStart
|
|
114
|
+
const ring = red ? m.error : androidGray(theme, "checkboxRing")
|
|
115
|
+
const fill = red ? m.error : selectionColor(theme)
|
|
116
|
+
const markColor = red ? m.onError : theme.color(`--color-text-${theme.selectionColor}-solid`, "#FFFFFF")
|
|
117
|
+
// The 48dp target reaches past the circle without taking room: on the outer side the circle keeps the row's edge,
|
|
118
|
+
// on the label's side the text starts 11dp after it. At a List row's end the circle stands 21dp in; leading a
|
|
119
|
+
// row the row places it
|
|
120
|
+
const reach: ViewStyle = atRowStart
|
|
121
|
+
? { margin: -ANDROID_REACH }
|
|
122
|
+
: inRow
|
|
123
|
+
? { marginStart: -ANDROID_REACH, marginEnd: -(ANDROID_REACH - (ANDROID_ROW_INSET - ANDROID_ROW_END)) }
|
|
124
|
+
: orientation === "right"
|
|
125
|
+
? { marginEnd: -ANDROID_REACH, marginStart: hasText ? -(ANDROID_REACH - ANDROID_LABEL_GAP) : 0 }
|
|
126
|
+
: { marginStart: -ANDROID_REACH, marginEnd: hasText ? -(ANDROID_REACH - ANDROID_LABEL_GAP) : 0 }
|
|
127
|
+
// No press of its own: a row shows the press. Disabled, the circle keeps its colors at half (as a checkbox row's)
|
|
107
128
|
box = (
|
|
108
129
|
<View style={[styles.androidTarget, reach]}>
|
|
109
130
|
<View style={disabled ? styles.half : null}>
|
|
110
|
-
<
|
|
131
|
+
<AndroidCheck fillIn={fillIn} draw={draw} markIn={markIn} ring={ring} fill={fill} markColor={markColor} indeterminate={state === "indeterminate"} />
|
|
111
132
|
</View>
|
|
112
133
|
</View>
|
|
113
134
|
)
|
|
@@ -180,98 +201,41 @@ export function Checkbox({
|
|
|
180
201
|
)
|
|
181
202
|
}
|
|
182
203
|
|
|
183
|
-
/** The
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const LONG_ARM = { length: 7 * Math.SQRT2, angle: -45 }
|
|
204
|
+
/** The reference's check in its 20dp circle, and the dash of a mixed one: 2dp strokes with round ends. */
|
|
205
|
+
const CHECK_PATH = "M5.2 11l3 3 6.6-6.6"
|
|
206
|
+
const DASH_PATH = "M6 10h8"
|
|
187
207
|
|
|
188
208
|
/**
|
|
189
|
-
*
|
|
190
|
-
*
|
|
209
|
+
* Android's round check: a 20dp circle whose 1.5dp ring turns from the gray to the fill as the fill comes in
|
|
210
|
+
* (`fillIn`), and the mark, shown by `markIn` and drawn from its start as a clip opens over it (`draw`).
|
|
191
211
|
*/
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
212
|
+
function AndroidCheck({
|
|
213
|
+
fillIn,
|
|
214
|
+
draw,
|
|
215
|
+
markIn,
|
|
216
|
+
ring,
|
|
217
|
+
fill,
|
|
218
|
+
markColor,
|
|
219
|
+
indeterminate,
|
|
220
|
+
}: {
|
|
221
|
+
fillIn: Animated.Value
|
|
222
|
+
draw: Animated.Value
|
|
223
|
+
markIn: Animated.Value
|
|
224
|
+
ring: string
|
|
225
|
+
fill: string
|
|
226
|
+
markColor: string
|
|
227
|
+
indeterminate: boolean
|
|
228
|
+
}) {
|
|
229
|
+
const borderColor = fillIn.interpolate({ inputRange: [0, 1], outputRange: [ring, fill] })
|
|
230
|
+
const backgroundColor = fillIn.interpolate({ inputRange: [0, 1], outputRange: [withAlpha(fill, 0), fill] })
|
|
196
231
|
return (
|
|
197
|
-
<Animated.View
|
|
198
|
-
style={[
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
width: Animated.add(along(1), 2),
|
|
203
|
-
// The bar's middle is half its length along the arm from the corner; its box is then half its width back
|
|
204
|
-
left: Animated.add(along((cos - 1) / 2), CORNER.x - 1),
|
|
205
|
-
top: Animated.add(along(sin / 2), CORNER.y - 1),
|
|
206
|
-
transform: [{ rotate: `${angle}deg` }],
|
|
207
|
-
},
|
|
208
|
-
]}
|
|
209
|
-
/>
|
|
210
|
-
)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/** A rounded rectangle from `from` to `to` on both axes, as a path of fixed shape (its numbers alone change). */
|
|
214
|
-
const roundedSquare = (from: number, to: number, corner: number) => {
|
|
215
|
-
const n = (value: number) => value.toFixed(4)
|
|
216
|
-
const [a, b, r] = [from, to, corner]
|
|
217
|
-
return (
|
|
218
|
-
`M ${n(a + r)} ${n(a)} H ${n(b - r)} A ${n(r)} ${n(r)} 0 0 1 ${n(b)} ${n(a + r)} V ${n(b - r)} A ${n(r)} ${n(r)} 0 0 1 ${n(b - r)} ${n(b)} ` +
|
|
219
|
-
`H ${n(a + r)} A ${n(r)} ${n(r)} 0 0 1 ${n(a)} ${n(b - r)} V ${n(a + r)} A ${n(r)} ${n(r)} 0 0 1 ${n(a + r)} ${n(a)} Z`
|
|
220
|
-
)
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/** The outline's width, at rest and around the hole. */
|
|
224
|
-
const ANDROID_RING = 1.33
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* The box at `progress`, a 4dp-cornered square with the hole it cuts. Over the first half the box shrinks 1dp on each
|
|
228
|
-
* side while the hole, fixed in the 18dp frame, closes 16dp per unit of progress (to 7dp in from the outline) with
|
|
229
|
-
* corners of 3dp, or of half its width once it is under 6dp; past the middle the box is solid and grows back.
|
|
230
|
-
*/
|
|
231
|
-
function androidBoxPath(progress: number) {
|
|
232
|
-
const half = Math.min(1, progress * 2)
|
|
233
|
-
const box = progress <= 0.5 ? half : 2 - progress * 2
|
|
234
|
-
const holed = progress <= 0.5
|
|
235
|
-
const closed = ANDROID_RING + Math.min(7, 8 * half)
|
|
236
|
-
const hole = holed ? ANDROID_BOX - 2 * closed : 0
|
|
237
|
-
const from = holed ? closed : ANDROID_BOX / 2
|
|
238
|
-
return `${roundedSquare(box, ANDROID_BOX - box, 4)} ${roundedSquare(from, from + hole, Math.min(3, hole / 2))}`
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Android's square checkbox, drawn from its numbers. Over the first half of `progress` the box shrinks 1dp on each
|
|
244
|
-
* side while its 1.33dp outline closes inward and turns from the outline's color to the fill's; over the second half
|
|
245
|
-
* the box grows back and the mark grows from its corner. One path draws the box and its hole, redrawn from the
|
|
246
|
-
* progress on each frame (an animated path's props do not reach an SVG element on the web).
|
|
247
|
-
*/
|
|
248
|
-
function AndroidBox({ progress, initial, ring, fill, markColor, indeterminate }: { progress: Animated.Value; initial: number; ring: string; fill: string; markColor: string; indeterminate: boolean }) {
|
|
249
|
-
const [at, setAt] = useState(initial)
|
|
250
|
-
useEffect(() => {
|
|
251
|
-
const id = progress.addListener(({ value }) => setAt(value))
|
|
252
|
-
return () => progress.removeListener(id)
|
|
253
|
-
}, [progress])
|
|
254
|
-
const grow = progress.interpolate({ inputRange: [0.5, 1], outputRange: [0, 1], extrapolate: "clamp" })
|
|
255
|
-
const shown = progress.interpolate({ inputRange: [0.5, 0.5001], outputRange: [0, 1], extrapolate: "clamp" })
|
|
256
|
-
return (
|
|
257
|
-
<View style={styles.androidFrame}>
|
|
258
|
-
<Svg width={ANDROID_BOX} height={ANDROID_BOX} style={StyleSheet.absoluteFill}>
|
|
259
|
-
<Path d={androidBoxPath(at)} fill={mix(fill, ring, Math.min(1, at * 2))} fillRule="evenodd" />
|
|
260
|
-
</Svg>
|
|
261
|
-
<Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, { opacity: shown }]}>
|
|
262
|
-
{indeterminate ? (
|
|
263
|
-
// The box has no indeterminate look: a 2dp dash with round ends across the middle, growing from its center
|
|
264
|
-
<Animated.View
|
|
265
|
-
style={[styles.arm, { backgroundColor: markColor, top: ANDROID_BOX / 2 - 1, width: grow.interpolate({ inputRange: [0, 1], outputRange: [2, 10] }), left: grow.interpolate({ inputRange: [0, 1], outputRange: [8, 4] }) }]}
|
|
266
|
-
/>
|
|
267
|
-
) : (
|
|
268
|
-
<>
|
|
269
|
-
<CheckArm grow={grow} color={markColor} {...SHORT_ARM} />
|
|
270
|
-
<CheckArm grow={grow} color={markColor} {...LONG_ARM} />
|
|
271
|
-
</>
|
|
272
|
-
)}
|
|
232
|
+
<Animated.View style={[styles.androidCircle, { borderColor, backgroundColor }]}>
|
|
233
|
+
<Animated.View pointerEvents="none" style={[styles.androidClip, { opacity: markIn, width: draw.interpolate({ inputRange: [0, 1], outputRange: [0, ANDROID_BOX] }) }]}>
|
|
234
|
+
<Svg width={ANDROID_BOX} height={ANDROID_BOX} viewBox="0 0 20 20">
|
|
235
|
+
<Path d={indeterminate ? DASH_PATH : CHECK_PATH} fill="none" stroke={markColor} strokeWidth={2} strokeLinecap="round" strokeLinejoin="round" />
|
|
236
|
+
</Svg>
|
|
273
237
|
</Animated.View>
|
|
274
|
-
</View>
|
|
238
|
+
</Animated.View>
|
|
275
239
|
)
|
|
276
240
|
}
|
|
277
241
|
|
|
@@ -284,6 +248,7 @@ const styles = StyleSheet.create({
|
|
|
284
248
|
fill: { flexGrow: 1 },
|
|
285
249
|
androidTarget: { width: 48, height: 48, alignItems: "center", justifyContent: "center" },
|
|
286
250
|
half: { opacity: 0.5 },
|
|
287
|
-
|
|
288
|
-
|
|
251
|
+
androidCircle: { width: ANDROID_BOX, height: ANDROID_BOX, borderRadius: ANDROID_BOX / 2, borderWidth: ANDROID_RING },
|
|
252
|
+
// The mark spans the circle's box, over its ring
|
|
253
|
+
androidClip: { position: "absolute", top: -ANDROID_RING, left: -ANDROID_RING, height: ANDROID_BOX, overflow: "hidden" },
|
|
289
254
|
})
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { useEffect, useState, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Easing, Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
2
|
+
import { Animated, Easing, Platform, Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import ChevronDownSm from "../../icons/plex/ChevronDownSm"
|
|
3
4
|
import CloseBold from "../../icons/plex/CloseBold"
|
|
4
5
|
import { spaceToggles } from "../../internal/a11y"
|
|
6
|
+
import { Glass } from "../../internal/Glass"
|
|
5
7
|
import { withAlpha } from "../../theme/material"
|
|
6
8
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
7
9
|
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
10
|
+
import { MaterialArrowDropDown } from "../Icon/material"
|
|
8
11
|
import { Text, textStyle } from "../Text/Text"
|
|
9
12
|
|
|
10
13
|
export type ChipProps = {
|
|
11
|
-
|
|
14
|
+
/** The label. Leave it out with an `icon` for a chip of the symbol alone, a circle named by `accessibilityLabel`. */
|
|
15
|
+
children?: ReactNode
|
|
12
16
|
/** A filter chip: chosen or not. Leave it out for an action chip. */
|
|
13
17
|
selected?: boolean
|
|
14
18
|
defaultSelected?: boolean
|
|
@@ -17,6 +21,23 @@ export type ChipProps = {
|
|
|
17
21
|
onPress?: () => void
|
|
18
22
|
/** A symbol before the label. */
|
|
19
23
|
icon?: ReactNode
|
|
24
|
+
/** A symbol after the label. */
|
|
25
|
+
trailingIcon?: ReactNode
|
|
26
|
+
/**
|
|
27
|
+
* The chip opens a menu (a filter that picks among options): a chevron after the label (iOS `chevron.down`, Material
|
|
28
|
+
* `arrow_drop_down`) unless `trailingIcon` is given, and `aria-haspopup` for a screen reader. `true` is a menu;
|
|
29
|
+
* `"listbox"` and `"dialog"` name what it opens.
|
|
30
|
+
*/
|
|
31
|
+
menu?: boolean | "menu" | "listbox" | "dialog"
|
|
32
|
+
/** Whether the chip's menu is open (`aria-expanded`). */
|
|
33
|
+
expanded?: boolean
|
|
34
|
+
accessibilityLabel?: string
|
|
35
|
+
/**
|
|
36
|
+
* iOS: `tag`, a capsule of the gray fill 40pt tall (a tag cloud in a sheet, as Maps' Filters), or `glass`, a glass
|
|
37
|
+
* capsule 44pt tall (a filter in a row over content, as Maps' filters under its search). Android draws its chip with
|
|
38
|
+
* either. @default "tag"
|
|
39
|
+
*/
|
|
40
|
+
appearance?: "tag" | "glass"
|
|
20
41
|
/** An input chip: a cross at the end that calls this. */
|
|
21
42
|
onRemove?: () => void
|
|
22
43
|
/** @default "Remove" */
|
|
@@ -28,11 +49,29 @@ export type ChipProps = {
|
|
|
28
49
|
|
|
29
50
|
/**
|
|
30
51
|
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
31
|
-
* selected one in the Plex primary
|
|
32
|
-
*
|
|
52
|
+
* selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
|
|
53
|
+
* an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
|
|
54
|
+
* one in the app's accent (its tint) with a white label. The web has
|
|
33
55
|
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
34
56
|
*/
|
|
35
|
-
export function Chip({
|
|
57
|
+
export function Chip({
|
|
58
|
+
children,
|
|
59
|
+
selected: selectedProp,
|
|
60
|
+
defaultSelected,
|
|
61
|
+
onSelectedChange,
|
|
62
|
+
onPress,
|
|
63
|
+
icon,
|
|
64
|
+
trailingIcon,
|
|
65
|
+
menu,
|
|
66
|
+
expanded,
|
|
67
|
+
accessibilityLabel,
|
|
68
|
+
appearance = "tag",
|
|
69
|
+
onRemove,
|
|
70
|
+
removeLabel = "Remove",
|
|
71
|
+
disabled = false,
|
|
72
|
+
testID,
|
|
73
|
+
style,
|
|
74
|
+
}: ChipProps) {
|
|
36
75
|
const theme = useTheme()
|
|
37
76
|
const [own, setOwn] = useState(defaultSelected ?? false)
|
|
38
77
|
const filter = selectedProp !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined
|
|
@@ -46,6 +85,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
46
85
|
onPress?.()
|
|
47
86
|
}
|
|
48
87
|
const android = theme.isAndroid
|
|
88
|
+
const glass = !android && appearance === "glass"
|
|
49
89
|
const m = theme.material
|
|
50
90
|
// Android: the label and the fill of either state, which a selection blends between
|
|
51
91
|
const androidColor = { off: m.onSurface, on: theme.color("--color-text-primary-solid") }
|
|
@@ -56,7 +96,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
56
96
|
? androidColor.on
|
|
57
97
|
: androidColor.off
|
|
58
98
|
: selected
|
|
59
|
-
? theme.color("--color-text-
|
|
99
|
+
? theme.color("--color-text-accent-solid", "#FFFFFF")
|
|
60
100
|
: disabled
|
|
61
101
|
? theme.colors.textDisabled
|
|
62
102
|
: theme.colors.text
|
|
@@ -65,9 +105,12 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
65
105
|
? androidFill.on
|
|
66
106
|
: androidFill.off
|
|
67
107
|
: selected
|
|
68
|
-
? //
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
? // The app's accent, as iOS tints a chosen filter; a disabled selected chip fades to 40%, so it still stands
|
|
109
|
+
// apart from an off one
|
|
110
|
+
withAlpha(theme.colors.accent, disabled ? 0.4 : 1)
|
|
111
|
+
: glass
|
|
112
|
+
? "transparent"
|
|
113
|
+
: theme.color("--color-background-secondary-soft-alpha")
|
|
71
114
|
// Android blends the fill and the label from one state to the other in 120ms, linear; iOS changes at once
|
|
72
115
|
const [blend] = useState(() => new Animated.Value(selected ? 1 : 0))
|
|
73
116
|
const blends = android && !theme.reducedMotion
|
|
@@ -84,11 +127,16 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
84
127
|
}, [blend, blends, selected])
|
|
85
128
|
const fillPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidFill.off, androidFill.on] }) : fill
|
|
86
129
|
const labelPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidColor.off, androidColor.on] }) : color
|
|
87
|
-
const height = android ? 32 :
|
|
88
|
-
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize:
|
|
130
|
+
const height = android ? 32 : glass ? 44 : 40
|
|
131
|
+
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize: 17, lineHeight: 22 }
|
|
89
132
|
const leading = icon
|
|
90
|
-
|
|
133
|
+
// iOS: a 17pt symbol draws about 20 (the label's size)
|
|
134
|
+
const iconSize = android ? 18 : 20
|
|
135
|
+
// A menu chip's chevron: Material's 18dp arrow_drop_down, iOS's small chevron.down at the label's weight
|
|
136
|
+
const trailing = trailingIcon ?? (menu ? android ? <MaterialArrowDropDown size={18} /> : <ChevronDownSm size={16} /> : null)
|
|
91
137
|
const leadingColor = color
|
|
138
|
+
// A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
|
|
139
|
+
const symbolOnly = leading != null && (children == null || children === "") && trailing == null && !onRemove
|
|
92
140
|
// The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
|
|
93
141
|
// HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
|
|
94
142
|
const target = android ? 48 : 44
|
|
@@ -96,7 +144,10 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
96
144
|
// A capsule, which stays one when a large text size makes it taller
|
|
97
145
|
const radius = 999
|
|
98
146
|
const [pressed, setPressed] = useState(false)
|
|
99
|
-
|
|
147
|
+
// iOS's glass filter: a glass capsule (its rim and sheen), filled with the accent once chosen
|
|
148
|
+
const glassLayer =
|
|
149
|
+
glass && !selected ? <Glass pointerEvents="none" radius={radius} style={[StyleSheet.absoluteFill, { top: inset, bottom: inset }]} /> : null
|
|
150
|
+
const layer = glassLayer ?? (
|
|
100
151
|
<Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: radius, backgroundColor: fillPaint, borderCurve: "continuous" }]}>
|
|
101
152
|
{/* Android's press: the list selector over the chip, 6% black and 5% white at night (the dark theme's); over a
|
|
102
153
|
selected chip's solid fill its label's color at 12%, which shows on either scheme */}
|
|
@@ -111,8 +162,9 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
111
162
|
minHeight: target,
|
|
112
163
|
paddingVertical: inset + (height - label.lineHeight) / 2,
|
|
113
164
|
// Android: 12 at the sides, 8 before an icon and 6 after it
|
|
114
|
-
paddingLeft: leading != null ? (android ? 8 : 12) : android ? 12 :
|
|
115
|
-
|
|
165
|
+
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
166
|
+
// Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
|
|
167
|
+
paddingRight: symbolOnly ? (height - iconSize) / 2 : onRemove ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
116
168
|
gap: 6,
|
|
117
169
|
opacity: !android && pressed ? 0.7 : 1,
|
|
118
170
|
}
|
|
@@ -126,7 +178,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
126
178
|
</IconDefaultsProvider>
|
|
127
179
|
</View>
|
|
128
180
|
) : null}
|
|
129
|
-
{android ? (
|
|
181
|
+
{symbolOnly ? null : android ? (
|
|
130
182
|
// Text's own face and tracking, in a color that blends
|
|
131
183
|
<Animated.Text
|
|
132
184
|
numberOfLines={1}
|
|
@@ -135,10 +187,17 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
135
187
|
{children}
|
|
136
188
|
</Animated.Text>
|
|
137
189
|
) : (
|
|
138
|
-
<Text color={color} weight="
|
|
190
|
+
<Text color={color} weight="regular" numberOfLines={1} style={{ fontSize: label.fontSize, lineHeight: label.lineHeight }}>
|
|
139
191
|
{children}
|
|
140
192
|
</Text>
|
|
141
193
|
)}
|
|
194
|
+
{trailing != null ? (
|
|
195
|
+
<View>
|
|
196
|
+
<IconDefaultsProvider size={iconSize} color={leadingColor}>
|
|
197
|
+
{trailing}
|
|
198
|
+
</IconDefaultsProvider>
|
|
199
|
+
</View>
|
|
200
|
+
) : null}
|
|
142
201
|
</>
|
|
143
202
|
)
|
|
144
203
|
const interactive = filter || !!onPress
|
|
@@ -146,9 +205,13 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
146
205
|
const dim = android && disabled ? styles.dim : null
|
|
147
206
|
const handlers = {
|
|
148
207
|
...(filter ? spaceToggles(press) : {}),
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
208
|
+
// A menu chip is a button that opens its menu, even when it shows a chosen filter
|
|
209
|
+
accessibilityRole: filter && !menu ? ("checkbox" as const) : ("button" as const),
|
|
210
|
+
accessibilityLabel,
|
|
211
|
+
accessibilityState: { disabled, checked: filter && !menu ? selected : undefined, selected: filter && menu && Platform.OS !== "web" ? selected : undefined, expanded },
|
|
212
|
+
"aria-checked": filter && !menu ? selected : undefined,
|
|
213
|
+
"aria-haspopup": menu ? (menu === true ? ("menu" as const) : menu) : undefined,
|
|
214
|
+
"aria-expanded": menu ? expanded : undefined,
|
|
152
215
|
disabled,
|
|
153
216
|
onPress: press,
|
|
154
217
|
onPressIn: () => setPressed(true),
|