@vvedantb/ui 0.61.0 → 0.62.1

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.
@@ -85,6 +85,7 @@ export * from "./ui/surface.js";
85
85
  export * from "./ui/switch.js";
86
86
  export * from "./ui/table.js";
87
87
  export * from "./ui/tabs.js";
88
+ export * from "./ui/tabs-transition.js";
88
89
  export * from "./ui/textarea.js";
89
90
  export * from "./ui/toolbar-search-input.js";
90
91
  export * from "./ui/time-picker.js";
package/dist/src/index.js CHANGED
@@ -81,6 +81,7 @@ export * from "./ui/surface.js";
81
81
  export * from "./ui/switch.js";
82
82
  export * from "./ui/table.js";
83
83
  export * from "./ui/tabs.js";
84
+ export * from "./ui/tabs-transition.js";
84
85
  export * from "./ui/textarea.js";
85
86
  export * from "./ui/toolbar-search-input.js";
86
87
  export * from "./ui/time-picker.js";
@@ -0,0 +1,174 @@
1
+ "use client";
2
+
3
+ import { c as _c } from "react/compiler-runtime";
4
+ import { AnimatePresence, m } from "motion/react";
5
+ import { useState } from "react";
6
+ import { motionEase } from "../motion/presets.js";
7
+ import { cn } from "../utils/cn.js";
8
+ import { useUiConfig } from "./ui-config.js";
9
+
10
+ /**
11
+ * How tab content moves when the tab changes. The new panel comes from the
12
+ * side of the tab that was picked (right of the old one: from the right), as a
13
+ * phone swipe does.
14
+ * - `"none"` (default): swap at once.
15
+ * - `"slide"`: a short 32px slide with a fade. Reads the direction without
16
+ * moving the page; the desktop default for apps that opt in.
17
+ * - `"push"`: the old panel leaves the full width as the new one enters, like
18
+ * a phone pager. Heavier; suits narrow or swipe-driven surfaces.
19
+ */
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ const SLIDE_PX = 32;
22
+ const variants = {
23
+ slide: {
24
+ enter: dir => ({
25
+ x: dir * SLIDE_PX,
26
+ opacity: 0
27
+ }),
28
+ center: {
29
+ x: 0,
30
+ opacity: 1,
31
+ transition: {
32
+ duration: 0.24,
33
+ ease: motionEase
34
+ }
35
+ },
36
+ // Leaves faster than it enters, so the old panel never lingers.
37
+ exit: dir => ({
38
+ x: -dir * SLIDE_PX,
39
+ opacity: 0,
40
+ transition: {
41
+ duration: 0.14,
42
+ ease: motionEase
43
+ }
44
+ })
45
+ },
46
+ push: {
47
+ enter: dir => ({
48
+ x: `${dir * 100}%`
49
+ }),
50
+ center: {
51
+ x: "0%",
52
+ transition: {
53
+ duration: 0.32,
54
+ ease: motionEase
55
+ }
56
+ },
57
+ exit: dir => ({
58
+ x: `${-dir * 100}%`,
59
+ transition: {
60
+ duration: 0.32,
61
+ ease: motionEase
62
+ }
63
+ })
64
+ }
65
+ };
66
+ /**
67
+ * Wraps the content of a tab set and moves it when the tab changes. Works with
68
+ * any tab content, routed or not: it keys on `value`, so the outgoing panel can
69
+ * leave while the new one enters. The container clips the slide sideways only,
70
+ * so content keeps its natural height. Motion settings apply: `MotionProvider
71
+ * reducedMotion` and page-motion off stop the slide.
72
+ */
73
+ export function TabsTransition(t0) {
74
+ const $ = _c(20);
75
+ const {
76
+ value,
77
+ order,
78
+ variant: variantProp,
79
+ className,
80
+ panelClassName,
81
+ children
82
+ } = t0;
83
+ const configVariant = useUiConfig("Tabs")?.transition;
84
+ const variant = variantProp ?? configVariant ?? "none";
85
+ const [previous, setPrevious] = useState(value);
86
+ const [direction, setDirection] = useState(1);
87
+ if (value !== previous) {
88
+ setDirection(order.indexOf(value) >= order.indexOf(previous) ? 1 : -1);
89
+ setPrevious(value);
90
+ }
91
+ if (variant === "none") {
92
+ let t1;
93
+ if ($[0] !== children || $[1] !== panelClassName) {
94
+ t1 = /*#__PURE__*/_jsx("div", {
95
+ className: panelClassName,
96
+ children: children
97
+ });
98
+ $[0] = children;
99
+ $[1] = panelClassName;
100
+ $[2] = t1;
101
+ } else {
102
+ t1 = $[2];
103
+ }
104
+ let t2;
105
+ if ($[3] !== className || $[4] !== t1) {
106
+ t2 = /*#__PURE__*/_jsx("div", {
107
+ className: className,
108
+ children: t1
109
+ });
110
+ $[3] = className;
111
+ $[4] = t1;
112
+ $[5] = t2;
113
+ } else {
114
+ t2 = $[5];
115
+ }
116
+ return t2;
117
+ }
118
+ let t1;
119
+ if ($[6] !== className) {
120
+ t1 = cn("relative overflow-x-clip", className);
121
+ $[6] = className;
122
+ $[7] = t1;
123
+ } else {
124
+ t1 = $[7];
125
+ }
126
+ const t2 = variants[variant];
127
+ let t3;
128
+ if ($[8] !== children || $[9] !== direction || $[10] !== panelClassName || $[11] !== t2 || $[12] !== value) {
129
+ t3 = /*#__PURE__*/_jsx(m.div, {
130
+ className: panelClassName,
131
+ custom: direction,
132
+ variants: t2,
133
+ initial: "enter",
134
+ animate: "center",
135
+ exit: "exit",
136
+ children: children
137
+ }, value);
138
+ $[8] = children;
139
+ $[9] = direction;
140
+ $[10] = panelClassName;
141
+ $[11] = t2;
142
+ $[12] = value;
143
+ $[13] = t3;
144
+ } else {
145
+ t3 = $[13];
146
+ }
147
+ let t4;
148
+ if ($[14] !== direction || $[15] !== t3) {
149
+ t4 = /*#__PURE__*/_jsx(AnimatePresence, {
150
+ initial: false,
151
+ custom: direction,
152
+ mode: "popLayout",
153
+ children: t3
154
+ });
155
+ $[14] = direction;
156
+ $[15] = t3;
157
+ $[16] = t4;
158
+ } else {
159
+ t4 = $[16];
160
+ }
161
+ let t5;
162
+ if ($[17] !== t1 || $[18] !== t4) {
163
+ t5 = /*#__PURE__*/_jsx("div", {
164
+ className: t1,
165
+ children: t4
166
+ });
167
+ $[17] = t1;
168
+ $[18] = t4;
169
+ $[19] = t5;
170
+ } else {
171
+ t5 = $[19];
172
+ }
173
+ return t5;
174
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/ui",
3
- "version": "0.61.0",
3
+ "version": "0.62.1",
4
4
  "license": "MIT",
5
5
  "description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
6
6
  "type": "module",
package/src/client.ts CHANGED
@@ -120,6 +120,7 @@ export * from "./ui/surface";
120
120
  export * from "./ui/switch";
121
121
  export * from "./ui/table";
122
122
  export * from "./ui/tabs";
123
+ export * from "./ui/tabs-transition";
123
124
  export * from "./ui/textarea";
124
125
  export * from "./ui/toolbar-search-input";
125
126
  export * from "./ui/time-picker";
package/src/index.ts CHANGED
@@ -116,6 +116,7 @@ export * from "./ui/surface";
116
116
  export * from "./ui/switch";
117
117
  export * from "./ui/table";
118
118
  export * from "./ui/tabs";
119
+ export * from "./ui/tabs-transition";
119
120
  export * from "./ui/textarea";
120
121
  export * from "./ui/toolbar-search-input";
121
122
  export * from "./ui/time-picker";
@@ -0,0 +1,115 @@
1
+ "use client";
2
+
3
+ import { AnimatePresence, m, type Variants } from "motion/react";
4
+ import { useState, type ReactNode } from "react";
5
+ import { motionEase } from "../motion/presets";
6
+ import { cn } from "../utils/cn";
7
+ import { useUiConfig } from "./ui-config";
8
+
9
+ /**
10
+ * How tab content moves when the tab changes. The new panel comes from the
11
+ * side of the tab that was picked (right of the old one: from the right), as a
12
+ * phone swipe does.
13
+ * - `"none"` (default): swap at once.
14
+ * - `"slide"`: a short 32px slide with a fade. Reads the direction without
15
+ * moving the page; the desktop default for apps that opt in.
16
+ * - `"push"`: the old panel leaves the full width as the new one enters, like
17
+ * a phone pager. Heavier; suits narrow or swipe-driven surfaces.
18
+ */
19
+ export type TabsTransitionVariant = "none" | "slide" | "push";
20
+
21
+ type Direction = 1 | -1;
22
+
23
+ const SLIDE_PX = 32;
24
+
25
+ const variants: Record<Exclude<TabsTransitionVariant, "none">, Variants> = {
26
+ slide: {
27
+ enter: (dir: Direction) => ({ x: dir * SLIDE_PX, opacity: 0 }),
28
+ center: { x: 0, opacity: 1, transition: { duration: 0.24, ease: motionEase } },
29
+ // Leaves faster than it enters, so the old panel never lingers.
30
+ exit: (dir: Direction) => ({
31
+ x: -dir * SLIDE_PX,
32
+ opacity: 0,
33
+ transition: { duration: 0.14, ease: motionEase },
34
+ }),
35
+ },
36
+ push: {
37
+ enter: (dir: Direction) => ({ x: `${dir * 100}%` }),
38
+ center: { x: "0%", transition: { duration: 0.32, ease: motionEase } },
39
+ exit: (dir: Direction) => ({
40
+ x: `${-dir * 100}%`,
41
+ transition: { duration: 0.32, ease: motionEase },
42
+ }),
43
+ },
44
+ };
45
+
46
+ export interface TabsTransitionProps {
47
+ /** The selected tab. A new value plays the transition. */
48
+ value: string;
49
+ /** Tab values in their on-screen order, left to right; gives the direction. */
50
+ order: ReadonlyArray<string>;
51
+ /** Defaults to the app's `UiConfig.Tabs.transition`, then `"none"`. */
52
+ variant?: TabsTransitionVariant;
53
+ className?: string;
54
+ /**
55
+ * Classes on the moving panel. Full-height layouts pass the same flex
56
+ * classes as their container (`flex min-h-0 flex-1 flex-col`) so the panel
57
+ * still fills it.
58
+ */
59
+ panelClassName?: string;
60
+ /** The selected tab's content. */
61
+ children: ReactNode;
62
+ }
63
+
64
+ /**
65
+ * Wraps the content of a tab set and moves it when the tab changes. Works with
66
+ * any tab content, routed or not: it keys on `value`, so the outgoing panel can
67
+ * leave while the new one enters. The container clips the slide sideways only,
68
+ * so content keeps its natural height. Motion settings apply: `MotionProvider
69
+ * reducedMotion` and page-motion off stop the slide.
70
+ */
71
+ export function TabsTransition({
72
+ value,
73
+ order,
74
+ variant: variantProp,
75
+ className,
76
+ panelClassName,
77
+ children,
78
+ }: TabsTransitionProps) {
79
+ const configVariant = useUiConfig("Tabs")?.transition;
80
+ const variant = variantProp ?? configVariant ?? "none";
81
+ // Direction follows the move from the previous tab to this one. Derived in
82
+ // render (adjust-state-on-change), so the first frame already knows it.
83
+ const [previous, setPrevious] = useState(value);
84
+ const [direction, setDirection] = useState<Direction>(1);
85
+ if (value !== previous) {
86
+ setDirection(order.indexOf(value) >= order.indexOf(previous) ? 1 : -1);
87
+ setPrevious(value);
88
+ }
89
+
90
+ if (variant === "none") {
91
+ return (
92
+ <div className={className}>
93
+ <div className={panelClassName}>{children}</div>
94
+ </div>
95
+ );
96
+ }
97
+
98
+ return (
99
+ <div className={cn("relative overflow-x-clip", className)}>
100
+ <AnimatePresence initial={false} custom={direction} mode="popLayout">
101
+ <m.div
102
+ key={value}
103
+ className={panelClassName}
104
+ custom={direction}
105
+ variants={variants[variant]}
106
+ initial="enter"
107
+ animate="center"
108
+ exit="exit"
109
+ >
110
+ {children}
111
+ </m.div>
112
+ </AnimatePresence>
113
+ </div>
114
+ );
115
+ }
package/src/ui/tabs.tsx CHANGED
@@ -4,6 +4,7 @@ import { cva, type VariantProps } from "class-variance-authority";
4
4
  import { assignRef } from "../utils/ref";
5
5
  import { syncTabsPill, type TabsPillMotion } from "./tabsSliding";
6
6
  import { useCn, useUiConfig } from "./ui-config";
7
+ import type { TabsTransitionVariant } from "./tabs-transition";
7
8
 
8
9
  const Tabs = TabsPrimitive.Root;
9
10
 
@@ -24,6 +25,8 @@ type TabsListSize = "default" | "sm";
24
25
  export interface TabsConfig {
25
26
  variant?: TabsListVariant;
26
27
  pillMotion?: TabsPillMotion;
28
+ /** Default `TabsTransition` variant for every tab set in the app. */
29
+ transition?: TabsTransitionVariant;
27
30
  classes?: {
28
31
  list?: string;
29
32
  size?: Partial<Record<TabsListSize, string>>;