@fluxus-ui/native 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +75 -2
- package/lib/module/AudioPlayer.js +174 -0
- package/lib/module/AudioPlayer.js.map +1 -0
- package/lib/module/Avatar.js +58 -0
- package/lib/module/Avatar.js.map +1 -0
- package/lib/module/Badge.js +72 -0
- package/lib/module/Badge.js.map +1 -0
- package/lib/module/BottomSheet.js +159 -0
- package/lib/module/BottomSheet.js.map +1 -0
- package/lib/module/Bubble.js +182 -0
- package/lib/module/Bubble.js.map +1 -0
- package/lib/module/Button.js +209 -0
- package/lib/module/Button.js.map +1 -0
- package/lib/module/Card.js +79 -0
- package/lib/module/Card.js.map +1 -0
- package/lib/module/Dialog.js +137 -0
- package/lib/module/Dialog.js.map +1 -0
- package/lib/module/Disclosure.js +153 -0
- package/lib/module/Disclosure.js.map +1 -0
- package/lib/module/EmptyState.js +71 -0
- package/lib/module/EmptyState.js.map +1 -0
- package/lib/module/Link.js +97 -0
- package/lib/module/Link.js.map +1 -0
- package/lib/module/ListItem.js +89 -0
- package/lib/module/ListItem.js.map +1 -0
- package/lib/module/Menu.js +76 -0
- package/lib/module/Menu.js.map +1 -0
- package/lib/module/Message.js +51 -0
- package/lib/module/Message.js.map +1 -0
- package/lib/module/Popover.js +153 -0
- package/lib/module/Popover.js.map +1 -0
- package/lib/module/Progress.js +54 -0
- package/lib/module/Progress.js.map +1 -0
- package/lib/module/Select.js +146 -0
- package/lib/module/Select.js.map +1 -0
- package/lib/module/Skeleton.js +40 -0
- package/lib/module/Skeleton.js.map +1 -0
- package/lib/module/Slider.js +137 -0
- package/lib/module/Slider.js.map +1 -0
- package/lib/module/Spinner.js +30 -0
- package/lib/module/Spinner.js.map +1 -0
- package/lib/module/Swap.js +87 -0
- package/lib/module/Swap.js.map +1 -0
- package/lib/module/Tabs.js +118 -0
- package/lib/module/Tabs.js.map +1 -0
- package/lib/module/Text.js +47 -0
- package/lib/module/Text.js.map +1 -0
- package/lib/module/TextField.js +190 -0
- package/lib/module/TextField.js.map +1 -0
- package/lib/module/Toast.js +157 -0
- package/lib/module/Toast.js.map +1 -0
- package/lib/module/audio.js +54 -0
- package/lib/module/audio.js.map +1 -0
- package/lib/module/blur.js +55 -0
- package/lib/module/blur.js.map +1 -0
- package/lib/module/controls.js +292 -0
- package/lib/module/controls.js.map +1 -0
- package/lib/module/feel.js +24 -0
- package/lib/module/feel.js.map +1 -0
- package/lib/module/generated/tokens.js +484 -0
- package/lib/module/generated/tokens.js.map +1 -0
- package/lib/module/haptics.js +25 -0
- package/lib/module/haptics.js.map +1 -0
- package/lib/module/icon-host.js +42 -0
- package/lib/module/icon-host.js.map +1 -0
- package/lib/module/icon-shape.js +222 -0
- package/lib/module/icon-shape.js.map +1 -0
- package/lib/module/icon.js +331 -0
- package/lib/module/icon.js.map +1 -0
- package/lib/module/index.js +39 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/layout.js +75 -0
- package/lib/module/layout.js.map +1 -0
- package/lib/module/marks.js +99 -0
- package/lib/module/marks.js.map +1 -0
- package/lib/module/motion.js +95 -0
- package/lib/module/motion.js.map +1 -0
- package/lib/module/overlay.js +99 -0
- package/lib/module/overlay.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/pending.js +181 -0
- package/lib/module/pending.js.map +1 -0
- package/lib/module/presence.js +71 -0
- package/lib/module/presence.js.map +1 -0
- package/lib/module/press.js +32 -0
- package/lib/module/press.js.map +1 -0
- package/lib/module/screen.js +50 -0
- package/lib/module/screen.js.map +1 -0
- package/lib/module/success.js +59 -0
- package/lib/module/success.js.map +1 -0
- package/lib/module/theme.js +41 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/typescript/AudioPlayer.d.ts +26 -0
- package/lib/typescript/AudioPlayer.d.ts.map +1 -0
- package/lib/typescript/Avatar.d.ts +17 -0
- package/lib/typescript/Avatar.d.ts.map +1 -0
- package/lib/typescript/Badge.d.ts +21 -0
- package/lib/typescript/Badge.d.ts.map +1 -0
- package/lib/typescript/BottomSheet.d.ts +27 -0
- package/lib/typescript/BottomSheet.d.ts.map +1 -0
- package/lib/typescript/Bubble.d.ts +23 -0
- package/lib/typescript/Bubble.d.ts.map +1 -0
- package/lib/typescript/Button.d.ts +29 -0
- package/lib/typescript/Button.d.ts.map +1 -0
- package/lib/typescript/Card.d.ts +17 -0
- package/lib/typescript/Card.d.ts.map +1 -0
- package/lib/typescript/Dialog.d.ts +34 -0
- package/lib/typescript/Dialog.d.ts.map +1 -0
- package/lib/typescript/Disclosure.d.ts +39 -0
- package/lib/typescript/Disclosure.d.ts.map +1 -0
- package/lib/typescript/EmptyState.d.ts +14 -0
- package/lib/typescript/EmptyState.d.ts.map +1 -0
- package/lib/typescript/Link.d.ts +23 -0
- package/lib/typescript/Link.d.ts.map +1 -0
- package/lib/typescript/ListItem.d.ts +20 -0
- package/lib/typescript/ListItem.d.ts.map +1 -0
- package/lib/typescript/Menu.d.ts +23 -0
- package/lib/typescript/Menu.d.ts.map +1 -0
- package/lib/typescript/Message.d.ts +14 -0
- package/lib/typescript/Message.d.ts.map +1 -0
- package/lib/typescript/Popover.d.ts +71 -0
- package/lib/typescript/Popover.d.ts.map +1 -0
- package/lib/typescript/Progress.d.ts +12 -0
- package/lib/typescript/Progress.d.ts.map +1 -0
- package/lib/typescript/Select.d.ts +30 -0
- package/lib/typescript/Select.d.ts.map +1 -0
- package/lib/typescript/Skeleton.d.ts +13 -0
- package/lib/typescript/Skeleton.d.ts.map +1 -0
- package/lib/typescript/Slider.d.ts +21 -0
- package/lib/typescript/Slider.d.ts.map +1 -0
- package/lib/typescript/Spinner.d.ts +12 -0
- package/lib/typescript/Spinner.d.ts.map +1 -0
- package/lib/typescript/Swap.d.ts +25 -0
- package/lib/typescript/Swap.d.ts.map +1 -0
- package/lib/typescript/Tabs.d.ts +18 -0
- package/lib/typescript/Tabs.d.ts.map +1 -0
- package/lib/typescript/Text.d.ts +20 -0
- package/lib/typescript/Text.d.ts.map +1 -0
- package/lib/typescript/TextField.d.ts +36 -0
- package/lib/typescript/TextField.d.ts.map +1 -0
- package/lib/typescript/Toast.d.ts +25 -0
- package/lib/typescript/Toast.d.ts.map +1 -0
- package/lib/typescript/audio.d.ts +10 -0
- package/lib/typescript/audio.d.ts.map +1 -0
- package/lib/typescript/blur.d.ts +4 -0
- package/lib/typescript/blur.d.ts.map +1 -0
- package/lib/typescript/controls.d.ts +37 -0
- package/lib/typescript/controls.d.ts.map +1 -0
- package/lib/typescript/feel.d.ts +10 -0
- package/lib/typescript/feel.d.ts.map +1 -0
- package/lib/typescript/generated/tokens.d.ts +499 -0
- package/lib/typescript/generated/tokens.d.ts.map +1 -0
- package/lib/typescript/haptics.d.ts +7 -0
- package/lib/typescript/haptics.d.ts.map +1 -0
- package/lib/typescript/icon-host.d.ts +30 -0
- package/lib/typescript/icon-host.d.ts.map +1 -0
- package/lib/typescript/icon-shape.d.ts +28 -0
- package/lib/typescript/icon-shape.d.ts.map +1 -0
- package/lib/typescript/icon.d.ts +24 -0
- package/lib/typescript/icon.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +37 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/layout.d.ts +24 -0
- package/lib/typescript/layout.d.ts.map +1 -0
- package/lib/typescript/marks.d.ts +23 -0
- package/lib/typescript/marks.d.ts.map +1 -0
- package/lib/typescript/motion.d.ts +30 -0
- package/lib/typescript/motion.d.ts.map +1 -0
- package/lib/typescript/overlay.d.ts +33 -0
- package/lib/typescript/overlay.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/pending.d.ts +26 -0
- package/lib/typescript/pending.d.ts.map +1 -0
- package/lib/typescript/presence.d.ts +37 -0
- package/lib/typescript/presence.d.ts.map +1 -0
- package/lib/typescript/press.d.ts +12 -0
- package/lib/typescript/press.d.ts.map +1 -0
- package/lib/typescript/screen.d.ts +21 -0
- package/lib/typescript/screen.d.ts.map +1 -0
- package/lib/typescript/success.d.ts +13 -0
- package/lib/typescript/success.d.ts.map +1 -0
- package/lib/typescript/theme.d.ts +32 -0
- package/lib/typescript/theme.d.ts.map +1 -0
- package/package.json +123 -3
- package/src/AudioPlayer.tsx +106 -0
- package/src/Avatar.tsx +44 -0
- package/src/Badge.tsx +45 -0
- package/src/BottomSheet.tsx +109 -0
- package/src/Bubble.tsx +112 -0
- package/src/Button.tsx +168 -0
- package/src/Card.tsx +70 -0
- package/src/Dialog.tsx +93 -0
- package/src/Disclosure.tsx +108 -0
- package/src/EmptyState.tsx +51 -0
- package/src/Link.tsx +61 -0
- package/src/ListItem.tsx +78 -0
- package/src/Menu.tsx +57 -0
- package/src/Message.tsx +43 -0
- package/src/Popover.tsx +145 -0
- package/src/Progress.tsx +33 -0
- package/src/Select.tsx +118 -0
- package/src/Skeleton.tsx +28 -0
- package/src/Slider.tsx +107 -0
- package/src/Spinner.tsx +18 -0
- package/src/Swap.tsx +74 -0
- package/src/Tabs.tsx +84 -0
- package/src/Text.tsx +44 -0
- package/src/TextField.tsx +137 -0
- package/src/Toast.tsx +122 -0
- package/src/audio.tsx +56 -0
- package/src/blur.tsx +33 -0
- package/src/controls.tsx +224 -0
- package/src/feel.ts +22 -0
- package/src/generated/tokens.ts +653 -0
- package/src/haptics.tsx +26 -0
- package/src/icon-host.tsx +46 -0
- package/src/icon-shape.ts +213 -0
- package/src/icon.tsx +276 -0
- package/src/index.ts +36 -0
- package/src/layout.tsx +40 -0
- package/src/marks.tsx +79 -0
- package/src/motion.ts +94 -0
- package/src/overlay.tsx +77 -0
- package/src/pending.tsx +135 -0
- package/src/presence.tsx +68 -0
- package/src/press.ts +23 -0
- package/src/screen.tsx +37 -0
- package/src/success.tsx +48 -0
- package/src/theme.tsx +49 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a control tells the icons inside it: whether it is on (open, checked) and that it was pressed. The icon
|
|
3
|
+
* of `@fluxus-ui/native/icon` reads it, so that the app wires nothing. No SVG here. (SPEC §15.12)
|
|
4
|
+
*/
|
|
5
|
+
import { createContext, useContext, useMemo, useRef, type ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
export interface IconHost {
|
|
8
|
+
on: boolean;
|
|
9
|
+
/** The colour of the control's text: its icons take it unless they are given one. */
|
|
10
|
+
ink?: string;
|
|
11
|
+
/** Called with the name of a push: 'press'. It returns how to stop listening. */
|
|
12
|
+
listen: (fn: (name: string) => void) => () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const Context = createContext<IconHost | null>(null);
|
|
16
|
+
|
|
17
|
+
export const useIconHost = (): IconHost | null => useContext(Context);
|
|
18
|
+
|
|
19
|
+
type Aria = { 'aria-expanded'?: boolean | null; 'aria-checked'?: boolean | 'mixed' | null };
|
|
20
|
+
|
|
21
|
+
/** On, as on the web: open, or checked. */
|
|
22
|
+
export const isOn = (props: Aria): boolean => props['aria-expanded'] === true || props['aria-checked'] === true;
|
|
23
|
+
|
|
24
|
+
/** For a control: the host its icons read, and the push to give them when it is pressed. */
|
|
25
|
+
export function useHostFor(on: boolean, ink?: string): { host: IconHost; push: (name: string) => void } {
|
|
26
|
+
const listeners = useRef(new Set<(name: string) => void>());
|
|
27
|
+
const host = useMemo<IconHost>(
|
|
28
|
+
() => ({
|
|
29
|
+
on,
|
|
30
|
+
ink,
|
|
31
|
+
listen: (fn) => {
|
|
32
|
+
listeners.current.add(fn);
|
|
33
|
+
return () => void listeners.current.delete(fn);
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
[on, ink],
|
|
37
|
+
);
|
|
38
|
+
const push = useRef((name: string) => {
|
|
39
|
+
for (const fn of listeners.current) fn(name);
|
|
40
|
+
}).current;
|
|
41
|
+
return { host, push };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function IconHostProvider({ host, children }: { host: IconHost; children: ReactNode }) {
|
|
45
|
+
return <Context.Provider value={host}>{children}</Context.Provider>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geometry of a live icon on native, where SVG transforms are not reliable and `pathLength` does not exist:
|
|
3
|
+
* an outline becomes numbers that know what they are (point, radius, angle, flag), its length is measured once,
|
|
4
|
+
* and every frame writes the outline already moved, turned and scaled. (SPEC §15.12)
|
|
5
|
+
*/
|
|
6
|
+
import { parse } from '@fluxus-ui/icons';
|
|
7
|
+
|
|
8
|
+
/** What each number of an outline is: the x or y of a point, a radius, the angle of an arc, or one of its flags. */
|
|
9
|
+
export const X = 0;
|
|
10
|
+
export const Y = 1;
|
|
11
|
+
export const RADIUS = 2;
|
|
12
|
+
export const ANGLE = 3;
|
|
13
|
+
export const FLAG = 4;
|
|
14
|
+
|
|
15
|
+
export interface Shape {
|
|
16
|
+
/** The letters, and '' where a number goes. */
|
|
17
|
+
tpl: string[];
|
|
18
|
+
/** What each number is, in order. */
|
|
19
|
+
kinds: number[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Outline {
|
|
23
|
+
nums: number[];
|
|
24
|
+
/** Its length, in units of the 16 × 16 grid. */
|
|
25
|
+
len: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ARGS: Record<string, number> = { M: 2, L: 2, H: 1, V: 1, C: 6, S: 4, Q: 4, T: 2, A: 7, Z: 0 };
|
|
29
|
+
|
|
30
|
+
type P = [number, number];
|
|
31
|
+
const dist = (a: P, b: P): number => Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
32
|
+
|
|
33
|
+
/** The length of a curve, by sampling it. */
|
|
34
|
+
const sampled = (at: (t: number) => P, steps: number): number => {
|
|
35
|
+
let len = 0;
|
|
36
|
+
let prev = at(0);
|
|
37
|
+
for (let i = 1; i <= steps; i++) {
|
|
38
|
+
const next = at(i / steps);
|
|
39
|
+
len += dist(prev, next);
|
|
40
|
+
prev = next;
|
|
41
|
+
}
|
|
42
|
+
return len;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const cubic = (a: P, b: P, c: P, d: P) => (t: number): P => {
|
|
46
|
+
const u = 1 - t;
|
|
47
|
+
return [u * u * u * a[0] + 3 * u * u * t * b[0] + 3 * u * t * t * c[0] + t * t * t * d[0], u * u * u * a[1] + 3 * u * u * t * b[1] + 3 * u * t * t * c[1] + t * t * t * d[1]];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const quad = (a: P, b: P, c: P) => (t: number): P => {
|
|
51
|
+
const u = 1 - t;
|
|
52
|
+
return [u * u * a[0] + 2 * u * t * b[0] + t * t * c[0], u * u * a[1] + 2 * u * t * b[1] + t * t * c[1]];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/** An arc of SVG from its end points to its centre (SVG 1.1, F.6.5), sampled. */
|
|
56
|
+
const arc = (from: P, rx0: number, ry0: number, phi: number, large: number, sweep: number, to: P): number => {
|
|
57
|
+
let rx = Math.abs(rx0);
|
|
58
|
+
let ry = Math.abs(ry0);
|
|
59
|
+
if (!rx || !ry) return dist(from, to);
|
|
60
|
+
const f = (phi * Math.PI) / 180;
|
|
61
|
+
const cos = Math.cos(f);
|
|
62
|
+
const sin = Math.sin(f);
|
|
63
|
+
const dx = (from[0] - to[0]) / 2;
|
|
64
|
+
const dy = (from[1] - to[1]) / 2;
|
|
65
|
+
const x1 = cos * dx + sin * dy;
|
|
66
|
+
const y1 = -sin * dx + cos * dy;
|
|
67
|
+
const fit = (x1 * x1) / (rx * rx) + (y1 * y1) / (ry * ry);
|
|
68
|
+
if (fit > 1) {
|
|
69
|
+
rx *= Math.sqrt(fit);
|
|
70
|
+
ry *= Math.sqrt(fit);
|
|
71
|
+
}
|
|
72
|
+
const num = rx * rx * ry * ry - rx * rx * y1 * y1 - ry * ry * x1 * x1;
|
|
73
|
+
const k = (large === sweep ? -1 : 1) * Math.sqrt(Math.max(0, num / (rx * rx * y1 * y1 + ry * ry * x1 * x1)));
|
|
74
|
+
const cx1 = (k * rx * y1) / ry;
|
|
75
|
+
const cy1 = (-k * ry * x1) / rx;
|
|
76
|
+
const angle = (ux: number, uy: number, vx: number, vy: number): number => Math.atan2(ux * vy - uy * vx, ux * vx + uy * vy);
|
|
77
|
+
const start = angle(1, 0, (x1 - cx1) / rx, (y1 - cy1) / ry);
|
|
78
|
+
let delta = angle((x1 - cx1) / rx, (y1 - cy1) / ry, (-x1 - cx1) / rx, (-y1 - cy1) / ry);
|
|
79
|
+
if (!sweep && delta > 0) delta -= 2 * Math.PI;
|
|
80
|
+
if (sweep && delta < 0) delta += 2 * Math.PI;
|
|
81
|
+
const mx = (from[0] + to[0]) / 2;
|
|
82
|
+
const my = (from[1] + to[1]) / 2;
|
|
83
|
+
return sampled((t) => {
|
|
84
|
+
const a = start + delta * t;
|
|
85
|
+
const px = rx * Math.cos(a);
|
|
86
|
+
const py = ry * Math.sin(a);
|
|
87
|
+
return [cos * px - sin * py + cos * cx1 - sin * cy1 + mx, sin * px + cos * py + sin * cx1 + cos * cy1 + my];
|
|
88
|
+
}, 32);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** An outline of absolute commands as a shape and its numbers. `H` and `V` become `L`: the same drawing. */
|
|
92
|
+
export function outline(d: string): { shape: Shape; outline: Outline } {
|
|
93
|
+
const tokens = parse(d);
|
|
94
|
+
const tpl: string[] = [];
|
|
95
|
+
const kinds: number[] = [];
|
|
96
|
+
const nums: number[] = [];
|
|
97
|
+
let len = 0;
|
|
98
|
+
let cur: P = [0, 0];
|
|
99
|
+
let start: P = [0, 0];
|
|
100
|
+
/** The last control point, for the smooth curves. */
|
|
101
|
+
let ctrl: P | null = null;
|
|
102
|
+
let prevCmd = '';
|
|
103
|
+
const point = (p: P): void => {
|
|
104
|
+
tpl.push('', '');
|
|
105
|
+
kinds.push(X, Y);
|
|
106
|
+
nums.push(p[0], p[1]);
|
|
107
|
+
};
|
|
108
|
+
let i = 0;
|
|
109
|
+
while (i < tokens.length) {
|
|
110
|
+
const cmd = tokens[i++] as string;
|
|
111
|
+
const per = ARGS[cmd];
|
|
112
|
+
if (per === undefined) throw new Error(`An outline command that is not absolute: ${cmd}`);
|
|
113
|
+
if (per === 0) {
|
|
114
|
+
tpl.push('Z');
|
|
115
|
+
len += dist(cur, start);
|
|
116
|
+
cur = start;
|
|
117
|
+
ctrl = null;
|
|
118
|
+
prevCmd = 'Z';
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
let first = true;
|
|
122
|
+
while (i < tokens.length && typeof tokens[i] === 'number') {
|
|
123
|
+
const a = tokens.slice(i, i + per) as number[];
|
|
124
|
+
i += per;
|
|
125
|
+
// Pairs after the first of an M are lines.
|
|
126
|
+
const c = cmd === 'M' && !first ? 'L' : cmd;
|
|
127
|
+
first = false;
|
|
128
|
+
if (c === 'M') {
|
|
129
|
+
tpl.push('M');
|
|
130
|
+
point([a[0]!, a[1]!]);
|
|
131
|
+
cur = start = [a[0]!, a[1]!];
|
|
132
|
+
ctrl = null;
|
|
133
|
+
} else if (c === 'L' || c === 'H' || c === 'V') {
|
|
134
|
+
const to: P = c === 'L' ? [a[0]!, a[1]!] : c === 'H' ? [a[0]!, cur[1]] : [cur[0], a[0]!];
|
|
135
|
+
tpl.push('L');
|
|
136
|
+
point(to);
|
|
137
|
+
len += dist(cur, to);
|
|
138
|
+
cur = to;
|
|
139
|
+
ctrl = null;
|
|
140
|
+
} else if (c === 'C' || c === 'S') {
|
|
141
|
+
const reflected: P = ctrl && (prevCmd === 'C' || prevCmd === 'S') ? [2 * cur[0] - ctrl[0], 2 * cur[1] - ctrl[1]] : cur;
|
|
142
|
+
const [b, cc, to]: P[] = c === 'C' ? [[a[0]!, a[1]!], [a[2]!, a[3]!], [a[4]!, a[5]!]] : [reflected, [a[0]!, a[1]!], [a[2]!, a[3]!]];
|
|
143
|
+
tpl.push(c);
|
|
144
|
+
if (c === 'C') point(b!);
|
|
145
|
+
point(cc!);
|
|
146
|
+
point(to!);
|
|
147
|
+
len += sampled(cubic(cur, b!, cc!, to!), 24);
|
|
148
|
+
ctrl = cc!;
|
|
149
|
+
cur = to!;
|
|
150
|
+
} else if (c === 'Q' || c === 'T') {
|
|
151
|
+
const b: P = c === 'Q' ? [a[0]!, a[1]!] : ctrl && (prevCmd === 'Q' || prevCmd === 'T') ? [2 * cur[0] - ctrl[0], 2 * cur[1] - ctrl[1]] : cur;
|
|
152
|
+
const to: P = c === 'Q' ? [a[2]!, a[3]!] : [a[0]!, a[1]!];
|
|
153
|
+
tpl.push(c);
|
|
154
|
+
if (c === 'Q') point(b);
|
|
155
|
+
point(to);
|
|
156
|
+
len += sampled(quad(cur, b, to), 24);
|
|
157
|
+
ctrl = b;
|
|
158
|
+
cur = to;
|
|
159
|
+
} else {
|
|
160
|
+
const to: P = [a[5]!, a[6]!];
|
|
161
|
+
tpl.push('A', '', '', '', '', '');
|
|
162
|
+
kinds.push(RADIUS, RADIUS, ANGLE, FLAG, FLAG);
|
|
163
|
+
nums.push(a[0]!, a[1]!, a[2]!, a[3]!, a[4]!);
|
|
164
|
+
point(to);
|
|
165
|
+
len += arc(cur, a[0]!, a[1]!, a[2]!, a[3]!, a[4]!, to);
|
|
166
|
+
cur = to;
|
|
167
|
+
ctrl = null;
|
|
168
|
+
}
|
|
169
|
+
prevCmd = c;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { shape: { tpl, kinds }, outline: { nums, len } };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const fmt = (v: number): string => {
|
|
176
|
+
'worklet';
|
|
177
|
+
return String(Math.round(v * 100) / 100);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The outline between two sets of numbers, at `t`, moved by (x, y), turned by r degrees and scaled by s around
|
|
182
|
+
* (cx, cy): what the transform of the web does to the same outline.
|
|
183
|
+
*/
|
|
184
|
+
export function written(shape: Shape, a: number[], b: number[], t: number, x: number, y: number, r: number, s: number, cx: number, cy: number): string {
|
|
185
|
+
'worklet';
|
|
186
|
+
const rad = (r * Math.PI) / 180;
|
|
187
|
+
const cos = Math.cos(rad);
|
|
188
|
+
const sin = Math.sin(rad);
|
|
189
|
+
const { tpl, kinds } = shape;
|
|
190
|
+
let out = '';
|
|
191
|
+
let j = 0;
|
|
192
|
+
for (let i = 0; i < tpl.length; i++) {
|
|
193
|
+
const letter = tpl[i];
|
|
194
|
+
if (letter) {
|
|
195
|
+
out += out ? ` ${letter}` : letter;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const kind = kinds[j]!;
|
|
199
|
+
const v = a[j]! + (b[j]! - a[j]!) * t;
|
|
200
|
+
if (kind === X) {
|
|
201
|
+
const w = a[j + 1]! + (b[j + 1]! - a[j + 1]!) * t;
|
|
202
|
+
const dx = v - cx;
|
|
203
|
+
const dy = w - cy;
|
|
204
|
+
out += ` ${fmt(cx + s * (dx * cos - dy * sin) + x)} ${fmt(cy + s * (dx * sin + dy * cos) + y)}`;
|
|
205
|
+
j += 2;
|
|
206
|
+
i++;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
out += ` ${fmt(kind === RADIUS ? v * s : kind === ANGLE ? v + r : v)}`;
|
|
210
|
+
j++;
|
|
211
|
+
}
|
|
212
|
+
return out;
|
|
213
|
+
}
|
package/src/icon.tsx
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@fluxus-ui/native/icon`: an icon of @fluxus-ui/icons, drawn with react-native-svg and moved on the UI thread.
|
|
3
|
+
* The same data and the same engine as the web (icons/src/attach.ts): a state takes every part to its pose with
|
|
4
|
+
* a spring, a push springs back, and at rest it draws what the web draws. Its own entry, so that an app that
|
|
5
|
+
* draws no icons does not need the libraries. (SPEC §15.5, §15.12)
|
|
6
|
+
*/
|
|
7
|
+
import { memo, useEffect, useMemo, useRef } from 'react';
|
|
8
|
+
import Svg, { Path } from 'react-native-svg';
|
|
9
|
+
import Animated, { cancelAnimation, makeMutable, useAnimatedProps, useReducedMotion, useSharedValue, type SharedValue } from 'react-native-reanimated';
|
|
10
|
+
import { ICON_SPRINGS, REST, poseOf, type Full, type IconDef, type IconPart } from '@fluxus-ui/icons';
|
|
11
|
+
import { useIconHost } from './icon-host';
|
|
12
|
+
import { outline, written, type Outline, type Shape } from './icon-shape';
|
|
13
|
+
import { withFluxSpring } from './motion';
|
|
14
|
+
import { useTheme } from './theme';
|
|
15
|
+
|
|
16
|
+
/** An icon of @fluxus-ui/icons. */
|
|
17
|
+
export type IconData = { name?: string; parts: IconDef['parts']; kicks?: IconDef['kicks'] };
|
|
18
|
+
|
|
19
|
+
export interface IconProps {
|
|
20
|
+
icon: IconData;
|
|
21
|
+
/** A size of the theme, or points. Default: 'md'. */
|
|
22
|
+
size?: 'sm' | 'md' | 'lg' | number;
|
|
23
|
+
/** Default: the colour of the text. */
|
|
24
|
+
color?: string;
|
|
25
|
+
/** What it means, for a screen reader. Without it the icon is decoration: the text beside it says it. */
|
|
26
|
+
label?: string;
|
|
27
|
+
/** A state the icon names. Without it, the control it is in says: 'on' when open or checked, else 'rest'. */
|
|
28
|
+
state?: string;
|
|
29
|
+
/** 0–1, for the parts that follow it (`draw: 'p'`). */
|
|
30
|
+
progress?: number;
|
|
31
|
+
testID?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A pose as numbers. `d` is the outline as written, when it is one of the icon's and not a pose caught between two. */
|
|
35
|
+
interface Num {
|
|
36
|
+
nums: number[];
|
|
37
|
+
len: number;
|
|
38
|
+
d: string | null;
|
|
39
|
+
x: number;
|
|
40
|
+
y: number;
|
|
41
|
+
r: number;
|
|
42
|
+
s: number;
|
|
43
|
+
draw: number;
|
|
44
|
+
o: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Prep {
|
|
48
|
+
part: IconPart;
|
|
49
|
+
shape: Shape;
|
|
50
|
+
cx: number;
|
|
51
|
+
cy: number;
|
|
52
|
+
lag: number;
|
|
53
|
+
outlines: Map<string, Outline>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface Live {
|
|
57
|
+
/** The pose it was made in: the props of its first frame, before the UI thread writes them. */
|
|
58
|
+
first: Num;
|
|
59
|
+
from: SharedValue<Num>;
|
|
60
|
+
to: SharedValue<Num>;
|
|
61
|
+
off: Record<'x' | 'y' | 'r' | 's', SharedValue<number>>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
65
|
+
const STROKE = 1.5;
|
|
66
|
+
|
|
67
|
+
const prepare = (icon: IconData): Prep[] =>
|
|
68
|
+
icon.parts.map((part) => {
|
|
69
|
+
const { shape, outline: rest } = outline(part.d);
|
|
70
|
+
const [cx, cy] = part.c ?? [8, 8];
|
|
71
|
+
return { part, shape, cx, cy, lag: part.lag ?? 0, outlines: new Map([[part.d, rest]]) };
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const numOf = (prep: Prep, pose: Full): Num => {
|
|
75
|
+
let o = prep.outlines.get(pose.d);
|
|
76
|
+
if (!o) prep.outlines.set(pose.d, (o = outline(pose.d).outline));
|
|
77
|
+
return { nums: o.nums, len: o.len, d: pose.d, x: pose.x, y: pose.y, r: pose.r, s: pose.s, draw: pose.draw, o: pose.o };
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const clamp01 = (v: number): number => {
|
|
81
|
+
'worklet';
|
|
82
|
+
return Math.min(1, Math.max(0, v));
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** Where a part is at `g` of the way between its two poses, as in attach.ts `now()`. */
|
|
86
|
+
const between = (a: Num, b: Num, g: number, lag: number): Num => {
|
|
87
|
+
'worklet';
|
|
88
|
+
const t = lag ? Math.max(0, (g - lag) / (1 - lag)) : g;
|
|
89
|
+
const pose: Num = { ...b, d: t >= 1 ? b.d : t <= 0 ? a.d : a.d !== null && a.d === b.d ? a.d : null };
|
|
90
|
+
pose.nums = t >= 1 ? b.nums : t <= 0 ? a.nums : a.nums.map((v, i) => v + (b.nums[i]! - v) * t);
|
|
91
|
+
pose.len = a.len + (b.len - a.len) * clamp01(t);
|
|
92
|
+
pose.x = a.x + (b.x - a.x) * t;
|
|
93
|
+
pose.y = a.y + (b.y - a.y) * t;
|
|
94
|
+
pose.r = a.r + (b.r - a.r) * t;
|
|
95
|
+
pose.s = a.s + (b.s - a.s) * t;
|
|
96
|
+
pose.draw = clamp01(a.draw + (b.draw - a.draw) * t);
|
|
97
|
+
pose.o = clamp01(a.o + (b.o - a.o) * t);
|
|
98
|
+
return pose;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** The props of a part in a pose, with what the pushes add: the attributes of attach.ts, without transforms. */
|
|
102
|
+
const propsOf = (shape: Shape, p: Num, cx: number, cy: number, ox: number, oy: number, or: number, os: number) => {
|
|
103
|
+
'worklet';
|
|
104
|
+
const x = p.x + ox;
|
|
105
|
+
const y = p.y + oy;
|
|
106
|
+
const r = p.r + or;
|
|
107
|
+
const s = p.s + os;
|
|
108
|
+
const still = Math.abs(x) < 1e-6 && Math.abs(y) < 1e-6 && Math.abs(r) < 1e-6 && Math.abs(s - 1) < 1e-6;
|
|
109
|
+
const d = still && p.d !== null ? p.d : written(shape, p.nums, p.nums, 0, x, y, r, s, cx, cy);
|
|
110
|
+
const hidden = p.draw < 0.001 || p.o < 0.001;
|
|
111
|
+
const len = Math.max(0, p.len * s);
|
|
112
|
+
return {
|
|
113
|
+
d,
|
|
114
|
+
strokeWidth: STROKE * Math.max(0, s),
|
|
115
|
+
// A part not drawn at all is hidden: with round caps a dash of 0 would still paint a dot.
|
|
116
|
+
opacity: hidden ? 0 : p.o,
|
|
117
|
+
// Whole: a dash longer than the outline. Part of it: drawn from where the outline starts.
|
|
118
|
+
strokeDasharray: hidden || p.draw > 0.999 ? [len * 2 + 1, 1] : [Math.max(0.001, p.draw * len), len * 2 + 1],
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const ids = new WeakMap<object, number>();
|
|
123
|
+
let lastId = 0;
|
|
124
|
+
const idOf = (icon: object): number => {
|
|
125
|
+
let id = ids.get(icon);
|
|
126
|
+
if (id === undefined) ids.set(icon, (id = ++lastId));
|
|
127
|
+
return id;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** An icon is live when it has another state or a push; else it is drawn once, with nothing animated. */
|
|
131
|
+
const isLive = (icon: IconData): boolean => !!(icon.kicks && Object.keys(icon.kicks).length) || icon.parts.some((p) => p.on && Object.keys(p.on).length);
|
|
132
|
+
|
|
133
|
+
export function Icon({ icon, size = 'md', color, label, state, progress = 0, testID }: IconProps) {
|
|
134
|
+
const theme = useTheme();
|
|
135
|
+
const host = useIconHost();
|
|
136
|
+
const side = typeof size === 'number' ? size : theme.size[`icon.${size}`];
|
|
137
|
+
const ink = color ?? host?.ink ?? theme.color['text.default'];
|
|
138
|
+
const a11y = label ? ({ accessible: true, accessibilityRole: 'image', accessibilityLabel: label } as const) : ({ accessible: false, accessibilityElementsHidden: true, importantForAccessibility: 'no-hide-descendants' } as const);
|
|
139
|
+
const preps = useMemo(() => prepare(icon), [icon]);
|
|
140
|
+
const now = state ?? (host?.on ? 'on' : REST);
|
|
141
|
+
return (
|
|
142
|
+
<Svg testID={testID} width={side} height={side} viewBox="0 0 16 16" fill="none" stroke={ink} strokeWidth={STROKE} strokeLinecap="round" strokeLinejoin="round" {...a11y}>
|
|
143
|
+
{isLive(icon) ? (
|
|
144
|
+
<LiveParts key={idOf(icon)} icon={icon} preps={preps} state={now} progress={progress} ink={ink} />
|
|
145
|
+
) : (
|
|
146
|
+
preps.map((prep) => {
|
|
147
|
+
const pose = numOf(prep, poseOf(prep.part, now, progress));
|
|
148
|
+
const props = propsOf(prep.shape, pose, prep.cx, prep.cy, 0, 0, 0, 0);
|
|
149
|
+
// A part that is hidden at rest only shows in another state of the icon.
|
|
150
|
+
if (props.opacity === 0) return null;
|
|
151
|
+
return <Path key={prep.part.id} d={props.d} opacity={pose.o < 1 ? pose.o : undefined} strokeWidth={pose.s !== 1 ? props.strokeWidth : undefined} strokeDasharray={pose.draw < 1 ? props.strokeDasharray : undefined} fill={prep.part.fill ? ink : undefined} />;
|
|
152
|
+
})
|
|
153
|
+
)}
|
|
154
|
+
</Svg>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function LiveParts({ icon, preps, state, progress, ink }: { icon: IconData; preps: Prep[]; state: string; progress: number; ink: string }) {
|
|
159
|
+
const host = useIconHost();
|
|
160
|
+
const reduced = useReducedMotion();
|
|
161
|
+
const g = useSharedValue(1);
|
|
162
|
+
const lives = useMemo<Live[]>(
|
|
163
|
+
() =>
|
|
164
|
+
preps.map((prep) => {
|
|
165
|
+
const pose = numOf(prep, poseOf(prep.part, state, progress));
|
|
166
|
+
return { first: pose, from: makeMutable(pose), to: makeMutable(pose), off: { x: makeMutable(0), y: makeMutable(0), r: makeMutable(0), s: makeMutable(0) } };
|
|
167
|
+
}),
|
|
168
|
+
// The poses it starts in; after that the engine moves them.
|
|
169
|
+
[preps],
|
|
170
|
+
);
|
|
171
|
+
const engine = useRef({ state, progress, ends: [state, state] as [string | null, string], aim: 1 as 0 | 1, timers: new Set<ReturnType<typeof setTimeout>>() });
|
|
172
|
+
|
|
173
|
+
const kick = (name: string): void => {
|
|
174
|
+
if (reduced) return;
|
|
175
|
+
for (const k of icon.kicks?.[name] ?? []) {
|
|
176
|
+
const start = (): void => {
|
|
177
|
+
preps.forEach((prep, i) => {
|
|
178
|
+
if (k.p !== '*' && k.p !== prep.part.id) return;
|
|
179
|
+
const sv = lives[i]!.off[k.k];
|
|
180
|
+
const to = k.to ?? 0;
|
|
181
|
+
// One push at a time on each property: a second one adds to the speed of the first.
|
|
182
|
+
sv.value = withFluxSpring(to, { ...(to ? ICON_SPRINGS.turn : ICON_SPRINGS.push), velocity: k.v ?? 0, restDelta: k.k === 's' ? 0.002 : 0.05, restSpeed: 0.05 }, (finished) => {
|
|
183
|
+
'worklet';
|
|
184
|
+
// A full turn looks like none: it starts from 0 again.
|
|
185
|
+
if (finished) sv.value = 0;
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
if (k.wait) {
|
|
190
|
+
const timer = setTimeout(() => {
|
|
191
|
+
engine.current.timers.delete(timer);
|
|
192
|
+
start();
|
|
193
|
+
}, k.wait);
|
|
194
|
+
engine.current.timers.add(timer);
|
|
195
|
+
} else start();
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const go = (next: string, force: boolean): void => {
|
|
200
|
+
const e = engine.current;
|
|
201
|
+
if (next === e.state && !force) return;
|
|
202
|
+
const at = g.value;
|
|
203
|
+
const running = Math.abs(at - e.aim) > 0.002;
|
|
204
|
+
if (reduced) {
|
|
205
|
+
cancelAnimation(g);
|
|
206
|
+
e.state = next;
|
|
207
|
+
e.aim = 1;
|
|
208
|
+
e.ends = [next, next];
|
|
209
|
+
preps.forEach((prep, i) => {
|
|
210
|
+
const pose = numOf(prep, poseOf(prep.part, next, e.progress));
|
|
211
|
+
lives[i]!.from.value = pose;
|
|
212
|
+
lives[i]!.to.value = pose;
|
|
213
|
+
});
|
|
214
|
+
g.value = 1;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (running && !force && next === e.ends[1 - e.aim]) {
|
|
218
|
+
// Back to where it came from: the same spring turns round with the speed it has.
|
|
219
|
+
e.aim = e.aim ? 0 : 1;
|
|
220
|
+
e.state = next;
|
|
221
|
+
g.value = withFluxSpring(e.aim, { ...ICON_SPRINGS.state, restDelta: 0.002 });
|
|
222
|
+
} else {
|
|
223
|
+
// Anywhere else: from the pose it is in.
|
|
224
|
+
preps.forEach((prep, i) => {
|
|
225
|
+
const live = lives[i]!;
|
|
226
|
+
live.from.value = between(live.from.value, live.to.value, at, prep.lag);
|
|
227
|
+
live.to.value = numOf(prep, poseOf(prep.part, next, e.progress));
|
|
228
|
+
});
|
|
229
|
+
e.ends = [running || force ? null : e.state, next];
|
|
230
|
+
e.state = next;
|
|
231
|
+
e.aim = 1;
|
|
232
|
+
g.value = 0;
|
|
233
|
+
g.value = withFluxSpring(1, { ...ICON_SPRINGS.state, restDelta: 0.002 });
|
|
234
|
+
}
|
|
235
|
+
if (!force) kick(next);
|
|
236
|
+
};
|
|
237
|
+
const latest = useRef({ go, kick });
|
|
238
|
+
latest.current = { go, kick };
|
|
239
|
+
|
|
240
|
+
useEffect(() => {
|
|
241
|
+
const e = engine.current;
|
|
242
|
+
const moved = progress !== e.progress;
|
|
243
|
+
e.progress = progress;
|
|
244
|
+
latest.current.go(state, moved);
|
|
245
|
+
}, [state, progress]);
|
|
246
|
+
|
|
247
|
+
useEffect(() => host?.listen((name) => latest.current.kick(name)), [host]);
|
|
248
|
+
|
|
249
|
+
useEffect(
|
|
250
|
+
() => () => {
|
|
251
|
+
for (const timer of engine.current.timers) clearTimeout(timer);
|
|
252
|
+
cancelAnimation(g);
|
|
253
|
+
for (const live of lives) for (const sv of Object.values(live.off)) cancelAnimation(sv);
|
|
254
|
+
},
|
|
255
|
+
[g, lives],
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
return (
|
|
259
|
+
<>
|
|
260
|
+
{preps.map((prep, i) => (
|
|
261
|
+
<LivePart key={prep.part.id} prep={prep} live={lives[i]!} g={g} ink={ink} />
|
|
262
|
+
))}
|
|
263
|
+
</>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const LivePart = memo(function LivePart({ prep, live, g, ink }: { prep: Prep; live: Live; g: SharedValue<number>; ink: string }) {
|
|
268
|
+
const { shape, cx, cy, lag } = prep;
|
|
269
|
+
const { from, to, off } = live;
|
|
270
|
+
const animated = useAnimatedProps(() => propsOf(shape, between(from.value, to.value, g.value, lag), cx, cy, off.x.value, off.y.value, off.r.value, off.s.value));
|
|
271
|
+
// The same every render: React does not send it again over what the UI thread writes.
|
|
272
|
+
const first = useMemo(() => propsOf(shape, live.first, cx, cy, 0, 0, 0, 0), [shape, live, cx, cy]);
|
|
273
|
+
return <AnimatedPath {...first} animatedProps={animated} fill={prep.part.fill ? ink : undefined} />;
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
export { Success, type SuccessProps } from './success';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { ThemeProvider, useTheme, type Theme, type ThemeProviderProps, type Mode, type Fonts } from './theme';
|
|
2
|
+
export { themes, motion, type ThemeTokens, type AppToken, type ColorToken, type SizeToken, type NumberToken, type WeightToken } from './generated/tokens';
|
|
3
|
+
export { spring, timing, ms, setMotionScale, withFluxSpring, type SpringPreset, type DurationToken, type EasingToken, type FluxSpringConfig } from './motion';
|
|
4
|
+
export { IconHostProvider, useHostFor, useIconHost, isOn, type IconHost } from './icon-host';
|
|
5
|
+
export { Mark, TICK, DASH, BANG, type MarkProps } from './marks';
|
|
6
|
+
export { setHaptics, feel, type HapticKind } from './feel';
|
|
7
|
+
export { Text, textStyle, type TextProps, type TextVariant, type TextTone, type TextWeight } from './Text';
|
|
8
|
+
export { Button, buttonStyle, type ButtonProps, type ButtonVariant, type ButtonSize } from './Button';
|
|
9
|
+
export { usePress } from './press';
|
|
10
|
+
export { Badge, toneColors, type BadgeProps, type Tone } from './Badge';
|
|
11
|
+
export { Card, cardStyle, type CardProps } from './Card';
|
|
12
|
+
export { Progress, type ProgressProps } from './Progress';
|
|
13
|
+
export { Message, type MessageProps } from './Message';
|
|
14
|
+
export { TextField, TextArea, SearchField, type TextFieldProps, type SearchFieldProps } from './TextField';
|
|
15
|
+
export { Stack, Row, Divider, type StackProps, type RowProps, type Space } from './layout';
|
|
16
|
+
export { Spinner, type SpinnerProps } from './Spinner';
|
|
17
|
+
export { Skeleton, type SkeletonProps } from './Skeleton';
|
|
18
|
+
export { ListItem, type ListItemProps } from './ListItem';
|
|
19
|
+
export { EmptyState, type EmptyStateProps } from './EmptyState';
|
|
20
|
+
export { Avatar, initials, type AvatarProps } from './Avatar';
|
|
21
|
+
export { Tabs, type TabsProps, type TabItem } from './Tabs';
|
|
22
|
+
export { ToastProvider, ToastLayer, useToast, announce, type ToastInput, type ToastProviderProps } from './Toast';
|
|
23
|
+
export { Appear, presence, enter, exit, shift, RISE, STAGGER, type AppearProps } from './presence';
|
|
24
|
+
export { Swap, useSwap, type SwapProps } from './Swap';
|
|
25
|
+
export { usePending, useAsyncPress, settle } from './pending';
|
|
26
|
+
export { Checkbox, Switch, RadioGroup, useControlled, type CheckboxProps, type SwitchProps, type RadioGroupProps, type RadioOption } from './controls';
|
|
27
|
+
export { Slider, type SliderProps } from './Slider';
|
|
28
|
+
export { BottomSheet, type BottomSheetProps } from './BottomSheet';
|
|
29
|
+
export { Dialog, ConfirmDialog, type DialogProps, type ConfirmDialogProps } from './Dialog';
|
|
30
|
+
export { Popover, place, type PopoverProps, type Placement, type Rect } from './Popover';
|
|
31
|
+
export { Menu, MenuItem, MenuSeparator, type MenuProps, type MenuItemProps } from './Menu';
|
|
32
|
+
export { Disclosure, Accordion, type DisclosureProps, type AccordionProps, type AccordionItem } from './Disclosure';
|
|
33
|
+
export { Select, type SelectProps, type SelectOption } from './Select';
|
|
34
|
+
export { Link, type LinkProps } from './Link';
|
|
35
|
+
export { Bubble, type BubbleProps, type BubbleStatus } from './Bubble';
|
|
36
|
+
export { AudioPlayer, clock, type AudioPlayerProps } from './AudioPlayer';
|
package/src/layout.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { View, type ViewProps, type ViewStyle } from 'react-native';
|
|
2
|
+
import { useTheme } from './theme';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* For what takes the room left in a row. Not `flex: 1`: that has no width of its own, and in what is only as
|
|
6
|
+
* wide as what it holds (a menu, a popover) the text would break letter by letter. (SPEC §15.8)
|
|
7
|
+
*/
|
|
8
|
+
export const fill: ViewStyle = { flexGrow: 1, flexShrink: 1, flexBasis: 'auto' };
|
|
9
|
+
|
|
10
|
+
/** A step of the space scale: `space.3` is 12 points. */
|
|
11
|
+
export type Space = '1' | '2' | '3' | '4' | '5' | '6' | '8' | '10' | '12' | '16';
|
|
12
|
+
|
|
13
|
+
export interface StackProps extends ViewProps {
|
|
14
|
+
gap?: Space;
|
|
15
|
+
align?: ViewStyle['alignItems'];
|
|
16
|
+
justify?: ViewStyle['justifyContent'];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** What it holds, one under the other. */
|
|
20
|
+
export function Stack({ gap = '3', align, justify, style, ...rest }: StackProps) {
|
|
21
|
+
const theme = useTheme();
|
|
22
|
+
return <View {...rest} style={[{ gap: theme.size[`space.${gap}`], alignItems: align, justifyContent: justify }, style]} />;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RowProps extends StackProps {
|
|
26
|
+
/** It goes on to the next line when it does not fit. */
|
|
27
|
+
wrap?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** What it holds, side by side, in the direction of the language. */
|
|
31
|
+
export function Row({ gap = '2', align = 'center', justify, wrap, style, ...rest }: RowProps) {
|
|
32
|
+
const theme = useTheme();
|
|
33
|
+
return <View {...rest} style={[{ flexDirection: 'row', flexWrap: wrap ? 'wrap' : 'nowrap', gap: theme.size[`space.${gap}`], alignItems: align, justifyContent: justify }, style]} />;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A rule between two things. It is not there for a screen reader. */
|
|
37
|
+
export function Divider({ style, ...rest }: ViewProps) {
|
|
38
|
+
const theme = useTheme();
|
|
39
|
+
return <View aria-hidden importantForAccessibility="no" {...rest} style={[{ height: 1, backgroundColor: theme.color['border.default'] }, style]} />;
|
|
40
|
+
}
|