@plexui/react-native 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/ActionSheet/ActionSheet.js +2 -1
- package/dist/es/components/Alert/Alert.js +2 -1
- package/dist/es/components/Avatar/Avatar.js +2 -1
- package/dist/es/components/Badge/Badge.js +2 -1
- package/dist/es/components/BottomActions/BottomActions.js +3 -3
- package/dist/es/components/BottomSheet/BottomSheet.js +2 -1
- package/dist/es/components/Button/Button.js +2 -1
- package/dist/es/components/Card/Card.js +2 -1
- package/dist/es/components/Checkbox/Checkbox.js +2 -1
- package/dist/es/components/Chip/Chip.js +2 -1
- package/dist/es/components/DatePicker/Calendar.js +2 -1
- package/dist/es/components/DatePicker/DatePicker.js +2 -1
- package/dist/es/components/DatePicker/TimeDial.js +2 -1
- package/dist/es/components/DatePicker/Wheel.js +2 -1
- package/dist/es/components/Dialog/Dialog.js +2 -1
- package/dist/es/components/Input/Input.js +2 -1
- package/dist/es/components/InputGroup/InputGroup.js +2 -1
- package/dist/es/components/IntroHeader/IntroHeader.js +32 -0
- package/dist/es/components/List/List.js +45 -18
- package/dist/es/components/Menu/Menu.js +2 -1
- package/dist/es/components/RadioGroup/RadioGroup.js +2 -1
- package/dist/es/components/SegmentedControl/SegmentedControl.js +52 -54
- package/dist/es/components/Select/Select.js +2 -1
- package/dist/es/components/Stepper/Stepper.js +2 -1
- package/dist/es/components/Switch/Switch.js +2 -1
- package/dist/es/components/TabBar/TabBar.js +2 -1
- package/dist/es/components/TagInput/TagInput.js +2 -1
- package/dist/es/components/Tip/Tip.js +2 -1
- package/dist/es/components/Toast/Toast.js +2 -1
- package/dist/es/index.js +1 -0
- package/dist/es/internal/Pressable.js +10 -0
- package/dist/es/theme/material.js +11 -2
- package/dist/types/components/BottomActions/BottomActions.d.ts +10 -1
- package/dist/types/components/IntroHeader/IntroHeader.d.ts +33 -0
- package/dist/types/components/List/List.d.ts +1 -1
- package/dist/types/components/SegmentedControl/SegmentedControl.d.ts +11 -2
- package/dist/types/index.d.ts +2 -1
- package/dist/types/internal/Pressable.d.ts +3 -0
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +2 -1
- package/src/components/Alert/Alert.tsx +2 -1
- package/src/components/Avatar/Avatar.tsx +2 -1
- package/src/components/Badge/Badge.tsx +2 -1
- package/src/components/BottomActions/BottomActions.tsx +14 -2
- package/src/components/BottomSheet/BottomSheet.tsx +2 -1
- package/src/components/Button/Button.tsx +2 -13
- package/src/components/Card/Card.tsx +2 -1
- package/src/components/Checkbox/Checkbox.tsx +2 -1
- package/src/components/Chip/Chip.tsx +2 -1
- package/src/components/DatePicker/Calendar.tsx +2 -1
- package/src/components/DatePicker/DatePicker.tsx +2 -1
- package/src/components/DatePicker/TimeDial.tsx +2 -1
- package/src/components/DatePicker/Wheel.tsx +2 -1
- package/src/components/Dialog/Dialog.tsx +2 -1
- package/src/components/Input/Input.tsx +2 -17
- package/src/components/InputGroup/InputGroup.tsx +2 -1
- package/src/components/IntroHeader/IntroHeader.tsx +79 -0
- package/src/components/List/List.tsx +55 -20
- package/src/components/Menu/Menu.tsx +2 -1
- package/src/components/RadioGroup/RadioGroup.tsx +2 -1
- package/src/components/SegmentedControl/SegmentedControl.tsx +68 -48
- package/src/components/Select/Select.tsx +2 -1
- package/src/components/Stepper/Stepper.tsx +2 -1
- package/src/components/Switch/Switch.tsx +2 -1
- package/src/components/TabBar/TabBar.tsx +2 -13
- package/src/components/TagInput/TagInput.tsx +2 -1
- package/src/components/Tip/Tip.tsx +2 -1
- package/src/components/Toast/Toast.tsx +2 -1
- package/src/index.ts +2 -1
- package/src/internal/Pressable.tsx +17 -0
- package/src/theme/material.ts +9 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { cloneElement, createContext, isValidElement, useCallback, useContext, useMemo, useRef, useState, type ComponentRef, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import {
|
|
1
|
+
import { cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useMemo, useRef, useState, type ComponentRef, type ReactElement, type ReactNode } from "react"
|
|
2
|
+
import { Animated, Easing, Platform, StyleSheet, View, type GestureResponderEvent, type LayoutChangeEvent, type StyleProp, type TextStyle, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import Disclosure from "../../icons/plex/Disclosure"
|
|
4
5
|
import ExclamationMarkCircle from "../../icons/plex/ExclamationMarkCircle"
|
|
5
6
|
import { spaceToggles, useDescription } from "../../internal/a11y"
|
|
@@ -340,7 +341,7 @@ export type ListItemProps = {
|
|
|
340
341
|
}
|
|
341
342
|
|
|
342
343
|
/**
|
|
343
|
-
* A row of a List: the label (17/22, `--field-row-*`: 52 tall,
|
|
344
|
+
* A row of a List: the label (17/22, `--field-row-*`: 52 tall, 62 with a description, 12 above and below the text at
|
|
344
345
|
* least) with a description, a leading symbol, a value (wrapping within 60% of the row, or under the label: `valuePlacement`) or a control, and the chevron
|
|
345
346
|
* of a drill-in (`Disclosure`, in the tertiary label, turned over right to left). A row with `checked` is a switch
|
|
346
347
|
* row. On Android a row of a settings screen: 50dp tall at least (64 with a description, its text 12 from the row's
|
|
@@ -417,8 +418,8 @@ export function ListItem({
|
|
|
417
418
|
const nativeRipple = theme.isAndroid && Platform.OS === "android"
|
|
418
419
|
// iOS lights a held choice row, not a switch row, as the web's phone rows
|
|
419
420
|
const lit = !switchRow && control?.kind !== "switch"
|
|
420
|
-
const row =
|
|
421
|
-
theme.isAndroid ? styles.androidRow : iosRow(theme,
|
|
421
|
+
const row =
|
|
422
|
+
theme.isAndroid ? styles.androidRow : iosRow(theme, last, description != null || error != null)
|
|
422
423
|
// A finger on the control at the end holds the row, as one on the row's text does
|
|
423
424
|
const [held, setHeld] = useState(false)
|
|
424
425
|
// Android's press is the list selector's ripple from the touch point, clipped to the row (and the card's corners):
|
|
@@ -483,11 +484,12 @@ export function ListItem({
|
|
|
483
484
|
onPressOut={drawn ? ripple.end : undefined}
|
|
484
485
|
android_ripple={nativeRipple ? { color: highlight, foreground: true } : undefined}
|
|
485
486
|
testID={testID}
|
|
486
|
-
style={
|
|
487
|
+
style={row}
|
|
487
488
|
>
|
|
488
489
|
{({ pressed }) => (
|
|
489
490
|
<RowHoldContext.Provider value={disabled ? null : theme.isAndroid ? hold : setHeld}>
|
|
490
491
|
{ripple.layer}
|
|
492
|
+
{theme.isAndroid ? null : <RowHighlight on={(pressed || held) && lit} last={last} />}
|
|
491
493
|
{content(pressed || held)}
|
|
492
494
|
</RowHoldContext.Provider>
|
|
493
495
|
)}
|
|
@@ -506,7 +508,7 @@ export function ListItem({
|
|
|
506
508
|
accessibilityLabel={accessibilityLabel}
|
|
507
509
|
accessibilityRole={named && Platform.OS !== "web" ? "text" : undefined}
|
|
508
510
|
role={named && Platform.OS === "web" ? "group" : undefined}
|
|
509
|
-
style={row
|
|
511
|
+
style={row}
|
|
510
512
|
>
|
|
511
513
|
{content(false)}
|
|
512
514
|
</View>
|
|
@@ -523,7 +525,8 @@ function ActionRow({ children }: { children: ReactNode }) {
|
|
|
523
525
|
{last ? null : (
|
|
524
526
|
<View
|
|
525
527
|
pointerEvents="none"
|
|
526
|
-
|
|
528
|
+
// iOS: from the text to 20 before the group's end, as the other rows' lines
|
|
529
|
+
style={[styles.actionSeparator, theme.isAndroid ? { start: ANDROID_INSET } : { start: theme.length("--list-row-inset", 20), end: theme.length("--list-row-inset", 20) }, { backgroundColor: theme.isAndroid ? divider(theme) : theme.colors.separator }]}
|
|
527
530
|
/>
|
|
528
531
|
)}
|
|
529
532
|
</View>
|
|
@@ -584,7 +587,8 @@ export function ListStackedRow({ label, description, error, disabled = false, ac
|
|
|
584
587
|
return (
|
|
585
588
|
<View testID={testID} style={[styles.stackedRow, { paddingStart: inset }]}>
|
|
586
589
|
<View style={[styles.stackedColumn, { paddingEnd: inset, paddingVertical: padding, gap: android ? 4 : 0 }]}>
|
|
587
|
-
{
|
|
590
|
+
{/* iOS stops the line 20 before the group's end, as its rows' text (Settings, iOS 26 and 27) */}
|
|
591
|
+
{last ? null : <View pointerEvents="none" style={[styles.iosSeparator, { backgroundColor: android ? divider(theme) : theme.colors.separator }, android ? null : { end: inset }]} />}
|
|
588
592
|
{labelText != null && action != null ? (
|
|
589
593
|
<View style={[styles.pair, { gap: 8 }, !android && error != null ? { marginBottom: theme.length("--mobile-field-error-offset", 4) } : null]}>
|
|
590
594
|
{labelText}
|
|
@@ -665,24 +669,52 @@ function endControl(found: Exclude<FoundControl, { kind: "radio" }>, own: boolea
|
|
|
665
669
|
return { kind: found.kind, node, toggle: rowDisabled || props.disabled ? undefined : () => change(state !== true) }
|
|
666
670
|
}
|
|
667
671
|
|
|
668
|
-
/** A row's least height: 52,
|
|
672
|
+
/** A row's least height: 52, 62 with a description (as Settings, iOS 26 and 27) (`--field-row-description-min-height`), as the web's NavigationRow. */
|
|
669
673
|
const iosMinHeight = (theme: Theme, described: boolean) =>
|
|
670
|
-
described ? theme.length("--field-row-description-min-height",
|
|
674
|
+
described ? theme.length("--field-row-description-min-height", 62) : theme.length("--field-row-min-height", 52)
|
|
671
675
|
|
|
672
|
-
function iosRow(theme: Theme,
|
|
676
|
+
function iosRow(theme: Theme, last: boolean, described: boolean): ViewStyle {
|
|
673
677
|
const inset = theme.length("--list-row-inset", 20)
|
|
674
678
|
return {
|
|
675
679
|
flexDirection: "row",
|
|
676
680
|
alignItems: "center",
|
|
677
681
|
minHeight: iosMinHeight(theme, described),
|
|
678
682
|
paddingStart: inset,
|
|
679
|
-
|
|
680
|
-
// The press fills the row to the group's rounded ends
|
|
683
|
+
// The press is RowHighlight's, under the content; the row's rounded end clips it to the group's
|
|
681
684
|
borderBottomLeftRadius: last ? theme.length("--field-group-radius", 26) : 0,
|
|
682
685
|
borderBottomRightRadius: last ? theme.length("--field-group-radius", 26) : 0,
|
|
683
686
|
}
|
|
684
687
|
}
|
|
685
688
|
|
|
689
|
+
/**
|
|
690
|
+
* iOS's press on a row: the row lights at once under a finger and, when it lifts, the light fades out over 0.3s, as
|
|
691
|
+
* UIKit deselects a cell (the system gray 4 of `--field-row-press-background`); at once with reduced motion.
|
|
692
|
+
*/
|
|
693
|
+
function RowHighlight({ on, last }: { on: boolean; last: boolean }) {
|
|
694
|
+
const theme = useTheme()
|
|
695
|
+
const opacity = useRef(new Animated.Value(0)).current
|
|
696
|
+
useEffect(() => {
|
|
697
|
+
if (on || theme.reducedMotion) {
|
|
698
|
+
opacity.stopAnimation()
|
|
699
|
+
opacity.setValue(on ? 1 : 0)
|
|
700
|
+
return
|
|
701
|
+
}
|
|
702
|
+
const fade = Animated.timing(opacity, { toValue: 0, duration: 300, easing: Easing.out(Easing.quad), useNativeDriver: Platform.OS !== "web" })
|
|
703
|
+
fade.start()
|
|
704
|
+
return () => fade.stop()
|
|
705
|
+
}, [on, opacity, theme.reducedMotion])
|
|
706
|
+
const radius = last ? theme.length("--field-group-radius", 26) : 0
|
|
707
|
+
return (
|
|
708
|
+
<Animated.View
|
|
709
|
+
pointerEvents="none"
|
|
710
|
+
style={[
|
|
711
|
+
StyleSheet.absoluteFill,
|
|
712
|
+
{ opacity, backgroundColor: theme.color("--field-row-press-background"), borderBottomLeftRadius: radius, borderBottomRightRadius: radius },
|
|
713
|
+
]}
|
|
714
|
+
/>
|
|
715
|
+
)
|
|
716
|
+
}
|
|
717
|
+
|
|
686
718
|
type ContentProps = Pick<ListItemProps, "label" | "description" | "leading" | "value" | "trailing" | "error"> & {
|
|
687
719
|
theme: Theme
|
|
688
720
|
/** The end is a switch, a checkbox or a radio: with `columns` it stays at the row's edge. */
|
|
@@ -742,15 +774,17 @@ function IOSContent({ theme, label, description, descriptionId, leading, leading
|
|
|
742
774
|
// The text's padding centres one line (or a label and its description) in the row's least height, 12 at least, as the
|
|
743
775
|
// web's: a row of more lines (a wrapped label, a value below) keeps those 15 (14) above and below
|
|
744
776
|
// A row with a control at its end is the web's form row (`Field row`): its text keeps the control's 44pt line, 4 above
|
|
745
|
-
// and below it, or
|
|
777
|
+
// and below it, or 10 around a description, so a wrapped label or description grows the row by its own lines only
|
|
746
778
|
const target = theme.length("--control-size-lg", 44)
|
|
747
779
|
const formRow = trailing != null
|
|
780
|
+
// A two-line row keeps 10 over its label and under its description, as Settings (62 in all)
|
|
781
|
+
const descriptionPadding = theme.length("--field-row-description-padding-block", 10)
|
|
748
782
|
const textPadding = formRow
|
|
749
783
|
? description != null
|
|
750
|
-
?
|
|
784
|
+
? descriptionPadding
|
|
751
785
|
: (iosMinHeight(theme, false) - target) / 2
|
|
752
786
|
: Math.max(
|
|
753
|
-
theme.length("--field-row-text-padding-block", 12),
|
|
787
|
+
description != null ? descriptionPadding : theme.length("--field-row-text-padding-block", 12),
|
|
754
788
|
(iosMinHeight(theme, description != null) - labelType.lineHeight - (description != null ? descriptionLine : 0)) / 2,
|
|
755
789
|
)
|
|
756
790
|
// A field at the end fills the room after the label (`RowEnd.fill`)
|
|
@@ -795,12 +829,13 @@ function IOSContent({ theme, label, description, descriptionId, leading, leading
|
|
|
795
829
|
error != null ? styles.iosColumn : styles.iosMain,
|
|
796
830
|
{ minHeight: iosMinHeight(theme, description != null || error != null), paddingEnd: inset },
|
|
797
831
|
error != null
|
|
798
|
-
? { paddingVertical: Math.max(
|
|
832
|
+
? { paddingVertical: Math.max(descriptionPadding, (iosMinHeight(theme, true) - labelType.lineHeight - errorOffset - errorLine) / 2) }
|
|
799
833
|
: { gap: below ? disclosureGap : gap },
|
|
800
834
|
]}
|
|
801
835
|
>
|
|
802
|
-
{/* Over the row's bottom edge, not under it: the row keeps its height, as the web's separator
|
|
803
|
-
|
|
836
|
+
{/* Over the row's bottom edge, not under it: the row keeps its height, as the web's separator. It runs from the
|
|
837
|
+
text to 20 before the group's end (the row's end inset), as Settings draws it on iOS 26 and 27 */}
|
|
838
|
+
{last ? null : <View pointerEvents="none" style={[styles.iosSeparator, { backgroundColor: theme.colors.separator, end: inset }]} />}
|
|
804
839
|
{probe}
|
|
805
840
|
{line(
|
|
806
841
|
<>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Children, cloneElement, createContext, Fragment, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Easing, I18nManager, PanResponder, Platform,
|
|
2
|
+
import { Animated, Easing, I18nManager, PanResponder, Platform, ScrollView, StyleSheet, View, useWindowDimensions, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
|
4
5
|
import Svg, { Path } from "react-native-svg"
|
|
5
6
|
import ArrowLeftLg from "../../icons/plex/ArrowLeftLg"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext, useContext, useEffect, useState, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Platform,
|
|
2
|
+
import { Animated, Platform, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import CheckMd from "../../icons/plex/CheckMd"
|
|
4
5
|
import { useDescription } from "../../internal/a11y"
|
|
5
6
|
import { ControlLabel } from "../../internal/ControlLabel"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext, isValidElement, useContext, useEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Easing,
|
|
2
|
+
import { Animated, Easing, StyleSheet, View, type LayoutChangeEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import { childrenOfType, isRenderable, textOf } from "../../internal/children"
|
|
4
5
|
import { Glass } from "../../internal/Glass"
|
|
5
6
|
import { curves } from "../../internal/motion"
|
|
@@ -44,6 +45,12 @@ export type SegmentedControlProps<T extends string> = {
|
|
|
44
45
|
* @default "equal"
|
|
45
46
|
*/
|
|
46
47
|
mobileSegmentWidth?: "equal" | "content"
|
|
48
|
+
/**
|
|
49
|
+
* Draws each tab's `badge`: a count in a small capsule after its label, as a messenger's folder tabs set their
|
|
50
|
+
* unread counts; each segment then takes its own width (`mobileSegmentWidth` content), 10 beside its label and
|
|
51
|
+
* count. Off, the count is only read with the segment's name, as the native controls draw none. @default false
|
|
52
|
+
*/
|
|
53
|
+
showBadges?: boolean
|
|
47
54
|
style?: StyleProp<ViewStyle>
|
|
48
55
|
testID?: string
|
|
49
56
|
/** `SegmentedControl.Tab` elements. */
|
|
@@ -60,7 +67,10 @@ export type SegmentedControlOptionProps = {
|
|
|
60
67
|
children?: ReactNode
|
|
61
68
|
/** A symbol before the label; with a label, iOS shows the symbol alone, as UISegmentedControl. */
|
|
62
69
|
icon?: ReactNode
|
|
63
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* A count. Read with the segment's name; drawn only with the control's `showBadges`, as the native controls (iOS and
|
|
72
|
+
* Material alike) draw none.
|
|
73
|
+
*/
|
|
64
74
|
badge?: SegmentedControlBadgeProp
|
|
65
75
|
disabled?: boolean
|
|
66
76
|
testID?: string
|
|
@@ -105,7 +115,7 @@ function iosLook(theme: Theme, size: ControlSize, material: "glass" | "flat" | u
|
|
|
105
115
|
glass: true,
|
|
106
116
|
fill: theme.color("--segmented-control-mobile-glass-background"),
|
|
107
117
|
thumb: theme.color("--segmented-control-mobile-thumb-background"),
|
|
108
|
-
duration:
|
|
118
|
+
duration: 300,
|
|
109
119
|
}
|
|
110
120
|
}
|
|
111
121
|
return {
|
|
@@ -124,42 +134,6 @@ function iosLook(theme: Theme, size: ControlSize, material: "glass" | "flat" | u
|
|
|
124
134
|
}
|
|
125
135
|
}
|
|
126
136
|
|
|
127
|
-
/**
|
|
128
|
-
* The curve the large control's lens lands on (touch.css `--tabs-thumb-transition-easing`, iOS 27.2 frame by frame):
|
|
129
|
-
* CSS `linear()` stops, each [progress, time], read between them as the browser does.
|
|
130
|
-
*/
|
|
131
|
-
const LENS_STOPS: [number, number][] = [
|
|
132
|
-
[0, 0],
|
|
133
|
-
[0.2, 0.03],
|
|
134
|
-
[0.33, 0.0625],
|
|
135
|
-
[0.45, 0.1],
|
|
136
|
-
[0.538, 0.1225],
|
|
137
|
-
[0.623, 0.1625],
|
|
138
|
-
[0.69, 0.2],
|
|
139
|
-
[0.747, 0.2425],
|
|
140
|
-
[0.793, 0.2875],
|
|
141
|
-
[0.83, 0.325],
|
|
142
|
-
[0.862, 0.3675],
|
|
143
|
-
[0.887, 0.41],
|
|
144
|
-
[0.908, 0.45],
|
|
145
|
-
[0.925, 0.4925],
|
|
146
|
-
[0.943, 0.535],
|
|
147
|
-
[0.956, 0.58],
|
|
148
|
-
[0.975, 0.66],
|
|
149
|
-
[0.981, 0.7],
|
|
150
|
-
[0.989, 0.7475],
|
|
151
|
-
[0.994, 0.825],
|
|
152
|
-
[1, 1],
|
|
153
|
-
]
|
|
154
|
-
const lensEasing = (t: number) => {
|
|
155
|
-
if (t <= 0) return 0
|
|
156
|
-
if (t >= 1) return 1
|
|
157
|
-
const after = LENS_STOPS.findIndex(([, at]) => at >= t)
|
|
158
|
-
const [fromValue, fromAt] = LENS_STOPS[after - 1]
|
|
159
|
-
const [toValue, toAt] = LENS_STOPS[after]
|
|
160
|
-
return fromValue + ((toValue - fromValue) * (t - fromAt)) / (toAt - fromAt)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
137
|
type ControlContext = { inRow: boolean }
|
|
164
138
|
/** A Toolbar.Row tells the control in it that it is in a row, not in the bar's own row. */
|
|
165
139
|
export const SegmentedControlRowContext = createContext<ControlContext>({ inRow: false })
|
|
@@ -197,6 +171,7 @@ function SegmentedControlRoot<T extends string>({
|
|
|
197
171
|
block = false,
|
|
198
172
|
mobileMaterial,
|
|
199
173
|
mobileSegmentWidth = "equal",
|
|
174
|
+
showBadges = false,
|
|
200
175
|
style,
|
|
201
176
|
testID,
|
|
202
177
|
children,
|
|
@@ -215,7 +190,9 @@ function SegmentedControlRoot<T extends string>({
|
|
|
215
190
|
if (option) select(option)
|
|
216
191
|
},
|
|
217
192
|
)
|
|
218
|
-
|
|
193
|
+
// Drawn counts differ from tab to tab, so each segment takes its own width with them, as a messenger's folder tabs
|
|
194
|
+
const counted = showBadges && options.some((option) => option.badge != null)
|
|
195
|
+
const common = { options, value, select, keys, disabled, block, equal: mobileSegmentWidth === "equal" && !counted, showBadges }
|
|
219
196
|
return (
|
|
220
197
|
<View accessibilityRole="tablist" aria-label={ariaLabel} accessibilityState={{ disabled }} testID={testID} style={[block ? styles.block : styles.hug, style]}>
|
|
221
198
|
{theme.isAndroid ? <AndroidControl {...common} size={size} /> : <IOSControl {...common} size={size} material={mobileMaterial} />}
|
|
@@ -232,9 +209,10 @@ type ControlProps = {
|
|
|
232
209
|
disabled: boolean
|
|
233
210
|
block: boolean
|
|
234
211
|
equal: boolean
|
|
212
|
+
showBadges: boolean
|
|
235
213
|
}
|
|
236
214
|
|
|
237
|
-
function IOSControl({ options, value, select, keys, disabled, block, equal, size, material }: ControlProps & { size: ControlSize; material?: "glass" | "flat" }) {
|
|
215
|
+
function IOSControl({ options, value, select, keys, disabled, block, equal, showBadges, size, material }: ControlProps & { size: ControlSize; material?: "glass" | "flat" }) {
|
|
238
216
|
const theme = useTheme()
|
|
239
217
|
const inBar = !!useContext(BarItemContext)
|
|
240
218
|
const { inRow } = useContext(SegmentedControlRowContext)
|
|
@@ -244,6 +222,9 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, size
|
|
|
244
222
|
const [widths, setWidths] = useState<Record<string, number>>({})
|
|
245
223
|
const widest = Math.max(0, ...options.map((option) => labels[option.value] ?? 0))
|
|
246
224
|
const optionRadius = look.height / 2 - look.gutter
|
|
225
|
+
// A drawn count ends a label in a capsule of its own: the thumb keeps 10 beside the label and the capsule, so the
|
|
226
|
+
// capsule does not touch the thumb's end
|
|
227
|
+
const gutter = showBadges && options.some((option) => option.badge != null) ? Math.max(look.optionGutter, 10) : look.optionGutter
|
|
247
228
|
// The large glass control held down, as the phone CSS ports it: the capsule grows 7% and whitens, the held label
|
|
248
229
|
// fades to 20%, with no capsule of its own under the finger
|
|
249
230
|
const largeGlass = look.glass && look.height >= 40
|
|
@@ -266,13 +247,14 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, size
|
|
|
266
247
|
placed.current = true
|
|
267
248
|
return
|
|
268
249
|
}
|
|
269
|
-
// The
|
|
270
|
-
|
|
250
|
+
// The thumb eases (CSS `ease`): in 300ms on the large control, 250 on the small one. The lens's own curve (fast,
|
|
251
|
+
// then a long settle) reads as a jump and a crawl when no lens is drawn over it (owner, 24.11)
|
|
252
|
+
const easing = Easing.bezier(0.25, 0.1, 0.25, 1)
|
|
271
253
|
Animated.parallel([
|
|
272
254
|
Animated.timing(x, { toValue: selectedX, duration: look.duration, easing, useNativeDriver: false }),
|
|
273
255
|
Animated.timing(width, { toValue: selectedWidth, duration: look.duration, easing, useNativeDriver: false }),
|
|
274
256
|
]).start()
|
|
275
|
-
}, [selectedX, selectedWidth, look.duration,
|
|
257
|
+
}, [selectedX, selectedWidth, look.duration, theme.reducedMotion, x, width])
|
|
276
258
|
// The segments take the capsule's whole height, so a press anywhere on it lands (the thumb keeps its inset); a
|
|
277
259
|
// minimum, so text a person enlarges is not cut
|
|
278
260
|
const track: ViewStyle = {
|
|
@@ -317,8 +299,8 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, size
|
|
|
317
299
|
}}
|
|
318
300
|
style={[
|
|
319
301
|
styles.option,
|
|
320
|
-
{ paddingHorizontal:
|
|
321
|
-
block ? styles.grow : equal && widest ? { width: widest + 2 *
|
|
302
|
+
{ paddingHorizontal: gutter, borderRadius: look.height / 2 },
|
|
303
|
+
block ? styles.grow : equal && widest ? { width: widest + 2 * gutter } : null,
|
|
322
304
|
]}
|
|
323
305
|
>
|
|
324
306
|
<View
|
|
@@ -343,6 +325,7 @@ function IOSControl({ options, value, select, keys, disabled, block, equal, size
|
|
|
343
325
|
{option.children}
|
|
344
326
|
</Text>
|
|
345
327
|
)}
|
|
328
|
+
{showBadges ? <SegmentCount badge={option.badge} selected={isSelected} off={off} /> : null}
|
|
346
329
|
</View>
|
|
347
330
|
</Pressable>
|
|
348
331
|
)
|
|
@@ -382,7 +365,7 @@ const ANDROID_MOVE = { duration: 320, easing: curves.easeOutQuint }
|
|
|
382
365
|
* its label in the accent, the others in the secondary gray. The pill slides to a new selection and takes its width.
|
|
383
366
|
* In a bar's row of controls the capsule takes the height of the circles beside it (46dp).
|
|
384
367
|
*/
|
|
385
|
-
function AndroidControl({ options, value, select, keys, disabled, block, equal, size }: ControlProps & { size: ControlSize }) {
|
|
368
|
+
function AndroidControl({ options, value, select, keys, disabled, block, equal, showBadges, size }: ControlProps & { size: ControlSize }) {
|
|
386
369
|
const theme = useTheme()
|
|
387
370
|
const m = theme.material
|
|
388
371
|
const bar = useContext(BarItemContext)
|
|
@@ -434,6 +417,7 @@ function AndroidControl({ options, value, select, keys, disabled, block, equal,
|
|
|
434
417
|
selected={option.value === value}
|
|
435
418
|
off={disabled || !!option.disabled}
|
|
436
419
|
framed={frame}
|
|
420
|
+
showBadges={showBadges}
|
|
437
421
|
height={inner}
|
|
438
422
|
// In a filled row equal segments share the width and the others take their label and share what is left; a
|
|
439
423
|
// control that hugs its segments gives equal ones the widest one's width
|
|
@@ -453,6 +437,7 @@ type AndroidSegmentProps = {
|
|
|
453
437
|
off: boolean
|
|
454
438
|
/** The pill is placed: the selected segment draws none of its own. */
|
|
455
439
|
framed: boolean
|
|
440
|
+
showBadges: boolean
|
|
456
441
|
height: number
|
|
457
442
|
size: ViewStyle | null
|
|
458
443
|
keys: ReturnType<typeof useTabKeys>
|
|
@@ -461,7 +446,7 @@ type AndroidSegmentProps = {
|
|
|
461
446
|
}
|
|
462
447
|
|
|
463
448
|
/** One segment of the capsule: its label turns from the gray to the accent as the pill comes, and back as it goes. */
|
|
464
|
-
function AndroidSegment({ option, selected, off, framed, height, size, keys, select, onWidth }: AndroidSegmentProps) {
|
|
449
|
+
function AndroidSegment({ option, selected, off, framed, showBadges, height, size, keys, select, onWidth }: AndroidSegmentProps) {
|
|
465
450
|
const theme = useTheme()
|
|
466
451
|
const m = theme.material
|
|
467
452
|
const [tint] = useState(() => new Animated.Value(selected ? 1 : 0))
|
|
@@ -509,10 +494,42 @@ function AndroidSegment({ option, selected, off, framed, height, size, keys, sel
|
|
|
509
494
|
{option.children}
|
|
510
495
|
</Animated.Text>
|
|
511
496
|
) : null}
|
|
497
|
+
{showBadges ? <SegmentCount badge={option.badge} selected={selected} off={off} /> : null}
|
|
512
498
|
</Pressable>
|
|
513
499
|
)
|
|
514
500
|
}
|
|
515
501
|
|
|
502
|
+
/**
|
|
503
|
+
* A tab's count drawn after its label (`showBadges`): a capsule 18 tall, the digits 12 semibold in the screen's color.
|
|
504
|
+
* iOS: the label's color on the selected segment, so it reads on the thumb, the secondary label on the others.
|
|
505
|
+
* Android: the accent on the selected segment, as its label, the gray on the others.
|
|
506
|
+
*/
|
|
507
|
+
function SegmentCount({ badge, selected, off }: { badge: SegmentedControlBadgeProp | undefined; selected: boolean; off: boolean }) {
|
|
508
|
+
const theme = useTheme()
|
|
509
|
+
const text = badge != null ? badgeText(badge) : undefined
|
|
510
|
+
if (!text) return null
|
|
511
|
+
// iOS: the label's color in a capsule, the bar's ink in it; Android: the segment's own ink, the selected one's
|
|
512
|
+
// container in it (onSecondaryContainer on secondaryContainer), the others' onSurfaceVariant on the surface, so the
|
|
513
|
+
// small digits keep their contrast
|
|
514
|
+
const fill = off
|
|
515
|
+
? theme.color("--alpha-20")
|
|
516
|
+
: theme.isAndroid
|
|
517
|
+
? selected
|
|
518
|
+
? theme.material.onSecondaryContainer
|
|
519
|
+
: theme.material.onSurfaceVariant
|
|
520
|
+
: selected
|
|
521
|
+
? theme.colors.text
|
|
522
|
+
: theme.colors.labelSecondary
|
|
523
|
+
const ink = theme.isAndroid ? (selected ? theme.material.secondaryContainer : theme.material.surface) : theme.colors.background
|
|
524
|
+
return (
|
|
525
|
+
<View aria-hidden style={[styles.count, { backgroundColor: fill }]}>
|
|
526
|
+
<Text numberOfLines={1} weight="semibold" color={ink} style={styles.countText}>
|
|
527
|
+
{text}
|
|
528
|
+
</Text>
|
|
529
|
+
</View>
|
|
530
|
+
)
|
|
531
|
+
}
|
|
532
|
+
|
|
516
533
|
export const SegmentedControl = Object.assign(SegmentedControlRoot, { Tab: SegmentedControlTab, Option: SegmentedControlTab })
|
|
517
534
|
|
|
518
535
|
const styles = StyleSheet.create({
|
|
@@ -523,6 +540,9 @@ const styles = StyleSheet.create({
|
|
|
523
540
|
stretch: { alignSelf: "stretch" },
|
|
524
541
|
heldControl: { transform: [{ scale: 1.07 }] },
|
|
525
542
|
heldLabel: { opacity: 0.2 },
|
|
543
|
+
// 18 tall, taller with a larger text size: the capsule grows round its digits
|
|
544
|
+
count: { minWidth: 18, minHeight: 18, paddingHorizontal: 5, borderRadius: 999, alignItems: "center", justifyContent: "center" },
|
|
545
|
+
countText: { fontSize: 12, lineHeight: 16, fontVariant: ["tabular-nums"] },
|
|
526
546
|
thumb: { position: "absolute", borderCurve: "continuous" },
|
|
527
547
|
option: { alignItems: "center", justifyContent: "center", minWidth: 0 },
|
|
528
548
|
label: { flexDirection: "row", alignItems: "center", justifyContent: "center", gap: 8 },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useContext, useEffect, useLayoutEffect, useState, type ReactNode } from "react"
|
|
2
|
-
import { Platform,
|
|
2
|
+
import { Platform, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import Svg, { Path } from "react-native-svg"
|
|
4
5
|
import ChevronUpDown from "../../icons/plex/ChevronUpDown"
|
|
5
6
|
import { spaceToggles } from "../../internal/a11y"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react"
|
|
2
|
-
import { Animated, Platform,
|
|
2
|
+
import { Animated, Platform, StyleSheet, View, type AccessibilityActionEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import Minus from "../../icons/plex/Minus"
|
|
4
5
|
import Plus from "../../icons/plex/Plus"
|
|
5
6
|
import RemoveTrash from "../../icons/plex/RemoveTrash"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useContext, useEffect, useState, type ReactNode } from "react"
|
|
2
|
-
import { Animated, Easing,
|
|
2
|
+
import { Animated, Easing, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import { spaceToggles, useDescription } from "../../internal/a11y"
|
|
4
5
|
import { ControlLabel } from "../../internal/ControlLabel"
|
|
5
6
|
import { RowEndContext, RowHoldContext, rowHold } from "../../internal/row"
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
import { createContext, useCallback, useContext, useEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
Easing,
|
|
5
|
-
Pressable,
|
|
6
|
-
StyleSheet,
|
|
7
|
-
View,
|
|
8
|
-
type LayoutChangeEvent,
|
|
9
|
-
type NativeScrollEvent,
|
|
10
|
-
type NativeSyntheticEvent,
|
|
11
|
-
type StyleProp,
|
|
12
|
-
type ViewProps,
|
|
13
|
-
type ViewStyle,
|
|
14
|
-
} from "react-native"
|
|
2
|
+
import { Animated, Easing, StyleSheet, View, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type StyleProp, type ViewProps, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
15
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
|
16
5
|
import Search from "../../icons/plex/Search"
|
|
17
6
|
import { BarBackdrop, SoftBottomEdge, TabBarFade, ANDROID_FADE_ALPHA, ANDROID_FADE_STOPS, glassBarBlur, useAndroidGlass } from "../../internal/BarBackdrop"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useContext, useRef, useState, type ComponentRef } from "react"
|
|
2
|
-
import {
|
|
2
|
+
import { StyleSheet, TextInput, View, type StyleProp, type TextInputKeyPressEvent, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import X from "../../icons/plex/X"
|
|
4
5
|
import { RowEndContext } from "../../internal/row"
|
|
5
6
|
import { dangerText, withAlpha } from "../../theme/material"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cloneElement, isValidElement, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
-
import {
|
|
2
|
+
import { StyleSheet, View, useWindowDimensions, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import Svg, { Path } from "react-native-svg"
|
|
4
5
|
import X from "../../icons/plex/X"
|
|
5
6
|
import { flattenChildren, isRenderable, textOf } from "../../internal/children"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore, type ReactNode } from "react"
|
|
2
|
-
import { AccessibilityInfo, Animated, Easing, PanResponder, PixelRatio, Platform,
|
|
2
|
+
import { AccessibilityInfo, Animated, Easing, PanResponder, PixelRatio, Platform, StyleSheet, View, useWindowDimensions } from "react-native"
|
|
3
|
+
import { Pressable } from "../../internal/Pressable"
|
|
3
4
|
import { useSafeAreaInsets } from "react-native-safe-area-context"
|
|
4
5
|
import CheckCircle from "../../icons/plex/CheckCircle"
|
|
5
6
|
import InfoCircle from "../../icons/plex/InfoCircle"
|
package/src/index.ts
CHANGED
|
@@ -91,7 +91,8 @@ export { Toaster, toast, type ToasterProps, type ToastId, type ToastOptions, typ
|
|
|
91
91
|
|
|
92
92
|
export { Avatar, AvatarGroup, type AvatarColor, type AvatarGroupProps, type AvatarProps, type AvatarVariant } from "./components/Avatar/Avatar"
|
|
93
93
|
export { Badge, type BadgeColor, type BadgeProps, type BadgeSize, type BadgeVariant } from "./components/Badge/Badge"
|
|
94
|
-
export { BottomActions, type BottomActionsProps } from "./components/BottomActions/BottomActions"
|
|
94
|
+
export { BottomActions, type BottomActionsBackground, type BottomActionsProps } from "./components/BottomActions/BottomActions"
|
|
95
|
+
export { IntroHeader, type IntroHeaderAlign, type IntroHeaderProps } from "./components/IntroHeader/IntroHeader"
|
|
95
96
|
export { Card, cardColors, type CardColor, type CardMediaProps, type CardProps, type CardSize, type CardVariant } from "./components/Card/Card"
|
|
96
97
|
export { List, ListItem, type ListItemProps, type ListProps } from "./components/List/List"
|
|
97
98
|
export { Chip, type ChipProps } from "./components/Chip/Chip"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { forwardRef, type ComponentRef } from "react"
|
|
2
|
+
import { Platform, Pressable as NativePressable, type PressableProps } from "react-native"
|
|
3
|
+
|
|
4
|
+
// A press target takes no text selection on the web: a drag or a long press over a row, a button or a segment selects
|
|
5
|
+
// nothing, as on iOS and Android, where a control's label is never selectable
|
|
6
|
+
const NO_SELECT = Platform.OS === "web" ? ({ userSelect: "none" } as object) : null
|
|
7
|
+
|
|
8
|
+
/** react-native's Pressable that selects no text on the web; every pressable control of the kit is drawn with it. */
|
|
9
|
+
export const Pressable = forwardRef<ComponentRef<typeof NativePressable>, PressableProps>(function Pressable({ style, ...props }, ref) {
|
|
10
|
+
return (
|
|
11
|
+
<NativePressable
|
|
12
|
+
ref={ref}
|
|
13
|
+
{...props}
|
|
14
|
+
style={typeof style === "function" ? (state) => [NO_SELECT, style(state)] : [NO_SELECT, style]}
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
17
|
+
})
|
package/src/theme/material.ts
CHANGED
|
@@ -242,13 +242,20 @@ export const elevationShadow = {
|
|
|
242
242
|
|
|
243
243
|
/** A color with its alpha multiplied: a state layer or a disabled container. */
|
|
244
244
|
export function withAlpha(color: string, alpha: number): string {
|
|
245
|
-
// `#rrggbb(aa)`, `rgb()
|
|
245
|
+
// `#rgb(a)`, `#rrggbb(aa)`, `rgb()`, `rgba()`, `white` or `black`; any other form is returned as it is
|
|
246
246
|
const c = channels(color)
|
|
247
247
|
return c ? `rgba(${c[0]}, ${c[1]}, ${c[2]}, ${Math.round(c[3] * alpha * 1000) / 1000})` : color
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
/** The channels of a `#rrggbb(aa)
|
|
250
|
+
/** The channels of a `#rgb(a)`, `#rrggbb(aa)`, `rgb(a)()`, `white` or `black` color, alpha 0–1; undefined for any other form. */
|
|
251
251
|
function channels(color: string): [number, number, number, number] | undefined {
|
|
252
|
+
// `#rgb(a)` reads as `#rrggbb(aa)`; `white` and `black`, the names a canvas is likeliest to be given
|
|
253
|
+
if (color === "white") return [255, 255, 255, 1]
|
|
254
|
+
if (color === "black") return [0, 0, 0, 1]
|
|
255
|
+
if (color.startsWith("#") && (color.length === 4 || color.length === 5)) {
|
|
256
|
+
const [r, g, b, a = "f"] = color.slice(1)
|
|
257
|
+
return [parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16), parseInt(a + a, 16) / 255]
|
|
258
|
+
}
|
|
252
259
|
if (color.startsWith("#") && (color.length === 7 || color.length === 9)) {
|
|
253
260
|
const a = color.length === 9 ? parseInt(color.slice(7, 9), 16) / 255 : 1
|
|
254
261
|
return [parseInt(color.slice(1, 3), 16), parseInt(color.slice(3, 5), 16), parseInt(color.slice(5, 7), 16), a]
|