@xaui/native 0.9.1-alpha.0 → 0.9.1-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-JDS6KGCM.cjs → chunk-2FEDC7U5.cjs} +39 -119
- package/dist/chunk-3QBT3Q65.cjs +125 -0
- package/dist/chunk-3TIDEII6.js +57 -0
- package/dist/chunk-66OVPWF4.js +716 -0
- package/dist/chunk-7D262JCJ.cjs +716 -0
- package/dist/{chunk-T3ZI2PZ6.js → chunk-7XGOXTGT.js} +9 -89
- package/dist/chunk-EQGTD5F6.js +353 -0
- package/dist/chunk-ERCOAOO6.cjs +353 -0
- package/dist/chunk-LMUPNKPH.cjs +57 -0
- package/dist/chunk-X2K2FX3W.js +125 -0
- package/dist/components/button/index.cjs +12 -0
- package/dist/components/button/index.d.cts +192 -0
- package/dist/components/button/index.d.ts +192 -0
- package/dist/components/button/index.js +12 -0
- package/dist/create-recipe-BjSP0zL_.d.cts +210 -0
- package/dist/create-recipe-Dn9kj5Rs.d.ts +210 -0
- package/dist/index.cjs +122 -3
- package/dist/index.d.cts +74 -2
- package/dist/index.d.ts +74 -2
- package/dist/index.js +122 -3
- package/dist/system/index.cjs +53 -0
- package/dist/system/index.d.cts +262 -0
- package/dist/system/index.d.ts +262 -0
- package/dist/system/index.js +53 -0
- package/dist/theme/index.cjs +6 -2
- package/dist/theme/index.d.cts +24 -153
- package/dist/theme/index.d.ts +24 -153
- package/dist/theme/index.js +7 -3
- package/dist/theme.type-C9bFJKFm.d.cts +159 -0
- package/dist/theme.type-C9bFJKFm.d.ts +159 -0
- package/package.json +39 -8
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { ComponentType, ReactNode } from 'react';
|
|
2
|
+
import { ImageSourcePropType, StyleProp, ImageStyle, PressableProps, ViewStyle, TextStyle } from 'react-native';
|
|
3
|
+
import { SharedValue } from 'react-native-reanimated';
|
|
4
|
+
import { g as XAUITheme, X as XAUIColors } from './theme.type-C9bFJKFm.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The props Lucide, Ionicons and `react-native-vector-icons` all accept — the shape
|
|
8
|
+
* `as` is handed. It is a convention rather than an interface anyone published, which is
|
|
9
|
+
* exactly why `Icon` exists: without it every call site computes the two values by hand.
|
|
10
|
+
*/
|
|
11
|
+
type IconComponentProps = {
|
|
12
|
+
size?: number;
|
|
13
|
+
color?: string;
|
|
14
|
+
};
|
|
15
|
+
type IconProps = {
|
|
16
|
+
/** An icon component. `size` and `color` are injected into it. */
|
|
17
|
+
as?: ComponentType<IconComponentProps>;
|
|
18
|
+
/** A raw `react-native-svg` element, cloned with the resolved size and colour. */
|
|
19
|
+
children?: ReactNode;
|
|
20
|
+
/** An image, tinted with the resolved colour. */
|
|
21
|
+
source?: ImageSourcePropType;
|
|
22
|
+
/** Overrides what the surrounding slot asked for. */
|
|
23
|
+
size?: number;
|
|
24
|
+
/** A raw value (R7), never a token. Overrides the slot's. */
|
|
25
|
+
color?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The **`source` form only** — it is the one of the three where we render the view.
|
|
28
|
+
* `as` hands its props to a third-party component and the children form clones an
|
|
29
|
+
* element the caller made; neither is a view this can style, and wrapping them would
|
|
30
|
+
* add a level of depth to every icon in the library. `size` and `color` are the
|
|
31
|
+
* escape hatch there.
|
|
32
|
+
*/
|
|
33
|
+
style?: StyleProp<ImageStyle>;
|
|
34
|
+
};
|
|
35
|
+
/** What a component root publishes so the icons inside it need no props at all. */
|
|
36
|
+
type IconContextValue = {
|
|
37
|
+
size?: number;
|
|
38
|
+
color?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* What the root does under the finger. `scale-highlight` and `scale-ripple` mount their
|
|
43
|
+
* overlay themselves; `scale` mounts none, which is what a root picks when it renders its
|
|
44
|
+
* own `<PressableFeedback.Highlight>` to style it (R1: no prop reaches into another
|
|
45
|
+
* component's insides).
|
|
46
|
+
*/
|
|
47
|
+
type FeedbackVariant = 'scale-highlight' | 'scale-ripple' | 'scale' | 'none';
|
|
48
|
+
type AnimationConfig = {
|
|
49
|
+
scale?: boolean;
|
|
50
|
+
highlight?: boolean;
|
|
51
|
+
ripple?: boolean;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* `false` and `'disabled'` turn this component's animations off. `'disable-all'` turns
|
|
55
|
+
* them off for its descendants too — a long list kills every row's worklets with one
|
|
56
|
+
* prop instead of threading it down. An object switches them off one at a time.
|
|
57
|
+
*/
|
|
58
|
+
type AnimationProp = boolean | 'disabled' | 'disable-all' | AnimationConfig;
|
|
59
|
+
/** `animation` once normalised — what the components actually read. */
|
|
60
|
+
type ResolvedAnimation = {
|
|
61
|
+
scale: boolean;
|
|
62
|
+
highlight: boolean;
|
|
63
|
+
ripple: boolean;
|
|
64
|
+
/** True when every sub-animation is off: the branch that mounts no worklet at all. */
|
|
65
|
+
none: boolean;
|
|
66
|
+
/** Propagated to descendants through context. */
|
|
67
|
+
disableAll: boolean;
|
|
68
|
+
};
|
|
69
|
+
type PressableFeedbackProps = Omit<PressableProps, 'style' | 'children' | 'disabled'> & {
|
|
70
|
+
/** Controlled: the root owns the state, because its recipe resolves on it (R5). */
|
|
71
|
+
isPressed?: boolean;
|
|
72
|
+
/** R8: `disabled` is not part of the public vocabulary, `isX` is. */
|
|
73
|
+
isDisabled?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Merge into the single child instead of rendering a pressable (R12) — **keeping the
|
|
76
|
+
* feedback**. Swapping this component out for a bare `Slot` would silently drop the
|
|
77
|
+
* touch feedback of every `asChild` control.
|
|
78
|
+
*/
|
|
79
|
+
asChild?: boolean;
|
|
80
|
+
feedbackVariant?: FeedbackVariant;
|
|
81
|
+
animation?: AnimationProp;
|
|
82
|
+
style?: StyleProp<ViewStyle>;
|
|
83
|
+
/**
|
|
84
|
+
* `Pressable`'s function form is dropped on purpose. It exists to hand the press state
|
|
85
|
+
* to children; here the root above already owns that state and this publishes it
|
|
86
|
+
* through context, so the function form would be a second, quieter source of truth.
|
|
87
|
+
*/
|
|
88
|
+
children?: ReactNode;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* A slot's own animation, overriding the blanket one on the root. `false` switches that
|
|
92
|
+
* slot off; the object tunes it. Deliberately two knobs rather than a full timing
|
|
93
|
+
* surface — anything past this is a different animation, and that is a component's job,
|
|
94
|
+
* not a prop's.
|
|
95
|
+
*/
|
|
96
|
+
type SlotAnimation = boolean | {
|
|
97
|
+
/** Milliseconds. Falls back to the shared press timing. */
|
|
98
|
+
duration?: number;
|
|
99
|
+
/** How far the overlay goes at full press, 0 to 1. */
|
|
100
|
+
opacity?: number;
|
|
101
|
+
};
|
|
102
|
+
type FeedbackContext = {
|
|
103
|
+
isPressed: boolean;
|
|
104
|
+
animation: ResolvedAnimation;
|
|
105
|
+
/** Absent on the static branch, where nothing animates and no worklet is mounted. */
|
|
106
|
+
progress?: SharedValue<number>;
|
|
107
|
+
/**
|
|
108
|
+
* Bumped on every press-in. The ripple starts from this rather than from a `useEffect`
|
|
109
|
+
* on `isPressed`: a one-shot driven by a boolean depends on React re-rendering between
|
|
110
|
+
* the two touch events, and starting it from the event that carries the coordinates is
|
|
111
|
+
* both simpler and impossible to miss.
|
|
112
|
+
*/
|
|
113
|
+
pressCount?: SharedValue<number>;
|
|
114
|
+
/** Where the finger landed, and how big the root is — the ripple needs both. */
|
|
115
|
+
origin?: SharedValue<{
|
|
116
|
+
x: number;
|
|
117
|
+
y: number;
|
|
118
|
+
}>;
|
|
119
|
+
size?: SharedValue<{
|
|
120
|
+
width: number;
|
|
121
|
+
height: number;
|
|
122
|
+
}>;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A slot is a view or a text node, and a recipe writes one object per slot, so the two
|
|
127
|
+
* RN style shapes are merged rather than discriminated per slot.
|
|
128
|
+
*/
|
|
129
|
+
type SlotStyle = ViewStyle & TextStyle;
|
|
130
|
+
type SlotStyles<Slot extends string> = Partial<Record<Slot, SlotStyle>>;
|
|
131
|
+
/** The roles a variant consumes. The variant names tokens; `paint` says where they land. */
|
|
132
|
+
type VariantRole = 'bg' | 'bgPressed' | 'fg' | 'border';
|
|
133
|
+
/** Token names per role — no colour value ever appears in a recipe. */
|
|
134
|
+
type VariantTokens = Partial<Record<VariantRole, keyof XAUIColors>>;
|
|
135
|
+
/** The same roles resolved: theme colours, or the slices of a raw `color`. */
|
|
136
|
+
type VariantColors = Partial<Record<VariantRole, string>>;
|
|
137
|
+
/**
|
|
138
|
+
* `disabled` is applied last of the three: a control that is both pressed and disabled
|
|
139
|
+
* has to read disabled.
|
|
140
|
+
*/
|
|
141
|
+
type StateName = 'focused' | 'pressed' | 'disabled';
|
|
142
|
+
type States = Partial<Record<StateName, boolean>>;
|
|
143
|
+
/** Reads the theme and the variant's resolved colours; returns one style per slot. */
|
|
144
|
+
type StyleFn<Slot extends string> = (theme: XAUITheme, colors: VariantColors) => SlotStyles<Slot>;
|
|
145
|
+
/** Named axes of finite token values — `{ size: { sm: fn, md: fn } }`. */
|
|
146
|
+
type Axes<Slot extends string> = Record<string, Record<string, StyleFn<Slot>>>;
|
|
147
|
+
/** One value per axis, plus the variant. Missing keys fall back to `defaultVariants`. */
|
|
148
|
+
type Selection<Variant extends string, A extends Axes<string>> = {
|
|
149
|
+
variant?: Variant;
|
|
150
|
+
} & {
|
|
151
|
+
[Axis in keyof A]?: Extract<keyof A[Axis], string>;
|
|
152
|
+
};
|
|
153
|
+
type CompoundVariant<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
|
|
154
|
+
when: Selection<Variant, A>;
|
|
155
|
+
style: StyleFn<Slot>;
|
|
156
|
+
};
|
|
157
|
+
type RecipeConfig<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
|
|
158
|
+
/** Every slot the component publishes. Slots a recipe never styles resolve to `{}`. */
|
|
159
|
+
slots: readonly Slot[];
|
|
160
|
+
base?: StyleFn<Slot>;
|
|
161
|
+
variantTokens?: Record<Variant, VariantTokens>;
|
|
162
|
+
/** Where the variant's colours land — written once, and it holds for every variant. */
|
|
163
|
+
paint?: StyleFn<Slot>;
|
|
164
|
+
variants?: A;
|
|
165
|
+
compoundVariants?: ReadonlyArray<CompoundVariant<Slot, Variant, A>>;
|
|
166
|
+
states?: Partial<Record<StateName, StyleFn<Slot>>>;
|
|
167
|
+
/**
|
|
168
|
+
* `NoInfer`, because this is the one place a single variant name appears on its own:
|
|
169
|
+
* without it, inference reads `Variant` off `{ variant: 'primary' }` and narrows the
|
|
170
|
+
* whole recipe to that one value, so every other variant becomes a type error at the
|
|
171
|
+
* call site. `variantTokens` is the declaration; this only picks a default from it.
|
|
172
|
+
*/
|
|
173
|
+
defaultVariants?: Selection<NoInfer<Variant>, A>;
|
|
174
|
+
};
|
|
175
|
+
/** Stable references: the same object for the same tokens, for the app's lifetime. */
|
|
176
|
+
type ResolvedStyles<Slot extends string> = Readonly<Record<Slot, SlotStyle>>;
|
|
177
|
+
/** A selection with `defaultVariants` already folded in, keyed by axis name. */
|
|
178
|
+
type ResolvedSelection = Readonly<Record<string, string | undefined>>;
|
|
179
|
+
|
|
180
|
+
type ResolveArgs<Variant extends string, A extends Axes<string>> = {
|
|
181
|
+
theme: XAUITheme;
|
|
182
|
+
selection?: Selection<Variant, A>;
|
|
183
|
+
states?: States;
|
|
184
|
+
};
|
|
185
|
+
type TintArgs<Variant extends string, A extends Axes<string>> = ResolveArgs<Variant, A> & {
|
|
186
|
+
color: string;
|
|
187
|
+
};
|
|
188
|
+
type Recipe<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
|
|
189
|
+
readonly slots: readonly Slot[];
|
|
190
|
+
/** The cached pass: stable `StyleSheet` references, keyed by tokens alone. */
|
|
191
|
+
resolve(args: ResolveArgs<Variant, A>): ResolvedStyles<Slot>;
|
|
192
|
+
/**
|
|
193
|
+
* The tint pass: the same functions run again with `color`'s slices in place of the
|
|
194
|
+
* theme's tokens. Uncached and allocating, and only ever called when `color` is set.
|
|
195
|
+
*/
|
|
196
|
+
tint(args: TintArgs<Variant, A>): SlotStyles<Slot>;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* A component's style, declared once. Resolution splits in two because the two halves
|
|
200
|
+
* have different lifetimes: everything keyed by a finite token is cached forever, and
|
|
201
|
+
* an arbitrary `color` is recomputed per render — which is what keeps the cache bounded
|
|
202
|
+
* by the number of token combinations rather than by the palette users invent.
|
|
203
|
+
*
|
|
204
|
+
* const styles = buttonRecipe.resolve({ theme, selection: { variant, size }, states })
|
|
205
|
+
* const tint = color ? buttonRecipe.tint({ theme, color, selection, states }) : undefined
|
|
206
|
+
* <View style={[styles.root, tint?.root, style]} />
|
|
207
|
+
*/
|
|
208
|
+
declare function createRecipe<Slot extends string, Variant extends string, const A extends Axes<Slot>>(config: RecipeConfig<Slot, Variant, A>): Recipe<Slot, Variant, A>;
|
|
209
|
+
|
|
210
|
+
export { type AnimationConfig as A, type CompoundVariant as C, type FeedbackContext as F, type IconComponentProps as I, type PressableFeedbackProps as P, type ResolvedAnimation as R, type SlotAnimation as S, type TintArgs as T, type VariantColors as V, type IconContextValue as a, type IconProps as b, type AnimationProp as c, type FeedbackVariant as d, createRecipe as e, type Recipe as f, type ResolveArgs as g, type Axes as h, type RecipeConfig as i, type ResolvedSelection as j, type ResolvedStyles as k, type Selection as l, type SlotStyle as m, type SlotStyles as n, type StateName as o, type States as p, type StyleFn as q, type VariantRole as r, type VariantTokens as s };
|
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
var _chunkERCOAOO6cjs = require('./chunk-ERCOAOO6.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
12
|
+
var _chunkLMUPNKPHcjs = require('./chunk-LMUPNKPH.cjs');
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
|
|
16
|
-
var _chunkJDS6KGCMcjs = require('./chunk-JDS6KGCM.cjs');
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
@@ -29,4 +30,122 @@ var _chunkJDS6KGCMcjs = require('./chunk-JDS6KGCM.cjs');
|
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
|
|
34
|
+
var _chunk7D262JCJcjs = require('./chunk-7D262JCJ.cjs');
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
var _chunk2FEDC7U5cjs = require('./chunk-2FEDC7U5.cjs');
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
var _chunk3QBT3Q65cjs = require('./chunk-3QBT3Q65.cjs');
|
|
54
|
+
|
|
55
|
+
// src/hooks/use-controllable-state.ts
|
|
56
|
+
var _react = require('react');
|
|
57
|
+
function useControllableState({
|
|
58
|
+
value,
|
|
59
|
+
defaultValue,
|
|
60
|
+
onChange
|
|
61
|
+
}) {
|
|
62
|
+
const [uncontrolled, setUncontrolled] = _react.useState.call(void 0, defaultValue);
|
|
63
|
+
const isControlled = value !== void 0;
|
|
64
|
+
const current = isControlled ? value : uncontrolled;
|
|
65
|
+
useControlWarning(isControlled);
|
|
66
|
+
const latest = _react.useRef.call(void 0, current);
|
|
67
|
+
latest.current = current;
|
|
68
|
+
const onChangeRef = _react.useRef.call(void 0, onChange);
|
|
69
|
+
onChangeRef.current = onChange;
|
|
70
|
+
const controlled = _react.useRef.call(void 0, isControlled);
|
|
71
|
+
controlled.current = isControlled;
|
|
72
|
+
const set = _react.useCallback.call(void 0, (next) => {
|
|
73
|
+
const resolved = typeof next === "function" ? next(latest.current) : next;
|
|
74
|
+
if (resolved === latest.current) return;
|
|
75
|
+
if (!controlled.current) setUncontrolled(resolved);
|
|
76
|
+
_optionalChain([onChangeRef, 'access', _ => _.current, 'optionalCall', _2 => _2(resolved)]);
|
|
77
|
+
}, []);
|
|
78
|
+
return [current, set];
|
|
79
|
+
}
|
|
80
|
+
function useControlWarning(isControlled) {
|
|
81
|
+
const wasControlled = _react.useRef.call(void 0, isControlled);
|
|
82
|
+
if (wasControlled.current !== isControlled) {
|
|
83
|
+
_chunkERCOAOO6cjs.warnDev.call(void 0,
|
|
84
|
+
`a component switched from ${wasControlled.current ? "controlled" : "uncontrolled"} to ${isControlled ? "controlled" : "uncontrolled"}. Decide for the life of the component: pass \`value\` always, or never. Passing \`undefined\` for a value you do control reads as "uncontrolled" here.`
|
|
85
|
+
);
|
|
86
|
+
wasControlled.current = isControlled;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/hooks/use-merged-ref.ts
|
|
91
|
+
|
|
92
|
+
function useMergedRef(...refs) {
|
|
93
|
+
return _react.useMemo.call(void 0, () => _chunk7D262JCJcjs.mergeRefs.call(void 0, ...refs), refs);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/hooks/use-previous.ts
|
|
97
|
+
|
|
98
|
+
function usePrevious(value) {
|
|
99
|
+
const previous = _react.useRef.call(void 0, void 0);
|
|
100
|
+
_react.useEffect.call(void 0, () => {
|
|
101
|
+
previous.current = value;
|
|
102
|
+
}, [value]);
|
|
103
|
+
return previous.current;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
exports.Button = _chunkERCOAOO6cjs.Button; exports.HIGHLIGHT_OPACITY = _chunk7D262JCJcjs.HIGHLIGHT_OPACITY; exports.Icon = _chunk7D262JCJcjs.Icon; exports.IconContext = _chunk7D262JCJcjs.IconContext; exports.PRESS_DURATION = _chunk7D262JCJcjs.PRESS_DURATION; exports.PRESS_SCALE = _chunk7D262JCJcjs.PRESS_SCALE; exports.Portal = _chunkLMUPNKPHcjs.Portal; exports.PortalContext = _chunkLMUPNKPHcjs.PortalContext; exports.PortalHost = _chunkLMUPNKPHcjs.PortalHost; exports.PressableFeedback = _chunk7D262JCJcjs.PressableFeedback; exports.RELEASE_DURATION = _chunk7D262JCJcjs.RELEASE_DURATION; exports.RIPPLE_COVERAGE = _chunk7D262JCJcjs.RIPPLE_COVERAGE; exports.RIPPLE_DURATION = _chunk7D262JCJcjs.RIPPLE_DURATION; exports.RIPPLE_OPACITY = _chunk7D262JCJcjs.RIPPLE_OPACITY; exports.Slot = _chunk7D262JCJcjs.Slot; exports.ThemeContext = _chunk3QBT3Q65cjs.ThemeContext; exports.XAUIProvider = _chunk2FEDC7U5cjs.XAUIProvider; exports.buildRadius = _chunk2FEDC7U5cjs.buildRadius; exports.buildShadows = _chunk2FEDC7U5cjs.buildShadows; exports.buttonRecipe = _chunkERCOAOO6cjs.buttonRecipe; exports.childrenToString = _chunk7D262JCJcjs.childrenToString; exports.createRecipe = _chunk7D262JCJcjs.createRecipe; exports.createSlotContext = _chunk7D262JCJcjs.createSlotContext; exports.createTheme = _chunk2FEDC7U5cjs.createTheme; exports.defaultTheme = _chunk2FEDC7U5cjs.defaultTheme; exports.deriveColors = _chunk2FEDC7U5cjs.deriveColors; exports.deriveTint = _chunk3QBT3Q65cjs.deriveTint; exports.mergeProps = _chunk7D262JCJcjs.mergeProps; exports.mergeRefs = _chunk7D262JCJcjs.mergeRefs; exports.palette = _chunk2FEDC7U5cjs.palette; exports.primitives = _chunk2FEDC7U5cjs.primitives; exports.resolveAnimation = _chunk7D262JCJcjs.resolveAnimation; exports.resolveSlotAnimation = _chunk7D262JCJcjs.resolveSlotAnimation; exports.sourceKeys = _chunk2FEDC7U5cjs.sourceKeys; exports.tokens = _chunk2FEDC7U5cjs.tokens; exports.useButton = _chunkERCOAOO6cjs.useButton; exports.useColorMode = _chunk3QBT3Q65cjs.useColorMode; exports.useControllableState = useControllableState; exports.useFeedback = _chunk7D262JCJcjs.useFeedback; exports.useIconContext = _chunk7D262JCJcjs.useIconContext; exports.useMergedRef = useMergedRef; exports.usePressState = _chunkERCOAOO6cjs.usePressState; exports.usePrevious = usePrevious; exports.useThemeColor = _chunk3QBT3Q65cjs.useThemeColor; exports.useXAUITheme = _chunk3QBT3Q65cjs.useXAUITheme;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,74 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import 'react';
|
|
1
|
+
export { Button, ButtonContextValue, ButtonIconProps, ButtonLabelProps, ButtonProps, ButtonSize, ButtonSlot, ButtonSpinnerProps, ButtonVariant, buttonRecipe, useButton } from './components/button/index.cjs';
|
|
2
|
+
import { RefCallback } from 'react';
|
|
3
|
+
import { PossibleRef } from './system/index.cjs';
|
|
4
|
+
export { AsChildProps, HIGHLIGHT_OPACITY, Icon, IconContext, MergeableProps, PRESS_DURATION, PRESS_SCALE, Portal, PortalContext, PortalHost, PortalHostProps, PortalMethods, PortalProps, PressableFeedback, PressableFeedbackHighlightProps, PressableFeedbackRippleProps, RELEASE_DURATION, RIPPLE_COVERAGE, RIPPLE_DURATION, RIPPLE_OPACITY, Slot, SlotProps, childrenToString, createSlotContext, mergeProps, mergeRefs, resolveAnimation, resolveSlotAnimation, useFeedback, useIconContext } from './system/index.cjs';
|
|
5
|
+
import { GestureResponderEvent } from 'react-native';
|
|
6
|
+
export { A as AnimationConfig, c as AnimationProp, h as Axes, C as CompoundVariant, F as FeedbackContext, d as FeedbackVariant, I as IconComponentProps, a as IconContextValue, b as IconProps, P as PressableFeedbackProps, f as Recipe, i as RecipeConfig, g as ResolveArgs, R as ResolvedAnimation, j as ResolvedSelection, k as ResolvedStyles, l as Selection, S as SlotAnimation, m as SlotStyle, n as SlotStyles, o as StateName, p as States, q as StyleFn, T as TintArgs, V as VariantColors, r as VariantRole, s as VariantTokens, e as createRecipe } from './create-recipe-BjSP0zL_.cjs';
|
|
7
|
+
export { ColorModePreference, PaletteFamily, PaletteShade, ThemeContext, XAUIProvider, XAUIProviderProps, XAUITint, buildRadius, buildShadows, createTheme, defaultTheme, deriveColors, deriveTint, palette, primitives, sourceKeys, tokens, useColorMode, useThemeColor, useXAUITheme } from './theme/index.cjs';
|
|
8
|
+
export { C as ColorMode, F as FontSizeKey, a as FontWeightKey, R as RadiusKey, S as Size, X as XAUIColors, b as XAUIDerivedColors, c as XAUIPrimitiveColors, d as XAUIRadius, e as XAUIShadow, f as XAUISourceColors, g as XAUITheme, h as XAUIThemeConfig, i as XAUIThemeSet } from './theme.type-C9bFJKFm.cjs';
|
|
9
|
+
import 'react-native-reanimated';
|
|
10
|
+
|
|
11
|
+
type ControllableStateOptions<T> = {
|
|
12
|
+
/** Present means controlled: the caller owns the value and this never stores one. */
|
|
13
|
+
value?: T;
|
|
14
|
+
/** The starting value when uncontrolled. */
|
|
15
|
+
defaultValue: T;
|
|
16
|
+
/** Called with every new value, controlled or not. */
|
|
17
|
+
onChange?: (value: T) => void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* One state that works both ways, so a component never has two code paths for "the
|
|
21
|
+
* caller drives this" and "we do".
|
|
22
|
+
*
|
|
23
|
+
* The setter is stable across renders and reads the current value from a ref, so a
|
|
24
|
+
* handler built on it can be passed to a memoized child without rebuilding it on every
|
|
25
|
+
* render — which is the whole reason components reach for this rather than a local
|
|
26
|
+
* `useState` plus an `if`.
|
|
27
|
+
*/
|
|
28
|
+
declare function useControllableState<T>({ value, defaultValue, onChange, }: ControllableStateOptions<T>): [T, (next: T | ((current: T) => T)) => void];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `mergeRefs` for a component that renders: memoized on the refs it was given, so React
|
|
32
|
+
* does not detach and reattach every one of them on each render — which it does whenever
|
|
33
|
+
* a ref callback changes identity, and which costs a node measurement every time.
|
|
34
|
+
*/
|
|
35
|
+
declare function useMergedRef<T>(...refs: Array<PossibleRef<T>>): RefCallback<T>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `null` as much as `undefined`: that is how `PressableProps` types its handlers, and a
|
|
39
|
+
* root forwarding what it was given should not have to launder them first.
|
|
40
|
+
*/
|
|
41
|
+
type PressHandlers = {
|
|
42
|
+
onPressIn?: PressHandler | null;
|
|
43
|
+
onPressOut?: PressHandler | null;
|
|
44
|
+
};
|
|
45
|
+
type PressHandler = (event: GestureResponderEvent) => void;
|
|
46
|
+
/**
|
|
47
|
+
* The press state a root owns, with the handlers that maintain it.
|
|
48
|
+
*
|
|
49
|
+
* It exists because every pressable component needs the same three things and gets one
|
|
50
|
+
* of them wrong on its own: the state has to be *up here* — the recipe resolves on it
|
|
51
|
+
* (R5) — the caller's handlers must be **composed, never replaced**, and the returned
|
|
52
|
+
* handlers must keep their identity so passing them down does not defeat a memo.
|
|
53
|
+
*
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const [isPressed, pressHandlers] = usePressState(props)
|
|
56
|
+
* const styles = recipe.resolve({ theme, selection, states: { pressed: isPressed } })
|
|
57
|
+
* <PressableFeedback isPressed={isPressed} {...pressHandlers} />
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function usePressState(handlers?: PressHandlers): [boolean, {
|
|
61
|
+
onPressIn: PressHandler;
|
|
62
|
+
onPressOut: PressHandler;
|
|
63
|
+
}];
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The value from the render before this one, `undefined` on the first.
|
|
67
|
+
*
|
|
68
|
+
* Written in an effect rather than during render on purpose: reading it mid-render would
|
|
69
|
+
* make "previous" mean something different depending on whether React re-ran the render,
|
|
70
|
+
* which under StrictMode it does.
|
|
71
|
+
*/
|
|
72
|
+
declare function usePrevious<T>(value: T): T | undefined;
|
|
73
|
+
|
|
74
|
+
export { type ControllableStateOptions, PossibleRef, type PressHandlers, useControllableState, useMergedRef, usePressState, usePrevious };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,74 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import 'react';
|
|
1
|
+
export { Button, ButtonContextValue, ButtonIconProps, ButtonLabelProps, ButtonProps, ButtonSize, ButtonSlot, ButtonSpinnerProps, ButtonVariant, buttonRecipe, useButton } from './components/button/index.js';
|
|
2
|
+
import { RefCallback } from 'react';
|
|
3
|
+
import { PossibleRef } from './system/index.js';
|
|
4
|
+
export { AsChildProps, HIGHLIGHT_OPACITY, Icon, IconContext, MergeableProps, PRESS_DURATION, PRESS_SCALE, Portal, PortalContext, PortalHost, PortalHostProps, PortalMethods, PortalProps, PressableFeedback, PressableFeedbackHighlightProps, PressableFeedbackRippleProps, RELEASE_DURATION, RIPPLE_COVERAGE, RIPPLE_DURATION, RIPPLE_OPACITY, Slot, SlotProps, childrenToString, createSlotContext, mergeProps, mergeRefs, resolveAnimation, resolveSlotAnimation, useFeedback, useIconContext } from './system/index.js';
|
|
5
|
+
import { GestureResponderEvent } from 'react-native';
|
|
6
|
+
export { A as AnimationConfig, c as AnimationProp, h as Axes, C as CompoundVariant, F as FeedbackContext, d as FeedbackVariant, I as IconComponentProps, a as IconContextValue, b as IconProps, P as PressableFeedbackProps, f as Recipe, i as RecipeConfig, g as ResolveArgs, R as ResolvedAnimation, j as ResolvedSelection, k as ResolvedStyles, l as Selection, S as SlotAnimation, m as SlotStyle, n as SlotStyles, o as StateName, p as States, q as StyleFn, T as TintArgs, V as VariantColors, r as VariantRole, s as VariantTokens, e as createRecipe } from './create-recipe-Dn9kj5Rs.js';
|
|
7
|
+
export { ColorModePreference, PaletteFamily, PaletteShade, ThemeContext, XAUIProvider, XAUIProviderProps, XAUITint, buildRadius, buildShadows, createTheme, defaultTheme, deriveColors, deriveTint, palette, primitives, sourceKeys, tokens, useColorMode, useThemeColor, useXAUITheme } from './theme/index.js';
|
|
8
|
+
export { C as ColorMode, F as FontSizeKey, a as FontWeightKey, R as RadiusKey, S as Size, X as XAUIColors, b as XAUIDerivedColors, c as XAUIPrimitiveColors, d as XAUIRadius, e as XAUIShadow, f as XAUISourceColors, g as XAUITheme, h as XAUIThemeConfig, i as XAUIThemeSet } from './theme.type-C9bFJKFm.js';
|
|
9
|
+
import 'react-native-reanimated';
|
|
10
|
+
|
|
11
|
+
type ControllableStateOptions<T> = {
|
|
12
|
+
/** Present means controlled: the caller owns the value and this never stores one. */
|
|
13
|
+
value?: T;
|
|
14
|
+
/** The starting value when uncontrolled. */
|
|
15
|
+
defaultValue: T;
|
|
16
|
+
/** Called with every new value, controlled or not. */
|
|
17
|
+
onChange?: (value: T) => void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* One state that works both ways, so a component never has two code paths for "the
|
|
21
|
+
* caller drives this" and "we do".
|
|
22
|
+
*
|
|
23
|
+
* The setter is stable across renders and reads the current value from a ref, so a
|
|
24
|
+
* handler built on it can be passed to a memoized child without rebuilding it on every
|
|
25
|
+
* render — which is the whole reason components reach for this rather than a local
|
|
26
|
+
* `useState` plus an `if`.
|
|
27
|
+
*/
|
|
28
|
+
declare function useControllableState<T>({ value, defaultValue, onChange, }: ControllableStateOptions<T>): [T, (next: T | ((current: T) => T)) => void];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* `mergeRefs` for a component that renders: memoized on the refs it was given, so React
|
|
32
|
+
* does not detach and reattach every one of them on each render — which it does whenever
|
|
33
|
+
* a ref callback changes identity, and which costs a node measurement every time.
|
|
34
|
+
*/
|
|
35
|
+
declare function useMergedRef<T>(...refs: Array<PossibleRef<T>>): RefCallback<T>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `null` as much as `undefined`: that is how `PressableProps` types its handlers, and a
|
|
39
|
+
* root forwarding what it was given should not have to launder them first.
|
|
40
|
+
*/
|
|
41
|
+
type PressHandlers = {
|
|
42
|
+
onPressIn?: PressHandler | null;
|
|
43
|
+
onPressOut?: PressHandler | null;
|
|
44
|
+
};
|
|
45
|
+
type PressHandler = (event: GestureResponderEvent) => void;
|
|
46
|
+
/**
|
|
47
|
+
* The press state a root owns, with the handlers that maintain it.
|
|
48
|
+
*
|
|
49
|
+
* It exists because every pressable component needs the same three things and gets one
|
|
50
|
+
* of them wrong on its own: the state has to be *up here* — the recipe resolves on it
|
|
51
|
+
* (R5) — the caller's handlers must be **composed, never replaced**, and the returned
|
|
52
|
+
* handlers must keep their identity so passing them down does not defeat a memo.
|
|
53
|
+
*
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const [isPressed, pressHandlers] = usePressState(props)
|
|
56
|
+
* const styles = recipe.resolve({ theme, selection, states: { pressed: isPressed } })
|
|
57
|
+
* <PressableFeedback isPressed={isPressed} {...pressHandlers} />
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function usePressState(handlers?: PressHandlers): [boolean, {
|
|
61
|
+
onPressIn: PressHandler;
|
|
62
|
+
onPressOut: PressHandler;
|
|
63
|
+
}];
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The value from the render before this one, `undefined` on the first.
|
|
67
|
+
*
|
|
68
|
+
* Written in an effect rather than during render on purpose: reading it mid-render would
|
|
69
|
+
* make "previous" mean something different depending on whether React re-ran the render,
|
|
70
|
+
* which under StrictMode it does.
|
|
71
|
+
*/
|
|
72
|
+
declare function usePrevious<T>(value: T): T | undefined;
|
|
73
|
+
|
|
74
|
+
export { type ControllableStateOptions, PossibleRef, type PressHandlers, useControllableState, useMergedRef, usePressState, usePrevious };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
Button,
|
|
3
|
+
buttonRecipe,
|
|
4
|
+
useButton,
|
|
5
|
+
usePressState,
|
|
6
|
+
warnDev
|
|
7
|
+
} from "./chunk-EQGTD5F6.js";
|
|
8
|
+
import {
|
|
9
|
+
Portal,
|
|
10
|
+
PortalContext,
|
|
11
|
+
PortalHost
|
|
12
|
+
} from "./chunk-3TIDEII6.js";
|
|
13
|
+
import {
|
|
14
|
+
HIGHLIGHT_OPACITY,
|
|
15
|
+
Icon,
|
|
16
|
+
IconContext,
|
|
17
|
+
PRESS_DURATION,
|
|
18
|
+
PRESS_SCALE,
|
|
19
|
+
PressableFeedback,
|
|
20
|
+
RELEASE_DURATION,
|
|
21
|
+
RIPPLE_COVERAGE,
|
|
22
|
+
RIPPLE_DURATION,
|
|
23
|
+
RIPPLE_OPACITY,
|
|
24
|
+
Slot,
|
|
25
|
+
childrenToString,
|
|
26
|
+
createRecipe,
|
|
27
|
+
createSlotContext,
|
|
28
|
+
mergeProps,
|
|
29
|
+
mergeRefs,
|
|
30
|
+
resolveAnimation,
|
|
31
|
+
resolveSlotAnimation,
|
|
32
|
+
useFeedback,
|
|
33
|
+
useIconContext
|
|
34
|
+
} from "./chunk-66OVPWF4.js";
|
|
35
|
+
import {
|
|
3
36
|
XAUIProvider,
|
|
4
37
|
buildRadius,
|
|
5
38
|
buildShadows,
|
|
@@ -9,24 +42,110 @@ import {
|
|
|
9
42
|
palette,
|
|
10
43
|
primitives,
|
|
11
44
|
sourceKeys,
|
|
12
|
-
tokens
|
|
45
|
+
tokens
|
|
46
|
+
} from "./chunk-7XGOXTGT.js";
|
|
47
|
+
import {
|
|
48
|
+
ThemeContext,
|
|
49
|
+
deriveTint,
|
|
13
50
|
useColorMode,
|
|
14
51
|
useThemeColor,
|
|
15
52
|
useXAUITheme
|
|
16
|
-
} from "./chunk-
|
|
53
|
+
} from "./chunk-X2K2FX3W.js";
|
|
54
|
+
|
|
55
|
+
// src/hooks/use-controllable-state.ts
|
|
56
|
+
import { useCallback, useRef, useState } from "react";
|
|
57
|
+
function useControllableState({
|
|
58
|
+
value,
|
|
59
|
+
defaultValue,
|
|
60
|
+
onChange
|
|
61
|
+
}) {
|
|
62
|
+
const [uncontrolled, setUncontrolled] = useState(defaultValue);
|
|
63
|
+
const isControlled = value !== void 0;
|
|
64
|
+
const current = isControlled ? value : uncontrolled;
|
|
65
|
+
useControlWarning(isControlled);
|
|
66
|
+
const latest = useRef(current);
|
|
67
|
+
latest.current = current;
|
|
68
|
+
const onChangeRef = useRef(onChange);
|
|
69
|
+
onChangeRef.current = onChange;
|
|
70
|
+
const controlled = useRef(isControlled);
|
|
71
|
+
controlled.current = isControlled;
|
|
72
|
+
const set = useCallback((next) => {
|
|
73
|
+
const resolved = typeof next === "function" ? next(latest.current) : next;
|
|
74
|
+
if (resolved === latest.current) return;
|
|
75
|
+
if (!controlled.current) setUncontrolled(resolved);
|
|
76
|
+
onChangeRef.current?.(resolved);
|
|
77
|
+
}, []);
|
|
78
|
+
return [current, set];
|
|
79
|
+
}
|
|
80
|
+
function useControlWarning(isControlled) {
|
|
81
|
+
const wasControlled = useRef(isControlled);
|
|
82
|
+
if (wasControlled.current !== isControlled) {
|
|
83
|
+
warnDev(
|
|
84
|
+
`a component switched from ${wasControlled.current ? "controlled" : "uncontrolled"} to ${isControlled ? "controlled" : "uncontrolled"}. Decide for the life of the component: pass \`value\` always, or never. Passing \`undefined\` for a value you do control reads as "uncontrolled" here.`
|
|
85
|
+
);
|
|
86
|
+
wasControlled.current = isControlled;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/hooks/use-merged-ref.ts
|
|
91
|
+
import { useMemo } from "react";
|
|
92
|
+
function useMergedRef(...refs) {
|
|
93
|
+
return useMemo(() => mergeRefs(...refs), refs);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/hooks/use-previous.ts
|
|
97
|
+
import { useEffect, useRef as useRef2 } from "react";
|
|
98
|
+
function usePrevious(value) {
|
|
99
|
+
const previous = useRef2(void 0);
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
previous.current = value;
|
|
102
|
+
}, [value]);
|
|
103
|
+
return previous.current;
|
|
104
|
+
}
|
|
17
105
|
export {
|
|
106
|
+
Button,
|
|
107
|
+
HIGHLIGHT_OPACITY,
|
|
108
|
+
Icon,
|
|
109
|
+
IconContext,
|
|
110
|
+
PRESS_DURATION,
|
|
111
|
+
PRESS_SCALE,
|
|
112
|
+
Portal,
|
|
113
|
+
PortalContext,
|
|
114
|
+
PortalHost,
|
|
115
|
+
PressableFeedback,
|
|
116
|
+
RELEASE_DURATION,
|
|
117
|
+
RIPPLE_COVERAGE,
|
|
118
|
+
RIPPLE_DURATION,
|
|
119
|
+
RIPPLE_OPACITY,
|
|
120
|
+
Slot,
|
|
18
121
|
ThemeContext,
|
|
19
122
|
XAUIProvider,
|
|
20
123
|
buildRadius,
|
|
21
124
|
buildShadows,
|
|
125
|
+
buttonRecipe,
|
|
126
|
+
childrenToString,
|
|
127
|
+
createRecipe,
|
|
128
|
+
createSlotContext,
|
|
22
129
|
createTheme,
|
|
23
130
|
defaultTheme,
|
|
24
131
|
deriveColors,
|
|
132
|
+
deriveTint,
|
|
133
|
+
mergeProps,
|
|
134
|
+
mergeRefs,
|
|
25
135
|
palette,
|
|
26
136
|
primitives,
|
|
137
|
+
resolveAnimation,
|
|
138
|
+
resolveSlotAnimation,
|
|
27
139
|
sourceKeys,
|
|
28
140
|
tokens,
|
|
141
|
+
useButton,
|
|
29
142
|
useColorMode,
|
|
143
|
+
useControllableState,
|
|
144
|
+
useFeedback,
|
|
145
|
+
useIconContext,
|
|
146
|
+
useMergedRef,
|
|
147
|
+
usePressState,
|
|
148
|
+
usePrevious,
|
|
30
149
|
useThemeColor,
|
|
31
150
|
useXAUITheme
|
|
32
151
|
};
|