@vvedantb/ui 0.61.0 → 0.62.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/dist/src/client.js +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/ui/tabs-transition.js +159 -0
- package/package.json +1 -1
- package/src/client.ts +1 -0
- package/src/index.ts +1 -0
- package/src/ui/tabs-transition.tsx +103 -0
- package/src/ui/tabs.tsx +3 -0
package/dist/src/client.js
CHANGED
|
@@ -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,159 @@
|
|
|
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(16);
|
|
75
|
+
const {
|
|
76
|
+
value,
|
|
77
|
+
order,
|
|
78
|
+
variant: variantProp,
|
|
79
|
+
className,
|
|
80
|
+
children
|
|
81
|
+
} = t0;
|
|
82
|
+
const configVariant = useUiConfig("Tabs")?.transition;
|
|
83
|
+
const variant = variantProp ?? configVariant ?? "none";
|
|
84
|
+
const [previous, setPrevious] = useState(value);
|
|
85
|
+
const [direction, setDirection] = useState(1);
|
|
86
|
+
if (value !== previous) {
|
|
87
|
+
setDirection(order.indexOf(value) >= order.indexOf(previous) ? 1 : -1);
|
|
88
|
+
setPrevious(value);
|
|
89
|
+
}
|
|
90
|
+
if (variant === "none") {
|
|
91
|
+
let t1;
|
|
92
|
+
if ($[0] !== children || $[1] !== className) {
|
|
93
|
+
t1 = /*#__PURE__*/_jsx("div", {
|
|
94
|
+
className: className,
|
|
95
|
+
children: children
|
|
96
|
+
});
|
|
97
|
+
$[0] = children;
|
|
98
|
+
$[1] = className;
|
|
99
|
+
$[2] = t1;
|
|
100
|
+
} else {
|
|
101
|
+
t1 = $[2];
|
|
102
|
+
}
|
|
103
|
+
return t1;
|
|
104
|
+
}
|
|
105
|
+
let t1;
|
|
106
|
+
if ($[3] !== className) {
|
|
107
|
+
t1 = cn("relative overflow-x-clip", className);
|
|
108
|
+
$[3] = className;
|
|
109
|
+
$[4] = t1;
|
|
110
|
+
} else {
|
|
111
|
+
t1 = $[4];
|
|
112
|
+
}
|
|
113
|
+
const t2 = variants[variant];
|
|
114
|
+
let t3;
|
|
115
|
+
if ($[5] !== children || $[6] !== direction || $[7] !== t2 || $[8] !== value) {
|
|
116
|
+
t3 = /*#__PURE__*/_jsx(m.div, {
|
|
117
|
+
custom: direction,
|
|
118
|
+
variants: t2,
|
|
119
|
+
initial: "enter",
|
|
120
|
+
animate: "center",
|
|
121
|
+
exit: "exit",
|
|
122
|
+
children: children
|
|
123
|
+
}, value);
|
|
124
|
+
$[5] = children;
|
|
125
|
+
$[6] = direction;
|
|
126
|
+
$[7] = t2;
|
|
127
|
+
$[8] = value;
|
|
128
|
+
$[9] = t3;
|
|
129
|
+
} else {
|
|
130
|
+
t3 = $[9];
|
|
131
|
+
}
|
|
132
|
+
let t4;
|
|
133
|
+
if ($[10] !== direction || $[11] !== t3) {
|
|
134
|
+
t4 = /*#__PURE__*/_jsx(AnimatePresence, {
|
|
135
|
+
initial: false,
|
|
136
|
+
custom: direction,
|
|
137
|
+
mode: "popLayout",
|
|
138
|
+
children: t3
|
|
139
|
+
});
|
|
140
|
+
$[10] = direction;
|
|
141
|
+
$[11] = t3;
|
|
142
|
+
$[12] = t4;
|
|
143
|
+
} else {
|
|
144
|
+
t4 = $[12];
|
|
145
|
+
}
|
|
146
|
+
let t5;
|
|
147
|
+
if ($[13] !== t1 || $[14] !== t4) {
|
|
148
|
+
t5 = /*#__PURE__*/_jsx("div", {
|
|
149
|
+
className: t1,
|
|
150
|
+
children: t4
|
|
151
|
+
});
|
|
152
|
+
$[13] = t1;
|
|
153
|
+
$[14] = t4;
|
|
154
|
+
$[15] = t5;
|
|
155
|
+
} else {
|
|
156
|
+
t5 = $[15];
|
|
157
|
+
}
|
|
158
|
+
return t5;
|
|
159
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.0",
|
|
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,103 @@
|
|
|
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
|
+
/** The selected tab's content. */
|
|
55
|
+
children: ReactNode;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Wraps the content of a tab set and moves it when the tab changes. Works with
|
|
60
|
+
* any tab content, routed or not: it keys on `value`, so the outgoing panel can
|
|
61
|
+
* leave while the new one enters. The container clips the slide sideways only,
|
|
62
|
+
* so content keeps its natural height. Motion settings apply: `MotionProvider
|
|
63
|
+
* reducedMotion` and page-motion off stop the slide.
|
|
64
|
+
*/
|
|
65
|
+
export function TabsTransition({
|
|
66
|
+
value,
|
|
67
|
+
order,
|
|
68
|
+
variant: variantProp,
|
|
69
|
+
className,
|
|
70
|
+
children,
|
|
71
|
+
}: TabsTransitionProps) {
|
|
72
|
+
const configVariant = useUiConfig("Tabs")?.transition;
|
|
73
|
+
const variant = variantProp ?? configVariant ?? "none";
|
|
74
|
+
// Direction follows the move from the previous tab to this one. Derived in
|
|
75
|
+
// render (adjust-state-on-change), so the first frame already knows it.
|
|
76
|
+
const [previous, setPrevious] = useState(value);
|
|
77
|
+
const [direction, setDirection] = useState<Direction>(1);
|
|
78
|
+
if (value !== previous) {
|
|
79
|
+
setDirection(order.indexOf(value) >= order.indexOf(previous) ? 1 : -1);
|
|
80
|
+
setPrevious(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (variant === "none") {
|
|
84
|
+
return <div className={className}>{children}</div>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className={cn("relative overflow-x-clip", className)}>
|
|
89
|
+
<AnimatePresence initial={false} custom={direction} mode="popLayout">
|
|
90
|
+
<m.div
|
|
91
|
+
key={value}
|
|
92
|
+
custom={direction}
|
|
93
|
+
variants={variants[variant]}
|
|
94
|
+
initial="enter"
|
|
95
|
+
animate="center"
|
|
96
|
+
exit="exit"
|
|
97
|
+
>
|
|
98
|
+
{children}
|
|
99
|
+
</m.div>
|
|
100
|
+
</AnimatePresence>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
}
|
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>>;
|