@avenue-ticketing/native 0.1.11 → 0.1.13

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/tabs.d.ts CHANGED
@@ -4,12 +4,15 @@ declare const TAB_ORIENTATIONS: readonly ["horizontal", "vertical"];
4
4
  type TabOrientation = (typeof TAB_ORIENTATIONS)[number];
5
5
  declare const TAB_SIZES: readonly ["sm", "md"];
6
6
  type TabSize = (typeof TAB_SIZES)[number];
7
- declare const HORIZONTAL_TAB_TYPES: readonly ["button-brand", "button-gray", "button-border", "button-minimal", "underline"];
7
+ declare const HORIZONTAL_TAB_TYPES: readonly ["button-brand", "button-gray", "button-border", "button-minimal", "button-pill", "underline"];
8
8
  /** `line` = vertical underline (icon + label in a row). `line-stacked` = same chrome, icon above label. */
9
9
  declare const VERTICAL_TAB_TYPES: readonly ["button-brand", "button-gray", "button-border", "button-minimal", "line", "line-stacked"];
10
10
  type HorizontalTabType = (typeof HORIZONTAL_TAB_TYPES)[number];
11
11
  type VerticalTabType = (typeof VERTICAL_TAB_TYPES)[number];
12
12
  type TabType = HorizontalTabType | VerticalTabType;
13
+ /** Fill color for `button-pill` only — maps to solid indicator + selected label. */
14
+ declare const PILL_TAB_COLORS: readonly ["brand", "primary"];
15
+ type PillTabColor = (typeof PILL_TAB_COLORS)[number];
13
16
 
