@xaui/native 0.9.1-alpha.10 → 0.9.1-alpha.11

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.
@@ -1,22 +1,24 @@
1
- import {
2
- Icon,
3
- PressableFeedback,
4
- childrenToString,
5
- createRecipe,
6
- createSlotContext
7
- } from "./chunk-66OVPWF4.js";
8
- import {
9
- useXAUITheme
10
- } from "./chunk-X2K2FX3W.js";
1
+ import { Icon, PressableFeedback, childrenToString, createRecipe, createSlotContext } from "./chunk-R4HJCQPI.js";
2
+ import { useXAUITheme } from "./chunk-X2K2FX3W.js";
11
3
 
12
4
  // src/components/button/button.context.ts
13
5
  var [ButtonProvider, useButton] = createSlotContext("Button");
14
6
 
15
7
  // src/components/button/button-icon.tsx
16
8
  import { jsx } from "react/jsx-runtime";
17
- function ButtonIcon({ size, color, ...rest }) {
18
- const { icon } = useButton();
19
- return /* @__PURE__ */ jsx(Icon, { size: size ?? icon.size, color: color ?? icon.color, ...rest });
9
+ function ButtonIcon({
10
+ size,
11
+ color,
12
+ ...rest
13
+ }) {
14
+ const {
15
+ icon
16
+ } = useButton();
17
+ return /* @__PURE__ */jsx(Icon, {
18
+ size: size ?? icon.size,
19
+ color: color ?? icon.color,
20
+ ...rest
21
+ });
20
22
  }
21
23
  ButtonIcon.displayName = "XAUI.Button.Icon";
22
24
 
@@ -24,55 +26,89 @@ ButtonIcon.displayName = "XAUI.Button.Icon";
24
26
  import { forwardRef } from "react";
25
27
  import { Text } from "react-native";
26
28
  import { jsx as jsx2 } from "react/jsx-runtime";
27
- var ButtonLabel = forwardRef(function ButtonLabel2({ children, style, numberOfLines = 1, ...rest }, ref) {
28
- const { labelStyle } = useButton();
29
- return /* @__PURE__ */ jsx2(
30
- Text,
31
- {
32
- ref,
33
- numberOfLines,
34
- style: [labelStyle, style],
35
- ...rest,
36
- children
37
- }
38
- );
29
+ var ButtonLabel = forwardRef(function ButtonLabel2({
30
+ children,
31
+ style,
32
+ numberOfLines = 1,
33
+ ...rest
34
+ }, ref) {
35
+ const {
36
+ labelStyle
37
+ } = useButton();
38
+ return /* @__PURE__ */jsx2(Text, {
39
+ ref,
40
+ numberOfLines,
41
+ style: [labelStyle, style],
42
+ ...rest,
43
+ children
44
+ });
39
45
  });
40
46
  ButtonLabel.displayName = "XAUI.Button.Label";
41
47
 
42
48
  // src/components/button/button-spinner.tsx
43
49
  import { useEffect } from "react";
44
50
  import { View } from "react-native";
45
- import Animated, {
46
- Easing,
47
- cancelAnimation,
48
- useAnimatedStyle,
49
- useSharedValue,
50
- withRepeat,
51
- withTiming
52
- } from "react-native-reanimated";
51
+ import Animated, { Easing, cancelAnimation, useAnimatedStyle, useSharedValue, withRepeat, withTiming } from "react-native-reanimated";
53
52
  import { jsx as jsx3 } from "react/jsx-runtime";
54
53
  var ROTATION_DURATION = 800;
55
- function ButtonSpinner({ style, animation = true }) {
56
- const { spinnerStyle } = useButton();
57
- if (!animation) return /* @__PURE__ */ jsx3(View, { style: [spinnerStyle, style] });
58
- return /* @__PURE__ */ jsx3(SpinningRing, { style: [spinnerStyle, style] });
54
+ function ButtonSpinner({
55
+ style,
56
+ animation = true
57
+ }) {
58
+ const {
59
+ spinnerStyle
60
+ } = useButton();
61
+ if (!animation) return /* @__PURE__ */jsx3(View, {
62
+ style: [spinnerStyle, style]
63
+ });
64
+ return /* @__PURE__ */jsx3(SpinningRing, {
65
+ style: [spinnerStyle, style]
66
+ });
59
67
  }
60
68
  ButtonSpinner.displayName = "XAUI.Button.Spinner";
61
- function SpinningRing({ style }) {
69
+ const _worklet_1014689086859_init_data = {
70
+ code: "function chunkNQ5WWF77Js1(){const{angle}=this.__closure;return{transform:[{rotate:angle.value+\"deg\"}]};}",
71
+ location: "/home/runner/work/xaui/xaui/packages/native/dist/chunk-NQ5WWF77.js",
72
+ sourceMap: "{\"version\":3,\"names\":[\"chunkNQ5WWF77Js1\",\"angle\",\"__closure\",\"transform\",\"rotate\",\"value\"],\"sources\":[\"/home/runner/work/xaui/xaui/packages/native/dist/chunk-NQ5WWF77.js\"],\"mappings\":\"AAsEyC,SAAAA,gBAAMA,CAAA,QAAAC,KAAA,OAAAC,SAAA,CAE3C,MAAO,CAAEC,SAAS,CAAE,CAAC,CAAEC,MAAM,CAAKH,KAAK,CAACI,KAAK,MAAM,CAAC,CAAE,CAAC,CACzD\",\"ignoreList\":[]}"
73
+ };
74
+ function SpinningRing({
75
+ style
76
+ }) {
62
77
  const angle = useSharedValue(0);
63
78
  useEffect(() => {
64
- angle.value = withRepeat(
65
- withTiming(360, { duration: ROTATION_DURATION, easing: Easing.linear }),
66
- -1,
67
- false
68
- );
79
+ angle.value = withRepeat(withTiming(360, {
80
+ duration: ROTATION_DURATION,
81
+ easing: Easing.linear
82
+ }), -1, false);
69
83
  return () => cancelAnimation(angle);
70
84
  }, [angle]);
71
- const animatedStyle = useAnimatedStyle(
72
- () => ({ transform: [{ rotate: `${angle.value}deg` }] }),
73
- [angle]
74
- );
75
- return /* @__PURE__ */ jsx3(Animated.View, { style: [style, animatedStyle] });
85
+ const animatedStyle = useAnimatedStyle(function chunkNQ5WWF77Js1Factory({
86
+ _worklet_1014689086859_init_data,
87
+ angle
88
+ }) {
89
+ const _e = [new global.Error(), -2, -27];
90
+ const chunkNQ5WWF77Js1 = function () {
91
+ return {
92
+ transform: [{
93
+ rotate: `${angle.value}deg`
94
+ }]
95
+ };
96
+ };
97
+ chunkNQ5WWF77Js1.__closure = {
98
+ angle
99
+ };
100
+ chunkNQ5WWF77Js1.__workletHash = 1014689086859;
101
+ chunkNQ5WWF77Js1.__pluginVersion = "0.7.4";
102
+ chunkNQ5WWF77Js1.__initData = _worklet_1014689086859_init_data;
103
+ chunkNQ5WWF77Js1.__stackDetails = _e;
104
+ return chunkNQ5WWF77Js1;
105
+ }({
106
+ _worklet_1014689086859_init_data,
107
+ angle
108
+ }), [angle]);
109
+ return /* @__PURE__ */jsx3(Animated.View, {
110
+ style: [style, animatedStyle]
111
+ });
76
112
  }
77
113
 
78
114
  // src/components/button/button.tsx
@@ -85,15 +121,18 @@ function usePressState(handlers = {}) {
85
121
  const [isPressed, setIsPressed] = useState(false);
86
122
  const latest = useRef(handlers);
87
123
  latest.current = handlers;
88
- const onPressIn = useCallback((event) => {
124
+ const onPressIn = useCallback(event => {
89
125
  setIsPressed(true);
90
126
  latest.current.onPressIn?.(event);
91
127
  }, []);
92
- const onPressOut = useCallback((event) => {
128
+ const onPressOut = useCallback(event => {
93
129
  setIsPressed(false);
94
130
  latest.current.onPressOut?.(event);
95
131
  }, []);
96
- const press = useRef({ onPressIn, onPressOut }).current;
132
+ const press = useRef({
133
+ onPressIn,
134
+ onPressOut
135
+ }).current;
97
136
  return [isPressed, press];
98
137
  }
99
138
 
@@ -106,27 +145,50 @@ function warnDev(message) {
106
145
  // src/components/button/button.recipe.ts
107
146
  var SLOTS = ["root", "label", "icon", "spinner"];
108
147
  var VARIANT_TOKENS = {
109
- primary: { bg: "accent", bgPressed: "accentPressed", fg: "accentForeground" },
110
- secondary: { bg: "default", bgPressed: "defaultPressed", fg: "defaultForeground" },
148
+ primary: {
149
+ bg: "accent",
150
+ bgPressed: "accentPressed",
151
+ fg: "accentForeground"
152
+ },
153
+ secondary: {
154
+ bg: "default",
155
+ bgPressed: "defaultPressed",
156
+ fg: "defaultForeground"
157
+ },
111
158
  tertiary: {
112
159
  border: "border",
113
160
  bgPressed: "defaultSoftPressed",
114
161
  fg: "foreground"
115
162
  },
116
- ghost: { bgPressed: "defaultSoftPressed", fg: "foreground" },
117
- success: { bg: "success", bgPressed: "successPressed", fg: "successForeground" },
163
+ ghost: {
164
+ bgPressed: "defaultSoftPressed",
165
+ fg: "foreground"
166
+ },
167
+ success: {
168
+ bg: "success",
169
+ bgPressed: "successPressed",
170
+ fg: "successForeground"
171
+ },
118
172
  "success-soft": {
119
173
  bg: "successSoft",
120
174
  bgPressed: "successSoftPressed",
121
175
  fg: "successSoftForeground"
122
176
  },
123
- warning: { bg: "warning", bgPressed: "warningPressed", fg: "warningForeground" },
177
+ warning: {
178
+ bg: "warning",
179
+ bgPressed: "warningPressed",
180
+ fg: "warningForeground"
181
+ },
124
182
  "warning-soft": {
125
183
  bg: "warningSoft",
126
184
  bgPressed: "warningSoftPressed",
127
185
  fg: "warningSoftForeground"
128
186
  },
129
- danger: { bg: "danger", bgPressed: "dangerPressed", fg: "dangerForeground" },
187
+ danger: {
188
+ bg: "danger",
189
+ bgPressed: "dangerPressed",
190
+ fg: "dangerForeground"
191
+ },
130
192
  "danger-soft": {
131
193
  bg: "dangerSoft",
132
194
  bgPressed: "dangerSoftPressed",
@@ -143,8 +205,14 @@ function ring(theme, size) {
143
205
  };
144
206
  }
145
207
  function sizeAxis(step) {
146
- const { size, padding, gap, glyph, radius } = step;
147
- return (theme) => ({
208
+ const {
209
+ size,
210
+ padding,
211
+ gap,
212
+ glyph,
213
+ radius
214
+ } = step;
215
+ return theme => ({
148
216
  root: {
149
217
  height: theme.controlHeights[size],
150
218
  paddingHorizontal: theme.spacing(padding),
@@ -155,13 +223,15 @@ function sizeAxis(step) {
155
223
  fontSize: theme.fontSizes[size],
156
224
  lineHeight: theme.lineHeights[size]
157
225
  },
158
- icon: { fontSize: theme.fontSizes[glyph] },
226
+ icon: {
227
+ fontSize: theme.fontSizes[glyph]
228
+ },
159
229
  spinner: ring(theme, theme.fontSizes[glyph])
160
230
  });
161
231
  }
162
232
  var buttonRecipe = createRecipe({
163
233
  slots: SLOTS,
164
- base: (theme) => ({
234
+ base: theme => ({
165
235
  root: {
166
236
  flexDirection: "row",
167
237
  alignItems: "center",
@@ -188,9 +258,15 @@ var buttonRecipe = createRecipe({
188
258
  borderColor: colors.border,
189
259
  borderWidth: colors.border ? theme.borderWidth.default : 0
190
260
  },
191
- label: { color: colors.fg },
192
- icon: { color: colors.fg },
193
- spinner: { borderColor: colors.fg }
261
+ label: {
262
+ color: colors.fg
263
+ },
264
+ icon: {
265
+ color: colors.fg
266
+ },
267
+ spinner: {
268
+ borderColor: colors.fg
269
+ }
194
270
  }),
195
271
  /**
196
272
  * Declaration order is application order: `radius` overrides the radius `size` set, and
@@ -200,7 +276,13 @@ var buttonRecipe = createRecipe({
200
276
  */
201
277
  variants: {
202
278
  size: {
203
- xs: sizeAxis({ size: "xs", padding: 3, gap: 1, glyph: "sm", radius: "3xl" }),
279
+ xs: sizeAxis({
280
+ size: "xs",
281
+ padding: 3,
282
+ gap: 1,
283
+ glyph: "sm",
284
+ radius: "3xl"
285
+ }),
204
286
  sm: sizeAxis({
205
287
  size: "sm",
206
288
  padding: 3.5,
@@ -208,24 +290,81 @@ var buttonRecipe = createRecipe({
208
290
  glyph: "md",
209
291
  radius: "3xl"
210
292
  }),
211
- md: sizeAxis({ size: "md", padding: 4, gap: 2, glyph: "lg", radius: "3xl" }),
212
- lg: sizeAxis({ size: "lg", padding: 5, gap: 2.5, glyph: "xl", radius: "4xl" })
293
+ md: sizeAxis({
294
+ size: "md",
295
+ padding: 4,
296
+ gap: 2,
297
+ glyph: "lg",
298
+ radius: "3xl"
299
+ }),
300
+ lg: sizeAxis({
301
+ size: "lg",
302
+ padding: 5,
303
+ gap: 2.5,
304
+ glyph: "xl",
305
+ radius: "4xl"
306
+ })
213
307
  },
214
308
  radius: {
215
- xs: (t) => ({ root: { borderRadius: t.radius.xs } }),
216
- sm: (t) => ({ root: { borderRadius: t.radius.sm } }),
217
- md: (t) => ({ root: { borderRadius: t.radius.md } }),
218
- lg: (t) => ({ root: { borderRadius: t.radius.lg } }),
219
- xl: (t) => ({ root: { borderRadius: t.radius.xl } }),
220
- "2xl": (t) => ({ root: { borderRadius: t.radius["2xl"] } }),
221
- "3xl": (t) => ({ root: { borderRadius: t.radius["3xl"] } }),
222
- "4xl": (t) => ({ root: { borderRadius: t.radius["4xl"] } }),
223
- field: (t) => ({ root: { borderRadius: t.radius.field } }),
224
- full: (t) => ({ root: { borderRadius: t.radius.full } })
309
+ xs: t => ({
310
+ root: {
311
+ borderRadius: t.radius.xs
312
+ }
313
+ }),
314
+ sm: t => ({
315
+ root: {
316
+ borderRadius: t.radius.sm
317
+ }
318
+ }),
319
+ md: t => ({
320
+ root: {
321
+ borderRadius: t.radius.md
322
+ }
323
+ }),
324
+ lg: t => ({
325
+ root: {
326
+ borderRadius: t.radius.lg
327
+ }
328
+ }),
329
+ xl: t => ({
330
+ root: {
331
+ borderRadius: t.radius.xl
332
+ }
333
+ }),
334
+ "2xl": t => ({
335
+ root: {
336
+ borderRadius: t.radius["2xl"]
337
+ }
338
+ }),
339
+ "3xl": t => ({
340
+ root: {
341
+ borderRadius: t.radius["3xl"]
342
+ }
343
+ }),
344
+ "4xl": t => ({
345
+ root: {
346
+ borderRadius: t.radius["4xl"]
347
+ }
348
+ }),
349
+ field: t => ({
350
+ root: {
351
+ borderRadius: t.radius.field
352
+ }
353
+ }),
354
+ full: t => ({
355
+ root: {
356
+ borderRadius: t.radius.full
357
+ }
358
+ })
225
359
  },
226
360
  // A square on a fixed height. No width is computed, and none needs to be.
227
361
  isIconOnly: {
228
- true: () => ({ root: { paddingHorizontal: 0, aspectRatio: 1 } })
362
+ true: () => ({
363
+ root: {
364
+ paddingHorizontal: 0,
365
+ aspectRatio: 1
366
+ }
367
+ })
229
368
  }
230
369
  },
231
370
  /**
@@ -236,18 +375,27 @@ var buttonRecipe = createRecipe({
236
375
  * presses through the same OKLab formula as a token one.
237
376
  */
238
377
  states: {
239
- pressed: (_theme, colors) => ({ root: { backgroundColor: colors.bgPressed } }),
240
- disabled: (theme) => ({ root: { opacity: theme.opacity.disabled } })
378
+ pressed: (_theme, colors) => ({
379
+ root: {
380
+ backgroundColor: colors.bgPressed
381
+ }
382
+ }),
383
+ disabled: theme => ({
384
+ root: {
385
+ opacity: theme.opacity.disabled
386
+ }
387
+ })
241
388
  },
242
- defaultVariants: { variant: "primary", size: "md" }
389
+ defaultVariants: {
390
+ variant: "primary",
391
+ size: "md"
392
+ }
243
393
  });
244
394
 
245
395
  // src/components/button/button.utils.ts
246
396
  import { Children, isValidElement } from "react";
247
397
  function containsElementOfType(children, type) {
248
- return Children.toArray(children).some(
249
- (child) => isValidElement(child) && child.type === type
250
- );
398
+ return Children.toArray(children).some(child => isValidElement(child) && child.type === type);
251
399
  }
252
400
 
253
401
  // src/components/button/button.tsx
@@ -273,16 +421,31 @@ var ButtonRoot = forwardRef2(function Button({
273
421
  ...rest
274
422
  }, ref) {
275
423
  const theme = useXAUITheme();
276
- const [isPressed, press] = usePressState({ onPressIn, onPressOut });
424
+ const [isPressed, press] = usePressState({
425
+ onPressIn,
426
+ onPressOut
427
+ });
277
428
  const selection = {
278
429
  variant,
279
430
  size,
280
431
  radius,
281
432
  isIconOnly: isIconOnly ? "true" : void 0
282
433
  };
283
- const states = { pressed: isPressed, disabled: isDisabled || isLoading };
284
- const styles = buttonRecipe.resolve({ theme, selection, states });
285
- const tint = color ? buttonRecipe.tint({ theme, color, selection, states }) : void 0;
434
+ const states = {
435
+ pressed: isPressed,
436
+ disabled: isDisabled || isLoading
437
+ };
438
+ const styles = buttonRecipe.resolve({
439
+ theme,
440
+ selection,
441
+ states
442
+ });
443
+ const tint = color ? buttonRecipe.tint({
444
+ theme,
445
+ color,
446
+ selection,
447
+ states
448
+ }) : void 0;
286
449
  const context = useMemo(() => {
287
450
  const icon = StyleSheet.flatten([styles.icon, tint?.icon]);
288
451
  return {
@@ -298,21 +461,17 @@ var ButtonRoot = forwardRef2(function Button({
298
461
  isLoading
299
462
  };
300
463
  }, [styles, tint, isDisabled, isLoading]);
301
- const rootStyle = [
302
- styles.root,
303
- tint?.root,
304
- typeof style === "function" ? style({ pressed: isPressed }) : style
305
- ];
464
+ const rootStyle = [styles.root, tint?.root, typeof style === "function" ? style({
465
+ pressed: isPressed
466
+ }) : style];
306
467
  const text = childrenToString(children);
307
468
  const showSpinner = isLoading && !containsElementOfType(children, ButtonSpinner);
308
469
  if (isIconOnly && !rest.accessibilityLabel && !rest["aria-label"]) {
309
- warnDev(
310
- "Button: an icon-only button needs an `accessibilityLabel` \u2014 there is no text for a screen reader to read, so it announces as an unlabelled button."
311
- );
470
+ warnDev("Button: an icon-only button needs an `accessibilityLabel` \u2014 there is no text for a screen reader to read, so it announces as an unlabelled button.");
312
471
  }
313
- return /* @__PURE__ */ jsx4(ButtonProvider, { value: context, children: /* @__PURE__ */ jsx4(
314
- PressableFeedback,
315
- {
472
+ return /* @__PURE__ */jsx4(ButtonProvider, {
473
+ value: context,
474
+ children: /* @__PURE__ */jsx4(PressableFeedback, {
316
475
  ref,
317
476
  isPressed,
318
477
  isDisabled: isDisabled || isLoading,
@@ -328,12 +487,13 @@ var ButtonRoot = forwardRef2(function Button({
328
487
  style: rootStyle,
329
488
  onPressIn: press.onPressIn,
330
489
  onPressOut: press.onPressOut,
331
- children: asChild ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
332
- showSpinner ? /* @__PURE__ */ jsx4(ButtonSpinner, {}) : null,
333
- text !== null ? /* @__PURE__ */ jsx4(ButtonLabel, { children: text }) : children
334
- ] })
335
- }
336
- ) });
490
+ children: asChild ? children : /* @__PURE__ */jsxs(Fragment, {
491
+ children: [showSpinner ? /* @__PURE__ */jsx4(ButtonSpinner, {}) : null, text !== null ? /* @__PURE__ */jsx4(ButtonLabel, {
492
+ children: text
493
+ }) : children]
494
+ })
495
+ })
496
+ });
337
497
  });
338
498
  ButtonRoot.displayName = "XAUI.Button.Root";
339
499
 
@@ -343,11 +503,4 @@ var Button2 = Object.assign(ButtonRoot, {
343
503
  Icon: ButtonIcon,
344
504
  Spinner: ButtonSpinner
345
505
  });
346
-
347
- export {
348
- useButton,
349
- usePressState,
350
- warnDev,
351
- buttonRecipe,
352
- Button2 as Button
353
- };
506
+ export { useButton, usePressState, warnDev, buttonRecipe, Button2 as Button };