@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,19 +1,23 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useState } from "react";
|
|
3
|
-
import { Animated, Easing, Pressable, StyleSheet, View } from "react-native";
|
|
3
|
+
import { Animated, Easing, Platform, Pressable, StyleSheet, View } from "react-native";
|
|
4
|
+
import ChevronDownSm from "../../icons/plex/ChevronDownSm";
|
|
4
5
|
import CloseBold from "../../icons/plex/CloseBold";
|
|
5
6
|
import { spaceToggles } from "../../internal/a11y";
|
|
7
|
+
import { Glass } from "../../internal/Glass";
|
|
6
8
|
import { withAlpha } from "../../theme/material";
|
|
7
9
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
8
10
|
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
11
|
+
import { MaterialArrowDropDown } from "../Icon/material";
|
|
9
12
|
import { Text, textStyle } from "../Text/Text";
|
|
10
13
|
/**
|
|
11
14
|
* A compact choice or action. Android: a chip (a 32dp capsule filled with the text color at 5%, Regular 14; a
|
|
12
|
-
* selected one in the Plex primary
|
|
13
|
-
*
|
|
15
|
+
* selected one in the Plex primary). iOS has no chip control: the filter capsules of iOS 26 apps (Maps), measured on
|
|
16
|
+
* an iPhone: a `tag` 40pt tall in the gray fill, or a `glass` capsule 44pt tall, the label 17/22 Regular; a selected
|
|
17
|
+
* one in the app's accent (its tint) with a white label. The web has
|
|
14
18
|
* no Chip; the props follow Toggle-like controls (`selected`, `onSelectedChange`) and Badge's `onRemove`.
|
|
15
19
|
*/
|
|
16
|
-
export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, onRemove, removeLabel = "Remove", disabled = false, testID, style }) {
|
|
20
|
+
export function Chip({ children, selected: selectedProp, defaultSelected, onSelectedChange, onPress, icon, trailingIcon, menu, expanded, accessibilityLabel, appearance = "tag", onRemove, removeLabel = "Remove", disabled = false, testID, style, }) {
|
|
17
21
|
const theme = useTheme();
|
|
18
22
|
const [own, setOwn] = useState(defaultSelected ?? false);
|
|
19
23
|
const filter = selectedProp !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined;
|
|
@@ -29,6 +33,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
29
33
|
onPress?.();
|
|
30
34
|
};
|
|
31
35
|
const android = theme.isAndroid;
|
|
36
|
+
const glass = !android && appearance === "glass";
|
|
32
37
|
const m = theme.material;
|
|
33
38
|
// Android: the label and the fill of either state, which a selection blends between
|
|
34
39
|
const androidColor = { off: m.onSurface, on: theme.color("--color-text-primary-solid") };
|
|
@@ -39,7 +44,7 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
39
44
|
? androidColor.on
|
|
40
45
|
: androidColor.off
|
|
41
46
|
: selected
|
|
42
|
-
? theme.color("--color-text-
|
|
47
|
+
? theme.color("--color-text-accent-solid", "#FFFFFF")
|
|
43
48
|
: disabled
|
|
44
49
|
? theme.colors.textDisabled
|
|
45
50
|
: theme.colors.text;
|
|
@@ -48,9 +53,12 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
48
53
|
? androidFill.on
|
|
49
54
|
: androidFill.off
|
|
50
55
|
: selected
|
|
51
|
-
? //
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
? // The app's accent, as iOS tints a chosen filter; a disabled selected chip fades to 40%, so it still stands
|
|
57
|
+
// apart from an off one
|
|
58
|
+
withAlpha(theme.colors.accent, disabled ? 0.4 : 1)
|
|
59
|
+
: glass
|
|
60
|
+
? "transparent"
|
|
61
|
+
: theme.color("--color-background-secondary-soft-alpha");
|
|
54
62
|
// Android blends the fill and the label from one state to the other in 120ms, linear; iOS changes at once
|
|
55
63
|
const [blend] = useState(() => new Animated.Value(selected ? 1 : 0));
|
|
56
64
|
const blends = android && !theme.reducedMotion;
|
|
@@ -67,11 +75,16 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
67
75
|
}, [blend, blends, selected]);
|
|
68
76
|
const fillPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidFill.off, androidFill.on] }) : fill;
|
|
69
77
|
const labelPaint = blends ? blend.interpolate({ inputRange: [0, 1], outputRange: [androidColor.off, androidColor.on] }) : color;
|
|
70
|
-
const height = android ? 32 :
|
|
71
|
-
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize:
|
|
78
|
+
const height = android ? 32 : glass ? 44 : 40;
|
|
79
|
+
const label = android ? { fontSize: 14, lineHeight: 18 } : { fontSize: 17, lineHeight: 22 };
|
|
72
80
|
const leading = icon;
|
|
73
|
-
|
|
81
|
+
// iOS: a 17pt symbol draws about 20 (the label's size)
|
|
82
|
+
const iconSize = android ? 18 : 20;
|
|
83
|
+
// A menu chip's chevron: Material's 18dp arrow_drop_down, iOS's small chevron.down at the label's weight
|
|
84
|
+
const trailing = trailingIcon ?? (menu ? android ? _jsx(MaterialArrowDropDown, { size: 18 }) : _jsx(ChevronDownSm, { size: 16 }) : null);
|
|
74
85
|
const leadingColor = color;
|
|
86
|
+
// A symbol alone (Maps' filter button before its chips): a circle as tall as the chip, named by accessibilityLabel
|
|
87
|
+
const symbolOnly = leading != null && (children == null || children === "") && trailing == null && !onRemove;
|
|
75
88
|
// The chip is drawn 32 (34) tall inside a 48dp (44pt) touch target, as Compose's minimum interactive size and the
|
|
76
89
|
// HIG ask: the target is the layout box, the chip a layer inside it, so every press in the target reaches it
|
|
77
90
|
const target = android ? 48 : 44;
|
|
@@ -79,29 +92,36 @@ export function Chip({ children, selected: selectedProp, defaultSelected, onSele
|
|
|
79
92
|
// A capsule, which stays one when a large text size makes it taller
|
|
80
93
|
const radius = 999;
|
|
81
94
|
const [pressed, setPressed] = useState(false);
|
|
82
|
-
|
|
95
|
+
// iOS's glass filter: a glass capsule (its rim and sheen), filled with the accent once chosen
|
|
96
|
+
const glassLayer = glass && !selected ? _jsx(Glass, { pointerEvents: "none", radius: radius, style: [StyleSheet.absoluteFill, { top: inset, bottom: inset }] }) : null;
|
|
97
|
+
const layer = glassLayer ?? (_jsx(Animated.View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: radius, backgroundColor: fillPaint, borderCurve: "continuous" }], children: android && pressed && !disabled ? (_jsx(View, { style: [StyleSheet.absoluteFill, { borderRadius: radius, backgroundColor: selected ? withAlpha(color, 0.12) : theme.scheme === "dark" ? "rgba(255, 255, 255, 0.05)" : "rgba(0, 0, 0, 0.06)" }] })) : null }));
|
|
83
98
|
const box = {
|
|
84
99
|
// The label's own air inside the chip, then the target's outside it: 48 (44) at the regular size, and taller
|
|
85
100
|
// with the text at a large font scale instead of cutting it (Compose's chips have a minimum height, not a height)
|
|
86
101
|
minHeight: target,
|
|
87
102
|
paddingVertical: inset + (height - label.lineHeight) / 2,
|
|
88
103
|
// Android: 12 at the sides, 8 before an icon and 6 after it
|
|
89
|
-
paddingLeft: leading != null ? (android ? 8 : 12) : android ? 12 :
|
|
90
|
-
|
|
104
|
+
paddingLeft: symbolOnly ? (height - iconSize) / 2 : leading != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
105
|
+
// Android: 8 after a trailing icon (Compose's FilterChip), iOS 12
|
|
106
|
+
paddingRight: symbolOnly ? (height - iconSize) / 2 : onRemove ? 0 : trailing != null ? (android ? 8 : 12) : android ? 12 : 16,
|
|
91
107
|
gap: 6,
|
|
92
108
|
opacity: !android && pressed ? 0.7 : 1,
|
|
93
109
|
};
|
|
94
|
-
const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, android ? (
|
|
110
|
+
const body = (_jsxs(_Fragment, { children: [leading != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: leading }) })) : null, symbolOnly ? null : android ? (
|
|
95
111
|
// Text's own face and tracking, in a color that blends
|
|
96
|
-
_jsx(Animated.Text, { numberOfLines: 1, style: [textStyle(theme, { weight: "regular" }), { fontSize: label.fontSize, lineHeight: label.lineHeight, letterSpacing: theme.tracking(label.fontSize), color: labelPaint }], children: children })) : (_jsx(Text, { color: color, weight: "
|
|
112
|
+
_jsx(Animated.Text, { numberOfLines: 1, style: [textStyle(theme, { weight: "regular" }), { fontSize: label.fontSize, lineHeight: label.lineHeight, letterSpacing: theme.tracking(label.fontSize), color: labelPaint }], children: children })) : (_jsx(Text, { color: color, weight: "regular", numberOfLines: 1, style: { fontSize: label.fontSize, lineHeight: label.lineHeight }, children: children })), trailing != null ? (_jsx(View, { children: _jsx(IconDefaultsProvider, { size: iconSize, color: leadingColor, children: trailing }) })) : null] }));
|
|
97
113
|
const interactive = filter || !!onPress;
|
|
98
114
|
// Android dims a disabled chip, its fill with it, to half (as its other disabled controls)
|
|
99
115
|
const dim = android && disabled ? styles.dim : null;
|
|
100
116
|
const handlers = {
|
|
101
117
|
...(filter ? spaceToggles(press) : {}),
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
// A menu chip is a button that opens its menu, even when it shows a chosen filter
|
|
119
|
+
accessibilityRole: filter && !menu ? "checkbox" : "button",
|
|
120
|
+
accessibilityLabel,
|
|
121
|
+
accessibilityState: { disabled, checked: filter && !menu ? selected : undefined, selected: filter && menu && Platform.OS !== "web" ? selected : undefined, expanded },
|
|
122
|
+
"aria-checked": filter && !menu ? selected : undefined,
|
|
123
|
+
"aria-haspopup": menu ? (menu === true ? "menu" : menu) : undefined,
|
|
124
|
+
"aria-expanded": menu ? expanded : undefined,
|
|
105
125
|
disabled,
|
|
106
126
|
onPress: press,
|
|
107
127
|
onPressIn: () => setPressed(true),
|
|
@@ -3,6 +3,7 @@ import { useId, useState } from "react";
|
|
|
3
3
|
import { Animated, KeyboardAvoidingView, Platform, Pressable, ScrollView, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
5
5
|
import { Glass } from "../../internal/Glass";
|
|
6
|
+
import { useRipple } from "../../internal/ripple";
|
|
6
7
|
import { useKeyboardHeight } from "../../internal/keyboard";
|
|
7
8
|
import { androidDialogMotion, canTransformGlass, glassOpacity, iosDim, Overlay, ANDROID_DIALOG, ANDROID_DIM } from "../../internal/Overlay";
|
|
8
9
|
import { withAlpha, dangerText } from "../../theme/material";
|
|
@@ -11,7 +12,7 @@ import { Text } from "../Text/Text";
|
|
|
11
12
|
/**
|
|
12
13
|
* A dialog that asks for a decision: on iOS the alert of iOS 26 (UIAlertController `.alert`: 320 wide, glass, radius
|
|
13
14
|
* 34, capsule actions 48 tall, `--dialog-alert-*`, Dialog.module.css), on Android a flat alert (at most 356 wide,
|
|
14
|
-
* radius
|
|
15
|
+
* radius 21, a Medium 20 title over 16 text, text buttons in the accent at the end, Android's dialog animation). The
|
|
15
16
|
* web Dialog's `mobileVariant="alert"` as one call; a sheet is `BottomSheet`.
|
|
16
17
|
*/
|
|
17
18
|
export function Dialog({ open, onOpenChange, title, description, actions = [], children, mobileLayout, dismissible, testID }) {
|
|
@@ -83,10 +84,11 @@ function androidDim(progress, opening) {
|
|
|
83
84
|
: progress.interpolate({ inputRange: [1 - DIM_END, 1], outputRange: [0, 1], extrapolate: "clamp" });
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
|
-
* Android's
|
|
87
|
-
*
|
|
87
|
+
* Android's choice alert: the dialog's panel, its title and rows across its width; one Cancel button for a single
|
|
88
|
+
* choice (a row picks and closes), Cancel and OK at the end, 8 apart, for a multiple one (the rows check, OK applies).
|
|
89
|
+
* Select's picker on Android; not part of the public API.
|
|
88
90
|
*/
|
|
89
|
-
export function ChoiceDialog({ open, onClose, title, cancelLabel, children, listProps, testID }) {
|
|
91
|
+
export function ChoiceDialog({ open, onClose, title, cancelLabel, okLabel, onOk, children, listProps, testID }) {
|
|
90
92
|
const theme = useTheme();
|
|
91
93
|
const ids = { title: useId(), description: useId() };
|
|
92
94
|
const a11y = Platform.OS === "web"
|
|
@@ -98,7 +100,12 @@ export function ChoiceDialog({ open, onClose, title, cancelLabel, children, list
|
|
|
98
100
|
action.onPress?.();
|
|
99
101
|
onClose();
|
|
100
102
|
};
|
|
101
|
-
return (_jsx(AndroidFrame, { open: open, onClose: onClose, dismissible: true, a11y: a11y, testID: testID, children: _jsx(AndroidDialog, { theme: theme, title: title, actions:
|
|
103
|
+
return (_jsx(AndroidFrame, { open: open, onClose: onClose, dismissible: true, a11y: a11y, testID: testID, children: _jsx(AndroidDialog, { theme: theme, title: title, actions: okLabel != null
|
|
104
|
+
? [
|
|
105
|
+
{ label: cancelLabel, variant: "cancel", testID: testID ? `${testID}-cancel` : undefined },
|
|
106
|
+
{ label: okLabel, preferred: true, onPress: onOk, testID: testID ? `${testID}-ok` : undefined },
|
|
107
|
+
]
|
|
108
|
+
: [{ label: cancelLabel, testID: testID ? `${testID}-cancel` : undefined }], run: run, ids: ids, list: _jsx(View, { ...listProps, children: children }) }) }));
|
|
102
109
|
}
|
|
103
110
|
function IOSAlert({ theme, title, description, actions, run, ids, layout, children }) {
|
|
104
111
|
const { width: screen } = useWindowDimensions();
|
|
@@ -183,20 +190,25 @@ function AndroidDialog({ theme, title, description, actions, run, ids, children,
|
|
|
183
190
|
const order = stacked ? [...bar.keys()].reverse() : [...bar.keys()];
|
|
184
191
|
const button = (index) => {
|
|
185
192
|
const action = bar[index];
|
|
186
|
-
|
|
187
|
-
// disabled; its press a pill of the label's color at 10%
|
|
188
|
-
const color = action.variant === "destructive" ? dangerText(theme) : m.primary;
|
|
189
|
-
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!action.disabled }, disabled: action.disabled, onPress: () => run(action), onLayout: (event) => {
|
|
190
|
-
const next = event.nativeEvent.layout.width;
|
|
191
|
-
setWidths((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next })));
|
|
192
|
-
}, testID: action.testID, style: ({ pressed }) => [styles.androidButton, { opacity: action.disabled ? 0.5 : 1 }, pressed ? { backgroundColor: withAlpha(color, 0.1) } : null], children: _jsx(Text, { color: color, style: [styles.androidLabel, { ...theme.font("medium") }], children: action.label }) }, actions.indexOf(action)));
|
|
193
|
+
return (_jsx(AndroidDialogButton, { theme: theme, action: action, run: run, onWidth: (next) => setWidths((current) => (current[index] === next ? current : Object.assign([...current], { [index]: next }))) }, actions.indexOf(action)));
|
|
193
194
|
};
|
|
194
195
|
return (_jsxs(View, { style: [styles.android, { width, backgroundColor: androidDialogBackground(theme) }], children: [list != null ? (
|
|
195
196
|
// A list: the title stays, 14 over the rows, and the rows scroll under it (AlertDialog with a custom view)
|
|
196
|
-
_jsxs(_Fragment, { children: [title != null ? (_jsx(Text, { nativeID: ids.title, color: m.onSurface, accessibilityRole: "header", style: [styles.androidTitle, styles.androidListTitle, theme.font("medium")], children: title })) : null, _jsx(ScrollView, { style: styles.scroll, contentContainerStyle: title != null ? null : styles.androidListTop, bounces: false, children: list })] })) : (_jsxs(ScrollView, { style: styles.scroll, contentContainerStyle: styles.androidText, bounces: false, children: [_jsx(Text, { nativeID: ids.title, color: m.onSurface, accessibilityRole: "header", style: [styles.androidTitle, theme.font("medium")], children: title }), description != null ? (_jsx(Text, { nativeID: ids.description, color: m.onSurface, style: styles.androidMessage, children: description })) : null, children != null ? _jsx(View, { style: styles.androidContent, children: children }) : null] })), bar.length ? (_jsx(View, { onLayout: (event) => setRoom(event.nativeEvent.layout.width - 16), style: stacked ? styles.androidStack :
|
|
197
|
+
_jsxs(_Fragment, { children: [title != null ? (_jsx(Text, { nativeID: ids.title, color: m.onSurface, accessibilityRole: "header", style: [styles.androidTitle, styles.androidListTitle, theme.font("medium")], children: title })) : null, _jsx(ScrollView, { style: styles.scroll, contentContainerStyle: title != null ? null : styles.androidListTop, bounces: false, children: list })] })) : (_jsxs(ScrollView, { style: styles.scroll, contentContainerStyle: styles.androidText, bounces: false, children: [_jsx(Text, { nativeID: ids.title, color: m.onSurface, accessibilityRole: "header", style: [styles.androidTitle, theme.font("medium")], children: title }), description != null ? (_jsx(Text, { nativeID: ids.description, color: m.onSurface, style: styles.androidMessage, children: description })) : null, children != null ? _jsx(View, { style: styles.androidContent, children: children }) : null] })), bar.length ? (_jsx(View, { onLayout: (event) => setRoom(event.nativeEvent.layout.width - 16), style: stacked ? styles.androidStack : styles.androidActions, children: order.map((index) =>
|
|
197
198
|
// The neutral actions at the start, a space, then the negative and the positive
|
|
198
199
|
!stacked && index === neutral.length && neutral.length ? [_jsx(View, { style: styles.grow }, "space"), button(index)] : button(index)) })) : null] }));
|
|
199
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Android's dialog button: Medium 16 in the accent, red for a destructive one, half faded when disabled; its press the
|
|
203
|
+
* ripple of the label's color at 10% from the touch point, clipped to its 20dp pill (the platform's on a device).
|
|
204
|
+
*/
|
|
205
|
+
function AndroidDialogButton({ theme, action, run, onWidth }) {
|
|
206
|
+
const color = action.variant === "destructive" ? dangerText(theme) : theme.material.primary;
|
|
207
|
+
const press = withAlpha(color, 0.1);
|
|
208
|
+
const nativeRipple = Platform.OS === "android";
|
|
209
|
+
const ripple = useRipple(press, !nativeRipple, theme.reducedMotion);
|
|
210
|
+
return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!action.disabled }, disabled: action.disabled, onPress: () => run(action), onPressIn: nativeRipple ? undefined : ripple.start, onPressOut: nativeRipple ? undefined : ripple.end, android_ripple: nativeRipple ? { color: press, foreground: true } : undefined, onLayout: (event) => onWidth(event.nativeEvent.layout.width), testID: action.testID, style: [styles.androidButton, { opacity: action.disabled ? 0.5 : 1 }], children: [ripple.layer, _jsx(Text, { color: color, style: [styles.androidLabel, { ...theme.font("medium") }], children: action.label })] }));
|
|
211
|
+
}
|
|
200
212
|
/** The space between dialog buttons, in a row and stacked. */
|
|
201
213
|
const GAP = 8;
|
|
202
214
|
/** The background of an Android dialog: white, a dark gray in dark mode. */
|
|
@@ -208,21 +220,22 @@ const styles = StyleSheet.create({
|
|
|
208
220
|
grow: { flex: 1, flexBasis: 0 },
|
|
209
221
|
centered: { textAlign: "center" },
|
|
210
222
|
iosAction: { alignItems: "center", justifyContent: "center", paddingVertical: 13, paddingHorizontal: 16, borderCurve: "continuous" },
|
|
211
|
-
// Android's alert:
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
223
|
+
// Android's alert: 21dp corners (the catalog's); the text 24 in. Measured on the reference's alerts: the title's
|
|
224
|
+
// baseline 40 under the top, the message's first 33 under it in lines 18.75 apart (16sp Roboto's), its last 59
|
|
225
|
+
// over the buttons' (Roboto's font padding sets these 2 to 3 lower than the layout's 19, 10 and 20 would)
|
|
226
|
+
android: { flexShrink: 1, borderRadius: 21, overflow: "hidden" },
|
|
227
|
+
androidText: { paddingHorizontal: 24, paddingTop: 21, paddingBottom: 21, gap: 13 },
|
|
215
228
|
androidTitle: { fontSize: 20, lineHeight: 24 },
|
|
216
|
-
// Over a list the title keeps its 24 at the sides
|
|
217
|
-
|
|
229
|
+
// Over a list the title keeps its 24 at the sides, its line 21 under the panel's top (its capitals 25 under it and
|
|
230
|
+
// its baseline 40, as the reference's) and 11 over the rows, which start 56 under the top (the first radio at 71), as
|
|
231
|
+
// the web's
|
|
232
|
+
androidListTitle: { paddingHorizontal: 24, paddingTop: 21, paddingBottom: 11 },
|
|
218
233
|
// A list with no title starts 8 under the panel's top
|
|
219
234
|
androidListTop: { paddingTop: 8 },
|
|
220
|
-
androidMessage: { fontSize: 16, lineHeight:
|
|
235
|
+
androidMessage: { fontSize: 16, lineHeight: 18.75 },
|
|
221
236
|
androidContent: { marginTop: 6 },
|
|
222
|
-
// The button row:
|
|
223
|
-
androidActions: { flexDirection: "row", justifyContent: "flex-end", alignItems: "center", gap: GAP, paddingHorizontal: 8, paddingVertical:
|
|
224
|
-
// Under a list of choices the row is 56: 8 over and under the buttons (measured on the platform's single-choice dialog)
|
|
225
|
-
androidListActions: { paddingVertical: 8 },
|
|
237
|
+
// The button row: 56 tall (8 over and under its 40dp buttons, measured on the reference's alerts), 8 in from the sides
|
|
238
|
+
androidActions: { flexDirection: "row", justifyContent: "flex-end", alignItems: "center", gap: GAP, paddingHorizontal: 8, paddingVertical: 8 },
|
|
226
239
|
// Stacked: 8 over and under the 40dp buttons (two make 96)
|
|
227
240
|
androidStack: { alignItems: "flex-end", paddingHorizontal: 8, paddingVertical: 8 },
|
|
228
241
|
// Android's dialog button: 40 tall, at least 64 wide, 12 at the sides; at least 40, so a larger font grows it
|
|
@@ -234,6 +247,7 @@ const styles = StyleSheet.create({
|
|
|
234
247
|
paddingHorizontal: 12,
|
|
235
248
|
paddingVertical: 8,
|
|
236
249
|
borderRadius: 20,
|
|
250
|
+
overflow: "hidden",
|
|
237
251
|
alignItems: "center",
|
|
238
252
|
justifyContent: "center",
|
|
239
253
|
},
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { cloneElement, isValidElement, useContext, useEffect } from "react";
|
|
3
|
+
import { StyleSheet, View } from "react-native";
|
|
4
|
+
import ExclamationMarkCircle from "../../icons/plex/ExclamationMarkCircle";
|
|
5
|
+
import { textOf } from "../../internal/children";
|
|
6
|
+
import { FieldStack, FloatLabelContext } from "../../internal/fieldStack";
|
|
7
|
+
import { RowEndContext } from "../../internal/row";
|
|
8
|
+
import { dangerText } from "../../theme/material";
|
|
9
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
10
|
+
import { Input } from "../Input/Input";
|
|
11
|
+
import { ListItem, ListStackedRow } from "../List/List";
|
|
12
|
+
import { Text } from "../Text/Text";
|
|
13
|
+
import { Textarea } from "../Textarea/Textarea";
|
|
14
|
+
/** A control a Field floats its label in on Android: the outlined field of an Input or a Textarea. */
|
|
15
|
+
const floats = (child) => isValidElement(child) && (child.type === Input || child.type === Textarea);
|
|
16
|
+
/**
|
|
17
|
+
* A label, a description and an error around a control, linked to it: Plex UI's Field. On its own the label stands over
|
|
18
|
+
* the control (TextField's stack: iOS 15/20 Medium 8 above it, the help 4 under it; on Android an Input or a Textarea
|
|
19
|
+
* floats the label in its outlined field). With `row` it is a line of a List, as the web's `Field row` on a phone: the
|
|
20
|
+
* label at the start and the control at the end (a ListItem), or with `orientation="vertical"` or `hideLabel` the value
|
|
21
|
+
* a line of its own under the label (iOS: 15/20 in the secondary label, 13 above and below).
|
|
22
|
+
*/
|
|
23
|
+
export function Field({ label, hideLabel = false, description, errorMessage, labelAction, required = false, orientation, row = false, fill = false, icon, action, disabled, children, style, testID, }) {
|
|
24
|
+
const theme = useTheme();
|
|
25
|
+
const name = textOf(label) || undefined;
|
|
26
|
+
const error = errorMessage != null && errorMessage !== false && errorMessage !== "";
|
|
27
|
+
const element = typeof children === "function" ? null : children;
|
|
28
|
+
const own = element?.props ?? {};
|
|
29
|
+
// The child's own name wins, as the web's
|
|
30
|
+
const control = (extra, bad) => {
|
|
31
|
+
const props = { accessibilityLabel: own.accessibilityLabel ?? own["aria-label"] ?? name, invalid: bad || own.invalid === true, ...extra };
|
|
32
|
+
if (typeof children === "function")
|
|
33
|
+
return children(props);
|
|
34
|
+
// A row is the frame of its field, whatever its variant, as the web's rows on a phone; beside the label the value
|
|
35
|
+
// ends at the row's end on Android too (the web's ghost row value), or starts the column of a List with `columns`
|
|
36
|
+
return cloneElement(children, row && floats(element) ? { ...props, variant: "ghost", valueAtEnd: true } : props);
|
|
37
|
+
};
|
|
38
|
+
const asterisk = required ? _jsx(Text, { color: theme.isAndroid ? dangerText(theme) : theme.color("--color-text-danger"), children: " *" }) : null;
|
|
39
|
+
if (row) {
|
|
40
|
+
const vertical = hideLabel || (orientation ?? "horizontal") === "vertical";
|
|
41
|
+
if (vertical) {
|
|
42
|
+
return (_jsx(ListStackedRow, { label: hideLabel ? undefined : _jsxs(_Fragment, { children: [label, asterisk] }), description: description, error: errorMessage, disabled: disabled, action: action ?? labelAction, testID: testID, children: control({}, error) }));
|
|
43
|
+
}
|
|
44
|
+
const end = control({}, error);
|
|
45
|
+
const ends = fill ? _jsx(FillEnd, { children: end }) : end;
|
|
46
|
+
return (_jsx(ListItem, { label: _jsxs(_Fragment, { children: [label, asterisk] }), description: description, error: errorMessage, leading: icon, disabled: disabled, accessibilityLabel: name, testID: testID, trailing: action != null ? _jsxs(View, { style: styles.ends, children: [ends, action] }) : ends }));
|
|
47
|
+
}
|
|
48
|
+
const dimmed = disabled ?? own.disabled === true;
|
|
49
|
+
const floating = theme.isAndroid && !hideLabel && (orientation ?? "vertical") === "vertical" && floats(element);
|
|
50
|
+
const stack = (_jsx(FieldStack, { label: label, hideLabel: hideLabel || orientation === "horizontal", required: required, description: description, errorMessage: errorMessage, labelAction: orientation === "horizontal" ? undefined : labelAction, disabled: dimmed, floating: floating, style: orientation === "horizontal" ? styles.grow : style, testID: orientation === "horizontal" ? undefined : testID, children: ({ described, invalid, shake }) => floating ? (_jsx(FloatLabelContext.Provider, { value: { label, required, shift: shake }, children: control(described, invalid) })) : (control(described, invalid)) }));
|
|
51
|
+
if (orientation !== "horizontal")
|
|
52
|
+
return stack;
|
|
53
|
+
// Beside the control: the label in its column, 40% of the field, as the web's horizontal Field
|
|
54
|
+
return (_jsxs(View, { testID: testID, style: [styles.horizontal, style], children: [_jsxs(View, { style: [styles.column, { minHeight: theme.isAndroid ? 50 : theme.length("--control-size-lg", 44) }], children: [_jsxs(Text, { weight: "medium", color: dimmed ? "disabled" : theme.isAndroid ? theme.colors.textSecondary : "primary", style: theme.isAndroid ? styles.androidLabel : styles.iosLabel, children: [label, asterisk] }), labelAction] }), stack] }));
|
|
55
|
+
}
|
|
56
|
+
/** A row's end that takes the rest of the line after the label (`fill`). */
|
|
57
|
+
function FillEnd({ children }) {
|
|
58
|
+
const rowEnd = useContext(RowEndContext);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (rowEnd == null)
|
|
61
|
+
return;
|
|
62
|
+
rowEnd.fill(true);
|
|
63
|
+
return () => rowEnd.fill(false);
|
|
64
|
+
}, [rowEnd]);
|
|
65
|
+
return _jsx(View, { style: styles.grow, children: children });
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A form's error message, announced when it appears: Plex UI's FieldError. iOS: 15/20 in the danger color after a 16pt
|
|
69
|
+
* exclamation mark, 4 apart (`--mobile-field-error-*`); Android: the help's 14sp in the error color, with no mark.
|
|
70
|
+
*/
|
|
71
|
+
export function FieldError({ children, icon = true, nativeID, style, testID }) {
|
|
72
|
+
const theme = useTheme();
|
|
73
|
+
if (theme.isAndroid) {
|
|
74
|
+
return (_jsx(Text, { nativeID: nativeID, testID: testID, color: dangerText(theme), accessibilityLiveRegion: "polite", style: [styles.androidError, style], children: children }));
|
|
75
|
+
}
|
|
76
|
+
const color = theme.color("--field-error-color", theme.color("--color-text-danger-outline", theme.color("--color-text-danger")));
|
|
77
|
+
const line = theme.length("--mobile-field-error-line-height", 20);
|
|
78
|
+
const size = theme.length("--mobile-field-error-icon-size", 16);
|
|
79
|
+
return (_jsxs(View, { nativeID: nativeID, testID: testID, accessibilityLiveRegion: "polite", style: [styles.error, { gap: theme.length("--mobile-field-error-icon-gap", 4) }, style], children: [icon ? _jsx(ExclamationMarkCircle, { size: size, color: color, style: { marginTop: (line - size) / 2 } }) : null, _jsx(Text, { color: color, style: [styles.shrink, { fontSize: theme.length("--mobile-field-error-font-size", 15), lineHeight: line }], children: children })] }));
|
|
80
|
+
}
|
|
81
|
+
const styles = StyleSheet.create({
|
|
82
|
+
grow: { flex: 1, minWidth: 0 },
|
|
83
|
+
shrink: { flexShrink: 1 },
|
|
84
|
+
ends: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
85
|
+
horizontal: { alignSelf: "stretch", flexDirection: "row", alignItems: "flex-start", gap: 16 },
|
|
86
|
+
column: { width: "40%", justifyContent: "center", gap: 4 },
|
|
87
|
+
iosLabel: { fontSize: 15, lineHeight: 20 },
|
|
88
|
+
androidLabel: { fontSize: 14, lineHeight: 18 },
|
|
89
|
+
error: { flexDirection: "row", alignItems: "flex-start" },
|
|
90
|
+
androidError: { fontSize: 14, lineHeight: 18 },
|
|
91
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import Eye from "../../icons/plex/Eye";
|
|
4
|
+
import EyeOff from "../../icons/plex/EyeOff";
|
|
5
|
+
import { FieldStack } from "../../internal/fieldStack";
|
|
6
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
7
|
+
import { Field } from "../Field/Field";
|
|
8
|
+
import { Input, InputField } from "../Input/Input";
|
|
9
|
+
import { List, useInList } from "../List/List";
|
|
10
|
+
import { Textarea } from "../Textarea/Textarea";
|
|
11
|
+
const KEYBOARD = {
|
|
12
|
+
text: {},
|
|
13
|
+
password: { autoCapitalize: "none", autoCorrect: false },
|
|
14
|
+
email: { inputMode: "email", autoCapitalize: "none", autoCorrect: false },
|
|
15
|
+
tel: { inputMode: "tel" },
|
|
16
|
+
url: { inputMode: "url", autoCapitalize: "none", autoCorrect: false },
|
|
17
|
+
number: { inputMode: "decimal" },
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A text field named by a label that floats into its frame: Plex UI's FloatingLabelInput. Android: the outlined field,
|
|
21
|
+
* its label 16sp at rest that springs to 12sp on the outline as the field takes focus or a value (or into a filled
|
|
22
|
+
* box with `labelPlacement="inside"`), the help 14sp under it and a shake on an error, as TextField. iOS has no
|
|
23
|
+
* floating label: the field is a cell named by its placeholder, as an iOS form (the web's phone view, a label-hidden
|
|
24
|
+
* `Field row`): a row of its List, or a List of its own with the description in its footer.
|
|
25
|
+
*/
|
|
26
|
+
export function FloatingLabelInput({ label, errorMessage, invalid: invalidProp, description, type = "text", revealable: revealableProp, onRevealedChange, multiline = false, rows = 2, labelPlacement = "border", pill, endAdornment, disabled = false, style, testID, accessibilityLabel, ...rest }) {
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const inList = useInList();
|
|
29
|
+
const [revealed, setRevealed] = useState(false);
|
|
30
|
+
const error = errorMessage != null && errorMessage !== "";
|
|
31
|
+
const invalid = invalidProp ?? error;
|
|
32
|
+
const revealable = revealableProp ?? (type === "password" && endAdornment == null);
|
|
33
|
+
const secure = (type === "password" || revealable) && !revealed && !multiline;
|
|
34
|
+
const reveal = () => {
|
|
35
|
+
const next = !revealed;
|
|
36
|
+
setRevealed(next);
|
|
37
|
+
onRevealedChange?.(next);
|
|
38
|
+
};
|
|
39
|
+
const eye = revealable && !multiline ? (_jsx(Input.AdornmentButton, { accessibilityLabel: revealed ? "Hide" : "Show", selected: revealed, disabled: disabled, onPress: reveal, children: revealed ? _jsx(EyeOff, {}) : _jsx(Eye, {}) })) : null;
|
|
40
|
+
const end = endAdornment != null && eye != null ? (_jsxs(_Fragment, { children: [endAdornment, eye] })) : (endAdornment ?? eye ?? undefined);
|
|
41
|
+
const field = {
|
|
42
|
+
...KEYBOARD[type],
|
|
43
|
+
...rest,
|
|
44
|
+
disabled,
|
|
45
|
+
invalid,
|
|
46
|
+
secureTextEntry: secure,
|
|
47
|
+
endAdornment: multiline ? undefined : end,
|
|
48
|
+
accessibilityLabel: accessibilityLabel ?? label,
|
|
49
|
+
};
|
|
50
|
+
if (theme.isAndroid) {
|
|
51
|
+
// The outlined field with its label floating on the line, or a filled box with the label inside
|
|
52
|
+
return (_jsx(FieldStack, { label: label, description: description, errorMessage: errorMessage, invalid: invalid, disabled: disabled, floating: true, style: style, testID: testID, children: ({ described, invalid: bad, shake }) => (_jsx(InputField, { ...field, ...described, variant: labelPlacement === "inside" ? "soft" : "outline", pill: labelPlacement === "border" && pill === true, label: label, invalid: bad, shift: shake, multiline: multiline, rows: multiline ? rows : undefined })) }));
|
|
53
|
+
}
|
|
54
|
+
// iOS: a cell named by its placeholder, its error inside it
|
|
55
|
+
const cell = (_jsx(Field, { row: true, hideLabel: true, label: label, description: inList ? description : undefined, errorMessage: errorMessage, disabled: disabled, testID: inList ? testID : undefined, children: multiline ? _jsx(Textarea, { ...field, placeholder: rest.placeholder ?? label, rows: 1, autoResize: true, maxRows: Math.max(rows, 10) }) : _jsx(Input, { ...field, placeholder: rest.placeholder ?? label }) }));
|
|
56
|
+
if (inList)
|
|
57
|
+
return cell;
|
|
58
|
+
return (_jsx(List, { footer: description, testID: testID, style: style, children: cell }));
|
|
59
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, createElement, memo, useContext } from "react";
|
|
3
|
-
import { StyleSheet } from "react-native";
|
|
3
|
+
import { Platform, StyleSheet } from "react-native";
|
|
4
4
|
import Svg, { Circle, Ellipse, G, Line, Path, Polygon, Polyline, Rect } from "react-native-svg";
|
|
5
5
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
6
|
const IconContext = createContext({});
|
|
@@ -38,6 +38,17 @@ function renderNodes(nodes, color, accent, keyPrefix = "", strokeScale = 1) {
|
|
|
38
38
|
return createElement(element, { key, ...resolved }, children ? renderNodes(children, color, accent, `${key}.`, strokeScale) : undefined);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
|
+
/** A named icon is an image for VoiceOver and TalkBack; an unnamed one is hidden from them. */
|
|
42
|
+
const nativeA11y = (label) => ({
|
|
43
|
+
accessible: !!label,
|
|
44
|
+
accessibilityLabel: label,
|
|
45
|
+
accessibilityRole: label ? "image" : undefined,
|
|
46
|
+
importantForAccessibility: label ? "yes" : "no-hide-descendants",
|
|
47
|
+
accessibilityElementsHidden: !label,
|
|
48
|
+
});
|
|
49
|
+
// On the web react-native-svg hands its props to the <svg> as they are, so the native names would reach the DOM (and
|
|
50
|
+
// React warns of them): there an icon takes the ARIA attributes instead
|
|
51
|
+
const webA11y = (label) => (label ? { role: "img", "aria-label": label } : { "aria-hidden": true, focusable: "false" });
|
|
41
52
|
/** Makes an icon component from its SVG data (scripts/build-icons.mjs writes one per icon of the shared sets). */
|
|
42
53
|
export function createIcon(name, viewBox, nodes) {
|
|
43
54
|
const Icon = memo(function Icon({ size, color, style, accessibilityLabel, testID }) {
|
|
@@ -48,7 +59,7 @@ export function createIcon(name, viewBox, nodes) {
|
|
|
48
59
|
return (_jsx(Svg, { width: px, height: px, viewBox: viewBox,
|
|
49
60
|
// Its own size and no margins, inline: a page's stylesheet (the docs' phone menu sizes `[role="menu"] svg`)
|
|
50
61
|
// does not reach a web icon then
|
|
51
|
-
style: StyleSheet.flatten([styles.reset, { width: px, height: px }, style]), testID: testID,
|
|
62
|
+
style: StyleSheet.flatten([styles.reset, { width: px, height: px }, style]), testID: testID, ...(Platform.OS === "web" ? webA11y(accessibilityLabel) : nativeA11y(accessibilityLabel)), children: renderNodes(nodes, fill, theme.colors.accent, "", defaults.weight === "semibold" ? 1.25 : 1) }));
|
|
52
63
|
});
|
|
53
64
|
Icon.displayName = name;
|
|
54
65
|
Icon.iconName = name;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import Svg, { Circle } from "react-native-svg";
|
|
5
|
+
import { curves } from "../../internal/motion";
|
|
6
|
+
import { cssEase, useTweenedNumber } from "../../internal/transition";
|
|
7
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
8
|
+
/**
|
|
9
|
+
* Deterministically returns a progress value between 0 and 100 that decays as it approaches 100, based on a maximum
|
|
10
|
+
* duration and the elapsed time, as @plexui/ui's simulated progress.
|
|
11
|
+
*/
|
|
12
|
+
export function getSimulatedProgress(maxTime, elapsedTime) {
|
|
13
|
+
const P_max = 99.9; // Maximum percentage to approach (less than 100%)
|
|
14
|
+
const P1 = 35; // Percentage at which the rate slows down
|
|
15
|
+
const initialRate = (3 * 100) / maxTime; // Initial rate (% per ms)
|
|
16
|
+
const t1 = P1 / initialRate; // Time when progress reaches P1
|
|
17
|
+
let percentage;
|
|
18
|
+
if (elapsedTime <= t1) {
|
|
19
|
+
// Phase 1: a linear increase at the start, to show consistency in progress
|
|
20
|
+
percentage = initialRate * elapsedTime;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// Phase 2: the progress slows down, approaching P_max
|
|
24
|
+
const k = 4;
|
|
25
|
+
const remainingTime = maxTime - t1;
|
|
26
|
+
const timeSinceT1 = elapsedTime - t1;
|
|
27
|
+
percentage = P1 + (P_max - P1) * (1 - Math.exp(-k * (timeSinceT1 / remainingTime)));
|
|
28
|
+
}
|
|
29
|
+
return Math.min(percentage, P_max);
|
|
30
|
+
}
|
|
31
|
+
/** A progress that rises every 100ms from the mount, slowing as it nears 100, and is 100 once `completed`. */
|
|
32
|
+
function useSimulatedProgress(maxDuration, completed) {
|
|
33
|
+
const [startAt] = useState(() => Date.now());
|
|
34
|
+
const [progress, setProgress] = useState(() => getSimulatedProgress(maxDuration, Date.now() - startAt));
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (completed)
|
|
37
|
+
return;
|
|
38
|
+
const id = setInterval(() => {
|
|
39
|
+
const elapsed = Date.now() - startAt;
|
|
40
|
+
setProgress(elapsed >= maxDuration ? 100 : getSimulatedProgress(maxDuration, elapsed));
|
|
41
|
+
}, 100);
|
|
42
|
+
return () => clearInterval(id);
|
|
43
|
+
}, [completed, maxDuration, startAt]);
|
|
44
|
+
return completed ? 100 : progress;
|
|
45
|
+
}
|
|
46
|
+
/** A color prop: a token (`var(--…)`) resolved for the scheme, or a color as it is. */
|
|
47
|
+
const resolve = (theme, value, fallback) => {
|
|
48
|
+
if (!value)
|
|
49
|
+
return fallback;
|
|
50
|
+
if (!value.includes("var(") && !value.includes("light-dark("))
|
|
51
|
+
return value;
|
|
52
|
+
const resolved = theme.value(value);
|
|
53
|
+
return typeof resolved === "string" ? resolved : fallback;
|
|
54
|
+
};
|
|
55
|
+
/** The drawing: a ring of radius 8 in a 20px box, its progress a dash of 50 that starts at 12 o'clock. */
|
|
56
|
+
const DASH = 50;
|
|
57
|
+
/**
|
|
58
|
+
* A progress ring, as @plexui/ui's CircularProgress: a light green track and a green arc for its share, 28px by
|
|
59
|
+
* default. Without `progress` it simulates one over `maxDuration`, and `done` fills it. Neither platform has a ring
|
|
60
|
+
* of its own for this, so both draw the Plex ring; a new value moves the arc in 300ms (ease) on iOS, as the web's
|
|
61
|
+
* transition, and in Android's determinate radial progress time (200ms, decelerating); at once with reduced motion.
|
|
62
|
+
*/
|
|
63
|
+
export function CircularProgress({ maxDuration = 15000, done = false, progress: progressProp, size = 28, strokeWidth, trackActiveColor, trackColor, "aria-label": ariaLabel, accessibilityLabel, testID, style, }) {
|
|
64
|
+
const theme = useTheme();
|
|
65
|
+
const simulated = useSimulatedProgress(maxDuration, progressProp !== undefined || done);
|
|
66
|
+
const progress = Math.max(0, Math.min(100, progressProp ?? simulated));
|
|
67
|
+
const shown = useTweenedNumber(progress, {
|
|
68
|
+
duration: theme.isAndroid ? 200 : 300,
|
|
69
|
+
easing: theme.isAndroid ? curves.decelerate : cssEase,
|
|
70
|
+
reducedMotion: theme.reducedMotion,
|
|
71
|
+
});
|
|
72
|
+
const stroke = strokeWidth ? Math.min(4, strokeWidth) : 2;
|
|
73
|
+
// The web's `light-dark(#deede9, var(--green-a50))`: a light green, the green at 15% at night
|
|
74
|
+
const track = resolve(theme, trackColor, theme.scheme === "dark" ? theme.color("--green-a50") : "#DEEDE9");
|
|
75
|
+
const active = resolve(theme, trackActiveColor, theme.color("--green-500"));
|
|
76
|
+
const name = accessibilityLabel ?? ariaLabel;
|
|
77
|
+
return (_jsx(View, { accessible: name != null, accessibilityRole: name != null ? "progressbar" : undefined, accessibilityLabel: name, accessibilityValue: name != null ? { min: 0, max: 100, now: Math.round(progress) } : undefined, importantForAccessibility: name != null ? undefined : "no-hide-descendants", accessibilityElementsHidden: name == null, testID: testID, style: [{ width: size, height: size }, style], children: _jsxs(Svg, { width: size, height: size, viewBox: "0 0 20 20", children: [_jsx(Circle, { cx: 10, cy: 10, r: 8, fill: "none", stroke: track, strokeWidth: stroke }), _jsx(Circle, { cx: 10, cy: 10, r: 8, fill: "none", stroke: active, strokeWidth: stroke, strokeLinecap: "round", strokeDasharray: [DASH, DASH], strokeDashoffset: DASH - DASH * (shown / 100),
|
|
78
|
+
// The dash starts at 12 o'clock, as the web's ring turned back a quarter
|
|
79
|
+
transform: "rotate(-90 10 10)" })] }) }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Animated, StyleSheet, View } from "react-native";
|
|
3
|
+
import { curves } from "../../internal/motion";
|
|
4
|
+
import { cssEase, useLoopClock } from "../../internal/transition";
|
|
5
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
|
+
import { textColor } from "../Text/Text";
|
|
7
|
+
const DOT = 8;
|
|
8
|
+
const GAP = 4;
|
|
9
|
+
/** iOS, as the web's dots: each pulses .15 → .4 → .15 in 1s (ease), 0.2s after the one before it. */
|
|
10
|
+
const IOS = { period: 1000, delays: [0, 200, 400] };
|
|
11
|
+
/** Android, the Plex Android look's typing dots: each grows over 320ms and shrinks over 320ms (decelerating) every 800ms, 150ms after the one before it; 1.33 to 2.33 of radius. */
|
|
12
|
+
const ANDROID = { period: 800, delays: [0, 150, 300], rest: 1.33 / 2.33 };
|
|
13
|
+
/**
|
|
14
|
+
* Three pulsing dots for typing or a short wait, as @plexui/ui's LoadingDots: 8px dots 4px apart, as tall as a line
|
|
15
|
+
* of text (24). iOS pulses their opacity as the web does; Android grows and shrinks them on the Plex Android look's
|
|
16
|
+
* typing timing, in the same tones. With reduced motion they stand still.
|
|
17
|
+
*/
|
|
18
|
+
export function LoadingDots({ color, "aria-label": ariaLabel, accessibilityLabel, testID, style }) {
|
|
19
|
+
const theme = useTheme();
|
|
20
|
+
const ink = textColor(theme, color ?? "primary");
|
|
21
|
+
const name = accessibilityLabel ?? ariaLabel;
|
|
22
|
+
const timing = theme.isAndroid ? ANDROID : IOS;
|
|
23
|
+
return (_jsx(View, { accessible: name != null, accessibilityRole: name != null ? "progressbar" : undefined, accessibilityLabel: name, accessibilityState: name != null ? { busy: true } : undefined, importantForAccessibility: name != null ? undefined : "no-hide-descendants", accessibilityElementsHidden: name == null, testID: testID, style: [styles.root, { height: theme.length("--font-text-md-line-height", 24) }, style], children: timing.delays.map((delay, index) => (_jsx(Dot, { delay: delay, color: ink, android: theme.isAndroid, still: theme.reducedMotion }, index))) }));
|
|
24
|
+
}
|
|
25
|
+
function Dot({ delay, color, android, still }) {
|
|
26
|
+
const { period } = android ? ANDROID : IOS;
|
|
27
|
+
const clock = useLoopClock(period, !still, true, delay);
|
|
28
|
+
if (android) {
|
|
29
|
+
// Grows for 320ms, shrinks for 320ms, rests until 800ms; its tone follows its size
|
|
30
|
+
const grow = clock.interpolate({ inputRange: [0, 320, 640, period], outputRange: [0, 1, 0, 0], easing: curves.decelerate });
|
|
31
|
+
return (_jsx(Animated.View, { style: [
|
|
32
|
+
styles.dot,
|
|
33
|
+
{
|
|
34
|
+
backgroundColor: color,
|
|
35
|
+
opacity: grow.interpolate({ inputRange: [0, 1], outputRange: [0.15, 0.4] }),
|
|
36
|
+
transform: [{ scale: grow.interpolate({ inputRange: [0, 1], outputRange: [ANDROID.rest, 1] }) }],
|
|
37
|
+
},
|
|
38
|
+
] }));
|
|
39
|
+
}
|
|
40
|
+
const opacity = clock.interpolate({ inputRange: [0, 0.2 * period, period], outputRange: [0.15, 0.4, 0.15], easing: cssEase });
|
|
41
|
+
return _jsx(Animated.View, { style: [styles.dot, { backgroundColor: color, opacity }] });
|
|
42
|
+
}
|
|
43
|
+
const styles = StyleSheet.create({
|
|
44
|
+
root: { flexDirection: "row", alignItems: "center", justifyContent: "flex-start", gap: GAP },
|
|
45
|
+
dot: { width: DOT, height: DOT, borderRadius: DOT / 2 },
|
|
46
|
+
});
|