@plexui/react-native 0.2.25 → 0.2.27
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 +3 -0
- package/dist/es/components/BottomActions/BottomActions.js +2 -2
- package/dist/es/components/BottomSheet/BottomSheet.js +7 -3
- package/dist/es/components/Button/Button.js +10 -6
- package/dist/es/components/Card/Card.js +9 -2
- package/dist/es/components/Checkbox/Checkbox.js +2 -2
- package/dist/es/components/Chip/Chip.js +19 -11
- package/dist/es/components/Dialog/Dialog.js +18 -6
- package/dist/es/components/EmptyMessage/EmptyMessage.js +2 -2
- package/dist/es/components/Indicator/CircularProgress.js +11 -5
- package/dist/es/components/Input/Input.js +17 -2
- package/dist/es/components/List/List.js +77 -9
- package/dist/es/components/Menu/Menu.js +15 -5
- package/dist/es/components/PageControl/PageControl.js +7 -3
- package/dist/es/components/RadioGroup/RadioGroup.js +2 -2
- package/dist/es/components/RollingNumber/RollingNumber.js +7 -7
- package/dist/es/components/ScrollEdge/ScrollEdge.js +12 -6
- package/dist/es/components/Select/Select.js +4 -2
- package/dist/es/components/Switch/Switch.js +2 -2
- package/dist/es/components/TabBar/TabBar.js +15 -0
- package/dist/es/components/TextLink/TextLink.js +23 -3
- package/dist/es/index.js +2 -2
- package/dist/es/internal/a11y.js +12 -0
- package/dist/es/internal/row.js +13 -0
- package/dist/es/theme/ThemeProvider.js +4 -2
- package/dist/es/theme/material.js +2 -0
- package/dist/types/components/BottomActions/BottomActions.d.ts +6 -1
- package/dist/types/components/Button/Button.d.ts +5 -0
- package/dist/types/components/Card/Card.d.ts +5 -1
- package/dist/types/components/Chip/Chip.d.ts +9 -3
- package/dist/types/components/Dialog/Dialog.d.ts +7 -1
- package/dist/types/components/EmptyMessage/EmptyMessage.d.ts +4 -2
- package/dist/types/components/Indicator/CircularProgress.d.ts +10 -2
- package/dist/types/components/Input/Input.d.ts +8 -1
- package/dist/types/components/List/List.d.ts +36 -1
- package/dist/types/components/Menu/Menu.d.ts +10 -4
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +3 -1
- package/dist/types/components/ScrollEdge/ScrollEdge.d.ts +7 -1
- package/dist/types/components/TabBar/TabBar.d.ts +13 -0
- package/dist/types/components/TextLink/TextLink.d.ts +7 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/internal/a11y.d.ts +22 -0
- package/dist/types/internal/row.d.ts +21 -2
- package/dist/types/theme/ThemeProvider.d.ts +3 -2
- package/dist/types/theme/material.d.ts +2 -0
- package/package.json +1 -1
- package/src/components/BottomActions/BottomActions.tsx +7 -2
- package/src/components/BottomSheet/BottomSheet.tsx +9 -4
- package/src/components/Button/Button.tsx +19 -4
- package/src/components/Card/Card.tsx +8 -3
- package/src/components/Checkbox/Checkbox.tsx +2 -1
- package/src/components/Chip/Chip.tsx +28 -9
- package/src/components/Dialog/Dialog.tsx +30 -6
- package/src/components/EmptyMessage/EmptyMessage.tsx +12 -3
- package/src/components/Indicator/CircularProgress.tsx +27 -11
- package/src/components/Input/Input.tsx +43 -3
- package/src/components/List/List.tsx +125 -7
- package/src/components/Menu/Menu.tsx +27 -11
- package/src/components/PageControl/PageControl.tsx +7 -3
- package/src/components/RadioGroup/RadioGroup.tsx +2 -1
- package/src/components/RollingNumber/RollingNumber.tsx +10 -8
- package/src/components/ScrollEdge/ScrollEdge.tsx +19 -6
- package/src/components/Select/Select.tsx +4 -1
- package/src/components/Switch/Switch.tsx +2 -1
- package/src/components/TabBar/TabBar.tsx +15 -0
- package/src/components/TextLink/TextLink.tsx +52 -3
- package/src/index.ts +2 -2
- package/src/internal/a11y.ts +13 -0
- package/src/internal/row.ts +14 -2
- package/src/theme/ThemeProvider.tsx +7 -4
- package/src/theme/material.ts +2 -0
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { useState, type ReactNode } from "react"
|
|
2
|
-
import { Linking, Platform, Text as RNText, type GestureResponderEvent, type StyleProp, type TextStyle } from "react-native"
|
|
2
|
+
import { Linking, Platform, Pressable, Text as RNText, type GestureResponderEvent, type StyleProp, type TextStyle } from "react-native"
|
|
3
3
|
import { controlHighlight } from "../../theme/material"
|
|
4
4
|
import { useTheme } from "../../theme/ThemeProvider"
|
|
5
5
|
import type { FontWeightName } from "../../theme/types"
|
|
6
|
+
import { Button, buttonColors } from "../Button/Button"
|
|
7
|
+
import { Text } from "../Text/Text"
|
|
6
8
|
|
|
7
9
|
export type TextLinkProps = {
|
|
8
10
|
/** The link's text; an icon after it (an external link's arrow) stands on the text's line. */
|
|
@@ -19,6 +21,12 @@ export type TextLinkProps = {
|
|
|
19
21
|
onPress?: (event: GestureResponderEvent) => void
|
|
20
22
|
/** The weight of the link's text; it takes the text's own around it by default (`--link-font-weight: inherit`). */
|
|
21
23
|
weight?: FontWeightName
|
|
24
|
+
/**
|
|
25
|
+
* A small action of its own outside running text (Restore Purchases under a store's plans): on iOS the text alone
|
|
26
|
+
* at the subheadline (15/20, regular) in the link color with a 44pt target and the system's pressed fade; on Android
|
|
27
|
+
* Material's small text button. @default false
|
|
28
|
+
*/
|
|
29
|
+
standalone?: boolean
|
|
22
30
|
accessibilityLabel?: string
|
|
23
31
|
testID?: string
|
|
24
32
|
style?: StyleProp<TextStyle>
|
|
@@ -26,6 +34,9 @@ export type TextLinkProps = {
|
|
|
26
34
|
|
|
27
35
|
const EXTERNAL = /^https?:\/\//
|
|
28
36
|
|
|
37
|
+
/** The underline's distance under the letters on the web: the token, else a tenth of the type. */
|
|
38
|
+
const underlineOffset = (value: unknown) => (typeof value === "number" ? value : typeof value === "string" && value !== "" ? value : "0.1em")
|
|
39
|
+
|
|
29
40
|
/**
|
|
30
41
|
* A link in running text, as @plexui/ui's TextLink: put it inside a `Text`, whose face, size and color it takes
|
|
31
42
|
* (the web's `currentcolor`), underlined; `primary` colors it with `--link-primary-text-color` and drops the underline.
|
|
@@ -33,19 +44,54 @@ const EXTERNAL = /^https?:\/\//
|
|
|
33
44
|
* 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
|
|
34
45
|
* URL (an `<a>` on the web, a new tab for an external one); with only `onPress` it is a `button`.
|
|
35
46
|
*/
|
|
36
|
-
export function TextLink({ children, href, primary = false, underline = !primary, forceExternal, onPress, weight, accessibilityLabel, testID, style }: TextLinkProps) {
|
|
47
|
+
export function TextLink({ children, href, primary = false, underline = !primary, forceExternal, onPress, weight, standalone = false, accessibilityLabel, testID, style }: TextLinkProps) {
|
|
37
48
|
const theme = useTheme()
|
|
38
49
|
const [pressed, setPressed] = useState(false)
|
|
39
50
|
const external = forceExternal ?? EXTERNAL.test(href ?? "")
|
|
40
51
|
const web = Platform.OS === "web"
|
|
41
52
|
const press = (event: GestureResponderEvent) => {
|
|
42
53
|
onPress?.(event)
|
|
54
|
+
// On the web the link is an anchor the browser opens (a new tab for an external one)
|
|
43
55
|
if (!href || web || prevented(event)) return
|
|
44
56
|
void Linking.openURL(href).catch(() => {})
|
|
45
57
|
}
|
|
46
|
-
const actionable = href != null || onPress != null
|
|
47
58
|
// react-native-web draws a Text with `href` as an anchor: the browser opens it, a new tab for an external one
|
|
48
59
|
const anchor = web && href ? { href, hrefAttrs: external ? { target: "_blank", rel: "noopener noreferrer" } : undefined } : null
|
|
60
|
+
if (standalone) {
|
|
61
|
+
const role = href ? "link" : "button"
|
|
62
|
+
// A pressable is a View, which react-native-web draws as an anchor with the same `href`
|
|
63
|
+
const link = anchor as object | null
|
|
64
|
+
if (theme.isAndroid)
|
|
65
|
+
return (
|
|
66
|
+
<Button {...link} variant="ghost" color="primary" size="sm" onPress={press} accessibilityRole={role} accessibilityLabel={accessibilityLabel} testID={testID}>
|
|
67
|
+
{weight != null || style != null ? (
|
|
68
|
+
// A caller's face or type over the button's label (14/20 Medium in the primary)
|
|
69
|
+
<Text weight={weight ?? "medium"} color={buttonColors(theme, "primary", "ghost", false, false).text} style={[{ fontSize: 14, lineHeight: 20 }, style]}>
|
|
70
|
+
{children}
|
|
71
|
+
</Text>
|
|
72
|
+
) : (
|
|
73
|
+
children
|
|
74
|
+
)}
|
|
75
|
+
</Button>
|
|
76
|
+
)
|
|
77
|
+
return (
|
|
78
|
+
// UIButton's plain style: no frame, the text faded while held, the target 44 tall
|
|
79
|
+
<Pressable
|
|
80
|
+
{...link}
|
|
81
|
+
onPress={press}
|
|
82
|
+
accessibilityRole={role}
|
|
83
|
+
accessibilityLabel={accessibilityLabel}
|
|
84
|
+
testID={testID}
|
|
85
|
+
hitSlop={{ left: 8, right: 8 }}
|
|
86
|
+
style={({ pressed: held }) => ({ minHeight: 44, justifyContent: "center", alignSelf: "flex-start", opacity: held ? 0.35 : 1 })}
|
|
87
|
+
>
|
|
88
|
+
<Text weight={weight ?? "regular"} color={theme.color("--link-primary-text-color", theme.colors.textAccent)} style={[{ fontSize: 15, lineHeight: 20 }, style]}>
|
|
89
|
+
{children}
|
|
90
|
+
</Text>
|
|
91
|
+
</Pressable>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
const actionable = href != null || onPress != null
|
|
49
95
|
// iOS's own Text highlights a press (as UITextView's links); elsewhere the press layer of a row
|
|
50
96
|
const highlight = theme.isIOS && !web ? null : pressed ? { backgroundColor: controlHighlight(theme.scheme) } : null
|
|
51
97
|
return (
|
|
@@ -60,6 +106,9 @@ export function TextLink({ children, href, primary = false, underline = !primary
|
|
|
60
106
|
style={[
|
|
61
107
|
primary ? { color: theme.color("--link-primary-text-color", theme.colors.textAccent) } : null,
|
|
62
108
|
underline ? { textDecorationLine: "underline" } : null,
|
|
109
|
+
// The web sets the line a tenth of the type under the letters (`--link-underline-decoration-offset`), clear of
|
|
110
|
+
// the descenders; a phone draws it where the platform does
|
|
111
|
+
underline && Platform.OS === "web" ? ({ textUnderlineOffset: underlineOffset(theme.token("--link-underline-decoration-offset")) } as TextStyle) : null,
|
|
63
112
|
weight ? theme.font(weight) : null,
|
|
64
113
|
highlight,
|
|
65
114
|
style,
|
package/src/index.ts
CHANGED
|
@@ -45,7 +45,7 @@ export {
|
|
|
45
45
|
} from "./components/Toolbar/Toolbar"
|
|
46
46
|
export {
|
|
47
47
|
TabBar,
|
|
48
|
-
useTabBarMinimize,
|
|
48
|
+
useTabBarMetrics, useTabBarMinimize,
|
|
49
49
|
type TabBarBackground,
|
|
50
50
|
type TabBarBadgeColor,
|
|
51
51
|
type TabBarItemProps,
|
|
@@ -95,7 +95,7 @@ export { Badge, type BadgeColor, type BadgeProps, type BadgeSize, type BadgeVari
|
|
|
95
95
|
export { BottomActions, type BottomActionsBackground, type BottomActionsProps } from "./components/BottomActions/BottomActions"
|
|
96
96
|
export { IntroHeader, type IntroHeaderAlign, type IntroHeaderProps } from "./components/IntroHeader/IntroHeader"
|
|
97
97
|
export { Card, cardColors, type CardColor, type CardMediaProps, type CardProps, type CardSize, type CardVariant } from "./components/Card/Card"
|
|
98
|
-
export { List, ListItem, type ListItemProps, type ListProps } from "./components/List/List"
|
|
98
|
+
export { List, ListItem, ListStack, useListMetrics, type ListItemProps, type ListProps, type ListStackProps } from "./components/List/List"
|
|
99
99
|
export { Chip, type ChipProps } from "./components/Chip/Chip"
|
|
100
100
|
export { Skeleton, type SkeletonProps } from "./components/Skeleton/Skeleton"
|
|
101
101
|
export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment, type ProgressSize } from "./components/Progress/Progress"
|
package/src/internal/a11y.ts
CHANGED
|
@@ -4,6 +4,19 @@ import { textOf } from "./children"
|
|
|
4
4
|
|
|
5
5
|
type KeyEvent = { key: string; preventDefault: () => void }
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* A hint (what a press does) for a screen reader: `accessibilityHint` on a phone; on the web, where React Native Web
|
|
9
|
+
* drops that prop, the id of an unseen text (`nodeProps`, the text's `nativeID`) that `aria-describedby` points at.
|
|
10
|
+
*/
|
|
11
|
+
export function useHint(hint: string | undefined) {
|
|
12
|
+
const id = useId()
|
|
13
|
+
if (hint == null || hint === "") return { id: undefined, props: {} }
|
|
14
|
+
return { id: Platform.OS === "web" ? id : undefined, props: Platform.OS === "web" ? { "aria-describedby": id } : { accessibilityHint: hint } }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Ids for `aria-describedby`, the empty ones left out. */
|
|
18
|
+
export const describedBy = (...ids: (string | undefined)[]) => ids.filter(Boolean).join(" ") || undefined
|
|
19
|
+
|
|
7
20
|
/**
|
|
8
21
|
* The description of a control for a screen reader: read after its label and state, as VoiceOver and TalkBack
|
|
9
22
|
* read a hint, and tied to the text by `aria-describedby` on the web. Give `id` to the description's text as its
|
package/src/internal/row.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext } from "react"
|
|
2
|
-
import type
|
|
2
|
+
import { Platform, type GestureResponderEvent } from "react-native"
|
|
3
3
|
|
|
4
4
|
/** The end of a List row, as its control sees it. */
|
|
5
5
|
export type RowEnd = {
|
|
@@ -69,7 +69,8 @@ export function rowHold(hold: ((held: boolean, event?: GestureResponderEvent) =>
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
/** A List row's touch and hold, for the control at its end, which takes the row's touches and its screen reader focus. */
|
|
72
|
-
|
|
72
|
+
/** A row's touch and hold (`run`, named by `label`) and its press's hint, for the control that takes the row's focus. */
|
|
73
|
+
export type RowAction = { run?: () => void; label?: string; hint?: string; hintId?: string }
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
76
|
* Set by a row with `onLongPress`: a control at its end that takes its own touches (a checkbox, a switch, a choice)
|
|
@@ -103,3 +104,14 @@ export function holdProps(
|
|
|
103
104
|
},
|
|
104
105
|
}
|
|
105
106
|
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The row's hint on the control that takes the row's focus, kept with the control's own description: a phone reads
|
|
110
|
+
* both as one hint; on the web the control is described by its description and the row's unseen hint text.
|
|
111
|
+
*/
|
|
112
|
+
export function rowHint(row: RowAction | null, described: { id?: string; props: { accessibilityHint?: string } }) {
|
|
113
|
+
if (row?.hint == null) return null
|
|
114
|
+
if (Platform.OS === "web") return row.hintId != null ? { "aria-describedby": [described.id, row.hintId].filter(Boolean).join(" ") } : null
|
|
115
|
+
const own = described.props.accessibilityHint
|
|
116
|
+
return { accessibilityHint: own ? `${own}. ${row.hint}` : row.hint }
|
|
117
|
+
}
|
|
@@ -24,9 +24,10 @@ export type ThemeProviderProps = {
|
|
|
24
24
|
selectionColor?: SelectionColor
|
|
25
25
|
/**
|
|
26
26
|
* The product's brand: colors, faces and radii over the Plex UI defaults. A nested ThemeProvider keeps its
|
|
27
|
-
* parent's brand and lays its own over it
|
|
27
|
+
* parent's brand and lays its own over it; `null` draws its subtree in Plex UI's own colors and radii, not the
|
|
28
|
+
* parent's brand (a stand-in for a system prompt, which is in the system's colors, never the app's). Faces stay.
|
|
28
29
|
*/
|
|
29
|
-
brand?: BrandTheme
|
|
30
|
+
brand?: BrandTheme | null
|
|
30
31
|
/**
|
|
31
32
|
* Faces of the kit (a nested ThemeProvider takes its parent's). Without them the platform's own face is used; see
|
|
32
33
|
* `interFonts` and `robotoFonts`. Faces per drawn platform, `{ ios, android }`, take the one of `platform`: the
|
|
@@ -261,8 +262,10 @@ export function ThemeProvider({ scheme, platform, selectionColor, brand, fonts:
|
|
|
261
262
|
// The phone layers of the CSS apply up to 767px: a tablet keeps the touch sizes. Only the bands of the CSS matter.
|
|
262
263
|
const band = width >= 414 ? 414 : 393
|
|
263
264
|
const highDensity = PixelRatio.get() >= 1.5
|
|
264
|
-
const own = brandOverrides(brand)
|
|
265
|
-
|
|
265
|
+
const own = brandOverrides(brand ?? undefined)
|
|
266
|
+
// `brand={null}` starts again from Plex UI's tokens rather than from the parent's brand
|
|
267
|
+
const inherited = brand === null ? undefined : parent?.overrides
|
|
268
|
+
const overrides = inherited || own ? { ...inherited, ...own } : undefined
|
|
266
269
|
const overridesKey = JSON.stringify(overrides ?? null)
|
|
267
270
|
const resolver = useMemo(() => {
|
|
268
271
|
const context: TokenContext = { width: band, highDensity, reducedMotion }
|
package/src/theme/material.ts
CHANGED
|
@@ -236,6 +236,8 @@ export const elevationShadow = {
|
|
|
236
236
|
bar: "0 2px 8px rgba(0, 0, 0, 0.06)",
|
|
237
237
|
/** The same over a dark screen, where a light shadow does not show: the controls stand apart by their fill. */
|
|
238
238
|
barDark: "0 2px 8px rgba(0, 0, 0, 0.3)",
|
|
239
|
+
/** Level 1: an elevated card. */
|
|
240
|
+
level1: "0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15)",
|
|
239
241
|
level2: "0 2px 6px 2px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.3)",
|
|
240
242
|
level3: "0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 8px 3px rgba(0, 0, 0, 0.15)",
|
|
241
243
|
} as const
|