@techsio/ui-kit 0.0.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/README.md +165 -0
- package/dist/atoms/badge.js +66 -0
- package/dist/atoms/button.js +275 -0
- package/dist/atoms/error-text.js +38 -0
- package/dist/atoms/extra-text.js +27 -0
- package/dist/atoms/icon.js +42 -0
- package/dist/atoms/image.js +11 -0
- package/dist/atoms/input.js +83 -0
- package/dist/atoms/label.js +43 -0
- package/dist/atoms/link-button.js +51 -0
- package/dist/atoms/link.js +23 -0
- package/dist/atoms/numeric-input.js +221 -0
- package/dist/atoms/rating.js +117 -0
- package/dist/atoms/textarea.js +81 -0
- package/dist/atoms/tooltip.js +119 -0
- package/dist/molecules/accordion.js +245 -0
- package/dist/molecules/breadcrumb.js +168 -0
- package/dist/molecules/carousel.js +333 -0
- package/dist/molecules/checkbox.js +92 -0
- package/dist/molecules/color-select.js +159 -0
- package/dist/molecules/combobox.js +253 -0
- package/dist/molecules/dialog.js +313 -0
- package/dist/molecules/form-checkbox.js +59 -0
- package/dist/molecules/form-input.js +55 -0
- package/dist/molecules/form-numeric-input.js +47 -0
- package/dist/molecules/form-textarea.js +54 -0
- package/dist/molecules/menu.js +302 -0
- package/dist/molecules/pagination.js +184 -0
- package/dist/molecules/popover.js +152 -0
- package/dist/molecules/product-card.js +194 -0
- package/dist/molecules/search-form.js +106 -0
- package/dist/molecules/select.js +217 -0
- package/dist/molecules/slider.js +249 -0
- package/dist/molecules/steps.js +178 -0
- package/dist/molecules/switch.js +109 -0
- package/dist/molecules/tabs.js +211 -0
- package/dist/molecules/toast.js +126 -0
- package/dist/molecules/tree-view.js +451 -0
- package/dist/organisms/footer.js +209 -0
- package/dist/organisms/header.js +245 -0
- package/dist/organisms/table.js +233 -0
- package/dist/src/atoms/badge.d.ts +59 -0
- package/dist/src/atoms/badge.d.ts.map +1 -0
- package/dist/src/atoms/button.d.ts +97 -0
- package/dist/src/atoms/button.d.ts.map +1 -0
- package/dist/src/atoms/error-text.d.ts +29 -0
- package/dist/src/atoms/error-text.d.ts.map +1 -0
- package/dist/src/atoms/extra-text.d.ts +27 -0
- package/dist/src/atoms/extra-text.d.ts.map +1 -0
- package/dist/src/atoms/icon.d.ts +65 -0
- package/dist/src/atoms/icon.d.ts.map +1 -0
- package/dist/src/atoms/image.d.ts +17 -0
- package/dist/src/atoms/image.d.ts.map +1 -0
- package/dist/src/atoms/input.d.ts +78 -0
- package/dist/src/atoms/input.d.ts.map +1 -0
- package/dist/src/atoms/label.d.ts +41 -0
- package/dist/src/atoms/label.d.ts.map +1 -0
- package/dist/src/atoms/link-button.d.ts +129 -0
- package/dist/src/atoms/link-button.d.ts.map +1 -0
- package/dist/src/atoms/link.d.ts +17 -0
- package/dist/src/atoms/link.d.ts.map +1 -0
- package/dist/src/atoms/numeric-input.d.ts +64 -0
- package/dist/src/atoms/numeric-input.d.ts.map +1 -0
- package/dist/src/atoms/rating.d.ts +108 -0
- package/dist/src/atoms/rating.d.ts.map +1 -0
- package/dist/src/atoms/textarea.d.ts +81 -0
- package/dist/src/atoms/textarea.d.ts.map +1 -0
- package/dist/src/atoms/tooltip.d.ts +88 -0
- package/dist/src/atoms/tooltip.d.ts.map +1 -0
- package/dist/src/molecules/accordion.d.ts +182 -0
- package/dist/src/molecules/accordion.d.ts.map +1 -0
- package/dist/src/molecules/breadcrumb.d.ts +117 -0
- package/dist/src/molecules/breadcrumb.d.ts.map +1 -0
- package/dist/src/molecules/carousel.d.ts +261 -0
- package/dist/src/molecules/carousel.d.ts.map +1 -0
- package/dist/src/molecules/checkbox.d.ts +19 -0
- package/dist/src/molecules/checkbox.d.ts.map +1 -0
- package/dist/src/molecules/color-select.d.ts +20 -0
- package/dist/src/molecules/color-select.d.ts.map +1 -0
- package/dist/src/molecules/combobox.d.ts +141 -0
- package/dist/src/molecules/combobox.d.ts.map +1 -0
- package/dist/src/molecules/dialog.d.ts +234 -0
- package/dist/src/molecules/dialog.d.ts.map +1 -0
- package/dist/src/molecules/form-checkbox.d.ts +15 -0
- package/dist/src/molecules/form-checkbox.d.ts.map +1 -0
- package/dist/src/molecules/form-input.d.ts +14 -0
- package/dist/src/molecules/form-input.d.ts.map +1 -0
- package/dist/src/molecules/form-numeric-input.d.ts +14 -0
- package/dist/src/molecules/form-numeric-input.d.ts.map +1 -0
- package/dist/src/molecules/form-textarea.d.ts +14 -0
- package/dist/src/molecules/form-textarea.d.ts.map +1 -0
- package/dist/src/molecules/menu.d.ts +153 -0
- package/dist/src/molecules/menu.d.ts.map +1 -0
- package/dist/src/molecules/pagination.d.ts +123 -0
- package/dist/src/molecules/pagination.d.ts.map +1 -0
- package/dist/src/molecules/popover.d.ts +124 -0
- package/dist/src/molecules/popover.d.ts.map +1 -0
- package/dist/src/molecules/product-card.d.ts +160 -0
- package/dist/src/molecules/product-card.d.ts.map +1 -0
- package/dist/src/molecules/search-form.d.ts +39 -0
- package/dist/src/molecules/search-form.d.ts.map +1 -0
- package/dist/src/molecules/select.d.ts +126 -0
- package/dist/src/molecules/select.d.ts.map +1 -0
- package/dist/src/molecules/slider.d.ts +120 -0
- package/dist/src/molecules/slider.d.ts.map +1 -0
- package/dist/src/molecules/steps.d.ts +96 -0
- package/dist/src/molecules/steps.d.ts.map +1 -0
- package/dist/src/molecules/switch.d.ts +71 -0
- package/dist/src/molecules/switch.d.ts.map +1 -0
- package/dist/src/molecules/tabs.d.ts +207 -0
- package/dist/src/molecules/tabs.d.ts.map +1 -0
- package/dist/src/molecules/toast.d.ts +83 -0
- package/dist/src/molecules/toast.d.ts.map +1 -0
- package/dist/src/molecules/tree-view.d.ts +202 -0
- package/dist/src/molecules/tree-view.d.ts.map +1 -0
- package/dist/src/organisms/footer.d.ts +254 -0
- package/dist/src/organisms/footer.d.ts.map +1 -0
- package/dist/src/organisms/header.d.ts +186 -0
- package/dist/src/organisms/header.d.ts.map +1 -0
- package/dist/src/organisms/table.d.ts +250 -0
- package/dist/src/organisms/table.d.ts.map +1 -0
- package/dist/src/templates/accordion.d.ts +15 -0
- package/dist/src/templates/accordion.d.ts.map +1 -0
- package/dist/src/templates/carousel.d.ts +13 -0
- package/dist/src/templates/carousel.d.ts.map +1 -0
- package/dist/src/templates/numeric-input.d.ts +14 -0
- package/dist/src/templates/numeric-input.d.ts.map +1 -0
- package/dist/src/templates/product-card.d.ts +33 -0
- package/dist/src/templates/product-card.d.ts.map +1 -0
- package/dist/src/templates/tabs.d.ts +16 -0
- package/dist/src/templates/tabs.d.ts.map +1 -0
- package/dist/src/types/zag.d.ts +19 -0
- package/dist/src/types/zag.d.ts.map +1 -0
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/templates/accordion.js +37 -0
- package/dist/templates/carousel.js +55 -0
- package/dist/templates/numeric-input.js +49 -0
- package/dist/templates/product-card.js +92 -0
- package/dist/templates/tabs.js +34 -0
- package/dist/types/zag.js +0 -0
- package/dist/utils.js +20 -0
- package/package.json +126 -0
- package/src/tokens/_base.css +25 -0
- package/src/tokens/_colors.css +5 -0
- package/src/tokens/_layout.css +34 -0
- package/src/tokens/_semantic.css +360 -0
- package/src/tokens/_spacing.css +22 -0
- package/src/tokens/_typography.css +17 -0
- package/src/tokens/components/atoms/_badge.css +61 -0
- package/src/tokens/components/atoms/_button.css +215 -0
- package/src/tokens/components/atoms/_icon.css +122 -0
- package/src/tokens/components/atoms/_input.css +125 -0
- package/src/tokens/components/atoms/_numeric-input.css +57 -0
- package/src/tokens/components/atoms/_rating.css +33 -0
- package/src/tokens/components/atoms/_textarea.css +93 -0
- package/src/tokens/components/atoms/_tooltip.css +21 -0
- package/src/tokens/components/components.css +32 -0
- package/src/tokens/components/molecules/_accordion.css +85 -0
- package/src/tokens/components/molecules/_breadcrumb.css +44 -0
- package/src/tokens/components/molecules/_carousel.css +72 -0
- package/src/tokens/components/molecules/_checkbox.css +29 -0
- package/src/tokens/components/molecules/_color-select.css +61 -0
- package/src/tokens/components/molecules/_combobox.css +116 -0
- package/src/tokens/components/molecules/_dialog.css +75 -0
- package/src/tokens/components/molecules/_menu.css +48 -0
- package/src/tokens/components/molecules/_pagination.css +75 -0
- package/src/tokens/components/molecules/_popover.css +39 -0
- package/src/tokens/components/molecules/_product-card.css +85 -0
- package/src/tokens/components/molecules/_search-form.css +10 -0
- package/src/tokens/components/molecules/_select.css +88 -0
- package/src/tokens/components/molecules/_slider.css +75 -0
- package/src/tokens/components/molecules/_steps.css +54 -0
- package/src/tokens/components/molecules/_switch.css +62 -0
- package/src/tokens/components/molecules/_tabs.css +69 -0
- package/src/tokens/components/molecules/_toast.css +77 -0
- package/src/tokens/components/molecules/_tree-view.css +80 -0
- package/src/tokens/components/molecules/index.css +2 -0
- package/src/tokens/components/organisms/_footer.css +90 -0
- package/src/tokens/components/organisms/_header.css +86 -0
- package/src/tokens/components/organisms/_table.css +63 -0
- package/src/tokens/index.css +67 -0
- package/src/tokens/tokens-only.css +66 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeProps, useMachine } from "@zag-js/react";
|
|
3
|
+
import { connect, machine } from "@zag-js/slider";
|
|
4
|
+
import { useId } from "react";
|
|
5
|
+
import { ErrorText } from "../atoms/error-text.js";
|
|
6
|
+
import { ExtraText } from "../atoms/extra-text.js";
|
|
7
|
+
import { Label } from "../atoms/label.js";
|
|
8
|
+
import { slugify, tv } from "../utils.js";
|
|
9
|
+
const sliderVariants = tv({
|
|
10
|
+
slots: {
|
|
11
|
+
root: [
|
|
12
|
+
'flex flex-col w-full gap-slider-root',
|
|
13
|
+
'data-[orientation=vertical]:h-full',
|
|
14
|
+
'data-[disabled]:opacity-slider-disabled data-[disabled]:cursor-not-allowed'
|
|
15
|
+
],
|
|
16
|
+
header: [
|
|
17
|
+
'flex items-center justify-between'
|
|
18
|
+
],
|
|
19
|
+
value: [
|
|
20
|
+
'text-slider-value-size'
|
|
21
|
+
],
|
|
22
|
+
label: [
|
|
23
|
+
'block font-medium'
|
|
24
|
+
],
|
|
25
|
+
control: [
|
|
26
|
+
'relative grid place-items-center ',
|
|
27
|
+
'data-[orientation=vertical]:h-full data-[orientation=vertical]:grid-rows-1'
|
|
28
|
+
],
|
|
29
|
+
track: [
|
|
30
|
+
'rounded-slider-track bg-slider-track-bg flex-1',
|
|
31
|
+
'data-[orientation=horizontal]:w-full',
|
|
32
|
+
'data-[orientation=vertical]:h-full ',
|
|
33
|
+
'data-[disabled]:bg-slider-bg-disabled',
|
|
34
|
+
'border-(length:--border-width-slider) border-slider-border',
|
|
35
|
+
'data-[disabled]:border-slider-border-disabled',
|
|
36
|
+
'transition-colors duration-200',
|
|
37
|
+
'hover:bg-slider-track-bg-hover',
|
|
38
|
+
'data-[invalid=true]:border-slider-border-error'
|
|
39
|
+
],
|
|
40
|
+
range: [
|
|
41
|
+
'bg-slider-range-bg rounded-slider-track h-full',
|
|
42
|
+
'data-[orientation=vertical]:h-auto data-[orientation=vertical]:w-full',
|
|
43
|
+
'data-[disabled]:bg-slider-bg-disabled',
|
|
44
|
+
'hover:bg-slider-range-bg-hover',
|
|
45
|
+
'data-[invalid=true]:bg-slider-range-bg-error'
|
|
46
|
+
],
|
|
47
|
+
thumb: [
|
|
48
|
+
'flex items-center justify-center',
|
|
49
|
+
'rounded-slider-thumb bg-slider-thumb-bg',
|
|
50
|
+
'focus:outline-none',
|
|
51
|
+
'focus-visible:ring',
|
|
52
|
+
'focus-visible:ring-slider-ring',
|
|
53
|
+
'data-[disabled]:bg-slider-thumb-bg-disabled',
|
|
54
|
+
'border-(length:--border-width-slider) border-slider-border',
|
|
55
|
+
'data-[disabled]:border-slider-border-disabled',
|
|
56
|
+
'hover:bg-slider-thumb-bg-hover',
|
|
57
|
+
'cursor-grab data-[dragging]:cursor-grabbing data-[disabled]:cursor-not-allowed',
|
|
58
|
+
'transition-colors duration-200',
|
|
59
|
+
'shadow-slider-thumb'
|
|
60
|
+
],
|
|
61
|
+
markerGroup: [
|
|
62
|
+
'relative h-full flex items-center'
|
|
63
|
+
],
|
|
64
|
+
marker: [
|
|
65
|
+
'relative h-full flex flex-col justify-center items-center',
|
|
66
|
+
'data-[orientation=vertical]:w-full',
|
|
67
|
+
'data-[orientation=vertical]:h-marker-vertical',
|
|
68
|
+
'data-[orientation=vertical]:flex-row'
|
|
69
|
+
],
|
|
70
|
+
markerLine: [
|
|
71
|
+
'w-slider-marker h-full bg-slider-marker-bg',
|
|
72
|
+
'data-[orientation=vertical]:h-slider-marker data-[orientation=vertical]:w-full'
|
|
73
|
+
],
|
|
74
|
+
markerText: [
|
|
75
|
+
'absolute top-full',
|
|
76
|
+
'data-[orientation=vertical]:top-0 data-[orientation=vertical]:left-full',
|
|
77
|
+
'data-[orientation=vertical]:h-full',
|
|
78
|
+
'data-[orientation=vertical]:p-marker-text'
|
|
79
|
+
],
|
|
80
|
+
footer: [
|
|
81
|
+
'flex flex-col'
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
variants: {
|
|
85
|
+
size: {
|
|
86
|
+
sm: {
|
|
87
|
+
track: [
|
|
88
|
+
'h-slider-track-sm data-[orientation=vertical]:w-slider-track-sm'
|
|
89
|
+
],
|
|
90
|
+
thumb: [
|
|
91
|
+
'w-slider-thumb-sm',
|
|
92
|
+
'h-slider-thumb-sm'
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
md: {
|
|
96
|
+
track: [
|
|
97
|
+
'h-slider-track-md data-[orientation=vertical]:w-slider-track-md'
|
|
98
|
+
],
|
|
99
|
+
thumb: [
|
|
100
|
+
'w-slider-thumb-md',
|
|
101
|
+
'h-slider-thumb-md'
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
lg: {
|
|
105
|
+
track: [
|
|
106
|
+
'h-slider-track-lg data-[orientation=vertical]:w-slider-track-lg'
|
|
107
|
+
],
|
|
108
|
+
thumb: [
|
|
109
|
+
'w-slider-thumb-lg',
|
|
110
|
+
'h-slider-thumb-lg'
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
defaultVariants: {
|
|
116
|
+
size: 'md'
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
function Slider({ id, name, label, helperText, error, errorText, value, origin, thumbAlignment = 'center', defaultValue = [
|
|
120
|
+
25,
|
|
121
|
+
75
|
|
122
|
+
], min = 0, max = 100, step = 1, minStepsBetweenThumbs = 0, disabled = false, readOnly = false, dir = 'ltr', orientation = 'horizontal', size = 'md', showMarkers = false, markerCount = 5, showValueText = false, formatRangeText, formatValue = (val)=>val.toString(), className, onChange, onChangeEnd }) {
|
|
123
|
+
const generatedId = useId();
|
|
124
|
+
const uniqueId = id || generatedId;
|
|
125
|
+
const service = useMachine(machine, {
|
|
126
|
+
id: uniqueId,
|
|
127
|
+
name,
|
|
128
|
+
value,
|
|
129
|
+
defaultValue,
|
|
130
|
+
min,
|
|
131
|
+
max,
|
|
132
|
+
origin,
|
|
133
|
+
thumbAlignment,
|
|
134
|
+
step,
|
|
135
|
+
minStepsBetweenThumbs,
|
|
136
|
+
disabled,
|
|
137
|
+
readOnly,
|
|
138
|
+
dir,
|
|
139
|
+
orientation,
|
|
140
|
+
onValueChange: (details)=>onChange?.(details.value),
|
|
141
|
+
onValueChangeEnd: (details)=>onChangeEnd?.(details.value)
|
|
142
|
+
});
|
|
143
|
+
const api = connect(service, normalizeProps);
|
|
144
|
+
const { root, label: labelSlot, control, track, range, thumb, header, value: valueSlot, markerGroup, marker, markerLine, markerText, footer } = sliderVariants({
|
|
145
|
+
className,
|
|
146
|
+
size
|
|
147
|
+
});
|
|
148
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
149
|
+
className: root({
|
|
150
|
+
className
|
|
151
|
+
}),
|
|
152
|
+
...api.getRootProps(),
|
|
153
|
+
children: [
|
|
154
|
+
(label || showValueText) && /*#__PURE__*/ jsxs("div", {
|
|
155
|
+
className: header(),
|
|
156
|
+
children: [
|
|
157
|
+
/*#__PURE__*/ jsx(Label, {
|
|
158
|
+
className: labelSlot(),
|
|
159
|
+
...api.getLabelProps(),
|
|
160
|
+
children: label
|
|
161
|
+
}),
|
|
162
|
+
showValueText && /*#__PURE__*/ jsxs("output", {
|
|
163
|
+
className: valueSlot(),
|
|
164
|
+
...api.getValueTextProps(),
|
|
165
|
+
children: [
|
|
166
|
+
/*#__PURE__*/ jsx("b", {
|
|
167
|
+
children: formatRangeText ? formatRangeText(api.value || defaultValue) : api.value && 2 === api.value.length && void 0 !== api.value[0] && void 0 !== api.value[1] ? `${formatValue(api.value[0])} - ${formatValue(api.value[1])}` : ''
|
|
168
|
+
}),
|
|
169
|
+
' '
|
|
170
|
+
]
|
|
171
|
+
})
|
|
172
|
+
]
|
|
173
|
+
}),
|
|
174
|
+
/*#__PURE__*/ jsxs("div", {
|
|
175
|
+
className: control(),
|
|
176
|
+
...api.getControlProps(),
|
|
177
|
+
children: [
|
|
178
|
+
/*#__PURE__*/ jsxs("div", {
|
|
179
|
+
className: track(),
|
|
180
|
+
...api.getTrackProps(),
|
|
181
|
+
"data-invalid": error,
|
|
182
|
+
children: [
|
|
183
|
+
/*#__PURE__*/ jsx("div", {
|
|
184
|
+
className: range(),
|
|
185
|
+
...api.getRangeProps(),
|
|
186
|
+
"data-invalid": error
|
|
187
|
+
}),
|
|
188
|
+
showMarkers && /*#__PURE__*/ jsx("div", {
|
|
189
|
+
...api.getMarkerGroupProps(),
|
|
190
|
+
className: markerGroup(),
|
|
191
|
+
children: Array.from({
|
|
192
|
+
length: markerCount
|
|
193
|
+
}).map((_, index)=>{
|
|
194
|
+
const markerValue = 1 === markerCount ? min : min + (max - min) / (markerCount - 1) * index;
|
|
195
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
196
|
+
className: marker(),
|
|
197
|
+
...api.getMarkerProps({
|
|
198
|
+
value: markerValue
|
|
199
|
+
}),
|
|
200
|
+
children: [
|
|
201
|
+
!('center' === thumbAlignment && (0 === index || index === markerCount - 1)) && /*#__PURE__*/ jsx("div", {
|
|
202
|
+
className: markerLine(),
|
|
203
|
+
"data-orientation": orientation
|
|
204
|
+
}),
|
|
205
|
+
/*#__PURE__*/ jsx("span", {
|
|
206
|
+
className: markerText(),
|
|
207
|
+
"data-orientation": orientation,
|
|
208
|
+
children: markerValue
|
|
209
|
+
})
|
|
210
|
+
]
|
|
211
|
+
}, slugify(`marker-${markerValue}`));
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
]
|
|
215
|
+
}),
|
|
216
|
+
api.value.map((_, index)=>/*#__PURE__*/ jsx("div", {
|
|
217
|
+
className: thumb(),
|
|
218
|
+
...api.getThumbProps({
|
|
219
|
+
index
|
|
220
|
+
}),
|
|
221
|
+
children: /*#__PURE__*/ jsx("input", {
|
|
222
|
+
...api.getHiddenInputProps({
|
|
223
|
+
index
|
|
224
|
+
})
|
|
225
|
+
})
|
|
226
|
+
}, index))
|
|
227
|
+
]
|
|
228
|
+
}),
|
|
229
|
+
(helperText || errorText) && /*#__PURE__*/ jsxs("div", {
|
|
230
|
+
className: footer(),
|
|
231
|
+
children: [
|
|
232
|
+
/*#__PURE__*/ jsx("div", {
|
|
233
|
+
className: error ? 'block' : 'invisible h-0 overflow-hidden',
|
|
234
|
+
children: /*#__PURE__*/ jsx(ErrorText, {
|
|
235
|
+
children: errorText
|
|
236
|
+
})
|
|
237
|
+
}),
|
|
238
|
+
/*#__PURE__*/ jsx("div", {
|
|
239
|
+
className: !error && helperText ? 'block' : 'invisible h-0 overflow-hidden',
|
|
240
|
+
children: /*#__PURE__*/ jsx(ExtraText, {
|
|
241
|
+
children: helperText
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
]
|
|
245
|
+
})
|
|
246
|
+
]
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
export { Slider };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeProps, useMachine } from "@zag-js/react";
|
|
3
|
+
import { connect, machine } from "@zag-js/steps";
|
|
4
|
+
import { useId } from "react";
|
|
5
|
+
import { Button } from "../atoms/button.js";
|
|
6
|
+
import { slugify, tv } from "../utils.js";
|
|
7
|
+
const stepsVariants = tv({
|
|
8
|
+
slots: {
|
|
9
|
+
root: [
|
|
10
|
+
'relative flex bg-steps-root-bg',
|
|
11
|
+
'gap-root',
|
|
12
|
+
'text-steps-fg',
|
|
13
|
+
'data-[orientation=horizontal]:flex-col',
|
|
14
|
+
'data-[orientation=vertical]:grid data-[orientation=vertical]:grid-cols-[auto_1fr]'
|
|
15
|
+
],
|
|
16
|
+
list: [
|
|
17
|
+
'relative flex bg-steps-list-bg gap-list',
|
|
18
|
+
'data-[orientation=vertical]:flex-col',
|
|
19
|
+
'data-[orientation=vertical]:h-full'
|
|
20
|
+
],
|
|
21
|
+
item: [
|
|
22
|
+
'relative flex bg-steps-item-bg items-center gap-item',
|
|
23
|
+
'focus-visible:outline-none',
|
|
24
|
+
'data-[orientation=horizontal]:w-full data-[orientation=horizontal]:justify-start',
|
|
25
|
+
'data-[orientation=vertical]:flex-col data-[orientation=vertical]:h-full'
|
|
26
|
+
],
|
|
27
|
+
trigger: [
|
|
28
|
+
'relative gap-trigger flex cursor-pointer group',
|
|
29
|
+
'items-center justify-center',
|
|
30
|
+
'transition-all duration-200',
|
|
31
|
+
'focus-visible:outline-none',
|
|
32
|
+
'data-[orientation=horizontal]:flex-row',
|
|
33
|
+
'data-[orientation=vertical]:flex-col'
|
|
34
|
+
],
|
|
35
|
+
content: [
|
|
36
|
+
'grid p-content bg-steps-content-bg',
|
|
37
|
+
'focus-visible:outline-none',
|
|
38
|
+
'focus-visible:ring',
|
|
39
|
+
'focus-visible:ring-steps-ring',
|
|
40
|
+
'data-[orientation=horizontal]:w-full',
|
|
41
|
+
'data-[orientation=vertical]:flex-1'
|
|
42
|
+
],
|
|
43
|
+
indicator: [
|
|
44
|
+
'grid place-items-center',
|
|
45
|
+
'h-steps-indicator rounded-full aspect-square',
|
|
46
|
+
'bg-steps-indicator-bg data-[complete]:bg-steps-indicator-bg-complete',
|
|
47
|
+
'group-focus-visible:ring',
|
|
48
|
+
'group-focus-visible:ring-steps-ring',
|
|
49
|
+
'group-hover:bg-steps-indicator-bg-hover',
|
|
50
|
+
'group-hover:text-steps-fg-active',
|
|
51
|
+
'transition-all duration-200 ease-out',
|
|
52
|
+
'data-[current]:bg-steps-indicator-bg-current',
|
|
53
|
+
'focus-visible:data-[current]:ring',
|
|
54
|
+
'focus-visible:data-[current]:ring-steps-ring',
|
|
55
|
+
'data-[current]:outline-none',
|
|
56
|
+
'data-[current]:text-steps-fg-current data-[complete]:text-steps-fg-active'
|
|
57
|
+
],
|
|
58
|
+
separator: [
|
|
59
|
+
'bg-steps-separator-bg',
|
|
60
|
+
'data-[complete]:bg-steps-separator-bg-complete',
|
|
61
|
+
'data-[orientation=horizontal]:h-steps-separator data-[orientation=horizontal]:w-full data-[orientation=horizontal]:flex-1',
|
|
62
|
+
'data-[orientation=vertical]:w-steps-separator data-[orientation=vertical]:h-full'
|
|
63
|
+
],
|
|
64
|
+
containerButtons: [
|
|
65
|
+
'flex gap-2 h-fit',
|
|
66
|
+
'data-[orientation=vertical]:col-start-2'
|
|
67
|
+
],
|
|
68
|
+
stepButton: [
|
|
69
|
+
'rounded-none p-steps-btn',
|
|
70
|
+
'focus-visible:ring',
|
|
71
|
+
'focus-visible:ring-steps-ring'
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
function Steps({ id, items, currentStep = 0, orientation = 'horizontal', linear = false, showControls = true, completeText, onStepChange, onStepComplete }) {
|
|
76
|
+
const generatedId = useId();
|
|
77
|
+
const uniqueId = id || generatedId;
|
|
78
|
+
const service = useMachine(machine, {
|
|
79
|
+
id: uniqueId,
|
|
80
|
+
count: items.length,
|
|
81
|
+
step: currentStep,
|
|
82
|
+
orientation,
|
|
83
|
+
linear,
|
|
84
|
+
onStepChange: (details)=>{
|
|
85
|
+
onStepChange?.(details.step);
|
|
86
|
+
},
|
|
87
|
+
onStepComplete: ()=>{
|
|
88
|
+
onStepComplete?.();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const api = connect(service, normalizeProps);
|
|
92
|
+
const { root, list, item, trigger, separator, indicator, content, containerButtons, stepButton } = stepsVariants();
|
|
93
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
94
|
+
className: root(),
|
|
95
|
+
...api.getRootProps(),
|
|
96
|
+
children: [
|
|
97
|
+
/*#__PURE__*/ jsx("div", {
|
|
98
|
+
className: list(),
|
|
99
|
+
...api.getListProps(),
|
|
100
|
+
children: items.map((step, index)=>/*#__PURE__*/ jsxs("div", {
|
|
101
|
+
className: item(),
|
|
102
|
+
...api.getItemProps({
|
|
103
|
+
index
|
|
104
|
+
}),
|
|
105
|
+
children: [
|
|
106
|
+
/*#__PURE__*/ jsxs("button", {
|
|
107
|
+
className: trigger(),
|
|
108
|
+
...api.getTriggerProps({
|
|
109
|
+
index
|
|
110
|
+
}),
|
|
111
|
+
children: [
|
|
112
|
+
/*#__PURE__*/ jsx("span", {
|
|
113
|
+
className: indicator(),
|
|
114
|
+
...api.getIndicatorProps({
|
|
115
|
+
index
|
|
116
|
+
}),
|
|
117
|
+
children: index + 1
|
|
118
|
+
}),
|
|
119
|
+
/*#__PURE__*/ jsx("span", {
|
|
120
|
+
children: step.title
|
|
121
|
+
})
|
|
122
|
+
]
|
|
123
|
+
}),
|
|
124
|
+
index < items.length - 1 && /*#__PURE__*/ jsx("div", {
|
|
125
|
+
className: separator(),
|
|
126
|
+
...api.getSeparatorProps({
|
|
127
|
+
index
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
}, slugify(step.title)))
|
|
132
|
+
}),
|
|
133
|
+
items.map((step, index)=>/*#__PURE__*/ jsx("div", {
|
|
134
|
+
className: content(),
|
|
135
|
+
...api.getContentProps({
|
|
136
|
+
index
|
|
137
|
+
}),
|
|
138
|
+
children: /*#__PURE__*/ jsxs("article", {
|
|
139
|
+
className: "h-fit",
|
|
140
|
+
children: [
|
|
141
|
+
/*#__PURE__*/ jsx("h3", {
|
|
142
|
+
children: step.title
|
|
143
|
+
}),
|
|
144
|
+
step.content
|
|
145
|
+
]
|
|
146
|
+
})
|
|
147
|
+
}, `content-${slugify(step.title)}`)),
|
|
148
|
+
/*#__PURE__*/ jsx("div", {
|
|
149
|
+
className: content(),
|
|
150
|
+
...api.getContentProps({
|
|
151
|
+
index: items.length
|
|
152
|
+
}),
|
|
153
|
+
children: completeText
|
|
154
|
+
}),
|
|
155
|
+
showControls && /*#__PURE__*/ jsxs("div", {
|
|
156
|
+
className: containerButtons(),
|
|
157
|
+
"data-orientation": orientation,
|
|
158
|
+
children: [
|
|
159
|
+
/*#__PURE__*/ jsx(Button, {
|
|
160
|
+
theme: "solid",
|
|
161
|
+
size: "sm",
|
|
162
|
+
className: stepButton(),
|
|
163
|
+
...api.getPrevTriggerProps(),
|
|
164
|
+
children: "Back"
|
|
165
|
+
}),
|
|
166
|
+
/*#__PURE__*/ jsx(Button, {
|
|
167
|
+
size: "sm",
|
|
168
|
+
theme: "solid",
|
|
169
|
+
className: stepButton(),
|
|
170
|
+
...api.getNextTriggerProps(),
|
|
171
|
+
children: "Next"
|
|
172
|
+
})
|
|
173
|
+
]
|
|
174
|
+
})
|
|
175
|
+
]
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
export { Steps };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { normalizeProps, useMachine } from "@zag-js/react";
|
|
3
|
+
import { connect, machine } from "@zag-js/switch";
|
|
4
|
+
import { useId } from "react";
|
|
5
|
+
import { ErrorText } from "../atoms/error-text.js";
|
|
6
|
+
import { ExtraText } from "../atoms/extra-text.js";
|
|
7
|
+
import { Label } from "../atoms/label.js";
|
|
8
|
+
import { tv } from "../utils.js";
|
|
9
|
+
const switchVariants = tv({
|
|
10
|
+
slots: {
|
|
11
|
+
root: [
|
|
12
|
+
'cursor-pointer',
|
|
13
|
+
'data-[disabled]:cursor-not-allowed'
|
|
14
|
+
],
|
|
15
|
+
control: [
|
|
16
|
+
'me-switch-root p-switch-control',
|
|
17
|
+
'relative inline-flex shrink-0 items-center justify-start',
|
|
18
|
+
'bg-switch-bg hover:bg-switch-bg-hover',
|
|
19
|
+
'w-switch-track-width h-switch-track-height',
|
|
20
|
+
'rounded-switch',
|
|
21
|
+
'transition-colors duration-200',
|
|
22
|
+
'ring-offset-transparent outline-none',
|
|
23
|
+
'border-(length:--border-width-switch) border-switch-border',
|
|
24
|
+
'data-[state=checked]:bg-switch-bg-checked',
|
|
25
|
+
'data-[state=checked]:hover:bg-switch-bg-checked-hover',
|
|
26
|
+
'data-[disabled]:bg-switch-bg-disabled',
|
|
27
|
+
'data-[disabled]:border-switch-border-disabled',
|
|
28
|
+
'data-[focus]:outline-none',
|
|
29
|
+
'data-[focus]:ring',
|
|
30
|
+
'data-[focus]:ring-switch-ring',
|
|
31
|
+
'data-[invalid]:bg-switch-bg-invalid data-[invalid]:ring-switch-ring-invalid'
|
|
32
|
+
],
|
|
33
|
+
thumb: [
|
|
34
|
+
'block rounded-full h-switch-thumb-height aspect-square bg-switch-thumb-bg',
|
|
35
|
+
'transform transition-transform duration-200',
|
|
36
|
+
'data-[disabled]:bg-switch-thumb-bg-disabled',
|
|
37
|
+
'data-[state=checked]:translate-x-switch-translate-track'
|
|
38
|
+
],
|
|
39
|
+
label: [
|
|
40
|
+
'select-none',
|
|
41
|
+
'text-switch-label-fg',
|
|
42
|
+
'data-[disabled]:text-switch-label-fg-disabled'
|
|
43
|
+
],
|
|
44
|
+
hiddenInput: 'sr-only'
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
function Switch({ id, name, value, checked, defaultChecked, disabled = false, invalid = false, readOnly = false, required = false, dir = 'ltr', children, className, onCheckedChange, helperText, errorText }) {
|
|
48
|
+
const generatedId = useId();
|
|
49
|
+
const uniqueId = id || generatedId;
|
|
50
|
+
const service = useMachine(machine, {
|
|
51
|
+
id: uniqueId,
|
|
52
|
+
name,
|
|
53
|
+
value,
|
|
54
|
+
checked,
|
|
55
|
+
defaultChecked,
|
|
56
|
+
dir,
|
|
57
|
+
disabled,
|
|
58
|
+
invalid,
|
|
59
|
+
readOnly,
|
|
60
|
+
required,
|
|
61
|
+
onCheckedChange: ({ checked })=>onCheckedChange?.(checked)
|
|
62
|
+
});
|
|
63
|
+
const api = connect(service, normalizeProps);
|
|
64
|
+
const { root, control, thumb, label, hiddenInput } = switchVariants({
|
|
65
|
+
className
|
|
66
|
+
});
|
|
67
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
68
|
+
className: className,
|
|
69
|
+
children: [
|
|
70
|
+
/*#__PURE__*/ jsxs(Label, {
|
|
71
|
+
className: root(),
|
|
72
|
+
required: required,
|
|
73
|
+
...api.getRootProps(),
|
|
74
|
+
children: [
|
|
75
|
+
/*#__PURE__*/ jsx("input", {
|
|
76
|
+
className: hiddenInput(),
|
|
77
|
+
...api.getHiddenInputProps()
|
|
78
|
+
}),
|
|
79
|
+
/*#__PURE__*/ jsx("span", {
|
|
80
|
+
className: control(),
|
|
81
|
+
...api.getControlProps(),
|
|
82
|
+
children: /*#__PURE__*/ jsx("span", {
|
|
83
|
+
className: thumb(),
|
|
84
|
+
...api.getThumbProps()
|
|
85
|
+
})
|
|
86
|
+
}),
|
|
87
|
+
children && /*#__PURE__*/ jsx("span", {
|
|
88
|
+
className: label(),
|
|
89
|
+
...api.getLabelProps(),
|
|
90
|
+
children: children
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
}),
|
|
94
|
+
(errorText || helperText) && /*#__PURE__*/ jsxs("div", {
|
|
95
|
+
children: [
|
|
96
|
+
invalid && errorText && /*#__PURE__*/ jsx(ErrorText, {
|
|
97
|
+
size: "sm",
|
|
98
|
+
children: errorText
|
|
99
|
+
}),
|
|
100
|
+
!invalid && helperText && /*#__PURE__*/ jsx(ExtraText, {
|
|
101
|
+
size: "sm",
|
|
102
|
+
children: helperText
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
export { Switch };
|