glacia-native 0.3.5 → 0.5.0
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/lib/module/Bars.js +176 -0
- package/lib/module/Button.js +15 -2
- package/lib/module/Card.js +29 -14
- package/lib/module/Carousel.js +103 -0
- package/lib/module/Dialog.js +43 -32
- package/lib/module/Display.js +240 -0
- package/lib/module/Feedback.js +172 -0
- package/lib/module/Form.js +51 -12
- package/lib/module/Forms2.js +227 -0
- package/lib/module/Glass.js +11 -2
- package/lib/module/Input.js +19 -7
- package/lib/module/Overlays.js +166 -0
- package/lib/module/Pickers.js +243 -0
- package/lib/module/SegmentedControl.js +65 -21
- package/lib/module/Slider.js +121 -25
- package/lib/module/Switch.js +33 -15
- package/lib/module/TabBar.js +63 -25
- package/lib/module/Table.js +24 -6
- package/lib/module/Tabs.js +55 -33
- package/lib/module/Text.js +37 -0
- package/lib/module/ai.js +49 -20
- package/lib/module/charts/BarChart.js +4 -2
- package/lib/module/charts/FunnelChart.js +4 -2
- package/lib/module/charts/HeatmapChart.js +4 -2
- package/lib/module/charts/LineChart.js +4 -2
- package/lib/module/charts/PlotChart.js +11 -3
- package/lib/module/charts/RadarChart.js +4 -2
- package/lib/module/charts/RingChart.js +4 -2
- package/lib/module/charts/ScatterChart.js +20 -3
- package/lib/module/charts/WaterfallChart.js +12 -3
- package/lib/module/charts/advanced.js +12 -6
- package/lib/module/charts/extra.js +6 -3
- package/lib/module/index.js +58 -1
- package/lib/module/internal/GlassView.js +31 -17
- package/lib/module/internal/fallback.js +14 -3
- package/lib/module/internal/glass-routing.js +56 -0
- package/lib/module/internal/motion.js +55 -0
- package/lib/module/internal/primitives.js +413 -0
- package/lib/module/internal/tokens.js +55 -1
- package/lib/typescript/Bars.d.ts +121 -0
- package/lib/typescript/Button.d.ts +11 -1
- package/lib/typescript/Card.d.ts +20 -8
- package/lib/typescript/Carousel.d.ts +47 -0
- package/lib/typescript/Dialog.d.ts +19 -6
- package/lib/typescript/Display.d.ts +119 -0
- package/lib/typescript/Feedback.d.ts +138 -0
- package/lib/typescript/Form.d.ts +27 -11
- package/lib/typescript/Forms2.d.ts +128 -0
- package/lib/typescript/Glass.d.ts +10 -1
- package/lib/typescript/Input.d.ts +11 -1
- package/lib/typescript/Overlays.d.ts +105 -0
- package/lib/typescript/Pickers.d.ts +105 -0
- package/lib/typescript/SegmentedControl.d.ts +11 -1
- package/lib/typescript/Slider.d.ts +13 -1
- package/lib/typescript/Switch.d.ts +12 -1
- package/lib/typescript/TabBar.d.ts +13 -1
- package/lib/typescript/Table.d.ts +14 -5
- package/lib/typescript/Tabs.d.ts +8 -5
- package/lib/typescript/Text.d.ts +28 -0
- package/lib/typescript/ai.d.ts +12 -9
- package/lib/typescript/charts/BarChart.d.ts +1 -1
- package/lib/typescript/charts/FunnelChart.d.ts +1 -1
- package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
- package/lib/typescript/charts/LineChart.d.ts +1 -1
- package/lib/typescript/charts/PlotChart.d.ts +1 -1
- package/lib/typescript/charts/RadarChart.d.ts +1 -1
- package/lib/typescript/charts/RingChart.d.ts +1 -1
- package/lib/typescript/charts/ScatterChart.d.ts +1 -1
- package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
- package/lib/typescript/charts/advanced.d.ts +5 -5
- package/lib/typescript/charts/extra.d.ts +2 -2
- package/lib/typescript/index.d.ts +9 -1
- package/lib/typescript/internal/GlassView.d.ts +21 -4
- package/lib/typescript/internal/fallback.d.ts +10 -1
- package/lib/typescript/internal/glass-routing.d.ts +30 -0
- package/lib/typescript/internal/motion.d.ts +19 -0
- package/lib/typescript/internal/primitives.d.ts +41 -0
- package/lib/typescript/internal/tokens.d.ts +61 -0
- package/package.json +2 -2
- package/src/Bars.tsx +570 -0
- package/src/Button.tsx +47 -22
- package/src/Card.tsx +52 -31
- package/src/Carousel.tsx +233 -0
- package/src/Dialog.tsx +99 -64
- package/src/Display.tsx +550 -0
- package/src/Feedback.tsx +579 -0
- package/src/Form.tsx +90 -25
- package/src/Forms2.tsx +608 -0
- package/src/Glass.tsx +24 -1
- package/src/Input.tsx +33 -12
- package/src/Overlays.tsx +474 -0
- package/src/Pickers.tsx +590 -0
- package/src/SegmentedControl.tsx +104 -32
- package/src/Slider.tsx +151 -47
- package/src/Switch.tsx +56 -32
- package/src/TabBar.tsx +100 -30
- package/src/Table.tsx +38 -14
- package/src/Tabs.tsx +85 -32
- package/src/Text.tsx +83 -0
- package/src/ai.tsx +77 -31
- package/src/charts/BarChart.tsx +4 -2
- package/src/charts/FunnelChart.tsx +4 -2
- package/src/charts/HeatmapChart.tsx +4 -2
- package/src/charts/LineChart.tsx +4 -2
- package/src/charts/PlotChart.tsx +23 -3
- package/src/charts/RadarChart.tsx +4 -2
- package/src/charts/RingChart.tsx +4 -2
- package/src/charts/ScatterChart.tsx +24 -3
- package/src/charts/WaterfallChart.tsx +21 -3
- package/src/charts/advanced.tsx +12 -6
- package/src/charts/extra.tsx +6 -3
- package/src/index.ts +101 -1
- package/src/internal/GlassView.tsx +51 -19
- package/src/internal/fallback.tsx +23 -8
- package/src/internal/glass-routing.ts +68 -0
- package/src/internal/motion.ts +60 -0
- package/src/internal/primitives.ts +482 -0
- package/src/internal/tokens.ts +62 -0
- package/lib/module/charts/primitives.js +0 -212
- package/lib/typescript/charts/primitives.d.ts +0 -23
- package/src/charts/primitives.ts +0 -262
package/src/Card.tsx
CHANGED
|
@@ -1,120 +1,141 @@
|
|
|
1
1
|
import { forwardRef, type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
3
|
+
|
|
2
4
|
import { Glass } from "./Glass";
|
|
3
5
|
import { colors, radii } from "./internal/tokens";
|
|
6
|
+
import { primitives } from "./internal/primitives";
|
|
7
|
+
import { useIsDark } from "./internal/motion";
|
|
4
8
|
|
|
5
9
|
export interface CardProps {
|
|
6
10
|
effect?: "clear" | "regular" | "none";
|
|
7
|
-
style?:
|
|
11
|
+
style?: StyleProp<ViewStyle>;
|
|
8
12
|
children?: ReactNode;
|
|
9
13
|
isDark?: boolean;
|
|
14
|
+
/** Passed through to the card's glass so it is testable. */
|
|
15
|
+
testID?: string;
|
|
10
16
|
}
|
|
11
17
|
|
|
18
|
+
/**
|
|
19
|
+
* A content panel on Glacia's glass: Apple's material on iOS 26+, Glacia's
|
|
20
|
+
* tint elsewhere. The padding, radius and stacking are ours on every platform.
|
|
21
|
+
*/
|
|
12
22
|
export const Card = forwardRef<any, CardProps>(function Card(
|
|
13
|
-
{ effect = "regular", style, children, isDark
|
|
23
|
+
{ effect = "regular", style, children, isDark: isDarkProp, testID, ...props },
|
|
14
24
|
ref,
|
|
15
25
|
) {
|
|
16
|
-
const
|
|
26
|
+
const isDark = useIsDark(isDarkProp);
|
|
27
|
+
|
|
28
|
+
const cardStyle: ViewStyle = {
|
|
17
29
|
padding: 20,
|
|
18
30
|
borderRadius: radii.lg,
|
|
19
|
-
|
|
20
|
-
flexDirection: "column" as const,
|
|
31
|
+
flexDirection: "column",
|
|
21
32
|
gap: 12,
|
|
22
|
-
...style,
|
|
33
|
+
...(style as ViewStyle),
|
|
23
34
|
};
|
|
24
35
|
|
|
25
36
|
return (
|
|
26
|
-
<Glass ref={ref} effect={effect} style={cardStyle} {...props}>
|
|
37
|
+
<Glass ref={ref} effect={effect} isDark={isDark} style={cardStyle} testID={testID} {...props}>
|
|
27
38
|
{children}
|
|
28
39
|
</Glass>
|
|
29
40
|
);
|
|
30
41
|
});
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
/** The block holding a card's title and description. */
|
|
44
|
+
export function CardHeader({ style, children, ...props }: { style?: StyleProp<ViewStyle>; children?: ReactNode }) {
|
|
45
|
+
const { View } = primitives();
|
|
33
46
|
return (
|
|
34
|
-
<
|
|
47
|
+
<View style={{ flexDirection: "column", gap: 4, ...(style as ViewStyle) }} {...props}>
|
|
35
48
|
{children}
|
|
36
|
-
</
|
|
49
|
+
</View>
|
|
37
50
|
);
|
|
38
51
|
}
|
|
39
52
|
|
|
53
|
+
/** A card's heading, announced as a heading by screen readers. */
|
|
40
54
|
export function CardTitle({
|
|
41
55
|
style,
|
|
42
56
|
children,
|
|
43
|
-
isDark
|
|
57
|
+
isDark: isDarkProp,
|
|
44
58
|
...props
|
|
45
59
|
}: {
|
|
46
|
-
style?:
|
|
60
|
+
style?: StyleProp<TextStyle>;
|
|
47
61
|
children?: ReactNode;
|
|
48
62
|
isDark?: boolean;
|
|
49
63
|
}) {
|
|
64
|
+
const isDark = useIsDark(isDarkProp);
|
|
50
65
|
const themeColors = isDark ? colors.dark : colors.light;
|
|
66
|
+
const { Text } = primitives();
|
|
51
67
|
return (
|
|
52
|
-
<
|
|
68
|
+
<Text
|
|
69
|
+
accessibilityRole="heading"
|
|
53
70
|
style={{
|
|
54
|
-
margin: 0,
|
|
55
71
|
fontSize: 18,
|
|
56
|
-
fontWeight: 600,
|
|
72
|
+
fontWeight: "600",
|
|
57
73
|
color: themeColors.foreground,
|
|
58
|
-
...style,
|
|
74
|
+
...(style as TextStyle),
|
|
59
75
|
}}
|
|
60
76
|
{...props}
|
|
61
77
|
>
|
|
62
78
|
{children}
|
|
63
|
-
</
|
|
79
|
+
</Text>
|
|
64
80
|
);
|
|
65
81
|
}
|
|
66
82
|
|
|
83
|
+
/** Supporting text under a card's title. */
|
|
67
84
|
export function CardDescription({
|
|
68
85
|
style,
|
|
69
86
|
children,
|
|
70
|
-
isDark
|
|
87
|
+
isDark: isDarkProp,
|
|
71
88
|
...props
|
|
72
89
|
}: {
|
|
73
|
-
style?:
|
|
90
|
+
style?: StyleProp<TextStyle>;
|
|
74
91
|
children?: ReactNode;
|
|
75
92
|
isDark?: boolean;
|
|
76
93
|
}) {
|
|
94
|
+
const isDark = useIsDark(isDarkProp);
|
|
77
95
|
const themeColors = isDark ? colors.dark : colors.light;
|
|
96
|
+
const { Text } = primitives();
|
|
78
97
|
return (
|
|
79
|
-
<
|
|
98
|
+
<Text
|
|
80
99
|
style={{
|
|
81
|
-
margin: 0,
|
|
82
100
|
fontSize: 13,
|
|
83
101
|
color: themeColors.muted,
|
|
84
|
-
...style,
|
|
102
|
+
...(style as TextStyle),
|
|
85
103
|
}}
|
|
86
104
|
{...props}
|
|
87
105
|
>
|
|
88
106
|
{children}
|
|
89
|
-
</
|
|
107
|
+
</Text>
|
|
90
108
|
);
|
|
91
109
|
}
|
|
92
110
|
|
|
93
|
-
|
|
111
|
+
/** The card's body. */
|
|
112
|
+
export function CardContent({ style, children, ...props }: { style?: StyleProp<ViewStyle>; children?: ReactNode }) {
|
|
113
|
+
const { View } = primitives();
|
|
94
114
|
return (
|
|
95
|
-
<
|
|
115
|
+
<View style={{ flexDirection: "column", gap: 8, ...(style as ViewStyle) }} {...props}>
|
|
96
116
|
{children}
|
|
97
|
-
</
|
|
117
|
+
</View>
|
|
98
118
|
);
|
|
99
119
|
}
|
|
100
120
|
|
|
101
121
|
export const CardBody = CardContent;
|
|
102
122
|
|
|
103
|
-
|
|
123
|
+
/** The card's action row. */
|
|
124
|
+
export function CardFooter({ style, children, ...props }: { style?: StyleProp<ViewStyle>; children?: ReactNode }) {
|
|
125
|
+
const { View } = primitives();
|
|
104
126
|
return (
|
|
105
|
-
<
|
|
127
|
+
<View
|
|
106
128
|
style={{
|
|
107
|
-
display: "flex",
|
|
108
129
|
flexDirection: "row",
|
|
109
130
|
alignItems: "center",
|
|
110
131
|
justifyContent: "flex-end",
|
|
111
132
|
gap: 8,
|
|
112
133
|
paddingTop: 8,
|
|
113
|
-
...style,
|
|
134
|
+
...(style as ViewStyle),
|
|
114
135
|
}}
|
|
115
136
|
{...props}
|
|
116
137
|
>
|
|
117
138
|
{children}
|
|
118
|
-
</
|
|
139
|
+
</View>
|
|
119
140
|
);
|
|
120
141
|
}
|
package/src/Carousel.tsx
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { forwardRef, useRef, useState, type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { colors } from "./internal/tokens";
|
|
5
|
+
import { primitives } from "./internal/primitives";
|
|
6
|
+
import { useIsDark, useSpring } from "./internal/motion";
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// Carousel
|
|
10
|
+
|
|
11
|
+
export interface CarouselProps {
|
|
12
|
+
/** One node per page. */
|
|
13
|
+
slides: ReactNode[];
|
|
14
|
+
/** Controlled page. Omit and the carousel tracks itself. */
|
|
15
|
+
index?: number;
|
|
16
|
+
defaultIndex?: number;
|
|
17
|
+
/** Fires when a swipe settles on a new page. */
|
|
18
|
+
onIndexChange?: (index: number) => void;
|
|
19
|
+
/** Gap between pages, so neighbours peek at the edges. */
|
|
20
|
+
gap?: number;
|
|
21
|
+
style?: StyleProp<ViewStyle>;
|
|
22
|
+
isDark?: boolean;
|
|
23
|
+
testID?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A horizontally paging swiper.
|
|
28
|
+
*
|
|
29
|
+
* It rides the resolver's ScrollView with `pagingEnabled`, so the paging feel is
|
|
30
|
+
* the platform's own and the pages are plain content the caller supplies. The
|
|
31
|
+
* active page is derived from the scroll offset, which is also what reports
|
|
32
|
+
* `onIndexChange`.
|
|
33
|
+
*/
|
|
34
|
+
export const Carousel = forwardRef<any, CarouselProps>(function Carousel(
|
|
35
|
+
{
|
|
36
|
+
slides,
|
|
37
|
+
index: indexProp,
|
|
38
|
+
defaultIndex = 0,
|
|
39
|
+
onIndexChange,
|
|
40
|
+
gap = 0,
|
|
41
|
+
style,
|
|
42
|
+
isDark: isDarkProp,
|
|
43
|
+
testID,
|
|
44
|
+
...props
|
|
45
|
+
},
|
|
46
|
+
ref,
|
|
47
|
+
) {
|
|
48
|
+
const isDark = useIsDark(isDarkProp);
|
|
49
|
+
const { getScrollView } = primitives();
|
|
50
|
+
const ScrollView = getScrollView();
|
|
51
|
+
const { View } = primitives();
|
|
52
|
+
|
|
53
|
+
const [internalIndex, setInternalIndex] = useState(defaultIndex);
|
|
54
|
+
const index = indexProp !== undefined ? indexProp : internalIndex;
|
|
55
|
+
|
|
56
|
+
const viewportWidth = useRef(0);
|
|
57
|
+
const scrollRef = useRef<any>(null);
|
|
58
|
+
|
|
59
|
+
// Derives the page from the offset rather than trusting a counter, so a
|
|
60
|
+
// fast swipe that skips pages still reports the page it landed on.
|
|
61
|
+
const handleScroll = (event: any) => {
|
|
62
|
+
const { contentOffset, layoutMeasurement } = event?.nativeEvent ?? {};
|
|
63
|
+
const width = layoutMeasurement?.width || viewportWidth.current;
|
|
64
|
+
if (!width || !contentOffset) return;
|
|
65
|
+
const next = Math.round(contentOffset.x / width);
|
|
66
|
+
const clamped = Math.min(Math.max(next, 0), Math.max(slides.length - 1, 0));
|
|
67
|
+
if (clamped !== index) {
|
|
68
|
+
if (indexProp === undefined) setInternalIndex(clamped);
|
|
69
|
+
onIndexChange?.(clamped);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const pages = slides.map((slide, i) => (
|
|
74
|
+
<View key={i} style={{ width: viewportWidth.current || "100%", paddingRight: gap }}>
|
|
75
|
+
{slide}
|
|
76
|
+
</View>
|
|
77
|
+
));
|
|
78
|
+
|
|
79
|
+
// Off-device there is no ScrollView; the pages still render in a row so the
|
|
80
|
+
// component mounts, and the tests drive `handleScroll` through onScroll.
|
|
81
|
+
if (!ScrollView) {
|
|
82
|
+
return (
|
|
83
|
+
<View ref={ref} testID={testID} style={[{ flexDirection: "row", overflow: "hidden" }, style as ViewStyle]} {...props}>
|
|
84
|
+
{pages}
|
|
85
|
+
</View>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<View
|
|
91
|
+
ref={ref}
|
|
92
|
+
testID={testID}
|
|
93
|
+
onLayout={(event: any) => {
|
|
94
|
+
viewportWidth.current = event?.nativeEvent?.layout?.width ?? 0;
|
|
95
|
+
}}
|
|
96
|
+
style={style as ViewStyle}
|
|
97
|
+
{...props}
|
|
98
|
+
>
|
|
99
|
+
<ScrollView
|
|
100
|
+
ref={scrollRef}
|
|
101
|
+
horizontal
|
|
102
|
+
pagingEnabled={gap === 0}
|
|
103
|
+
showsHorizontalScrollIndicator={false}
|
|
104
|
+
onScroll={handleScroll}
|
|
105
|
+
scrollEventThrottle={16}
|
|
106
|
+
accessibilityRole="adjustable"
|
|
107
|
+
accessibilityLabel="Carousel"
|
|
108
|
+
accessibilityValue={{ min: 0, max: Math.max(slides.length - 1, 0), now: index }}
|
|
109
|
+
accessibilityActions={[{ name: "increment" }, { name: "decrement" }]}
|
|
110
|
+
onAccessibilityAction={(event: any) => {
|
|
111
|
+
const step = event?.nativeEvent?.actionName === "increment" ? 1 : -1;
|
|
112
|
+
const next = Math.min(Math.max(index + step, 0), Math.max(slides.length - 1, 0));
|
|
113
|
+
if (next === index) return;
|
|
114
|
+
if (indexProp === undefined) setInternalIndex(next);
|
|
115
|
+
onIndexChange?.(next);
|
|
116
|
+
}}
|
|
117
|
+
>
|
|
118
|
+
{pages}
|
|
119
|
+
</ScrollView>
|
|
120
|
+
</View>
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// PageControl
|
|
126
|
+
|
|
127
|
+
export interface PageControlProps {
|
|
128
|
+
count: number;
|
|
129
|
+
/** Controlled active page. Omit and the control keeps its own. */
|
|
130
|
+
activeIndex?: number;
|
|
131
|
+
defaultActiveIndex?: number;
|
|
132
|
+
/** Called when a dot is tapped. */
|
|
133
|
+
onChange?: (index: number) => void;
|
|
134
|
+
/** Tint the active dot; defaults to the theme accent. */
|
|
135
|
+
tint?: string;
|
|
136
|
+
/** Hide the dots when there is only one page. */
|
|
137
|
+
hidesForSinglePage?: boolean;
|
|
138
|
+
style?: StyleProp<ViewStyle>;
|
|
139
|
+
isDark?: boolean;
|
|
140
|
+
testID?: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const DOT = 7;
|
|
144
|
+
const ACTIVE_DOT = 18;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The page dots.
|
|
148
|
+
*
|
|
149
|
+
* The active dot elongates and the others stay narrow, which is how iOS reads
|
|
150
|
+
* "you are here". The width change runs on the springs token through Animated.
|
|
151
|
+
*/
|
|
152
|
+
export const PageControl = forwardRef<any, PageControlProps>(function PageControl(
|
|
153
|
+
{
|
|
154
|
+
count,
|
|
155
|
+
activeIndex: activeProp,
|
|
156
|
+
defaultActiveIndex = 0,
|
|
157
|
+
onChange,
|
|
158
|
+
tint,
|
|
159
|
+
hidesForSinglePage = false,
|
|
160
|
+
style,
|
|
161
|
+
isDark: isDarkProp,
|
|
162
|
+
testID,
|
|
163
|
+
...props
|
|
164
|
+
},
|
|
165
|
+
ref,
|
|
166
|
+
) {
|
|
167
|
+
const isDark = useIsDark(isDarkProp);
|
|
168
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
169
|
+
const { View, Pressable } = primitives();
|
|
170
|
+
|
|
171
|
+
const [internalIndex, setInternalIndex] = useState(defaultActiveIndex);
|
|
172
|
+
const active = activeProp !== undefined ? activeProp : internalIndex;
|
|
173
|
+
|
|
174
|
+
if (hidesForSinglePage && count <= 1) return null;
|
|
175
|
+
|
|
176
|
+
// The accent tints the active dot; the resting dots sit on `glassActive` so
|
|
177
|
+
// selection reads the same way it does in SegmentedControl and TabBar.
|
|
178
|
+
const accent = tint ?? theme.fill;
|
|
179
|
+
const resting = theme.glassActive;
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<View
|
|
183
|
+
ref={ref}
|
|
184
|
+
testID={testID}
|
|
185
|
+
accessibilityRole="tablist"
|
|
186
|
+
style={[{ flexDirection: "row", alignItems: "center", gap: 6, alignSelf: "center" }, style as ViewStyle]}
|
|
187
|
+
{...props}
|
|
188
|
+
>
|
|
189
|
+
{Array.from({ length: Math.max(count, 0) }, (_, index) => {
|
|
190
|
+
const isActive = index === active;
|
|
191
|
+
return (
|
|
192
|
+
<Pressable
|
|
193
|
+
key={index}
|
|
194
|
+
accessibilityRole="tab"
|
|
195
|
+
accessibilityLabel={`Page ${index + 1} of ${count}`}
|
|
196
|
+
accessibilityState={{ selected: isActive }}
|
|
197
|
+
onPress={() => {
|
|
198
|
+
if (activeProp === undefined) setInternalIndex(index);
|
|
199
|
+
onChange?.(index);
|
|
200
|
+
}}
|
|
201
|
+
hitSlop={8}
|
|
202
|
+
>
|
|
203
|
+
<Dot active={isActive} accent={accent} muted={resting} />
|
|
204
|
+
</Pressable>
|
|
205
|
+
);
|
|
206
|
+
})}
|
|
207
|
+
</View>
|
|
208
|
+
);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
/** One dot, whose width springs between the resting and active lengths. */
|
|
212
|
+
function Dot({ active, accent, muted }: { active: boolean; accent: string; muted: string }) {
|
|
213
|
+
const { Animated, View } = primitives();
|
|
214
|
+
const { value: progress, animated } = useSpring(active ? 1 : 0, "snappy");
|
|
215
|
+
|
|
216
|
+
const width = animated
|
|
217
|
+
? progress.interpolate({ inputRange: [0, 1], outputRange: [DOT, ACTIVE_DOT] })
|
|
218
|
+
: active
|
|
219
|
+
? ACTIVE_DOT
|
|
220
|
+
: DOT;
|
|
221
|
+
|
|
222
|
+
const style: ViewStyle = {
|
|
223
|
+
height: DOT,
|
|
224
|
+
borderRadius: DOT / 2,
|
|
225
|
+
backgroundColor: active ? accent : muted,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
return animated ? (
|
|
229
|
+
<Animated.View style={{ ...style, width }} />
|
|
230
|
+
) : (
|
|
231
|
+
<View style={{ ...style, width: width as number }} />
|
|
232
|
+
);
|
|
233
|
+
}
|
package/src/Dialog.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState, type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
2
3
|
|
|
3
4
|
import { colors, radii } from "./internal/tokens";
|
|
4
|
-
import { primitives } from "./
|
|
5
|
+
import { primitives } from "./internal/primitives";
|
|
6
|
+
import { useIsDark } from "./internal/motion";
|
|
7
|
+
import { Glass } from "./Glass";
|
|
5
8
|
import { Button } from "./Button";
|
|
6
9
|
|
|
7
10
|
export interface DialogProps {
|
|
8
|
-
/** Controlled visibility. Omit
|
|
11
|
+
/** Controlled visibility. Omit it and the dialog keeps its own state. */
|
|
9
12
|
open?: boolean;
|
|
10
13
|
onOpenChange?: (open: boolean) => void;
|
|
11
14
|
title?: string;
|
|
@@ -15,16 +18,24 @@ export interface DialogProps {
|
|
|
15
18
|
/** Tapping the backdrop dismisses. Off for destructive confirmations. */
|
|
16
19
|
dismissOnBackdropPress?: boolean;
|
|
17
20
|
isDark?: boolean;
|
|
18
|
-
style?:
|
|
21
|
+
style?: StyleProp<ViewStyle>;
|
|
22
|
+
/** Passed through to the dialog panel so it is testable. */
|
|
23
|
+
testID?: string;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
|
-
* A centred modal
|
|
27
|
+
* A centred modal panel above a dimmed backdrop.
|
|
28
|
+
*
|
|
29
|
+
* The panel is a glass surface, so it is Apple's real Liquid Glass on iOS 26+
|
|
30
|
+
* and Glacia's translucent tint elsewhere; the text sits on it with the
|
|
31
|
+
* theme's foreground colour, so contrast holds either way.
|
|
23
32
|
*
|
|
24
33
|
* React Native has no built-in focus trap, so this component covers what the
|
|
25
34
|
* platform can actually do: `Modal` blocks touches behind it, Android's back
|
|
26
35
|
* button routes to `onOpenChange(false)`, and the heading is marked as such so
|
|
27
36
|
* screen readers announce the dialog as it appears.
|
|
37
|
+
*
|
|
38
|
+
* To open a dialog from a button, use `DialogTrigger`.
|
|
28
39
|
*/
|
|
29
40
|
export function Dialog({
|
|
30
41
|
open: controlledOpen,
|
|
@@ -34,9 +45,11 @@ export function Dialog({
|
|
|
34
45
|
children,
|
|
35
46
|
footer,
|
|
36
47
|
dismissOnBackdropPress = true,
|
|
37
|
-
isDark
|
|
48
|
+
isDark: isDarkProp,
|
|
38
49
|
style,
|
|
50
|
+
testID,
|
|
39
51
|
}: DialogProps) {
|
|
52
|
+
const isDark = useIsDark(isDarkProp);
|
|
40
53
|
const theme = isDark ? colors.dark : colors.light;
|
|
41
54
|
const { View, Text, Pressable, Modal, getBackHandler } = primitives();
|
|
42
55
|
|
|
@@ -86,34 +99,38 @@ export function Dialog({
|
|
|
86
99
|
<Pressable
|
|
87
100
|
accessibilityRole="none"
|
|
88
101
|
onPress={() => {}}
|
|
89
|
-
style={{
|
|
90
|
-
width: "100%",
|
|
91
|
-
maxWidth: 380,
|
|
92
|
-
borderRadius: radii.lg,
|
|
93
|
-
borderWidth: 1,
|
|
94
|
-
borderColor: theme.edge,
|
|
95
|
-
backgroundColor: isDark ? "#1c1c1e" : "#ffffff",
|
|
96
|
-
padding: 20,
|
|
97
|
-
gap: 8,
|
|
98
|
-
...style,
|
|
99
|
-
}}
|
|
102
|
+
style={{ width: "100%", maxWidth: 380 }}
|
|
100
103
|
>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
<Glass
|
|
105
|
+
effect="regular"
|
|
106
|
+
isDark={isDark}
|
|
107
|
+
testID={testID}
|
|
108
|
+
style={{
|
|
109
|
+
borderRadius: radii.lg,
|
|
110
|
+
borderWidth: 1,
|
|
111
|
+
borderColor: theme.edge,
|
|
112
|
+
padding: 20,
|
|
113
|
+
gap: 8,
|
|
114
|
+
...(style as ViewStyle),
|
|
115
|
+
}}
|
|
116
|
+
>
|
|
117
|
+
{title && (
|
|
118
|
+
<Text
|
|
119
|
+
accessibilityRole="heading"
|
|
120
|
+
style={{ fontSize: 17, fontWeight: "600", color: theme.foreground }}
|
|
121
|
+
>
|
|
122
|
+
{title}
|
|
123
|
+
</Text>
|
|
124
|
+
)}
|
|
109
125
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
126
|
+
{description && (
|
|
127
|
+
<Text style={{ fontSize: 13, color: theme.muted, lineHeight: 18 }}>{description}</Text>
|
|
128
|
+
)}
|
|
113
129
|
|
|
114
|
-
|
|
130
|
+
{children}
|
|
115
131
|
|
|
116
|
-
|
|
132
|
+
{footer && <View style={{ marginTop: 12, gap: 8 }}>{footer}</View>}
|
|
133
|
+
</Glass>
|
|
117
134
|
</Pressable>
|
|
118
135
|
</Pressable>
|
|
119
136
|
</Modal>
|
|
@@ -150,6 +167,8 @@ export interface AlertDialogProps {
|
|
|
150
167
|
onConfirm?: () => void;
|
|
151
168
|
onCancel?: () => void;
|
|
152
169
|
isDark?: boolean;
|
|
170
|
+
/** Passed through to the dialog panel so it is testable. */
|
|
171
|
+
testID?: string;
|
|
153
172
|
}
|
|
154
173
|
|
|
155
174
|
/**
|
|
@@ -169,8 +188,10 @@ export function AlertDialog({
|
|
|
169
188
|
destructive = false,
|
|
170
189
|
onConfirm,
|
|
171
190
|
onCancel,
|
|
172
|
-
isDark
|
|
191
|
+
isDark: isDarkProp,
|
|
192
|
+
testID,
|
|
173
193
|
}: AlertDialogProps) {
|
|
194
|
+
const isDark = useIsDark(isDarkProp);
|
|
174
195
|
const theme = isDark ? colors.dark : colors.light;
|
|
175
196
|
const { View } = primitives();
|
|
176
197
|
const [uncontrolled, setUncontrolled] = useState(false);
|
|
@@ -181,24 +202,31 @@ export function AlertDialog({
|
|
|
181
202
|
onOpenChange?.(next);
|
|
182
203
|
};
|
|
183
204
|
|
|
205
|
+
const cancel = () => {
|
|
206
|
+
onCancel?.();
|
|
207
|
+
close(false);
|
|
208
|
+
};
|
|
209
|
+
|
|
184
210
|
return (
|
|
185
211
|
<Dialog
|
|
186
212
|
open={open}
|
|
187
|
-
|
|
213
|
+
testID={testID}
|
|
214
|
+
// Android's back button routes here as a dismissal, and a dismissal of a
|
|
215
|
+
// confirmation question is a cancellation, so onCancel fires too.
|
|
216
|
+
onOpenChange={(next) => {
|
|
217
|
+
if (!next) {
|
|
218
|
+
cancel();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
close(true);
|
|
222
|
+
}}
|
|
188
223
|
title={title}
|
|
189
224
|
description={description}
|
|
190
225
|
dismissOnBackdropPress={false}
|
|
191
226
|
isDark={isDark}
|
|
192
227
|
footer={
|
|
193
228
|
<View style={{ flexDirection: "row", gap: 8, justifyContent: "flex-end" }}>
|
|
194
|
-
<Button
|
|
195
|
-
accessibilityLabel={cancelLabel}
|
|
196
|
-
variant="ghost"
|
|
197
|
-
onPress={() => {
|
|
198
|
-
onCancel?.();
|
|
199
|
-
close(false);
|
|
200
|
-
}}
|
|
201
|
-
>
|
|
229
|
+
<Button accessibilityLabel={cancelLabel} variant="ghost" onPress={cancel}>
|
|
202
230
|
{cancelLabel}
|
|
203
231
|
</Button>
|
|
204
232
|
<Button
|
|
@@ -233,6 +261,8 @@ export interface ActionSheetProps {
|
|
|
233
261
|
options: ActionSheetOption[];
|
|
234
262
|
cancelLabel?: string;
|
|
235
263
|
isDark?: boolean;
|
|
264
|
+
/** Passed through to the sheet so it is testable. */
|
|
265
|
+
testID?: string;
|
|
236
266
|
}
|
|
237
267
|
|
|
238
268
|
/**
|
|
@@ -248,10 +278,14 @@ export function ActionSheet({
|
|
|
248
278
|
message,
|
|
249
279
|
options,
|
|
250
280
|
cancelLabel = "Cancel",
|
|
251
|
-
isDark
|
|
281
|
+
isDark: isDarkProp,
|
|
282
|
+
testID,
|
|
252
283
|
}: ActionSheetProps) {
|
|
284
|
+
const isDark = useIsDark(isDarkProp);
|
|
253
285
|
const theme = isDark ? colors.dark : colors.light;
|
|
254
|
-
|
|
286
|
+
// Android's back button is handled by Modal's onRequestClose, so no
|
|
287
|
+
// BackHandler subscription is needed here.
|
|
288
|
+
const { View, Text, Pressable, Modal } = primitives();
|
|
255
289
|
const [uncontrolled, setUncontrolled] = useState(false);
|
|
256
290
|
const open = controlledOpen ?? uncontrolled;
|
|
257
291
|
|
|
@@ -261,7 +295,13 @@ export function ActionSheet({
|
|
|
261
295
|
};
|
|
262
296
|
|
|
263
297
|
return (
|
|
264
|
-
<Modal
|
|
298
|
+
<Modal
|
|
299
|
+
visible={open}
|
|
300
|
+
transparent
|
|
301
|
+
animationType="slide"
|
|
302
|
+
onRequestClose={close}
|
|
303
|
+
testID={testID}
|
|
304
|
+
>
|
|
265
305
|
<Pressable
|
|
266
306
|
accessibilityRole="button"
|
|
267
307
|
accessibilityLabel="Dismiss actions"
|
|
@@ -273,12 +313,10 @@ export function ActionSheet({
|
|
|
273
313
|
onPress={() => {}}
|
|
274
314
|
style={{ padding: 10, gap: 8 }}
|
|
275
315
|
>
|
|
276
|
-
<
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
backgroundColor: isDark ? "#1c1c1e" : "#ffffff",
|
|
281
|
-
}}
|
|
316
|
+
<Glass
|
|
317
|
+
effect="regular"
|
|
318
|
+
isDark={isDark}
|
|
319
|
+
style={{ borderRadius: radii.lg, overflow: "hidden" }}
|
|
282
320
|
>
|
|
283
321
|
{(title || message) && (
|
|
284
322
|
<View style={{ paddingVertical: 12, paddingHorizontal: 16, alignItems: "center" }}>
|
|
@@ -321,23 +359,20 @@ export function ActionSheet({
|
|
|
321
359
|
</Text>
|
|
322
360
|
</Pressable>
|
|
323
361
|
))}
|
|
324
|
-
</
|
|
362
|
+
</Glass>
|
|
325
363
|
|
|
326
|
-
<
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
paddingVertical: 14,
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
{cancelLabel}
|
|
339
|
-
</Text>
|
|
340
|
-
</Pressable>
|
|
364
|
+
<Glass effect="regular" isDark={isDark} style={{ borderRadius: radii.lg }}>
|
|
365
|
+
<Pressable
|
|
366
|
+
accessibilityRole="button"
|
|
367
|
+
accessibilityLabel={cancelLabel}
|
|
368
|
+
onPress={close}
|
|
369
|
+
style={{ paddingVertical: 14, alignItems: "center" }}
|
|
370
|
+
>
|
|
371
|
+
<Text style={{ fontSize: 16, fontWeight: "600", color: theme.foreground }}>
|
|
372
|
+
{cancelLabel}
|
|
373
|
+
</Text>
|
|
374
|
+
</Pressable>
|
|
375
|
+
</Glass>
|
|
341
376
|
</Pressable>
|
|
342
377
|
</Pressable>
|
|
343
378
|
</Modal>
|