@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
|
@@ -4,6 +4,7 @@ import { Animated, Easing, Pressable, StyleSheet, View } from "react-native";
|
|
|
4
4
|
import { spaceToggles, useDescription } from "../../internal/a11y";
|
|
5
5
|
import { ControlLabel } from "../../internal/ControlLabel";
|
|
6
6
|
import { RowEndContext, RowHoldContext, rowHold } from "../../internal/row";
|
|
7
|
+
import { androidGray } from "../../theme/material";
|
|
7
8
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
8
9
|
/**
|
|
9
10
|
* The on color of a switch, a checkbox and a radio: the Plex primary solid, or the accent. A control's own `color`
|
|
@@ -21,16 +22,16 @@ export function iosCheckmarkColor(theme) {
|
|
|
21
22
|
return theme.selectionColor === "accent" ? selectionColor(theme) : theme.color("--radio-group-checkmark-color", theme.colors.text);
|
|
22
23
|
}
|
|
23
24
|
/**
|
|
24
|
-
* The gray of an Android off switch and of the dots past the choice of a stepped slider: #
|
|
25
|
-
*
|
|
25
|
+
* The gray of an Android off switch and of the dots past the choice of a stepped slider: #A7ADB2 on white, --gray-500
|
|
26
|
+
* (#5D5D5D) at night, as the web's `--android-switch-off`.
|
|
26
27
|
*/
|
|
27
28
|
export function androidSwitchOff(theme) {
|
|
28
|
-
return
|
|
29
|
+
return androidGray(theme, "switchOff");
|
|
29
30
|
}
|
|
30
31
|
/** Android's default ease-in-out (AccelerateDecelerateInterpolator), which an ObjectAnimator runs by default. */
|
|
31
32
|
export const androidEaseInOut = Easing.inOut(Easing.sin);
|
|
32
|
-
/** A List row on Android ends
|
|
33
|
-
export const ANDROID_ROW_END =
|
|
33
|
+
/** A List row on Android ends 21dp in from the card's edge (`--list-row-inset`): a control at its end moves in from there. */
|
|
34
|
+
export const ANDROID_ROW_END = 21;
|
|
34
35
|
/** A switch row: the switch's 37dp view stands 22dp in from the row's end. */
|
|
35
36
|
const ANDROID_SWITCH_END = 22;
|
|
36
37
|
/** The switch's place along its track, 0 off to 1 on: Android's 200ms ease-in-out, iOS's 200ms ease-out. */
|
|
@@ -45,7 +46,7 @@ function useSwitchProgress(theme, checked) {
|
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* A switch: the iOS 26 switch of the phone layer (a 63x28 track, a 37x24 capsule thumb, `--switch-*`), or Android's
|
|
48
|
-
* (a 31x14dp track and a
|
|
49
|
+
* (a 31x14dp track and a 20.6dp thumb over it, a 2dp ring of the track's color around a knob of the card's color, the
|
|
49
50
|
* track's color changing as the thumb moves; a 50dp switch row, the label 11dp from the switch). Props follow
|
|
50
51
|
* @plexui/ui.
|
|
51
52
|
*/
|
|
@@ -127,10 +128,15 @@ function IOSTrack({ theme, checked, disabled, color, progress, held = false }) {
|
|
|
127
128
|
],
|
|
128
129
|
} }) }));
|
|
129
130
|
}
|
|
130
|
-
/**
|
|
131
|
+
/**
|
|
132
|
+
* Android's switch: its view 37x20dp, the track 31x14 in it, the 20.6dp thumb (a 2dp ring) reaching 3dp past the
|
|
133
|
+
* track's ends, its center 7.3 to 23.7 along the track (the reference: 31.2x14.1, a 20.6 thumb with a 1.9 ring).
|
|
134
|
+
*/
|
|
131
135
|
const ANDROID_VIEW = { width: 37, height: 20 };
|
|
132
136
|
const ANDROID_TRACK = { width: 31, height: 14 };
|
|
133
137
|
const ANDROID_START = (ANDROID_VIEW.width - ANDROID_TRACK.width) / 2;
|
|
138
|
+
const ANDROID_THUMB = 20.6;
|
|
139
|
+
const ANDROID_RING = 2;
|
|
134
140
|
function AndroidTrack({ theme, color, progress }) {
|
|
135
141
|
// The knob is the card's color (the white of a card); the track off the gray of an off switch, on the selection
|
|
136
142
|
// color (the switch's own, or the ThemeProvider's)
|
|
@@ -138,18 +144,26 @@ function AndroidTrack({ theme, color, progress }) {
|
|
|
138
144
|
const off = androidSwitchOff(theme);
|
|
139
145
|
const on = selectionColor(theme, color);
|
|
140
146
|
const track = progress.interpolate({ inputRange: [0, 1], outputRange: [off, on] });
|
|
141
|
-
// The thumb's
|
|
142
|
-
const start = progress.interpolate({ inputRange: [0, 1], outputRange: [ANDROID_START
|
|
147
|
+
// The thumb's start edge: 3dp before the track's start off, 3dp past its end on (mirrored in a right-to-left row)
|
|
148
|
+
const start = progress.interpolate({ inputRange: [0, 1], outputRange: [ANDROID_START - 3, ANDROID_START + ANDROID_TRACK.width + 3 - ANDROID_THUMB] });
|
|
143
149
|
return (_jsxs(View, { style: styles.androidView, children: [_jsx(Animated.View, { style: [styles.androidTrack, { backgroundColor: track }] }), _jsx(Animated.View, { style: [styles.androidThumb, { start, backgroundColor: track }], children: _jsx(View, { style: [styles.androidKnob, { backgroundColor: card }] }) })] }));
|
|
144
150
|
}
|
|
145
151
|
const styles = StyleSheet.create({
|
|
146
152
|
row: { flexDirection: "row", alignItems: "center", alignSelf: "stretch" },
|
|
147
153
|
grow: { flex: 1, minWidth: 0 },
|
|
148
154
|
dim: { opacity: 0.5 },
|
|
149
|
-
// The row ends
|
|
155
|
+
// The row ends 21dp in; Android's switch stands 22dp in
|
|
150
156
|
androidRowEnd: { marginEnd: ANDROID_SWITCH_END - ANDROID_ROW_END },
|
|
151
157
|
androidView: { width: ANDROID_VIEW.width, height: ANDROID_VIEW.height, justifyContent: "center" },
|
|
152
158
|
androidTrack: { position: "absolute", start: ANDROID_START, top: (ANDROID_VIEW.height - ANDROID_TRACK.height) / 2, width: ANDROID_TRACK.width, height: ANDROID_TRACK.height, borderRadius: ANDROID_TRACK.height / 2 },
|
|
153
|
-
androidThumb: {
|
|
154
|
-
|
|
159
|
+
androidThumb: {
|
|
160
|
+
position: "absolute",
|
|
161
|
+
top: (ANDROID_VIEW.height - ANDROID_THUMB) / 2,
|
|
162
|
+
width: ANDROID_THUMB,
|
|
163
|
+
height: ANDROID_THUMB,
|
|
164
|
+
borderRadius: ANDROID_THUMB / 2,
|
|
165
|
+
alignItems: "center",
|
|
166
|
+
justifyContent: "center",
|
|
167
|
+
},
|
|
168
|
+
androidKnob: { width: ANDROID_THUMB - 2 * ANDROID_RING, height: ANDROID_THUMB - 2 * ANDROID_RING, borderRadius: ANDROID_THUMB / 2 - ANDROID_RING },
|
|
155
169
|
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useContext, useRef, useState } from "react";
|
|
3
|
+
import { Pressable, StyleSheet, TextInput, View } from "react-native";
|
|
4
|
+
import X from "../../icons/plex/X";
|
|
5
|
+
import { RowEndContext } from "../../internal/row";
|
|
6
|
+
import { dangerText, withAlpha } from "../../theme/material";
|
|
7
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
8
|
+
import { Text } from "../Text/Text";
|
|
9
|
+
/** The tag sizes of the web's control table: the field's height, which a tag's line keeps. */
|
|
10
|
+
const HEIGHT = { sm: 28, md: 32, lg: 36, xl: 40, "2xl": 44, "3xl": 48 };
|
|
11
|
+
/**
|
|
12
|
+
* A field that turns what is typed into tags: Plex UI's TagInput. A delimiter (a comma, a space) or Return makes the
|
|
13
|
+
* text a tag; Backspace in an empty field takes the last one; each tag's × removes it. iOS: the web's phone tags, a
|
|
14
|
+
* 44pt line for each with a 32pt gray pill (`--color-background-secondary-soft-alpha`), its 17pt words 8 in and the ×
|
|
15
|
+
* in a 44pt target after them, 8 apart; an invalid tag in the danger color. Android: 32dp chips, 16 round, filled with
|
|
16
|
+
* the text color at 5%, their words 14sp, the × in a 32dp target, 8 apart. In a List row (`Field row`, vertical) it is
|
|
17
|
+
* the row's bare value; elsewhere it has the frame of an outlined field.
|
|
18
|
+
*/
|
|
19
|
+
export function TagInput({ defaultValue, value, size = "xl", variant = "outline", onChange, placeholder, validator, maxTags, autoFocus = false, rows = 1, delimiters = [",", " "], disabled = false, pill = false, accessibilityLabel, style, testID, }) {
|
|
20
|
+
const theme = useTheme();
|
|
21
|
+
const android = theme.isAndroid;
|
|
22
|
+
const rowEnd = useContext(RowEndContext);
|
|
23
|
+
const bare = rowEnd != null || variant === "ghost";
|
|
24
|
+
const [own, setOwn] = useState(defaultValue ?? []);
|
|
25
|
+
const tags = value ?? own;
|
|
26
|
+
const [text, setText] = useState("");
|
|
27
|
+
const input = useRef(null);
|
|
28
|
+
const set = (next) => {
|
|
29
|
+
if (value === undefined)
|
|
30
|
+
setOwn(next);
|
|
31
|
+
onChange?.(next);
|
|
32
|
+
};
|
|
33
|
+
// New tags from words: trimmed, no repeats, up to `maxTags`, judged as they are made
|
|
34
|
+
const add = (words) => {
|
|
35
|
+
const next = [...tags];
|
|
36
|
+
for (const word of words) {
|
|
37
|
+
const trimmed = word.trim();
|
|
38
|
+
if (!trimmed || next.some((tag) => tag.value === trimmed))
|
|
39
|
+
continue;
|
|
40
|
+
if (maxTags && next.length >= maxTags)
|
|
41
|
+
break;
|
|
42
|
+
next.push({ value: trimmed, valid: validator?.(trimmed) ?? true });
|
|
43
|
+
}
|
|
44
|
+
if (next.length !== tags.length)
|
|
45
|
+
set(next);
|
|
46
|
+
};
|
|
47
|
+
const remove = (index) => set(tags.filter((_, at) => at !== index));
|
|
48
|
+
const onChangeText = (next) => {
|
|
49
|
+
if (disabled)
|
|
50
|
+
return;
|
|
51
|
+
// A delimiter typed or pasted ends the words before it
|
|
52
|
+
const pattern = new RegExp(`[${delimiters.map((d) => d.replace(/[-\\\]^]/g, "\\$&")).join("")}\n]`);
|
|
53
|
+
if (delimiters.length > 0 && pattern.test(next)) {
|
|
54
|
+
const parts = next.split(pattern);
|
|
55
|
+
add(parts.slice(0, -1));
|
|
56
|
+
setText(parts[parts.length - 1] ?? "");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setText(next);
|
|
60
|
+
};
|
|
61
|
+
const onKeyPress = (event) => {
|
|
62
|
+
if (event.nativeEvent.key === "Backspace" && text === "" && tags.length > 0)
|
|
63
|
+
remove(tags.length - 1);
|
|
64
|
+
};
|
|
65
|
+
const full = maxTags != null && tags.length >= maxTags;
|
|
66
|
+
// iOS's tag: a 44pt line, the pill 6 inside it; Android's chip 32dp
|
|
67
|
+
const line = android ? 32 : bare ? theme.length("--control-size-lg", 44) : HEIGHT[size];
|
|
68
|
+
const inset = android ? 0 : bare ? 6 : 4;
|
|
69
|
+
const type = android
|
|
70
|
+
? { fontSize: 14, lineHeight: 18 }
|
|
71
|
+
: { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) };
|
|
72
|
+
const fieldType = android ? { fontSize: 17, lineHeight: 20 } : type;
|
|
73
|
+
const ink = theme.colors.text;
|
|
74
|
+
const fill = android ? withAlpha(theme.colors.text, 0.05) : theme.color("--color-background-secondary-soft-alpha");
|
|
75
|
+
const badFill = android ? withAlpha(dangerText(theme), 0.1) : theme.color("--color-background-danger-soft-alpha", fill);
|
|
76
|
+
const badInk = android ? dangerText(theme) : theme.color("--color-text-danger");
|
|
77
|
+
const gap = 8;
|
|
78
|
+
// Lines of tags 8 apart in a row, as the web's phone rows (2 in a frame)
|
|
79
|
+
const rowGap = android || bare ? gap : 2;
|
|
80
|
+
// The field is as tall as its text: after the last tag it stands in the middle of the tag's line, under the tags a
|
|
81
|
+
// line of its own (28, the web's phone row)
|
|
82
|
+
const fieldLine = android ? 20 : bare ? 28 : line;
|
|
83
|
+
// As wide as its text (or its hint) and a cursor gutter of 10, as the web's: it takes the rest of the last tag's
|
|
84
|
+
// line when that fits, else a line of its own under the tags
|
|
85
|
+
const [textWidth, setTextWidth] = useState(0);
|
|
86
|
+
const minHeight = rows > 1 ? rows * line + (rows - 1) * rowGap : undefined;
|
|
87
|
+
const frame = bare
|
|
88
|
+
? null
|
|
89
|
+
: {
|
|
90
|
+
borderWidth: StyleSheet.hairlineWidth * 2,
|
|
91
|
+
borderColor: theme.colors.border,
|
|
92
|
+
borderRadius: pill ? 9999 : android ? 8 : theme.length("--control-radius-lg", 10),
|
|
93
|
+
paddingHorizontal: android ? 12 : 8,
|
|
94
|
+
paddingVertical: 4,
|
|
95
|
+
};
|
|
96
|
+
return (_jsxs(Pressable, { testID: testID, accessible: false, disabled: disabled, onPress: () => input.current?.focus(), style: [
|
|
97
|
+
styles.box,
|
|
98
|
+
{ columnGap: gap, rowGap, minHeight, opacity: disabled ? 0.5 : 1 },
|
|
99
|
+
// Tags are solid, so they stand 2 further from a label than a line of text (the web's ghost TagInput)
|
|
100
|
+
bare && !android && tags.length > 0 ? { marginVertical: 2 } : null,
|
|
101
|
+
frame,
|
|
102
|
+
style,
|
|
103
|
+
], children: [full ? null : (
|
|
104
|
+
// A hidden copy of the text or the hint across the whole box, which sizes the field
|
|
105
|
+
_jsx(Text, { accessible: false, importantForAccessibility: "no-hide-descendants", numberOfLines: 1, onLayout: (event) => setTextWidth(Math.ceil(event.nativeEvent.layout.width)), style: [fieldType, theme.font("regular"), styles.measure], children: text || placeholder || "" })), tags.map((tag, index) => {
|
|
106
|
+
const color = tag.valid ? ink : badInk;
|
|
107
|
+
return (_jsxs(View, { style: [styles.tag, { height: line, paddingStart: android ? 12 : 8 }], children: [_jsx(View, { pointerEvents: "none", style: [StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: 9999, backgroundColor: tag.valid ? fill : badFill }] }), _jsx(Text, { numberOfLines: 1, color: color, style: [type, styles.shrink], children: tag.value }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: `Remove ${tag.value}`, disabled: disabled, hitSlop: android ? 8 : 0, onPress: () => remove(index), style: ({ pressed }) => [styles.remove, { width: android ? 32 : line, height: line, opacity: pressed ? 0.3 : 0.5, marginStart: android ? 0 : -4 }], children: _jsx(X, { size: android ? 18 : theme.length("--control-icon-size-sm", 16), color: color }) })] }, tag.value));
|
|
108
|
+
}), full ? null : (_jsx(View, { style: [styles.field, { height: fieldLine, minWidth: Math.max(20, textWidth) + 10 }], children: _jsx(TextInput, { ref: input, value: text, onChangeText: onChangeText, onKeyPress: onKeyPress, onSubmitEditing: () => {
|
|
109
|
+
add([text]);
|
|
110
|
+
setText("");
|
|
111
|
+
}, submitBehavior: "submit", autoFocus: autoFocus, editable: !disabled, placeholder: placeholder, placeholderTextColor: theme.isAndroid ? theme.colors.textTertiary : theme.colors.labelTertiary, accessibilityLabel: accessibilityLabel ?? placeholder, autoCapitalize: "none", autoCorrect: false, style: [styles.input, fieldType, theme.font("regular"), { color: ink, height: fieldLine }] }) }))] }));
|
|
112
|
+
}
|
|
113
|
+
const styles = StyleSheet.create({
|
|
114
|
+
box: { alignSelf: "stretch", flexDirection: "row", flexWrap: "wrap", alignItems: "center" },
|
|
115
|
+
tag: { flexDirection: "row", alignItems: "center", maxWidth: "100%", gap: 4 },
|
|
116
|
+
shrink: { flexShrink: 1 },
|
|
117
|
+
remove: { alignItems: "center", justifyContent: "center" },
|
|
118
|
+
field: { flexGrow: 1, flexBasis: 0, maxWidth: "100%", justifyContent: "center" },
|
|
119
|
+
measure: { position: "absolute", start: 0, top: 0, opacity: 0, alignSelf: "flex-start", pointerEvents: "none" },
|
|
120
|
+
input: { padding: 0, margin: 0, borderWidth: 0, outlineStyle: "none" },
|
|
121
|
+
});
|
|
@@ -53,6 +53,7 @@ export function textStyle(theme, { variant = "body", size, weight, mono }) {
|
|
|
53
53
|
base = style.weight;
|
|
54
54
|
}
|
|
55
55
|
return {
|
|
56
|
+
...WEB_SMOOTHING,
|
|
56
57
|
fontSize,
|
|
57
58
|
lineHeight,
|
|
58
59
|
...(mono ? { ...theme.monoFont, fontWeight: weight ? weightNumber(weight) : undefined } : theme.font(weight ?? base)),
|
|
@@ -69,10 +70,12 @@ function trackingFor(theme, style, mono) {
|
|
|
69
70
|
const flat = StyleSheet.flatten(style);
|
|
70
71
|
return typeof flat?.fontSize === "number" && flat.letterSpacing === undefined ? { letterSpacing: theme.tracking(flat.fontSize) } : null;
|
|
71
72
|
}
|
|
72
|
-
// On the web
|
|
73
|
-
//
|
|
73
|
+
// On the web, Chromium and Firefox on a Mac draw text with subpixel smoothing, 11–20% heavier than an iPhone draws the
|
|
74
|
+
// same words; grayscale smoothing draws them within 1–2% of it
|
|
75
|
+
const WEB_SMOOTHING = (Platform.OS === "web" ? { WebkitFontSmoothing: "antialiased", MozOsxFontSmoothing: "grayscale" } : {});
|
|
76
|
+
// A mono face's weights: the web's 501–549 of a system face draw as a synthesized bold in Chromium, so Medium is 500
|
|
74
77
|
const weightNumber = (weight) => (Platform.OS === "web"
|
|
75
|
-
? { regular: "400", medium: "
|
|
78
|
+
? { regular: "400", medium: "500", semibold: "590", bold: "700" }
|
|
76
79
|
: { regular: "400", medium: "500", semibold: "600", bold: "700" })[weight];
|
|
77
80
|
/**
|
|
78
81
|
* Text in the faces, sizes and colors of Plex UI. `variant` takes the platform's text styles (Body 17 on iOS, Body
|
|
@@ -96,7 +99,7 @@ export function Heading({ size = "md", weight = "semibold", color, align, mono,
|
|
|
96
99
|
const fontSize = theme.length(`--font-heading-${size}-size`, 20);
|
|
97
100
|
const lineHeight = theme.length(`--font-heading-${size}-line-height`, fontSize * 1.3);
|
|
98
101
|
return (_jsx(RNText, { accessibilityRole: "header", ...rest, style: [
|
|
99
|
-
{ fontSize, lineHeight },
|
|
102
|
+
{ ...WEB_SMOOTHING, fontSize, lineHeight },
|
|
100
103
|
mono ? { ...theme.monoFont, fontWeight: weightNumber(weight), letterSpacing: 0 } : { letterSpacing: theme.tracking(fontSize), ...theme.font(weight) },
|
|
101
104
|
tabularNums ? { fontVariant: ["tabular-nums"] } : null,
|
|
102
105
|
{ color: textColor(theme, color ?? "primary") },
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Linking, Platform, Text as RNText } from "react-native";
|
|
4
|
+
import { controlHighlight } from "../../theme/material";
|
|
5
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
6
|
+
const EXTERNAL = /^https?:\/\//;
|
|
7
|
+
/**
|
|
8
|
+
* A link in running text, as @plexui/ui's TextLink: put it inside a `Text`, whose face, size and color it takes
|
|
9
|
+
* (the web's `currentcolor`), underlined; `primary` colors it with `--link-primary-text-color` and drops the underline.
|
|
10
|
+
* iOS highlights a pressed link as its text views do (a gray behind the text); Android and the web draw the press of a
|
|
11
|
+
* row in the Plex Android look (the text's ink at 11%, white at 5% at night). With `href` it is a `link` and opens the
|
|
12
|
+
* URL (an `<a>` on the web, a new tab for an external one); with only `onPress` it is a `button`.
|
|
13
|
+
*/
|
|
14
|
+
export function TextLink({ children, href, primary = false, underline = !primary, forceExternal, onPress, weight, accessibilityLabel, testID, style }) {
|
|
15
|
+
const theme = useTheme();
|
|
16
|
+
const [pressed, setPressed] = useState(false);
|
|
17
|
+
const external = forceExternal ?? EXTERNAL.test(href ?? "");
|
|
18
|
+
const web = Platform.OS === "web";
|
|
19
|
+
const press = (event) => {
|
|
20
|
+
onPress?.(event);
|
|
21
|
+
if (!href || web || prevented(event))
|
|
22
|
+
return;
|
|
23
|
+
void Linking.openURL(href).catch(() => { });
|
|
24
|
+
};
|
|
25
|
+
const actionable = href != null || onPress != null;
|
|
26
|
+
// react-native-web draws a Text with `href` as an anchor: the browser opens it, a new tab for an external one
|
|
27
|
+
const anchor = web && href ? { href, hrefAttrs: external ? { target: "_blank", rel: "noopener noreferrer" } : undefined } : null;
|
|
28
|
+
// iOS's own Text highlights a press (as UITextView's links); elsewhere the press layer of a row
|
|
29
|
+
const highlight = theme.isIOS && !web ? null : pressed ? { backgroundColor: controlHighlight(theme.scheme) } : null;
|
|
30
|
+
return (_jsx(RNText, { ...anchor, accessibilityRole: href ? "link" : onPress ? "button" : undefined, accessibilityLabel: accessibilityLabel, testID: testID, onPress: actionable ? press : undefined, onPressIn: actionable ? () => setPressed(true) : undefined, onPressOut: actionable ? () => setPressed(false) : undefined, style: [
|
|
31
|
+
primary ? { color: theme.color("--link-primary-text-color", theme.colors.textAccent) } : null,
|
|
32
|
+
underline ? { textDecorationLine: "underline" } : null,
|
|
33
|
+
weight ? theme.font(weight) : null,
|
|
34
|
+
highlight,
|
|
35
|
+
style,
|
|
36
|
+
], children: children }));
|
|
37
|
+
}
|
|
38
|
+
/** A press the handler kept from going on (`event.preventDefault()`). */
|
|
39
|
+
function prevented(event) {
|
|
40
|
+
const synthetic = event;
|
|
41
|
+
return synthetic.defaultPrevented === true || synthetic.isDefaultPrevented?.() === true;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { InputField } from "../Input/Input";
|
|
3
|
+
/**
|
|
4
|
+
* A text field of several lines: Plex UI's Textarea. It is the Input's field with `multiline` (the same variants, sizes
|
|
5
|
+
* and states, the same frames on both platforms), `rows` lines tall, its text from the top. In a List row (a `Field
|
|
6
|
+
* row`) it is the row's bare value: under its label, or alone, from the row's text start, as the web's on a phone.
|
|
7
|
+
* iOS: the field's 17/22 lines, 11 above and below them in a frame; Android: the outlined field's 17/20 lines, a
|
|
8
|
+
* label floating in its frame inside a Field.
|
|
9
|
+
*/
|
|
10
|
+
export function Textarea({ rows = 3, autoResize = false, maxRows, autoSelect = false, ...rest }) {
|
|
11
|
+
return _jsx(InputField, { ...rest, multiline: true, rows: rows, autoResize: autoResize, maxRows: maxRows, selectTextOnFocus: autoSelect });
|
|
12
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { cloneElement, isValidElement, useState } from "react";
|
|
3
|
+
import { Pressable, StyleSheet, View, useWindowDimensions } from "react-native";
|
|
4
|
+
import Svg, { Path } from "react-native-svg";
|
|
5
|
+
import X from "../../icons/plex/X";
|
|
6
|
+
import { flattenChildren, isRenderable, textOf } from "../../internal/children";
|
|
7
|
+
import { FloatingPanel } from "../../internal/FloatingPanel";
|
|
8
|
+
import { anchorProps } from "../../internal/floating";
|
|
9
|
+
import { Glass } from "../../internal/Glass";
|
|
10
|
+
import { accentText, barSurface, controlHighlight, dangerText, elevationShadow } from "../../theme/material";
|
|
11
|
+
import { useTheme } from "../../theme/ThemeProvider";
|
|
12
|
+
import { Button } from "../Button/Button";
|
|
13
|
+
import { IconDefaultsProvider } from "../Icon/createIcon";
|
|
14
|
+
import { useMenuAnchor } from "../Menu/Menu";
|
|
15
|
+
import { Text, TextColorProvider } from "../Text/Text";
|
|
16
|
+
/** Material's text button sets its label 12dp in: the row moves out by as much, so the labels line up with the text. */
|
|
17
|
+
const ANDROID_TEXT_BUTTON_INSET = 12;
|
|
18
|
+
/** The kit's arrow (47 by 13), pointing down: the same path as the web's clip-path. */
|
|
19
|
+
const ARROW_PATH = "M0 0C1.71 0 3.42 -.01 5.14 .01C6.78 .03 8.61 .06 10.21 .66C11.93 1.31 13.07 2.44 14.22 3.78C15.04 4.74 16.67 6.8 17.46 7.79C18.1 8.6 19.37 10.21 20.06 10.98C20.93 11.96 22.01 13 23.5 13C24.99 13 26.07 11.96 26.94 10.98C27.63 10.21 28.9 8.6 29.54 7.79C30.33 6.8 31.96 4.74 32.78 3.78C33.93 2.44 35.07 1.31 36.79 .66C38.39 .06 40.22 .03 41.86 .01C43.58 -.01 45.29 0 47 0Z";
|
|
20
|
+
/** Material 3's rich tooltip caret, 16 by 8, pointing down. */
|
|
21
|
+
const CARET_PATH = "M0 0L8 8L16 0Z";
|
|
22
|
+
/**
|
|
23
|
+
* The numbers of each platform. iOS: Tip.module.css at 767px and below (TipKit: 26 corners, 14 top and the layout
|
|
24
|
+
* margin across, a 36 symbol 12 from the text, 17/22 semibold over 15/20 secondary, a bare 22 Close in the tertiary
|
|
25
|
+
* label in a 44 target 1 from the top and 6 from the end, rows of 17 regular 46 tall under a separator, capsules of
|
|
26
|
+
* 48 10 apart). Android: a card of the Plex Android look with Material 3's rich tooltip inside (16dp corners, 16dp
|
|
27
|
+
* padding, a 24dp symbol, Title M over Body M, Close 24dp in a 48dp target, text buttons, 40dp capsules).
|
|
28
|
+
*/
|
|
29
|
+
function metricsOf(theme) {
|
|
30
|
+
if (theme.isAndroid) {
|
|
31
|
+
return { radius: 16, top: 16, inline: 16, bottomRows: 8, bottomNone: 16, bottomButtons: 16, gap: 12, gapButtons: 16, iconFrame: 24, icon: 24, iconGap: 16, closeTarget: 48, closeIcon: 24, closeTop: 4, closeEnd: 4, messageEnd: 28, arrow: { width: 16, height: 8, path: CARET_PATH } };
|
|
32
|
+
}
|
|
33
|
+
const inline = theme.length("--mobile-layout-margin", 16);
|
|
34
|
+
const closeSize = 22;
|
|
35
|
+
const closeOffset = 17;
|
|
36
|
+
return {
|
|
37
|
+
radius: 26,
|
|
38
|
+
top: 14,
|
|
39
|
+
inline,
|
|
40
|
+
bottomRows: 0,
|
|
41
|
+
bottomNone: 14,
|
|
42
|
+
bottomButtons: 16,
|
|
43
|
+
gap: 11,
|
|
44
|
+
gapButtons: 16,
|
|
45
|
+
iconFrame: 36,
|
|
46
|
+
icon: 36,
|
|
47
|
+
iconGap: 12,
|
|
48
|
+
closeTarget: 44,
|
|
49
|
+
closeIcon: 22,
|
|
50
|
+
// The 44 target centers the 22 glyph 12 from the top and 17 from the end
|
|
51
|
+
closeTop: 12 - (44 - closeSize) / 2,
|
|
52
|
+
closeEnd: closeOffset - (44 - closeSize) / 2,
|
|
53
|
+
messageEnd: closeSize + closeOffset - inline + 1,
|
|
54
|
+
arrow: { width: theme.length("--tip-arrow-width", 47), height: theme.length("--tip-arrow-height", 13), path: ARROW_PATH },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function TipBody({ title, description, icon, actions, mobileActions = "rows", onClose, closeLabel, background, role, testID, style, children }) {
|
|
58
|
+
const theme = useTheme();
|
|
59
|
+
const android = theme.isAndroid;
|
|
60
|
+
const m = metricsOf(theme);
|
|
61
|
+
const items = flattenChildren(actions).filter(isRenderable);
|
|
62
|
+
const hasActions = items.length > 0;
|
|
63
|
+
const buttons = mobileActions === "buttons";
|
|
64
|
+
const hasIcon = isRenderable(icon);
|
|
65
|
+
const closable = onClose != null;
|
|
66
|
+
const descriptionColor = android ? theme.colors.textSecondary : theme.color("--tip-description-color", theme.colors.textSecondary);
|
|
67
|
+
const paddingBottom = !hasActions ? m.bottomNone : buttons ? m.bottomButtons : m.bottomRows;
|
|
68
|
+
const textStart = hasIcon ? m.iconFrame + m.iconGap : 0;
|
|
69
|
+
return (_jsxs(View, { role: role, "aria-label": role ? textOf(title) || undefined : undefined, testID: testID, style: [
|
|
70
|
+
styles.tip,
|
|
71
|
+
{
|
|
72
|
+
borderRadius: m.radius,
|
|
73
|
+
paddingTop: m.top,
|
|
74
|
+
paddingHorizontal: m.inline,
|
|
75
|
+
paddingBottom,
|
|
76
|
+
columnGap: m.iconGap,
|
|
77
|
+
rowGap: hasActions && buttons ? m.gapButtons : m.gap,
|
|
78
|
+
backgroundColor: background ?? theme.colors.groupedSurface,
|
|
79
|
+
},
|
|
80
|
+
style,
|
|
81
|
+
], children: [children, hasIcon ? (_jsx(View, { style: [styles.icon, { width: m.iconFrame, height: m.iconFrame }], children: _jsx(IconDefaultsProvider, { size: m.icon, color: descriptionColor, children: icon }) })) : null, _jsxs(View, { style: [styles.message, closable ? { paddingEnd: m.messageEnd } : null], children: [_jsx(Text, { variant: "headline", children: title }), isRenderable(description) ? (_jsx(TextColorProvider, { value: descriptionColor, children: _jsx(Text, { variant: "subheadline", color: descriptionColor, style: android ? styles.androidDescription : null, children: description }) })) : null] }), hasActions ? (_jsx(View, { style: [
|
|
82
|
+
styles.actions,
|
|
83
|
+
buttons ? styles.buttons : android ? [styles.androidActions, { marginStart: textStart - ANDROID_TEXT_BUTTON_INSET }] : { paddingStart: textStart },
|
|
84
|
+
], children: items.map((item, index) => (buttons ? _jsx(ActionButton, { item: item }, index) : _jsx(ActionRow, { item: item }, index))) })) : null, closable ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: closeLabel, onPress: onClose, style: [styles.close, { width: m.closeTarget, height: m.closeTarget, top: m.closeTop, end: m.closeEnd, borderRadius: m.closeTarget / 2 }], children: ({ pressed }) => (_jsx(View, { style: [styles.closeGlyph, android && pressed ? { backgroundColor: controlHighlight(theme.scheme), borderRadius: m.closeTarget / 2 } : null], children: _jsx(X, { size: m.closeIcon, color: android ? theme.colors.labelSecondary : theme.colors.labelTertiary, style: !android && pressed ? styles.pressed : undefined }) })) })) : null] }));
|
|
85
|
+
}
|
|
86
|
+
/** An action as a capsule across the tip, its Button's color and variant kept: 48 tall on iOS, 40dp on Android. */
|
|
87
|
+
function ActionButton({ item }) {
|
|
88
|
+
const theme = useTheme();
|
|
89
|
+
if (!isValidElement(item) || item.type !== Button)
|
|
90
|
+
return _jsx(_Fragment, { children: item });
|
|
91
|
+
const button = item;
|
|
92
|
+
return cloneElement(button, {
|
|
93
|
+
size: theme.isAndroid ? "lg" : "xl",
|
|
94
|
+
pill: true,
|
|
95
|
+
block: true,
|
|
96
|
+
style: [button.props.style, theme.isAndroid ? null : { minHeight: 48 }],
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 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
|
|
101
|
+
* text button in the accent, as Material 3's rich tooltip sets its actions. Other elements stand as given.
|
|
102
|
+
*/
|
|
103
|
+
function ActionRow({ item }) {
|
|
104
|
+
const theme = useTheme();
|
|
105
|
+
if (!isValidElement(item) || item.type !== Button)
|
|
106
|
+
return _jsx(_Fragment, { children: item });
|
|
107
|
+
const { color = "primary", children, onPress, disabled, accessibilityLabel, testID } = item.props;
|
|
108
|
+
if (theme.isAndroid) {
|
|
109
|
+
// Material's text button: 40dp, 12dp in, the label in the accent (red for a danger action), a press layer behind
|
|
110
|
+
const label = disabled ? theme.colors.labelTertiary : color === "danger" ? dangerText(theme) : accentText(theme);
|
|
111
|
+
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled: !!disabled }, disabled: disabled ?? undefined, onPress: onPress, testID: testID, style: ({ pressed }) => [styles.androidRow, pressed ? { backgroundColor: controlHighlight(theme.scheme) } : null], children: _jsx(Text, { variant: "subheadline", weight: "medium", color: label, children: children }) }));
|
|
112
|
+
}
|
|
113
|
+
const ink = theme.color(`--color-text-${color}-ghost`, theme.colors.text);
|
|
114
|
+
return (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityState: { disabled: !!disabled }, disabled: disabled ?? undefined, onPress: onPress, testID: testID, style: ({ pressed }) => [styles.row, { borderTopColor: theme.color("--color-border", theme.colors.border) }, pressed ? { backgroundColor: theme.color("--alpha-05") } : null], children: _jsx(Text, { variant: "body", color: disabled ? theme.colors.labelTertiary : ink, children: children }) }));
|
|
115
|
+
}
|
|
116
|
+
/** The arrow of a tip at its edge, in the tip's fill: the kit's 47 by 13 on iOS, Material's 16 by 8 caret on Android. */
|
|
117
|
+
function TipArrow({ edge, color, offset, length }) {
|
|
118
|
+
const theme = useTheme();
|
|
119
|
+
const { arrow } = metricsOf(theme);
|
|
120
|
+
const rotate = edge === "bottom" ? "0deg" : edge === "top" ? "180deg" : edge === "left" ? "90deg" : "-90deg";
|
|
121
|
+
// A sideways arrow turns about its own center: it is moved by half its length less half its height
|
|
122
|
+
const shift = (arrow.width - arrow.height) / 2;
|
|
123
|
+
const along = offset != null ? offset - arrow.width / 2 : length != null ? (length - arrow.width) / 2 : undefined;
|
|
124
|
+
const position = edge === "bottom"
|
|
125
|
+
? { top: "100%", left: along ?? "50%", marginLeft: along == null ? -arrow.width / 2 : 0 }
|
|
126
|
+
: edge === "top"
|
|
127
|
+
? { bottom: "100%", left: along ?? "50%", marginLeft: along == null ? -arrow.width / 2 : 0 }
|
|
128
|
+
: edge === "left"
|
|
129
|
+
? { top: along != null ? along + shift : "50%", marginTop: along == null ? -arrow.height / 2 : 0, right: "100%", marginRight: -shift }
|
|
130
|
+
: { top: along != null ? along + shift : "50%", marginTop: along == null ? -arrow.height / 2 : 0, left: "100%", marginLeft: -shift };
|
|
131
|
+
return (_jsx(View, { pointerEvents: "none", style: [styles.arrow, position, { width: arrow.width, height: arrow.height, transform: [{ rotate }] }], children: _jsx(Svg, { width: arrow.width, height: arrow.height, viewBox: `0 0 ${arrow.width} ${arrow.height}`, children: _jsx(Path, { d: arrow.path, fill: color }) }) }));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* A tip inside the page, as @plexui/ui's Tip on a phone (TipKit's inline tip): a title, a description, an optional
|
|
135
|
+
* symbol, actions and Close, on the card of a grouped list; `arrowEdge` adds TipKit's annotation arrow. On Android the
|
|
136
|
+
* same card in the Plex Android look, laid out as Material 3's rich tooltip.
|
|
137
|
+
*/
|
|
138
|
+
export function Tip({ onClose, closeLabel = "Close tip", arrowEdge, testID, style, ...content }) {
|
|
139
|
+
const theme = useTheme();
|
|
140
|
+
const { arrow } = metricsOf(theme);
|
|
141
|
+
const fill = theme.colors.groupedSurface;
|
|
142
|
+
const room = arrowEdge
|
|
143
|
+
? { [arrowEdge === "top" ? "marginTop" : arrowEdge === "bottom" ? "marginBottom" : arrowEdge === "left" ? "marginLeft" : "marginRight"]: arrow.height }
|
|
144
|
+
: null;
|
|
145
|
+
return (_jsx(TipBody, { ...content, onClose: onClose, closeLabel: closeLabel, role: "note", testID: testID, background: fill, style: [room, style], children: arrowEdge ? _jsx(TipArrow, { edge: arrowEdge, color: fill }) : null }));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* A tip anchored to a control, as @plexui/ui's Tip.Popover on a phone (TipKit's popover tip): the tip's content on the
|
|
149
|
+
* iOS 27 alert's glass with the kit's popover shadow, 300 wide, its arrow pointing at the control; on Android the
|
|
150
|
+
* popup surface of the Plex Android look with Material's caret. It does not take the focus.
|
|
151
|
+
*/
|
|
152
|
+
function TipPopover({ open: controlledOpen, defaultOpen = false, onOpenChange, children, side = "bottom", align = "center", sideOffset = 4, closeButton = true, closeLabel = "Close tip", testID, style, ...content }) {
|
|
153
|
+
const theme = useTheme();
|
|
154
|
+
const window = useWindowDimensions();
|
|
155
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);
|
|
156
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
157
|
+
const setOpen = (next) => {
|
|
158
|
+
if (controlledOpen === undefined)
|
|
159
|
+
setUncontrolledOpen(next);
|
|
160
|
+
onOpenChange?.(next);
|
|
161
|
+
};
|
|
162
|
+
const { anchor, place, setTrigger } = useMenuAnchor(open);
|
|
163
|
+
const android = theme.isAndroid;
|
|
164
|
+
const { arrow } = metricsOf(theme);
|
|
165
|
+
const padding = 16;
|
|
166
|
+
const width = Math.min(theme.length("--tip-popover-width", 300), window.width - padding * 2);
|
|
167
|
+
const fill = android ? barSurface(theme.material, theme.scheme) : theme.color("--dialog-alert-background", theme.color("--tip-popover-background"));
|
|
168
|
+
const body = (_jsx(TipBody, { ...content, onClose: closeButton ? () => setOpen(false) : undefined, closeLabel: closeLabel, background: "transparent" }));
|
|
169
|
+
return (_jsxs(_Fragment, { children: [isValidElement(children)
|
|
170
|
+
? cloneElement(children, anchorProps(children.props, setTrigger, open ? () => place() : undefined))
|
|
171
|
+
: children, _jsx(FloatingPanel, { open: open, onDismiss: () => setOpen(false), anchor: anchor, side: side, align: align,
|
|
172
|
+
// Radix adds the arrow's height to the offset: the distance is to the arrow's point
|
|
173
|
+
sideOffset: sideOffset + arrow.height, collisionPadding: padding, arrow: { width: arrow.width, padding: android ? 12 : 26 }, glass: !android, autoFocus: false, role: "dialog", "aria-label": textOf(content.title) || undefined, testID: testID, style: [{ width }, style], children: (placement) => (_jsxs(_Fragment, { children: [android ? (_jsx(View, { style: [styles.popupSurface, { backgroundColor: fill, boxShadow: elevationShadow.level2 }], children: body })) : (_jsx(Glass, { radius: metricsOf(theme).radius, fillToken: "--dialog-alert-background", filterToken: "--dialog-alert-backdrop-filter", shadowToken: "--tip-popover-shadow", children: body })), _jsx(TipArrow, { edge: opposite[placement.side], color: fill, offset: placement.size ? placement.arrow : undefined })] })) })] }));
|
|
174
|
+
}
|
|
175
|
+
/** The tip's edge that faces the control: the arrow points back at it. */
|
|
176
|
+
const opposite = { bottom: "top", top: "bottom", left: "right", right: "left" };
|
|
177
|
+
const styles = StyleSheet.create({
|
|
178
|
+
tip: { position: "relative", flexDirection: "row", flexWrap: "wrap", alignItems: "flex-start", alignSelf: "stretch", borderCurve: "continuous" },
|
|
179
|
+
icon: { flexShrink: 0, alignItems: "center", justifyContent: "center" },
|
|
180
|
+
message: { flex: 1, minWidth: 0 },
|
|
181
|
+
androidDescription: { marginTop: 2 },
|
|
182
|
+
actions: { flexBasis: "100%", flexGrow: 1, flexDirection: "column" },
|
|
183
|
+
buttons: { gap: 10 },
|
|
184
|
+
androidActions: { flexDirection: "row", flexWrap: "wrap", gap: 8 },
|
|
185
|
+
row: { minHeight: 46, paddingVertical: 12, borderTopWidth: 1, justifyContent: "center" },
|
|
186
|
+
androidRow: { alignSelf: "flex-start", minHeight: 40, paddingHorizontal: 12, borderRadius: 20, justifyContent: "center" },
|
|
187
|
+
close: { position: "absolute", alignItems: "center", justifyContent: "center" },
|
|
188
|
+
closeGlyph: { width: "100%", height: "100%", alignItems: "center", justifyContent: "center" },
|
|
189
|
+
pressed: { opacity: 0.5 },
|
|
190
|
+
arrow: { position: "absolute" },
|
|
191
|
+
popupSurface: { borderRadius: 12, borderCurve: "continuous" },
|
|
192
|
+
});
|
|
193
|
+
Tip.Popover = TipPopover;
|
|
@@ -7,6 +7,7 @@ import { physicalPadding, useRTL } from "../../internal/direction";
|
|
|
7
7
|
import { Glass } from "../../internal/Glass";
|
|
8
8
|
import { curves } from "../../internal/motion";
|
|
9
9
|
import { divider, withAlpha } from "../../theme/material";
|
|
10
|
+
import { textOf } from "../../internal/children";
|
|
10
11
|
import { useTheme } from "../../theme/ThemeProvider";
|
|
11
12
|
import { flattenChildren } from "../../internal/children";
|
|
12
13
|
import { BarFieldContext, BarItemContext } from "../Button/Button";
|
|
@@ -127,7 +128,7 @@ function barItem(theme, placement, plain) {
|
|
|
127
128
|
return { height: 48, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 12, plain: true };
|
|
128
129
|
// Android: 46dp circles with 24dp glyphs; a label (Save) Medium 15 in a capsule 16 in from its ends
|
|
129
130
|
if (theme.isAndroid)
|
|
130
|
-
return { height: 46, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 16 };
|
|
131
|
+
return { height: 46, fontSize: 15, lineHeight: 20, weight: "medium", prominentWeight: "medium", iconSize: 24, gutter: 16, bottom: placement === "bottom" };
|
|
131
132
|
const bottom = placement === "bottom";
|
|
132
133
|
const weight = (name, fallback) => {
|
|
133
134
|
const value = theme.length(name, fallback);
|
|
@@ -188,7 +189,9 @@ function BarTitle({ title, large, start, plain = false, afterLeading = false, })
|
|
|
188
189
|
styles.heading,
|
|
189
190
|
{ alignItems: start || large ? "flex-start" : "center", minHeight: large ? 0 : plain ? 48 : android ? 46 : theme.length("--toolbar-top-item-size", 44) },
|
|
190
191
|
android && start && !large ? { marginStart: plain ? (afterLeading ? 20 : 14) : 18 } : null,
|
|
191
|
-
], children: [
|
|
192
|
+
], children: [title.image != null ? (
|
|
193
|
+
// A logo is the header: one element named for a screen reader, the picture itself hidden from it
|
|
194
|
+
_jsx(View, { accessible: true, accessibilityRole: "header", accessibilityLabel: title.accessibilityLabel ?? (textOf(title.children) || undefined), style: styles.titleImage, children: _jsx(View, { importantForAccessibility: "no-hide-descendants", accessibilityElementsHidden: true, "aria-hidden": true, children: title.image }) })) : (_jsx(Text, { accessibilityRole: "header", accessibilityLabel: title.accessibilityLabel, numberOfLines: title.numberOfLines ?? 1, weight: android ? "medium" : large ? "bold" : "semibold", align: start || large ? "auto" : "center", style: font, children: title.children })), subtitle ? (_jsx(Text, { numberOfLines: 1, weight: android || large ? "regular" : "medium", color: android && !plain ? theme.colors.textSecondary : theme.colors.labelSecondary, style: sub, children: title.subtitle })) : null] }));
|
|
192
195
|
}
|
|
193
196
|
/**
|
|
194
197
|
* A bar of controls at the top or the bottom of a screen. On iOS 26 its items stand in glass on the content (44pt at
|
|
@@ -385,6 +388,7 @@ export const Toolbar = Object.assign(ToolbarRoot, {
|
|
|
385
388
|
Row: ToolbarRow,
|
|
386
389
|
});
|
|
387
390
|
const styles = StyleSheet.create({
|
|
391
|
+
titleImage: { flexDirection: "row", alignItems: "center" },
|
|
388
392
|
slot: { flexDirection: "row", alignItems: "center" },
|
|
389
393
|
trailing: { justifyContent: "flex-end" },
|
|
390
394
|
content: { justifyContent: "center" },
|