14
17
  declare const TabsRoot: FC<{
15
18
  children?: ReactNode;
@@ -23,6 +26,13 @@ declare const TabList: FC<{
23
26
  children?: ReactNode;
24
27
  size?: TabSize;
25
28
  type?: TabType;
29
+ /** `button-pill` only — indicator fill. Ignored for other types. */
30
+ color?: PillTabColor;
31
+ /**
32
+ * Traveling underline / line border for `underline`, `line`, and `line-stacked`.
33
+ * Defaults to `true`. Ignored for button types (`button-pill` always travels).
34
+ */
35
+ travel?: boolean;
26
36
  fullWidth?: boolean;
27
37
  className?: string;
28
38
  items?: TabItemProps[];
@@ -55,6 +65,13 @@ declare const Tabs: FC<{
55
65
  children?: ReactNode;
56
66
  size?: TabSize;
57
67
  type?: TabType;
68
+ /** `button-pill` only — indicator fill. Ignored for other types. */
69
+ color?: PillTabColor;
70
+ /**
71
+ * Traveling underline / line border for `underline`, `line`, and `line-stacked`.
72
+ * Defaults to `true`. Ignored for button types (`button-pill` always travels).
73
+ */
74
+ travel?: boolean;
58
75
  fullWidth?: boolean;
59
76
  className?: string;
60
77
  items?: TabItemProps[];
@@ -67,4 +84,4 @@ declare const Tabs: FC<{
67
84
  }>;
68
85
  };
69
86
 
70
- export { Tab, type TabItemProps, TabList, type TabOrientation, TabPanel, type TabSize, type TabType, Tabs, TabsRoot };
87
+ export { type PillTabColor, Tab, type TabItemProps, TabList, type TabOrientation, TabPanel, type TabSize, type TabType, Tabs, TabsRoot };
package/dist/tabs.js CHANGED
@@ -1,7 +1,8 @@
1
- import { createContext, useState, useMemo, useContext } from 'react';
2
- import { ScrollView } from 'react-native';
1
+ import { createContext, useState, useMemo, useContext, useCallback, useRef, useEffect } from 'react';
2
+ import { StyleSheet, ScrollView } from 'react-native';
3
3
  import { View, Pressable, Text } from 'react-native-css/components';
4
4
  import { useNativeVariable } from 'react-native-css';
5
+ import Animated, { Easing, useSharedValue, withTiming, useAnimatedStyle } from 'react-native-reanimated';
5
6
  import { extendTailwindMerge } from 'tailwind-merge';
6
7
  import Svg from 'react-native-svg';
7
8
  import 'phosphor-react-native/src/icons/X';
@@ -36,6 +37,23 @@ var isReactComponent = (component) => {
36
37
  };
37
38
 
38
39
  // ../core/src/tabs.ts
40
+ function isLineTabType(type) {
41
+ return type === "underline" || type === "line" || type === "line-stacked";
42
+ }
43
+ var pillTabColorStyles = {
44
+ brand: {
45
+ indicator: "bg-brand-solid",
46
+ selected: "text-primary_on-brand *:data-icon:text-primary_on-brand",
47
+ nativeSelected: "rounded-full bg-brand-solid",
48
+ nativeLabel: "text-primary_on-brand"
49
+ },
50
+ primary: {
51
+ indicator: "bg-primary-solid",
52
+ selected: "text-fg-white *:data-icon:text-fg-white",
53
+ nativeSelected: "rounded-full bg-primary-solid",
54
+ nativeLabel: "text-fg-white"
55
+ }
56
+ };
39
57
  var tabSizes = {
40
58
  sm: {
41
59
  base: "text-sm font-semibold gap-1 *:data-icon:size-4",
@@ -43,6 +61,8 @@ var tabSizes = {
43
61
  "button-gray": "py-2 px-2.5",
44
62
  "button-border": "py-2 px-2.5",
45
63
  "button-minimal": "py-2 px-2.5",
64
+ // Match legacy Avenue UI pill: h-9 + px-4.
65
+ "button-pill": "h-9 rounded-full px-4 py-0",
46
66
  underline: "px-0.5 pb-2.5 pt-0",
47
67
  line: "pl-2.5 pr-3 py-0.5",
48
68
  // Vertical underline + stacked: pl-5 / pr-3, icon size-5.
@@ -55,6 +75,7 @@ var tabSizes = {
55
75
  "button-gray": "py-2.5 px-2.5",
56
76
  "button-border": "py-2.5 px-2.5",
57
77
  "button-minimal": "py-2.5 px-2.5",
78
+ "button-pill": "h-10 rounded-full px-4 py-0",
58
79
  underline: "px-0.5 pb-2.5 pt-0",
59
80
  line: "pr-3.5 pl-3 py-1",
60
81
  "line-stacked": "gap-1.5 py-2 pr-3 pl-5 text-sm font-medium *:data-icon:size-5",
@@ -67,6 +88,7 @@ function tabListStyles({ size, fullWidth }) {
67
88
  "button-gray": "gap-1",
68
89
  "button-border": cx("gap-1 rounded-[10px] bg-secondary_alt p-1 ring-1 ring-secondary ring-inset", size === "md" && "rounded-xl p-1.5"),
69
90
  "button-minimal": "gap-0.5 rounded-lg bg-secondary_alt ring-1 ring-inset ring-secondary",
91
+ "button-pill": "relative items-center gap-1",
70
92
  underline: cx("gap-3", fullWidth && "w-full gap-4"),
71
93
  line: "gap-2",
72
94
  "line-stacked": "gap-1"
@@ -87,9 +109,9 @@ var tabsStyles = {
87
109
  labelRow: "flex-row items-center gap-1.5",
88
110
  labelStacked: "w-full min-w-0",
89
111
  iconStacked: "relative size-5 shrink-0 items-center justify-center overflow-visible",
90
- badgeStacked: "absolute top-0 right-0 z-10 -translate-y-1/2 translate-x-1/2"
91
- };
92
- function tabNativeItemState(type, selected) {
112
+ badgeStacked: "absolute top-0 right-0 z-10 -translate-y-1/2 translate-x-1/2"};
113
+ function tabNativeItemState(type, selected, options = {}) {
114
+ const travel = options.travel !== false;
93
115
  if (!selected) {
94
116
  if (type === "underline" || type === "line" || type === "line-stacked") return "border-transparent";
95
117
  return "";
@@ -103,11 +125,13 @@ function tabNativeItemState(type, selected) {
103
125
  return "bg-primary_alt";
104
126
  case "button-minimal":
105
127
  return "rounded-lg bg-primary_alt border border-primary";
128
+ case "button-pill":
129
+ return "rounded-full";
106
130
  case "underline":
107
- return "rounded-none border-b-2 border-fg-brand-primary_alt";
131
+ return travel ? "rounded-none border-b-2 border-transparent" : "rounded-none border-b-2 border-fg-brand-primary_alt";
108
132
  case "line":
109
133
  case "line-stacked":
110
- return "rounded-none border-l-2 border-fg-brand-primary_alt";
134
+ return travel ? "rounded-none border-l-2 border-transparent" : "rounded-none border-l-2 border-fg-brand-primary_alt";
111
135
  default: {
112
136
  const _exhaustive = type;
113
137
  return _exhaustive;
@@ -116,12 +140,14 @@ function tabNativeItemState(type, selected) {
116
140
  }
117
141
  function tabNativeLabelState(type, selected) {
118
142
  if (!selected) {
119
- if (type === "button-brand") return "text-secondary";
143
+ if (type === "button-brand" || type === "button-pill") return "text-secondary";
120
144
  return "text-quaternary";
121
145
  }
122
146
  switch (type) {
123
147
  case "button-brand":
124
148
  return "text-primary";
149
+ case "button-pill":
150
+ return pillTabColorStyles.brand.nativeLabel;
125
151
  case "button-gray":
126
152
  case "button-border":
127
153
  case "button-minimal":
@@ -293,10 +319,14 @@ var Badge = ({
293
319
  const colorRoot = colors.styles[color].root;
294
320
  return /* @__PURE__ */ jsx(View, { className: cx(colors.common, resolveBadgeSizeClass(type, size), colorRoot, className), children: /* @__PURE__ */ jsx(BadgeLabel, { size, colorClass: colorRoot, children }) });
295
321
  };
322
+ var PILL_EASE = Easing.bezier(0, 0.55, 0.45, 1);
323
+ var PILL_MS = 300;
296
324
  var TabsContext = createContext(void 0);
297
325
  var TabListContext = createContext({
298
326
  size: "sm",
299
327
  type: "button-brand",
328
+ color: "brand",
329
+ travel: true,
300
330
  orientation: "horizontal"
301
331
  });
302
332
  var TabsRoot = ({ children, selectedKey, defaultSelectedKey, onSelectionChange, orientation = "horizontal", className }) => {
@@ -312,9 +342,98 @@ var TabsRoot = ({ children, selectedKey, defaultSelectedKey, onSelectionChange,
312
342
  );
313
343
  return /* @__PURE__ */ jsx(TabsContext.Provider, { value, children: /* @__PURE__ */ jsx(View, { className: cx(orientation === "vertical" ? tabsStyles.rootVertical : tabsStyles.root, className), children }) });
314
344
  };
315
- var TabList = ({ children, size = "sm", type = "button-brand", fullWidth, className, items }) => {
345
+ var TabList = ({ children, size = "sm", type = "button-brand", color = "brand", travel = true, fullWidth, className, items }) => {
316
346
  const tabs = useContext(TabsContext);
317
347
  const orientation = tabs?.orientation ?? "horizontal";
348
+ const isPill = type === "button-pill";
349
+ const isLine = isLineTabType(type);
350
+ const isVerticalLine = type === "line" || type === "line-stacked";
351
+ const useTravelIndicator = isPill || isLine && travel;
352
+ const selectedKey = tabs?.selectedKey;
353
+ const brandSolid = useNativeVariable("--color-bg-brand-solid") ?? "#7c3aed";
354
+ const primarySolid = useNativeVariable("--color-bg-primary-solid") ?? "#171717";
355
+ const brandLine = useNativeVariable("--color-fg-brand-primary_alt") ?? "#9e77ed";
356
+ const layoutsRef = useRef(/* @__PURE__ */ new Map());
357
+ const hasPlacedRef = useRef(false);
358
+ const indicatorX = useSharedValue(0);
359
+ const indicatorY = useSharedValue(0);
360
+ const indicatorW = useSharedValue(0);
361
+ const indicatorH = useSharedValue(0);
362
+ const indicatorOpacity = useSharedValue(0);
363
+ const moveIndicator = useCallback(
364
+ (key, animate) => {
365
+ if (!key) return;
366
+ const layout = layoutsRef.current.get(key);
367
+ if (!layout || layout.width <= 0 || layout.height <= 0) return;
368
+ const cfg = { duration: PILL_MS, easing: PILL_EASE };
369
+ let nextX = layout.x;
370
+ let nextY = layout.y;
371
+ let nextW = layout.width;
372
+ let nextH = layout.height;
373
+ if (isLine && !isPill) {
374
+ if (isVerticalLine) {
375
+ nextX = layout.x;
376
+ nextY = layout.y;
377
+ nextW = 2;
378
+ nextH = layout.height;
379
+ } else {
380
+ nextX = layout.x;
381
+ nextY = layout.y + Math.max(layout.height - 2, 0);
382
+ nextW = layout.width;
383
+ nextH = 2;
384
+ }
385
+ }
386
+ if (animate && hasPlacedRef.current) {
387
+ indicatorX.value = withTiming(nextX, cfg);
388
+ indicatorY.value = withTiming(nextY, cfg);
389
+ indicatorW.value = withTiming(nextW, cfg);
390
+ indicatorH.value = withTiming(nextH, cfg);
391
+ } else {
392
+ indicatorX.value = nextX;
393
+ indicatorY.value = nextY;
394
+ indicatorW.value = nextW;
395
+ indicatorH.value = nextH;
396
+ hasPlacedRef.current = true;
397
+ }
398
+ indicatorOpacity.value = 1;
399
+ },
400
+ [indicatorH, indicatorOpacity, indicatorW, indicatorX, indicatorY, isLine, isPill, isVerticalLine]
401
+ );
402
+ const registerTravelLayout = useCallback(
403
+ (id, layout) => {
404
+ layoutsRef.current.set(id, layout);
405
+ if (id === selectedKey) {
406
+ moveIndicator(id, hasPlacedRef.current);
407
+ }
408
+ },
409
+ [moveIndicator, selectedKey]
410
+ );
411
+ useEffect(() => {
412
+ if (!useTravelIndicator) return;
413
+ moveIndicator(selectedKey, true);
414
+ }, [useTravelIndicator, selectedKey, moveIndicator]);
415
+ const indicatorStyle = useAnimatedStyle(() => ({
416
+ opacity: indicatorOpacity.value,
417
+ width: indicatorW.value,
418
+ height: indicatorH.value,
419
+ transform: [{ translateX: indicatorX.value }, { translateY: indicatorY.value }]
420
+ }));
421
+ const indicatorColor = isPill ? color === "primary" ? primarySolid : brandSolid : brandLine;
422
+ const travelIndicator = useTravelIndicator ? /* @__PURE__ */ jsx(
423
+ Animated.View,
424
+ {
425
+ pointerEvents: "none",
426
+ style: [
427
+ styles.indicatorBase,
428
+ {
429
+ backgroundColor: indicatorColor,
430
+ borderRadius: isPill ? 9999 : 0,
431
+ zIndex: isPill ? 0 : 1
432
+ },
433
+ indicatorStyle
434
+ ]
435
+ }
436
+ ) : null;
318
437
  const list = /* @__PURE__ */ jsxs(
319
438
  View,
320
439
  {
@@ -322,42 +441,78 @@ var TabList = ({ children, size = "sm", type = "button-brand", fullWidth, classN
322
441
  orientation === "vertical" ? tabsStyles.listVertical : tabsStyles.list,
323
442
  type === "button-border" ? cx(tabsStyles.listButtonBorder, size === "md" && tabsStyles.listButtonBorderMd) : type === "button-minimal" ? tabsStyles.listButtonMinimal : tabListStyles({ size, fullWidth })[type],
324
443
  orientation === "horizontal" && type === "underline" && "relative",
444
+ useTravelIndicator && "relative",
325
445
  fullWidth && "w-full",
326
446
  className
327
447
  ),
448
+ style: useTravelIndicator ? styles.listTravel : void 0,
328
449
  children: [
329
450
  orientation === "horizontal" && type === "underline" && /* @__PURE__ */ jsx(View, { className: "absolute right-0 bottom-0 left-0 h-px bg-border-secondary" }),
330
- children ?? items?.map((item) => /* @__PURE__ */ jsx(Tab, { ...item }, item.id))
451
+ isPill && travelIndicator,
452
+ children ?? items?.map((item) => /* @__PURE__ */ jsx(Tab, { ...item }, item.id)),
453
+ !isPill && travelIndicator
331
454
  ]
332
455
  }
333
456
  );
334
- return /* @__PURE__ */ jsx(TabListContext.Provider, { value: { size, type, fullWidth, orientation }, children: orientation === "horizontal" ? /* @__PURE__ */ jsx(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, contentContainerClassName: fullWidth ? "grow" : void 0, children: list }) : list });
457
+ return /* @__PURE__ */ jsx(
458
+ TabListContext.Provider,
459
+ {
460
+ value: {
461
+ size,
462
+ type,
463
+ color,
464
+ travel,
465
+ fullWidth,
466
+ orientation,
467
+ registerTravelLayout: useTravelIndicator ? registerTravelLayout : void 0
468
+ },
469
+ children: orientation === "horizontal" ? /* @__PURE__ */ jsx(ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, contentContainerClassName: fullWidth ? "grow" : void 0, children: list }) : list
470
+ }
471
+ );
335
472
  };
336
473
  var Tab = ({ id, label, children, badge, icon: Icon }) => {
337
474
  const tabs = useContext(TabsContext);
338
- const { size, type, fullWidth, orientation } = useContext(TabListContext);
475
+ const { size, type, color, travel, fullWidth, orientation, registerTravelLayout } = useContext(TabListContext);
339
476
  const selected = tabs?.selectedKey === id;
340
477
  const isLineChrome = type === "line" || type === "line-stacked";
341
478
  const isStacked = type === "line-stacked";
342
- const showPill = type === "underline" || isLineChrome || type === "button-brand";
479
+ const isPill = type === "button-pill";
480
+ const showPill = type === "underline" || isLineChrome || type === "button-brand" || isPill;
343
481
  const fg = useNativeVariable(selected ? "--color-fg-primary" : "--color-fg-quaternary") ?? "#717680";
344
482
  const brand = useNativeVariable("--color-fg-brand-secondary") ?? "#6941c6";
345
483
  const fgQuaternary = useNativeVariable("--color-fg-quaternary") ?? "#717680";
346
- const iconColor = selected && (type === "underline" || isLineChrome) ? brand : selected ? fg : fgQuaternary;
484
+ const onBrand = useNativeVariable("--color-text-primary_on-brand") ?? "#ffffff";
485
+ const fgWhite = useNativeVariable("--color-fg-white") ?? "#ffffff";
486
+ const iconColor = isPill ? selected ? color === "primary" ? fgWhite : onBrand : fgQuaternary : selected && (type === "underline" || isLineChrome) ? brand : selected ? fg : fgQuaternary;
487
+ const onLayout = useCallback(
488
+ (event) => {
489
+ if (!registerTravelLayout) return;
490
+ const { x, y, width, height } = event.nativeEvent.layout;
491
+ if (width <= 0 || height <= 0) return;
492
+ registerTravelLayout(id, { x, y, width, height });
493
+ },
494
+ [id, registerTravelLayout]
495
+ );
347
496
  return /* @__PURE__ */ jsxs(
348
497
  Pressable,
349
498
  {
350
499
  accessibilityRole: "tab",
351
500
  accessibilityState: { selected },
352
501
  onPress: () => tabs?.setSelectedKey(id),
353
- style: orientation === "horizontal" ? { flexShrink: 0, zIndex: 1 } : { zIndex: 1 },
502
+ onLayout,
503
+ style: ({ pressed }) => [
504
+ orientation === "horizontal" ? { flexShrink: 0, zIndex: 1 } : { zIndex: 1 },
505
+ isPill && {
506
+ transform: [{ scale: pressed ? 0.98 : 1 }]
507
+ }
508
+ ],
354
509
  className: cx(
355
510
  tabsStyles.item,
356
511
  orientation === "vertical" && tabsStyles.itemVertical,
357
512
  isStacked && tabsStyles.itemStacked,
358
513
  fullWidth && orientation === "vertical" && tabsStyles.itemFull,
359
514
  tabSizes[size][type],
360
- tabNativeItemState(type, selected)
515
+ tabNativeItemState(type, selected, { travel: isLineTabType(type) ? travel : void 0 })
361
516
  ),
362
517
  children: [
363
518
  isStacked && isReactComponent(Icon) && /* @__PURE__ */ jsxs(View, { className: tabsStyles.iconStacked, children: [
@@ -365,7 +520,7 @@ var Tab = ({ id, label, children, badge, icon: Icon }) => {
365
520
  badge != null && /* @__PURE__ */ jsx(View, { className: tabsStyles.badgeStacked, children: /* @__PURE__ */ jsx(Badge, { size: "sm", type: showPill ? "pill-color" : "modern", color: showPill && selected ? "brand" : "gray", children: badge }) })
366
521
  ] }),
367
522
  !isStacked && isReactComponent(Icon) && /* @__PURE__ */ jsx(Icon, { size: tabSizes[size].icon, color: iconColor }),
368
- /* @__PURE__ */ jsxs(View, { className: cx(isStacked ? tabsStyles.labelStacked : tabsStyles.labelRow, !isLineChrome && "px-0.5"), children: [
523
+ /* @__PURE__ */ jsxs(View, { className: cx(isStacked ? tabsStyles.labelStacked : tabsStyles.labelRow, !isLineChrome && type !== "underline" && "px-0.5"), children: [
369
524
  /* @__PURE__ */ jsx(
370
525
  Text,
371
526
  {
@@ -373,7 +528,7 @@ var Tab = ({ id, label, children, badge, icon: Icon }) => {
373
528
  className: cx(
374
529
  isStacked ? "text-sm font-medium" : size === "sm" ? "text-sm font-semibold" : "text-md font-semibold",
375
530
  isStacked && "text-left",
376
- tabNativeLabelState(type, selected)
531
+ isPill && selected ? pillTabColorStyles[color].nativeLabel : tabNativeLabelState(type, selected)
377
532
  ),
378
533
  children: children || label
379
534
  }
@@ -394,6 +549,16 @@ var Tabs = Object.assign(TabsRoot, {
394
549
  Item: Tab,
395
550
  Panel: TabPanel
396
551
  });
552
+ var styles = StyleSheet.create({
553
+ listTravel: {
554
+ overflow: "visible"
555
+ },
556
+ indicatorBase: {
557
+ position: "absolute",
558
+ top: 0,
559
+ left: 0
560
+ }
561
+ });
397
562
 
398
563
  export { Tab, TabList, TabPanel, Tabs, TabsRoot };
399
564
  //# sourceMappingURL=tabs.js.map