glacia-native 0.3.3 → 0.3.5
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/Dialog.js +128 -0
- package/lib/module/Form.js +125 -0
- package/lib/module/Input.js +64 -0
- package/lib/module/Table.js +81 -0
- package/lib/module/ai.js +246 -0
- package/lib/module/charts/AreaChart.js +32 -0
- package/lib/module/charts/BarChart.js +65 -0
- package/lib/module/charts/FunnelChart.js +48 -0
- package/lib/module/charts/HeatmapChart.js +69 -0
- package/lib/module/charts/LineChart.js +79 -0
- package/lib/module/charts/PlotChart.js +44 -0
- package/lib/module/charts/RadarChart.js +76 -0
- package/lib/module/charts/RingChart.js +50 -0
- package/lib/module/charts/ScatterChart.js +78 -0
- package/lib/module/charts/WaterfallChart.js +76 -0
- package/lib/module/charts/advanced.js +307 -0
- package/lib/module/charts/extra.js +105 -0
- package/lib/module/charts/index.js +50 -0
- package/lib/module/charts/primitives.js +212 -0
- package/lib/module/charts/scales.js +140 -0
- package/lib/module/index.js +48 -1
- package/lib/module/internal/tokens.js +3 -0
- package/lib/typescript/Dialog.d.ts +71 -0
- package/lib/typescript/Form.d.ts +81 -0
- package/lib/typescript/Input.d.ts +47 -0
- package/lib/typescript/Table.d.ts +55 -0
- package/lib/typescript/ai.d.ts +163 -0
- package/lib/typescript/charts/AreaChart.d.ts +44 -0
- package/lib/typescript/charts/BarChart.d.ts +19 -0
- package/lib/typescript/charts/FunnelChart.d.ts +25 -0
- package/lib/typescript/charts/HeatmapChart.d.ts +23 -0
- package/lib/typescript/charts/LineChart.d.ts +30 -0
- package/lib/typescript/charts/PlotChart.d.ts +31 -0
- package/lib/typescript/charts/RadarChart.d.ts +27 -0
- package/lib/typescript/charts/RingChart.d.ts +28 -0
- package/lib/typescript/charts/ScatterChart.d.ts +34 -0
- package/lib/typescript/charts/WaterfallChart.d.ts +22 -0
- package/lib/typescript/charts/advanced.d.ts +107 -0
- package/lib/typescript/charts/extra.d.ts +63 -0
- package/lib/typescript/charts/index.d.ts +13 -0
- package/lib/typescript/charts/primitives.d.ts +23 -0
- package/lib/typescript/charts/scales.d.ts +35 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/internal/tokens.d.ts +2 -0
- package/package.json +10 -3
- package/src/Dialog.tsx +345 -0
- package/src/Form.tsx +360 -0
- package/src/Input.tsx +172 -0
- package/src/Table.tsx +207 -0
- package/src/ai.tsx +655 -0
- package/src/charts/AreaChart.tsx +73 -0
- package/src/charts/BarChart.tsx +181 -0
- package/src/charts/FunnelChart.tsx +123 -0
- package/src/charts/HeatmapChart.tsx +153 -0
- package/src/charts/LineChart.tsx +245 -0
- package/src/charts/PlotChart.tsx +148 -0
- package/src/charts/RadarChart.tsx +206 -0
- package/src/charts/RingChart.tsx +131 -0
- package/src/charts/ScatterChart.tsx +202 -0
- package/src/charts/WaterfallChart.tsx +183 -0
- package/src/charts/advanced.tsx +670 -0
- package/src/charts/extra.tsx +239 -0
- package/src/charts/index.ts +86 -0
- package/src/charts/primitives.ts +262 -0
- package/src/charts/scales.ts +163 -0
- package/src/index.ts +68 -0
- package/src/internal/tokens.ts +3 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export interface NativeCandle {
|
|
2
|
+
label: string;
|
|
3
|
+
open: number;
|
|
4
|
+
high: number;
|
|
5
|
+
low: number;
|
|
6
|
+
close: number;
|
|
7
|
+
}
|
|
8
|
+
export interface NativeCandlestickChartProps {
|
|
9
|
+
candles: NativeCandle[];
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
isDark?: boolean;
|
|
13
|
+
style?: any;
|
|
14
|
+
onCandlePress?: (index: number) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Open, high, low and close for each period.
|
|
18
|
+
*
|
|
19
|
+
* A filled body means the period closed up and a hollow body means it closed
|
|
20
|
+
* down, which is the convention traders read without a legend. Each candle is
|
|
21
|
+
* tappable to reveal the four prices, replacing the web hover tooltip.
|
|
22
|
+
*/
|
|
23
|
+
export declare function NativeCandlestickChart({ candles, width, height, isDark, style, onCandlePress, }: NativeCandlestickChartProps): import("react").JSX.Element;
|
|
24
|
+
export interface NativeTreemapItem {
|
|
25
|
+
label: string;
|
|
26
|
+
value: number;
|
|
27
|
+
color?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface NativeTreemapChartProps {
|
|
30
|
+
items: NativeTreemapItem[];
|
|
31
|
+
width?: number;
|
|
32
|
+
height?: number;
|
|
33
|
+
isDark?: boolean;
|
|
34
|
+
palette?: readonly string[];
|
|
35
|
+
style?: any;
|
|
36
|
+
onItemPress?: (index: number) => void;
|
|
37
|
+
}
|
|
38
|
+
/** Proportional rectangles for part-to-whole comparison. */
|
|
39
|
+
export declare function NativeTreemapChart({ items, width, height, isDark, palette, style, onItemPress, }: NativeTreemapChartProps): import("react").JSX.Element;
|
|
40
|
+
export interface NativeSankeyNode {
|
|
41
|
+
id: string;
|
|
42
|
+
label: string;
|
|
43
|
+
}
|
|
44
|
+
export interface NativeSankeyLink {
|
|
45
|
+
from: string;
|
|
46
|
+
to: string;
|
|
47
|
+
value: number;
|
|
48
|
+
}
|
|
49
|
+
export interface NativeSankeyChartProps {
|
|
50
|
+
nodes: NativeSankeyNode[];
|
|
51
|
+
links: NativeSankeyLink[];
|
|
52
|
+
width?: number;
|
|
53
|
+
height?: number;
|
|
54
|
+
isDark?: boolean;
|
|
55
|
+
palette?: readonly string[];
|
|
56
|
+
style?: any;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Flow between stages, drawn as stacked columns joined by bands.
|
|
60
|
+
*
|
|
61
|
+
* Columns are assigned by longest path from a source, so a node always sits
|
|
62
|
+
* after everything feeding it. Rendering uses Views rather than SVG because the
|
|
63
|
+
* bands are axis-aligned rectangles.
|
|
64
|
+
*/
|
|
65
|
+
export declare function NativeSankeyChart({ nodes, links, width, height, isDark, palette, style, }: NativeSankeyChartProps): import("react").JSX.Element;
|
|
66
|
+
export interface NativeBumpSeries {
|
|
67
|
+
name: string;
|
|
68
|
+
/** Rank per period; 1 is best. */
|
|
69
|
+
ranks: number[];
|
|
70
|
+
color?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface NativeBumpChartProps {
|
|
73
|
+
labels: string[];
|
|
74
|
+
series: NativeBumpSeries[];
|
|
75
|
+
width?: number;
|
|
76
|
+
height?: number;
|
|
77
|
+
isDark?: boolean;
|
|
78
|
+
palette?: readonly string[];
|
|
79
|
+
style?: any;
|
|
80
|
+
onPointPress?: (seriesIndex: number, periodIndex: number) => void;
|
|
81
|
+
}
|
|
82
|
+
/** Rank changes over time, where the vertical position is the rank itself. */
|
|
83
|
+
export declare function NativeBumpChart({ labels, series, width, height, isDark, palette, style, onPointPress, }: NativeBumpChartProps): import("react").JSX.Element;
|
|
84
|
+
export interface NativeHexPoint {
|
|
85
|
+
x: number;
|
|
86
|
+
y: number;
|
|
87
|
+
/** Drives the bin's colour. */
|
|
88
|
+
value: number;
|
|
89
|
+
label?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface NativeHexChartProps {
|
|
92
|
+
points: NativeHexPoint[];
|
|
93
|
+
/** Bin radius in points. */
|
|
94
|
+
radius?: number;
|
|
95
|
+
width?: number;
|
|
96
|
+
height?: number;
|
|
97
|
+
isDark?: boolean;
|
|
98
|
+
style?: any;
|
|
99
|
+
onBinPress?: (index: number) => void;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Points aggregated into hexagonal bins whose colour is the mean value.
|
|
103
|
+
*
|
|
104
|
+
* Binning keeps thousands of points legible: reading one mark's exact position
|
|
105
|
+
* matters less than seeing where density is concentrated.
|
|
106
|
+
*/
|
|
107
|
+
export declare function NativeHexChart({ points, radius, width, height, isDark, style, onBinPress, }: NativeHexChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type NativeLineSeries } from "./LineChart";
|
|
2
|
+
export interface NativePolarSegment {
|
|
3
|
+
label: string;
|
|
4
|
+
value: number;
|
|
5
|
+
color?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface NativePolarAreaChartProps {
|
|
8
|
+
segments: NativePolarSegment[];
|
|
9
|
+
size?: number;
|
|
10
|
+
/** Value mapped to the full radius. Defaults to the largest segment. */
|
|
11
|
+
max?: number;
|
|
12
|
+
isDark?: boolean;
|
|
13
|
+
palette?: readonly string[];
|
|
14
|
+
style?: any;
|
|
15
|
+
onSegmentPress?: (index: number) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Equal-angle wedges whose radius encodes value.
|
|
19
|
+
*
|
|
20
|
+
* Unlike a pie chart, every wedge uses the same angle, so the reader compares
|
|
21
|
+
* one dimension (radius) rather than area. Each wedge is separately tappable
|
|
22
|
+
* because a phone has no hover.
|
|
23
|
+
*/
|
|
24
|
+
export declare function NativePolarAreaChart({ segments, size, max, isDark, palette, style, onSegmentPress, }: NativePolarAreaChartProps): import("react").JSX.Element;
|
|
25
|
+
export interface NativePyramidLevel {
|
|
26
|
+
label: string;
|
|
27
|
+
value: number;
|
|
28
|
+
color?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface NativePyramidChartProps {
|
|
31
|
+
levels: NativePyramidLevel[];
|
|
32
|
+
/** Height of each level band. */
|
|
33
|
+
levelHeight?: number;
|
|
34
|
+
width?: number;
|
|
35
|
+
isDark?: boolean;
|
|
36
|
+
palette?: readonly string[];
|
|
37
|
+
style?: any;
|
|
38
|
+
onLevelPress?: (index: number) => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stacked bands that narrow toward the top.
|
|
42
|
+
*
|
|
43
|
+
* Bands are Views rather than SVG: each is a centred rectangle whose width is
|
|
44
|
+
* the band's share of the widest level, which native layout computes exactly.
|
|
45
|
+
*/
|
|
46
|
+
export declare function NativePyramidChart({ levels, levelHeight, width, isDark, palette, style, onLevelPress, }: NativePyramidChartProps): import("react").JSX.Element;
|
|
47
|
+
export interface NativeLiveLineChartProps {
|
|
48
|
+
labels: string[];
|
|
49
|
+
series: NativeLineSeries[];
|
|
50
|
+
width?: number;
|
|
51
|
+
height?: number;
|
|
52
|
+
isDark?: boolean;
|
|
53
|
+
palette?: readonly string[];
|
|
54
|
+
style?: any;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A line chart that keeps only the most recent window of points.
|
|
58
|
+
*
|
|
59
|
+
* The caller pushes new values; this trims to `labels.length` so the window
|
|
60
|
+
* slides instead of growing without bound. Pausing is the caller's decision —
|
|
61
|
+
* a chart that stops itself would hide data the user expects to see arrive.
|
|
62
|
+
*/
|
|
63
|
+
export declare function NativeLiveLineChart(props: NativeLiveLineChartProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { NativeLineChart, type NativeLineChartProps, type NativeLineSeries } from "./LineChart";
|
|
2
|
+
export { NativeBarChart, type NativeBarChartProps, type NativeBarSeries } from "./BarChart";
|
|
3
|
+
export { NativeRingChart, type NativeRingChartProps, type NativeRingSlice } from "./RingChart";
|
|
4
|
+
export { NativeAreaChart, NativeMirrorAreaChart, type NativeAreaChartProps, type NativeMirrorAreaChartProps, type NativeMirrorAreaSeries, } from "./AreaChart";
|
|
5
|
+
export { NativeScatterChart, NativeBubbleChart, type NativeScatterChartProps, type NativeScatterSeries, type NativeScatterPoint, } from "./ScatterChart";
|
|
6
|
+
export { NativeFunnelChart, type NativeFunnelChartProps, type NativeFunnelStage, } from "./FunnelChart";
|
|
7
|
+
export { NativeHeatmapChart, type NativeHeatmapChartProps } from "./HeatmapChart";
|
|
8
|
+
export { NativeRadarChart, type NativeRadarChartProps, type NativeRadarSeries, } from "./RadarChart";
|
|
9
|
+
export { NativeWaterfallChart, type NativeWaterfallChartProps, type NativeWaterfallStep, } from "./WaterfallChart";
|
|
10
|
+
export { linearScale, niceDomain, ticks, bandScale, smoothPath, arcPath, formatValue, seriesColor, SERIES_COLORS, type Scale, } from "./scales";
|
|
11
|
+
export { NativePolarAreaChart, NativePyramidChart, NativeLiveLineChart, type NativePolarAreaChartProps, type NativePolarSegment, type NativePyramidChartProps, type NativePyramidLevel, type NativeLiveLineChartProps, } from "./extra";
|
|
12
|
+
export { NativeCandlestickChart, NativeTreemapChart, NativeSankeyChart, NativeBumpChart, NativeHexChart, type NativeCandlestickChartProps, type NativeCandle, type NativeTreemapChartProps, type NativeTreemapItem, type NativeSankeyChartProps, type NativeSankeyNode, type NativeSankeyLink, type NativeBumpChartProps, type NativeBumpSeries, type NativeHexChartProps, type NativeHexPoint, } from "./advanced";
|
|
13
|
+
export { NativePlotChart, type NativePlotChartProps, type NativePlotPoint, type NativePlotRenderArgs, } from "./PlotChart";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Minimal shapes of the RN primitives the charts use. */
|
|
2
|
+
export interface RNPrimitives {
|
|
3
|
+
View: any;
|
|
4
|
+
Text: any;
|
|
5
|
+
Pressable: any;
|
|
6
|
+
Svg: any;
|
|
7
|
+
G: any;
|
|
8
|
+
Line: any;
|
|
9
|
+
Path: any;
|
|
10
|
+
Circle: any;
|
|
11
|
+
Rect: any;
|
|
12
|
+
Polygon: any;
|
|
13
|
+
SvgText: any;
|
|
14
|
+
TextInput: any;
|
|
15
|
+
Modal: any;
|
|
16
|
+
Image: any;
|
|
17
|
+
/** React Native's ScrollView, or null when it is unavailable. */
|
|
18
|
+
getScrollView: () => any;
|
|
19
|
+
/** React Native's BackHandler, or null outside a native runtime. */
|
|
20
|
+
getBackHandler: () => any;
|
|
21
|
+
}
|
|
22
|
+
/** The resolved primitives, computed once per process. */
|
|
23
|
+
export declare function primitives(): RNPrimitives;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Maps a value into pixel space along one axis. */
|
|
2
|
+
export interface Scale {
|
|
3
|
+
(value: number): number;
|
|
4
|
+
invert(pixel: number): number;
|
|
5
|
+
domain: [number, number];
|
|
6
|
+
range: [number, number];
|
|
7
|
+
}
|
|
8
|
+
export declare function linearScale(domain: [number, number], range: [number, number], options?: {
|
|
9
|
+
nice?: boolean;
|
|
10
|
+
ticks?: number;
|
|
11
|
+
}): Scale;
|
|
12
|
+
/** Rounds a domain outward to values that read cleanly on an axis. */
|
|
13
|
+
export declare function niceDomain(min: number, max: number, tickCount?: number): [number, number];
|
|
14
|
+
export declare function ticks(domain: [number, number], count?: number): number[];
|
|
15
|
+
/** Evenly divided bands; returns the centre and width of each. */
|
|
16
|
+
export declare function bandScale(count: number, range: [number, number], padding?: number): {
|
|
17
|
+
bandWidth: number;
|
|
18
|
+
width: number;
|
|
19
|
+
start: (i: number) => number;
|
|
20
|
+
center: (i: number) => number;
|
|
21
|
+
};
|
|
22
|
+
/** Compact number formatting, matching the web charts. */
|
|
23
|
+
export declare function formatValue(value: number, options?: {
|
|
24
|
+
compact?: boolean;
|
|
25
|
+
decimals?: number;
|
|
26
|
+
}): string;
|
|
27
|
+
/** Points along a smooth (monotone) path, as SVG path segments. */
|
|
28
|
+
export declare function smoothPath(points: {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
}[]): string;
|
|
32
|
+
/** A pie/donut arc, with an optional inner radius. */
|
|
33
|
+
export declare function arcPath(cx: number, cy: number, outer: number, inner: number, startAngle: number, endAngle: number): string;
|
|
34
|
+
export declare const SERIES_COLORS: readonly ["#0088ff", "#34c759", "#ff9f0a", "#ff375f", "#bf5af2", "#64d2ff", "#ffd60a"];
|
|
35
|
+
export declare const seriesColor: (index: number, palette?: readonly string[]) => string;
|
|
@@ -6,5 +6,11 @@ export { SegmentedControl, type SegmentedControlProps, } from "./SegmentedContro
|
|
|
6
6
|
export { TabBar, type TabBarProps, type TabBarItem } from "./TabBar";
|
|
7
7
|
export { Tabs, type TabsProps, type TabItem } from "./Tabs";
|
|
8
8
|
export { Card, CardHeader, CardTitle, CardDescription, CardContent, CardBody, CardFooter, type CardProps, } from "./Card";
|
|
9
|
+
export { Input, Textarea, type InputProps, type TextareaProps, } from "./Input";
|
|
10
|
+
export { Label, Field, Checkbox, RadioGroup, Select, type LabelProps, type FieldProps, type CheckboxProps, type RadioOption, type RadioGroupProps, type SelectOption, type SelectProps, } from "./Form";
|
|
11
|
+
export { Dialog, DialogTrigger, AlertDialog, ActionSheet, type DialogProps, type AlertDialogProps, type ActionSheetProps, type ActionSheetOption, } from "./Dialog";
|
|
12
|
+
export { NativePlan, NativeSources, NativeResponse, NativeTask, NativeSoundwave, NativeThinkingOrb, NativePanelside, NativeAIInput, NativeImageGeneration, type NativePlanProps, type NativePlanStep, type NativeSourcesProps, type NativeSource, type NativeResponseProps, type NativeTaskProps, type NativeSoundwaveProps, type NativeThinkingOrbProps, type NativePanelsideProps, type NativePanelNavItem, type NativeAIInputProps, type NativeImageGenerationProps, type NativeGeneratedImage, } from "./ai";
|
|
13
|
+
export { NativeTable, NativeScrollArea, type NativeTableProps, type NativeTableColumn, type NativeTableRow, type NativeScrollAreaProps, } from "./Table";
|
|
14
|
+
export * from "./charts";
|
|
9
15
|
export { isGlassSupported } from "./internal/GlassView";
|
|
10
16
|
export { colors, radii, springs } from "./internal/tokens";
|
|
@@ -31,6 +31,7 @@ export declare const colors: {
|
|
|
31
31
|
edge: string;
|
|
32
32
|
fill: string;
|
|
33
33
|
destructive: string;
|
|
34
|
+
axis: string;
|
|
34
35
|
};
|
|
35
36
|
dark: {
|
|
36
37
|
foreground: string;
|
|
@@ -40,5 +41,6 @@ export declare const colors: {
|
|
|
40
41
|
edge: string;
|
|
41
42
|
fill: string;
|
|
42
43
|
destructive: string;
|
|
44
|
+
axis: string;
|
|
43
45
|
};
|
|
44
46
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glacia-native",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Liquid Glass UI components for React Native — real iOS 26 glass, with a clean fallback on Android and older iOS.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -21,21 +21,28 @@
|
|
|
21
21
|
"src"
|
|
22
22
|
],
|
|
23
23
|
"peerDependencies": {
|
|
24
|
+
"@callstack/liquid-glass": ">=0.7.0",
|
|
24
25
|
"react": ">=18",
|
|
25
26
|
"react-native": ">=0.80",
|
|
26
|
-
"
|
|
27
|
+
"react-native-svg": ">=13"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"glacia-tokens": "0.3.
|
|
30
|
+
"glacia-tokens": "0.3.5"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@testing-library/react": "^16.3.3",
|
|
33
34
|
"@types/react": "^19.3.0",
|
|
34
35
|
"jsdom": "^29.1.1",
|
|
35
36
|
"react": "^19.3.1",
|
|
37
|
+
"react-native-svg": "^15.16.1",
|
|
36
38
|
"typescript": "^5.7.3",
|
|
37
39
|
"vitest": "^3.0.0"
|
|
38
40
|
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"react-native-svg": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
39
46
|
"scripts": {
|
|
40
47
|
"build": "tsc --project tsconfig.build.json",
|
|
41
48
|
"typecheck": "tsc --noEmit",
|
package/src/Dialog.tsx
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState, type ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { colors, radii } from "./internal/tokens";
|
|
4
|
+
import { primitives } from "./charts/primitives";
|
|
5
|
+
import { Button } from "./Button";
|
|
6
|
+
|
|
7
|
+
export interface DialogProps {
|
|
8
|
+
/** Controlled visibility. Omit to use `trigger` and uncontrolled state. */
|
|
9
|
+
open?: boolean;
|
|
10
|
+
onOpenChange?: (open: boolean) => void;
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
footer?: ReactNode;
|
|
15
|
+
/** Tapping the backdrop dismisses. Off for destructive confirmations. */
|
|
16
|
+
dismissOnBackdropPress?: boolean;
|
|
17
|
+
isDark?: boolean;
|
|
18
|
+
style?: any;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A centred modal surface above a dimmed backdrop.
|
|
23
|
+
*
|
|
24
|
+
* React Native has no built-in focus trap, so this component covers what the
|
|
25
|
+
* platform can actually do: `Modal` blocks touches behind it, Android's back
|
|
26
|
+
* button routes to `onOpenChange(false)`, and the heading is marked as such so
|
|
27
|
+
* screen readers announce the dialog as it appears.
|
|
28
|
+
*/
|
|
29
|
+
export function Dialog({
|
|
30
|
+
open: controlledOpen,
|
|
31
|
+
onOpenChange,
|
|
32
|
+
title,
|
|
33
|
+
description,
|
|
34
|
+
children,
|
|
35
|
+
footer,
|
|
36
|
+
dismissOnBackdropPress = true,
|
|
37
|
+
isDark = false,
|
|
38
|
+
style,
|
|
39
|
+
}: DialogProps) {
|
|
40
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
41
|
+
const { View, Text, Pressable, Modal, getBackHandler } = primitives();
|
|
42
|
+
|
|
43
|
+
const [uncontrolled, setUncontrolled] = useState(false);
|
|
44
|
+
const open = controlledOpen ?? uncontrolled;
|
|
45
|
+
|
|
46
|
+
const setOpen = useCallback(
|
|
47
|
+
(next: boolean) => {
|
|
48
|
+
if (controlledOpen === undefined) setUncontrolled(next);
|
|
49
|
+
onOpenChange?.(next);
|
|
50
|
+
},
|
|
51
|
+
[controlledOpen, onOpenChange],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Android's hardware back must close the dialog, not the screen behind it.
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!open) return;
|
|
57
|
+
const BackHandler = getBackHandler();
|
|
58
|
+
if (!BackHandler) return;
|
|
59
|
+
const sub = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
60
|
+
setOpen(false);
|
|
61
|
+
return true;
|
|
62
|
+
});
|
|
63
|
+
return () => sub.remove();
|
|
64
|
+
}, [open, setOpen, getBackHandler]);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Modal
|
|
68
|
+
visible={open}
|
|
69
|
+
transparent
|
|
70
|
+
animationType="fade"
|
|
71
|
+
onRequestClose={() => setOpen(false)}
|
|
72
|
+
>
|
|
73
|
+
<Pressable
|
|
74
|
+
accessibilityRole="button"
|
|
75
|
+
accessibilityLabel="Close dialog"
|
|
76
|
+
onPress={dismissOnBackdropPress ? () => setOpen(false) : undefined}
|
|
77
|
+
style={{
|
|
78
|
+
flex: 1,
|
|
79
|
+
alignItems: "center",
|
|
80
|
+
justifyContent: "center",
|
|
81
|
+
padding: 24,
|
|
82
|
+
backgroundColor: "rgba(0, 0, 0, 0.45)",
|
|
83
|
+
}}
|
|
84
|
+
>
|
|
85
|
+
{/* Stops a press inside the panel from reaching the backdrop. */}
|
|
86
|
+
<Pressable
|
|
87
|
+
accessibilityRole="none"
|
|
88
|
+
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
|
+
}}
|
|
100
|
+
>
|
|
101
|
+
{title && (
|
|
102
|
+
<Text
|
|
103
|
+
accessibilityRole="heading"
|
|
104
|
+
style={{ fontSize: 17, fontWeight: "600", color: theme.foreground }}
|
|
105
|
+
>
|
|
106
|
+
{title}
|
|
107
|
+
</Text>
|
|
108
|
+
)}
|
|
109
|
+
|
|
110
|
+
{description && (
|
|
111
|
+
<Text style={{ fontSize: 13, color: theme.muted, lineHeight: 18 }}>{description}</Text>
|
|
112
|
+
)}
|
|
113
|
+
|
|
114
|
+
{children}
|
|
115
|
+
|
|
116
|
+
{footer && <View style={{ marginTop: 12, gap: 8 }}>{footer}</View>}
|
|
117
|
+
</Pressable>
|
|
118
|
+
</Pressable>
|
|
119
|
+
</Modal>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Opens the dialog without the caller tracking state. */
|
|
124
|
+
export function DialogTrigger({
|
|
125
|
+
label,
|
|
126
|
+
children,
|
|
127
|
+
...dialogProps
|
|
128
|
+
}: Omit<DialogProps, "open" | "onOpenChange"> & { label: string }) {
|
|
129
|
+
const [open, setOpen] = useState(false);
|
|
130
|
+
return (
|
|
131
|
+
<>
|
|
132
|
+
<Button accessibilityLabel={label} onPress={() => setOpen(true)}>
|
|
133
|
+
{label}
|
|
134
|
+
</Button>
|
|
135
|
+
<Dialog {...dialogProps} open={open} onOpenChange={setOpen} />
|
|
136
|
+
</>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface AlertDialogProps {
|
|
141
|
+
open?: boolean;
|
|
142
|
+
onOpenChange?: (open: boolean) => void;
|
|
143
|
+
title: string;
|
|
144
|
+
description?: string;
|
|
145
|
+
/** Label for the confirming action. */
|
|
146
|
+
confirmLabel?: string;
|
|
147
|
+
cancelLabel?: string;
|
|
148
|
+
/** Tints the confirm button destructive. */
|
|
149
|
+
destructive?: boolean;
|
|
150
|
+
onConfirm?: () => void;
|
|
151
|
+
onCancel?: () => void;
|
|
152
|
+
isDark?: boolean;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* A dialog that asks for confirmation.
|
|
157
|
+
*
|
|
158
|
+
* Deliberately not dismissible by tapping the backdrop: a destructive question
|
|
159
|
+
* should require a real answer, so the only ways out are the two buttons or the
|
|
160
|
+
* Android back button, which counts as cancel.
|
|
161
|
+
*/
|
|
162
|
+
export function AlertDialog({
|
|
163
|
+
open: controlledOpen,
|
|
164
|
+
onOpenChange,
|
|
165
|
+
title,
|
|
166
|
+
description,
|
|
167
|
+
confirmLabel = "Confirm",
|
|
168
|
+
cancelLabel = "Cancel",
|
|
169
|
+
destructive = false,
|
|
170
|
+
onConfirm,
|
|
171
|
+
onCancel,
|
|
172
|
+
isDark = false,
|
|
173
|
+
}: AlertDialogProps) {
|
|
174
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
175
|
+
const { View } = primitives();
|
|
176
|
+
const [uncontrolled, setUncontrolled] = useState(false);
|
|
177
|
+
const open = controlledOpen ?? uncontrolled;
|
|
178
|
+
|
|
179
|
+
const close = (next: boolean) => {
|
|
180
|
+
if (controlledOpen === undefined) setUncontrolled(next);
|
|
181
|
+
onOpenChange?.(next);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<Dialog
|
|
186
|
+
open={open}
|
|
187
|
+
onOpenChange={close}
|
|
188
|
+
title={title}
|
|
189
|
+
description={description}
|
|
190
|
+
dismissOnBackdropPress={false}
|
|
191
|
+
isDark={isDark}
|
|
192
|
+
footer={
|
|
193
|
+
<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
|
+
>
|
|
202
|
+
{cancelLabel}
|
|
203
|
+
</Button>
|
|
204
|
+
<Button
|
|
205
|
+
accessibilityLabel={confirmLabel}
|
|
206
|
+
variant="filled"
|
|
207
|
+
tint={destructive ? theme.destructive : undefined}
|
|
208
|
+
onPress={() => {
|
|
209
|
+
onConfirm?.();
|
|
210
|
+
close(false);
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
{confirmLabel}
|
|
214
|
+
</Button>
|
|
215
|
+
</View>
|
|
216
|
+
}
|
|
217
|
+
/>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export interface ActionSheetOption {
|
|
222
|
+
label: string;
|
|
223
|
+
/** Tints the row destructive, for delete actions. */
|
|
224
|
+
destructive?: boolean;
|
|
225
|
+
onPress?: () => void;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export interface ActionSheetProps {
|
|
229
|
+
open?: boolean;
|
|
230
|
+
onOpenChange?: (open: boolean) => void;
|
|
231
|
+
title?: string;
|
|
232
|
+
message?: string;
|
|
233
|
+
options: ActionSheetOption[];
|
|
234
|
+
cancelLabel?: string;
|
|
235
|
+
isDark?: boolean;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* A list of choices attached to the bottom of the screen.
|
|
240
|
+
*
|
|
241
|
+
* Anchored to the bottom because that is where a thumb reaches, and it keeps a
|
|
242
|
+
* separate Cancel row so a mis-tap is always reversible.
|
|
243
|
+
*/
|
|
244
|
+
export function ActionSheet({
|
|
245
|
+
open: controlledOpen,
|
|
246
|
+
onOpenChange,
|
|
247
|
+
title,
|
|
248
|
+
message,
|
|
249
|
+
options,
|
|
250
|
+
cancelLabel = "Cancel",
|
|
251
|
+
isDark = false,
|
|
252
|
+
}: ActionSheetProps) {
|
|
253
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
254
|
+
const { View, Text, Pressable, Modal, getBackHandler } = primitives();
|
|
255
|
+
const [uncontrolled, setUncontrolled] = useState(false);
|
|
256
|
+
const open = controlledOpen ?? uncontrolled;
|
|
257
|
+
|
|
258
|
+
const close = () => {
|
|
259
|
+
if (controlledOpen === undefined) setUncontrolled(false);
|
|
260
|
+
onOpenChange?.(false);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<Modal visible={open} transparent animationType="slide" onRequestClose={close}>
|
|
265
|
+
<Pressable
|
|
266
|
+
accessibilityRole="button"
|
|
267
|
+
accessibilityLabel="Dismiss actions"
|
|
268
|
+
onPress={close}
|
|
269
|
+
style={{ flex: 1, justifyContent: "flex-end", backgroundColor: "rgba(0,0,0,0.4)" }}
|
|
270
|
+
>
|
|
271
|
+
<Pressable
|
|
272
|
+
accessibilityRole="none"
|
|
273
|
+
onPress={() => {}}
|
|
274
|
+
style={{ padding: 10, gap: 8 }}
|
|
275
|
+
>
|
|
276
|
+
<View
|
|
277
|
+
style={{
|
|
278
|
+
borderRadius: radii.lg,
|
|
279
|
+
overflow: "hidden",
|
|
280
|
+
backgroundColor: isDark ? "#1c1c1e" : "#ffffff",
|
|
281
|
+
}}
|
|
282
|
+
>
|
|
283
|
+
{(title || message) && (
|
|
284
|
+
<View style={{ paddingVertical: 12, paddingHorizontal: 16, alignItems: "center" }}>
|
|
285
|
+
{title && (
|
|
286
|
+
<Text style={{ fontSize: 13, fontWeight: "600", color: theme.foreground }}>
|
|
287
|
+
{title}
|
|
288
|
+
</Text>
|
|
289
|
+
)}
|
|
290
|
+
{message && (
|
|
291
|
+
<Text style={{ fontSize: 12, color: theme.muted, marginTop: 4, textAlign: "center" }}>
|
|
292
|
+
{message}
|
|
293
|
+
</Text>
|
|
294
|
+
)}
|
|
295
|
+
</View>
|
|
296
|
+
)}
|
|
297
|
+
|
|
298
|
+
{options.map((option, index) => (
|
|
299
|
+
<Pressable
|
|
300
|
+
key={option.label}
|
|
301
|
+
accessibilityRole="button"
|
|
302
|
+
accessibilityLabel={option.label}
|
|
303
|
+
onPress={() => {
|
|
304
|
+
option.onPress?.();
|
|
305
|
+
close();
|
|
306
|
+
}}
|
|
307
|
+
style={{
|
|
308
|
+
paddingVertical: 14,
|
|
309
|
+
alignItems: "center",
|
|
310
|
+
borderTopWidth: index === 0 && !title && !message ? 0 : 1,
|
|
311
|
+
borderTopColor: theme.edge,
|
|
312
|
+
}}
|
|
313
|
+
>
|
|
314
|
+
<Text
|
|
315
|
+
style={{
|
|
316
|
+
fontSize: 16,
|
|
317
|
+
color: option.destructive ? theme.destructive : theme.foreground,
|
|
318
|
+
}}
|
|
319
|
+
>
|
|
320
|
+
{option.label}
|
|
321
|
+
</Text>
|
|
322
|
+
</Pressable>
|
|
323
|
+
))}
|
|
324
|
+
</View>
|
|
325
|
+
|
|
326
|
+
<Pressable
|
|
327
|
+
accessibilityRole="button"
|
|
328
|
+
accessibilityLabel={cancelLabel}
|
|
329
|
+
onPress={close}
|
|
330
|
+
style={{
|
|
331
|
+
paddingVertical: 14,
|
|
332
|
+
alignItems: "center",
|
|
333
|
+
borderRadius: radii.lg,
|
|
334
|
+
backgroundColor: isDark ? "#1c1c1e" : "#ffffff",
|
|
335
|
+
}}
|
|
336
|
+
>
|
|
337
|
+
<Text style={{ fontSize: 16, fontWeight: "600", color: theme.foreground }}>
|
|
338
|
+
{cancelLabel}
|
|
339
|
+
</Text>
|
|
340
|
+
</Pressable>
|
|
341
|
+
</Pressable>
|
|
342
|
+
</Pressable>
|
|
343
|
+
</Modal>
|
|
344
|
+
);
|
|
345
|
+
}
|