aplance-ui 1.0.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.
- package/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/api.d.ts +175 -0
- package/dist/api.js +1954 -0
- package/dist/api.js.map +1 -0
- package/dist/frameworks/astro/astro.config.snippet.md +23 -0
- package/dist/frameworks/astro/postcss.config.mjs.template +20 -0
- package/dist/frameworks/astro/vite-inline.snippet.md +22 -0
- package/dist/frameworks/electron-vite/vite.config.snippet.md +44 -0
- package/dist/frameworks/next/layout-import.snippet.md +19 -0
- package/dist/frameworks/next/next.config.snippet.md +15 -0
- package/dist/frameworks/next/postcss.config.js.template +16 -0
- package/dist/frameworks/tanstack-start/postcss.config.ts.template +17 -0
- package/dist/frameworks/tanstack-start/vite-inline.snippet.md +22 -0
- package/dist/frameworks/vite-react/postcss.config.ts.template +16 -0
- package/dist/frameworks/vite-react/vite-inline.snippet.md +20 -0
- package/dist/frameworks/vite-react/vite.config.ts.template +48 -0
- package/dist/index.js +2047 -0
- package/dist/index.js.map +1 -0
- package/package.json +63 -0
- package/registry/components/primitives/icon/icon.module.css +63 -0
- package/registry/components/primitives/icon/icon.tsx +53 -0
- package/registry/components/primitives/modal/modal-context.ts +19 -0
- package/registry/components/primitives/modal/modal.module.css +415 -0
- package/registry/components/primitives/modal/modal.tsx +550 -0
- package/registry/components/primitives/popover/popover-context.ts +28 -0
- package/registry/components/primitives/popover/popover.module.css +28 -0
- package/registry/components/primitives/popover/popover.tsx +465 -0
- package/registry/components/ui/accordion/accordion.module.css +208 -0
- package/registry/components/ui/accordion/accordion.tsx +327 -0
- package/registry/components/ui/avatar/avatar.module.css +32 -0
- package/registry/components/ui/avatar/avatar.tsx +37 -0
- package/registry/components/ui/badge/badge.module.css +103 -0
- package/registry/components/ui/badge/badge.tsx +29 -0
- package/registry/components/ui/button/button.module.css +216 -0
- package/registry/components/ui/button/button.tsx +133 -0
- package/registry/components/ui/chart/chart.module.css +168 -0
- package/registry/components/ui/chart/chart.tsx +1293 -0
- package/registry/components/ui/chart/types.ts +210 -0
- package/registry/components/ui/chart/utils.ts +59 -0
- package/registry/components/ui/copy-button/copy-button.module.css +21 -0
- package/registry/components/ui/copy-button/copy-button.tsx +123 -0
- package/registry/components/ui/countdown/countdown.module.css +5 -0
- package/registry/components/ui/countdown/countdown.tsx +152 -0
- package/registry/components/ui/data-table/checkbox-column.tsx +59 -0
- package/registry/components/ui/data-table/data-table.module.css +594 -0
- package/registry/components/ui/data-table/data-table.tsx +1109 -0
- package/registry/components/ui/data-table/filter-bar.tsx +33 -0
- package/registry/components/ui/data-table/pagination-bar.tsx +125 -0
- package/registry/components/ui/data-table/types.ts +594 -0
- package/registry/components/ui/data-table/useDataTable.tsx +573 -0
- package/registry/components/ui/data-table/utils.ts +445 -0
- package/registry/components/ui/empty-state/empty-state.module.css +26 -0
- package/registry/components/ui/empty-state/empty-state.tsx +32 -0
- package/registry/components/ui/input-fields/color-picker/color-palette.module.css +102 -0
- package/registry/components/ui/input-fields/color-picker/color-palette.tsx +92 -0
- package/registry/components/ui/input-fields/color-picker/color-picker.module.css +29 -0
- package/registry/components/ui/input-fields/color-picker/color-picker.tsx +168 -0
- package/registry/components/ui/input-fields/common/field-message/field-message.module.css +28 -0
- package/registry/components/ui/input-fields/common/field-message/field-message.tsx +39 -0
- package/registry/components/ui/input-fields/common/input-field-common.module.css +318 -0
- package/registry/components/ui/input-fields/common/input-field-native.module.css +267 -0
- package/registry/components/ui/input-fields/common/picker-popover-common.module.css +40 -0
- package/registry/components/ui/input-fields/common/select-button/select-button.module.css +9 -0
- package/registry/components/ui/input-fields/common/select-button/select-button.tsx +171 -0
- package/registry/components/ui/input-fields/common/types.ts +38 -0
- package/registry/components/ui/input-fields/custom-select/custom-select.module.css +56 -0
- package/registry/components/ui/input-fields/custom-select/custom-select.tsx +403 -0
- package/registry/components/ui/input-fields/date-picker/calendar.module.css +311 -0
- package/registry/components/ui/input-fields/date-picker/calendar.tsx +186 -0
- package/registry/components/ui/input-fields/date-picker/date-picker.module.css +57 -0
- package/registry/components/ui/input-fields/date-picker/date-picker.tsx +945 -0
- package/registry/components/ui/input-fields/date-picker/types.ts +102 -0
- package/registry/components/ui/input-fields/date-picker/utils.ts +236 -0
- package/registry/components/ui/input-fields/emoji-picker/emoji-palette.module.css +90 -0
- package/registry/components/ui/input-fields/emoji-picker/emoji-palette.tsx +168 -0
- package/registry/components/ui/input-fields/emoji-picker/emoji-picker.module.css +8 -0
- package/registry/components/ui/input-fields/emoji-picker/emoji-picker.tsx +102 -0
- package/registry/components/ui/input-fields/emoji-picker/utils.ts +505 -0
- package/registry/components/ui/input-fields/field-group/field-group.module.css +86 -0
- package/registry/components/ui/input-fields/field-group/field-group.tsx +86 -0
- package/registry/components/ui/input-fields/input/input.tsx +319 -0
- package/registry/components/ui/input-fields/media-input/kind-icons.tsx +62 -0
- package/registry/components/ui/input-fields/media-input/media-input.module.css +294 -0
- package/registry/components/ui/input-fields/media-input/media-input.tsx +327 -0
- package/registry/components/ui/input-fields/media-input/media-preview.tsx +101 -0
- package/registry/components/ui/input-fields/media-input/types.ts +129 -0
- package/registry/components/ui/input-fields/media-input/useMediaUpload.tsx +302 -0
- package/registry/components/ui/input-fields/media-input/utils.ts +325 -0
- package/registry/components/ui/input-fields/otp-input/otp-input.module.css +24 -0
- package/registry/components/ui/input-fields/otp-input/otp-input.tsx +291 -0
- package/registry/components/ui/input-fields/select/select.tsx +118 -0
- package/registry/components/ui/input-fields/switch/switch.module.css +70 -0
- package/registry/components/ui/input-fields/switch/switch.tsx +59 -0
- package/registry/components/ui/input-fields/textarea/textarea.tsx +133 -0
- package/registry/components/ui/input-fields/time-picker/time-picker.module.css +57 -0
- package/registry/components/ui/input-fields/time-picker/time-picker.tsx +437 -0
- package/registry/components/ui/loader/loader.module.css +156 -0
- package/registry/components/ui/loader/loader.tsx +102 -0
- package/registry/components/ui/stepper/stepper.module.css +294 -0
- package/registry/components/ui/stepper/stepper.tsx +197 -0
- package/registry/components/ui/tabs/tabs.module.css +150 -0
- package/registry/components/ui/tabs/tabs.tsx +134 -0
- package/registry/components/ui/toast/toast.module.css +159 -0
- package/registry/components/ui/toast/toast.tsx +104 -0
- package/registry/components/ui/tooltip/tooltip.module.css +82 -0
- package/registry/components/ui/tooltip/tooltip.tsx +72 -0
- package/registry/global.d.ts +4 -0
- package/registry/hooks/useFocusOutside.tsx +33 -0
- package/registry/hooks/useResizeObserver.tsx +32 -0
- package/registry/lib/dom.ts +25 -0
- package/registry/lib/string.ts +23 -0
- package/registry/registry.json +719 -0
- package/registry/styles/app.css +240 -0
- package/registry/styles/components.css +78 -0
- package/registry/styles/fonts/geist-regular.woff2 +0 -0
- package/registry/styles/globals.css +7 -0
- package/registry/styles/media.css +25 -0
- package/registry/styles/utilities.css +90 -0
- package/registry/themes/colors/blue.css +37 -0
- package/registry/themes/colors/green.css +37 -0
- package/registry/themes/colors/rose.css +37 -0
- package/registry/themes/colors/slate.css +37 -0
- package/registry/themes/colors/stone.css +37 -0
- package/registry/themes/colors/violet.css +37 -0
- package/registry/themes/colors/zinc.css +37 -0
- package/registry/themes/radius/pill.css +8 -0
- package/registry/themes/radius/rounded.css +8 -0
- package/registry/themes/radius/sharp.css +8 -0
- package/registry/themes/spacing/compact.css +17 -0
- package/registry/themes/spacing/spacious.css +17 -0
- package/registry/tsconfig.json +25 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import clsx from "clsx";
|
|
2
|
+
import type { CSSProperties } from "react";
|
|
3
|
+
import s from "./loader.module.css";
|
|
4
|
+
|
|
5
|
+
export type LoaderVariant = "spinner" | "dots" | "skeleton";
|
|
6
|
+
export type LoaderMode = "inline" | "page" | "overlay";
|
|
7
|
+
export type LoaderSize = "sm" | "md" | "lg" | number;
|
|
8
|
+
|
|
9
|
+
export type LoaderProps = {
|
|
10
|
+
variant?: LoaderVariant;
|
|
11
|
+
mode?: LoaderMode;
|
|
12
|
+
size?: LoaderSize;
|
|
13
|
+
color?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const SIZE_MAP: Record<Exclude<LoaderSize, number>, string> = {
|
|
19
|
+
sm: "1rem",
|
|
20
|
+
md: "1.5rem",
|
|
21
|
+
lg: "2.5rem",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getSize = (size: LoaderSize): string => {
|
|
25
|
+
if (typeof size === "number") return `${size}rem`;
|
|
26
|
+
return SIZE_MAP[size];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const Loader = ({
|
|
30
|
+
variant = "spinner",
|
|
31
|
+
mode = "inline",
|
|
32
|
+
size = "md",
|
|
33
|
+
color = "var(--color-primary)",
|
|
34
|
+
className,
|
|
35
|
+
style,
|
|
36
|
+
}: LoaderProps) => {
|
|
37
|
+
const indicatorStyle: CSSProperties = {
|
|
38
|
+
"--loader-size": getSize(size),
|
|
39
|
+
"--loader-color": color,
|
|
40
|
+
} as CSSProperties;
|
|
41
|
+
|
|
42
|
+
const renderIndicator = (indicatorClassName?: string, indicatorStyleOverride?: CSSProperties) => {
|
|
43
|
+
if (variant === "skeleton") {
|
|
44
|
+
return (
|
|
45
|
+
<div
|
|
46
|
+
className={clsx(s.skeleton_shape, indicatorClassName)}
|
|
47
|
+
style={indicatorStyleOverride}
|
|
48
|
+
role="status"
|
|
49
|
+
aria-live="polite"
|
|
50
|
+
aria-label="Loading"
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (variant === "dots") {
|
|
56
|
+
return (
|
|
57
|
+
<div
|
|
58
|
+
className={clsx(s.dots_loader, indicatorClassName)}
|
|
59
|
+
style={indicatorStyleOverride}
|
|
60
|
+
role="status"
|
|
61
|
+
aria-live="polite"
|
|
62
|
+
aria-label="Loading"
|
|
63
|
+
>
|
|
64
|
+
<span />
|
|
65
|
+
<span />
|
|
66
|
+
<span />
|
|
67
|
+
</div>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
className={clsx(s.spinner_loader, indicatorClassName)}
|
|
74
|
+
style={indicatorStyleOverride}
|
|
75
|
+
role="status"
|
|
76
|
+
aria-live="polite"
|
|
77
|
+
aria-label="Loading"
|
|
78
|
+
>
|
|
79
|
+
<svg className={s.loading_spinner} viewBox="0 0 50 50">
|
|
80
|
+
<circle className={s.loading_path} cx="25" cy="25" r="20" fill="none" />
|
|
81
|
+
</svg>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (mode === "inline") {
|
|
87
|
+
return renderIndicator(
|
|
88
|
+
className,
|
|
89
|
+
variant === "skeleton" ? style : { ...indicatorStyle, ...style },
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div
|
|
95
|
+
className={clsx(mode === "overlay" ? s.overlay_loader : s.page_loader, className)}
|
|
96
|
+
style={style}
|
|
97
|
+
aria-busy="true"
|
|
98
|
+
>
|
|
99
|
+
{renderIndicator(undefined, variant === "skeleton" ? undefined : indicatorStyle)}
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
};
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/* --------------------------------------------------------------------------
|
|
2
|
+
Stepper – root + token contract
|
|
3
|
+
-------------------------------------------------------------------------- */
|
|
4
|
+
.root {
|
|
5
|
+
--stepper-gap-h: var(--spacing-3);
|
|
6
|
+
--stepper-gap-v: var(--spacing-8);
|
|
7
|
+
--stepper-indicator-size: var(--spacing-10);
|
|
8
|
+
--stepper-indicator-font-size: var(--font-size-sm);
|
|
9
|
+
--stepper-line-thickness: var(--border-2);
|
|
10
|
+
--stepper-line-inset: var(--spacing-2);
|
|
11
|
+
|
|
12
|
+
width: 100%;
|
|
13
|
+
display: flex;
|
|
14
|
+
flex-direction: column;
|
|
15
|
+
gap: var(--spacing-6);
|
|
16
|
+
|
|
17
|
+
&.root_lg {
|
|
18
|
+
--stepper-indicator-size: var(--spacing-11);
|
|
19
|
+
--stepper-indicator-font-size: var(--font-size-base);
|
|
20
|
+
--stepper-gap-h: var(--spacing-4);
|
|
21
|
+
--stepper-gap-v: var(--spacing-9);
|
|
22
|
+
--stepper-line-inset: var(--spacing-3);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* --------------------------------------------------------------------------
|
|
27
|
+
List
|
|
28
|
+
-------------------------------------------------------------------------- */
|
|
29
|
+
.list {
|
|
30
|
+
list-style: none;
|
|
31
|
+
margin: 0;
|
|
32
|
+
padding: 0;
|
|
33
|
+
display: flex;
|
|
34
|
+
width: 100%;
|
|
35
|
+
|
|
36
|
+
&.list_horizontal {
|
|
37
|
+
flex-direction: row;
|
|
38
|
+
align-items: stretch;
|
|
39
|
+
gap: var(--stepper-gap-h);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
&.list_vertical {
|
|
43
|
+
flex-direction: column;
|
|
44
|
+
align-items: stretch;
|
|
45
|
+
gap: var(--stepper-gap-v);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* style2 horizontal items must touch so the connector spans cleanly */
|
|
49
|
+
&.list_style2.list_horizontal {
|
|
50
|
+
gap: 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* --------------------------------------------------------------------------
|
|
55
|
+
Step (list item) – holds the connector pseudo-element for style2
|
|
56
|
+
-------------------------------------------------------------------------- */
|
|
57
|
+
.step {
|
|
58
|
+
--stepper-line: var(--color-border);
|
|
59
|
+
position: relative;
|
|
60
|
+
flex: 1 1 0;
|
|
61
|
+
min-width: 0;
|
|
62
|
+
|
|
63
|
+
&.step_vertical {
|
|
64
|
+
flex: 0 0 auto;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
&[data-disabled] {
|
|
68
|
+
opacity: 0.55;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* Filled accent for both active and complete */
|
|
72
|
+
&[data-status="active"],
|
|
73
|
+
&[data-status="complete"] {
|
|
74
|
+
--stepper-line: var(--color-primary);
|
|
75
|
+
|
|
76
|
+
.indicator {
|
|
77
|
+
background: var(--color-primary);
|
|
78
|
+
border-color: var(--color-primary);
|
|
79
|
+
color: var(--color-primary-foreground);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* Active focus ring - only on the line variant's dot, since
|
|
84
|
+
style1 surfaces the same ring on the surrounding card. */
|
|
85
|
+
&[data-status="active"] .indicator_style2 {
|
|
86
|
+
box-shadow: var(--shadow-ring);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&[data-status="error"] {
|
|
90
|
+
--stepper-line: var(--color-error-foreground);
|
|
91
|
+
|
|
92
|
+
.indicator {
|
|
93
|
+
background: var(--color-error-subtle);
|
|
94
|
+
border-color: color-mix(
|
|
95
|
+
in oklch,
|
|
96
|
+
var(--color-error-foreground) 35%,
|
|
97
|
+
var(--color-border)
|
|
98
|
+
);
|
|
99
|
+
color: var(--color-error-foreground);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.label {
|
|
103
|
+
color: var(--color-error-foreground);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
&[data-status="upcoming"] .label {
|
|
108
|
+
color: var(--color-muted-foreground);
|
|
109
|
+
font-weight: var(--font-weight-normal);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* style2 connector – horizontal */
|
|
114
|
+
.step_style2.step_horizontal:not(:last-child)::after {
|
|
115
|
+
content: "";
|
|
116
|
+
position: absolute;
|
|
117
|
+
top: calc(var(--stepper-indicator-size) / 2);
|
|
118
|
+
left: calc(50% + var(--stepper-indicator-size) / 2 + var(--stepper-line-inset));
|
|
119
|
+
width: calc(
|
|
120
|
+
100% - var(--stepper-indicator-size) - var(--stepper-line-inset) * 2
|
|
121
|
+
);
|
|
122
|
+
height: var(--stepper-line-thickness);
|
|
123
|
+
background: var(--stepper-line);
|
|
124
|
+
border-radius: var(--radius-full);
|
|
125
|
+
transform: translateY(-50%);
|
|
126
|
+
transition: background var(--transition-base);
|
|
127
|
+
z-index: 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* style2 connector – vertical */
|
|
131
|
+
.step_style2.step_vertical:not(:last-child)::after {
|
|
132
|
+
content: "";
|
|
133
|
+
position: absolute;
|
|
134
|
+
left: calc(var(--stepper-indicator-size) / 2);
|
|
135
|
+
top: calc(var(--stepper-indicator-size) + var(--stepper-line-inset));
|
|
136
|
+
bottom: calc(-1 * var(--stepper-gap-v) + var(--stepper-line-inset));
|
|
137
|
+
width: var(--stepper-line-thickness);
|
|
138
|
+
background: var(--stepper-line);
|
|
139
|
+
border-radius: var(--radius-full);
|
|
140
|
+
transform: translateX(-50%);
|
|
141
|
+
transition: background var(--transition-base);
|
|
142
|
+
z-index: 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* --------------------------------------------------------------------------
|
|
146
|
+
Step button (shared base)
|
|
147
|
+
-------------------------------------------------------------------------- */
|
|
148
|
+
.button {
|
|
149
|
+
width: 100%;
|
|
150
|
+
position: relative;
|
|
151
|
+
z-index: 1;
|
|
152
|
+
display: flex;
|
|
153
|
+
align-items: center;
|
|
154
|
+
gap: var(--spacing-4);
|
|
155
|
+
text-align: left;
|
|
156
|
+
font-family: var(--font-family-1);
|
|
157
|
+
color: var(--color-foreground);
|
|
158
|
+
background: transparent;
|
|
159
|
+
border: none;
|
|
160
|
+
outline: none;
|
|
161
|
+
padding: 0;
|
|
162
|
+
user-select: none;
|
|
163
|
+
-webkit-user-select: none;
|
|
164
|
+
transition:
|
|
165
|
+
background var(--transition-base),
|
|
166
|
+
border-color var(--transition-base),
|
|
167
|
+
color var(--transition-base),
|
|
168
|
+
box-shadow var(--transition-base);
|
|
169
|
+
|
|
170
|
+
&.button_interactive {
|
|
171
|
+
cursor: pointer;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
&:disabled {
|
|
175
|
+
cursor: not-allowed;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
&:focus-visible {
|
|
179
|
+
box-shadow: var(--shadow-ring);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Style1 - boxed/card */
|
|
183
|
+
&.button_style1 {
|
|
184
|
+
padding: var(--spacing-4) var(--spacing-5);
|
|
185
|
+
border-radius: var(--radius-md);
|
|
186
|
+
border: var(--border-1) solid var(--color-border);
|
|
187
|
+
background: var(--color-background);
|
|
188
|
+
|
|
189
|
+
&.button_interactive:hover:not(:disabled):not(.button_active) {
|
|
190
|
+
background: var(--color-muted);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
&.button_active {
|
|
194
|
+
background: var(--color-muted);
|
|
195
|
+
border-color: var(--color-ring);
|
|
196
|
+
box-shadow: var(--shadow-ring);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* Style2 - line/dot */
|
|
201
|
+
&.button_style2 {
|
|
202
|
+
padding: var(--spacing-1) var(--spacing-2);
|
|
203
|
+
border-radius: var(--radius-sm);
|
|
204
|
+
|
|
205
|
+
&.button_horizontal {
|
|
206
|
+
flex-direction: column;
|
|
207
|
+
align-items: center;
|
|
208
|
+
text-align: center;
|
|
209
|
+
gap: var(--spacing-3);
|
|
210
|
+
padding-block: 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
&.button_vertical {
|
|
214
|
+
align-items: flex-start;
|
|
215
|
+
padding: 0;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/* --------------------------------------------------------------------------
|
|
221
|
+
Indicator – shared shape + status colors
|
|
222
|
+
-------------------------------------------------------------------------- */
|
|
223
|
+
.indicator {
|
|
224
|
+
width: var(--stepper-indicator-size);
|
|
225
|
+
height: var(--stepper-indicator-size);
|
|
226
|
+
display: inline-flex;
|
|
227
|
+
align-items: center;
|
|
228
|
+
justify-content: center;
|
|
229
|
+
border-radius: var(--radius-full);
|
|
230
|
+
border: var(--border-1) solid var(--color-border);
|
|
231
|
+
background: var(--color-muted);
|
|
232
|
+
color: var(--color-muted-foreground);
|
|
233
|
+
font-size: var(--stepper-indicator-font-size);
|
|
234
|
+
font-weight: var(--font-weight-semibold);
|
|
235
|
+
line-height: 1;
|
|
236
|
+
flex-shrink: 0;
|
|
237
|
+
transition:
|
|
238
|
+
background var(--transition-base),
|
|
239
|
+
border-color var(--transition-base),
|
|
240
|
+
color var(--transition-base),
|
|
241
|
+
box-shadow var(--transition-base);
|
|
242
|
+
|
|
243
|
+
&.indicator_style2 {
|
|
244
|
+
background: var(--color-background);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* --------------------------------------------------------------------------
|
|
249
|
+
Step text (label + description)
|
|
250
|
+
-------------------------------------------------------------------------- */
|
|
251
|
+
.text {
|
|
252
|
+
min-width: 0;
|
|
253
|
+
display: flex;
|
|
254
|
+
flex-direction: column;
|
|
255
|
+
gap: var(--spacing-1);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
.button_style2.button_horizontal .text {
|
|
259
|
+
align-items: center;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
.label {
|
|
263
|
+
font-size: var(--font-size-sm);
|
|
264
|
+
line-height: var(--line-height-sm);
|
|
265
|
+
font-weight: var(--font-weight-medium);
|
|
266
|
+
color: var(--color-foreground);
|
|
267
|
+
overflow-wrap: anywhere;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.description {
|
|
271
|
+
font-size: var(--font-size-xs);
|
|
272
|
+
line-height: var(--line-height-sm);
|
|
273
|
+
color: var(--color-muted-foreground);
|
|
274
|
+
overflow-wrap: anywhere;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/* --------------------------------------------------------------------------
|
|
278
|
+
Panel
|
|
279
|
+
-------------------------------------------------------------------------- */
|
|
280
|
+
.panel {
|
|
281
|
+
outline: none;
|
|
282
|
+
animation: panel_fade_in var(--transition-base) ease both;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@keyframes panel_fade_in {
|
|
286
|
+
from {
|
|
287
|
+
opacity: 0;
|
|
288
|
+
transform: translateY(4px);
|
|
289
|
+
}
|
|
290
|
+
to {
|
|
291
|
+
opacity: 1;
|
|
292
|
+
transform: translateY(0);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useId,
|
|
3
|
+
useState,
|
|
4
|
+
type CSSProperties,
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
} from "react";
|
|
8
|
+
import clsx from "clsx";
|
|
9
|
+
import { IconAlertTriangle, IconCheck } from "@tabler/icons-react";
|
|
10
|
+
import s from "./stepper.module.css";
|
|
11
|
+
|
|
12
|
+
export const variants = ["style1", "style2"] as const;
|
|
13
|
+
export const sizes = ["sm", "lg"] as const;
|
|
14
|
+
export const orientations = ["horizontal", "vertical"] as const;
|
|
15
|
+
export const statuses = ["upcoming", "active", "complete", "error"] as const;
|
|
16
|
+
|
|
17
|
+
export type StepperVariant = (typeof variants)[number];
|
|
18
|
+
export type StepperSize = (typeof sizes)[number];
|
|
19
|
+
export type StepperOrientation = (typeof orientations)[number];
|
|
20
|
+
export type StepStatus = (typeof statuses)[number];
|
|
21
|
+
|
|
22
|
+
export type StepItem = {
|
|
23
|
+
id: string;
|
|
24
|
+
label: ReactNode;
|
|
25
|
+
description?: ReactNode;
|
|
26
|
+
content?: ReactNode;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
status?: StepStatus;
|
|
29
|
+
indicator?: ReactNode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type StepperProps = {
|
|
33
|
+
steps: StepItem[];
|
|
34
|
+
defaultStep?: string;
|
|
35
|
+
activeStep?: string;
|
|
36
|
+
onStepChange?: (id: string) => void;
|
|
37
|
+
variant?: StepperVariant;
|
|
38
|
+
size?: StepperSize;
|
|
39
|
+
orientation?: StepperOrientation;
|
|
40
|
+
allowStepClick?: boolean;
|
|
41
|
+
verticalGap?: string;
|
|
42
|
+
ariaLabel?: string;
|
|
43
|
+
className?: string;
|
|
44
|
+
} & Omit<ComponentProps<"div">, "onChange">;
|
|
45
|
+
|
|
46
|
+
const iconSizes: Record<StepperSize, number> = {
|
|
47
|
+
sm: 14,
|
|
48
|
+
lg: 18,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const resolveStatus = (
|
|
52
|
+
step: StepItem,
|
|
53
|
+
index: number,
|
|
54
|
+
activeIndex: number,
|
|
55
|
+
): StepStatus => {
|
|
56
|
+
if (step.status) return step.status;
|
|
57
|
+
if (index < activeIndex) return "complete";
|
|
58
|
+
if (index === activeIndex) return "active";
|
|
59
|
+
return "upcoming";
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const renderIndicator = (
|
|
63
|
+
step: StepItem,
|
|
64
|
+
status: StepStatus,
|
|
65
|
+
index: number,
|
|
66
|
+
size: StepperSize,
|
|
67
|
+
): ReactNode => {
|
|
68
|
+
if (step.indicator) return step.indicator;
|
|
69
|
+
if (status === "complete") return <IconCheck size={iconSizes[size]} />;
|
|
70
|
+
if (status === "error") return <IconAlertTriangle size={iconSizes[size]} />;
|
|
71
|
+
return index + 1;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const Stepper = ({
|
|
75
|
+
steps,
|
|
76
|
+
defaultStep,
|
|
77
|
+
activeStep: controlledActive,
|
|
78
|
+
onStepChange,
|
|
79
|
+
variant = "style1",
|
|
80
|
+
size = "sm",
|
|
81
|
+
orientation = "horizontal",
|
|
82
|
+
allowStepClick = true,
|
|
83
|
+
verticalGap,
|
|
84
|
+
ariaLabel = "Progress",
|
|
85
|
+
className,
|
|
86
|
+
style,
|
|
87
|
+
...rest
|
|
88
|
+
}: StepperProps) => {
|
|
89
|
+
const uid = useId();
|
|
90
|
+
const isControlled = controlledActive !== undefined;
|
|
91
|
+
const [internalActive, setInternalActive] = useState(
|
|
92
|
+
() =>
|
|
93
|
+
defaultStep ??
|
|
94
|
+
steps.find((step) => !step.disabled)?.id ??
|
|
95
|
+
steps[0]?.id ??
|
|
96
|
+
"",
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (steps.length === 0) return null;
|
|
100
|
+
|
|
101
|
+
const activeId = isControlled ? controlledActive : internalActive;
|
|
102
|
+
const foundIndex = steps.findIndex((step) => step.id === activeId);
|
|
103
|
+
const activeIndex = foundIndex >= 0 ? foundIndex : 0;
|
|
104
|
+
const activeStepDomId = `${uid}-step-${activeIndex}`;
|
|
105
|
+
const activePanelDomId = `${uid}-panel-${activeIndex}`;
|
|
106
|
+
const activeContent = steps[activeIndex]?.content;
|
|
107
|
+
|
|
108
|
+
const handleStepClick = (id: string, disabled?: boolean) => {
|
|
109
|
+
if (!allowStepClick || disabled) return;
|
|
110
|
+
if (!isControlled) setInternalActive(id);
|
|
111
|
+
onStepChange?.(id);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const rootStyle: CSSProperties | undefined =
|
|
115
|
+
verticalGap !== undefined
|
|
116
|
+
? ({ ...style, "--stepper-gap-v": verticalGap } as CSSProperties)
|
|
117
|
+
: style;
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
<div
|
|
121
|
+
className={clsx(s.root, s[`root_${size}`], className)}
|
|
122
|
+
style={rootStyle}
|
|
123
|
+
{...rest}
|
|
124
|
+
>
|
|
125
|
+
<ol
|
|
126
|
+
className={clsx(s.list, s[`list_${variant}`], s[`list_${orientation}`])}
|
|
127
|
+
aria-label={ariaLabel}
|
|
128
|
+
aria-orientation={orientation}
|
|
129
|
+
>
|
|
130
|
+
{steps.map((step, index) => {
|
|
131
|
+
const status = resolveStatus(step, index, activeIndex);
|
|
132
|
+
const isActive = index === activeIndex;
|
|
133
|
+
const isDisabled = Boolean(step.disabled);
|
|
134
|
+
const stepDomId = `${uid}-step-${index}`;
|
|
135
|
+
const panelDomId = `${uid}-panel-${index}`;
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<li
|
|
139
|
+
key={step.id}
|
|
140
|
+
className={clsx(
|
|
141
|
+
s.step,
|
|
142
|
+
s[`step_${variant}`],
|
|
143
|
+
s[`step_${orientation}`],
|
|
144
|
+
)}
|
|
145
|
+
data-status={status}
|
|
146
|
+
data-disabled={isDisabled || undefined}
|
|
147
|
+
>
|
|
148
|
+
<button
|
|
149
|
+
type="button"
|
|
150
|
+
id={stepDomId}
|
|
151
|
+
aria-current={isActive ? "step" : undefined}
|
|
152
|
+
aria-controls={
|
|
153
|
+
isActive && step.content !== undefined
|
|
154
|
+
? panelDomId
|
|
155
|
+
: undefined
|
|
156
|
+
}
|
|
157
|
+
aria-disabled={isDisabled || !allowStepClick}
|
|
158
|
+
disabled={isDisabled}
|
|
159
|
+
tabIndex={allowStepClick ? undefined : -1}
|
|
160
|
+
onClick={() => handleStepClick(step.id, isDisabled)}
|
|
161
|
+
className={clsx(
|
|
162
|
+
s.button,
|
|
163
|
+
s[`button_${variant}`],
|
|
164
|
+
s[`button_${orientation}`],
|
|
165
|
+
isActive && s.button_active,
|
|
166
|
+
allowStepClick && !isDisabled && s.button_interactive,
|
|
167
|
+
)}
|
|
168
|
+
>
|
|
169
|
+
<span className={clsx(s.indicator, s[`indicator_${variant}`])}>
|
|
170
|
+
{renderIndicator(step, status, index, size)}
|
|
171
|
+
</span>
|
|
172
|
+
<span className={s.text}>
|
|
173
|
+
<span className={s.label}>{step.label}</span>
|
|
174
|
+
{step.description && (
|
|
175
|
+
<span className={s.description}>{step.description}</span>
|
|
176
|
+
)}
|
|
177
|
+
</span>
|
|
178
|
+
</button>
|
|
179
|
+
</li>
|
|
180
|
+
);
|
|
181
|
+
})}
|
|
182
|
+
</ol>
|
|
183
|
+
|
|
184
|
+
{activeContent !== undefined && (
|
|
185
|
+
<div
|
|
186
|
+
key={activeId}
|
|
187
|
+
id={activePanelDomId}
|
|
188
|
+
role="region"
|
|
189
|
+
aria-labelledby={activeStepDomId}
|
|
190
|
+
className={s.panel}
|
|
191
|
+
>
|
|
192
|
+
{activeContent}
|
|
193
|
+
</div>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
};
|