@zentauri-ui/zentauri-components 1.7.7 → 1.7.8
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 +6 -4
- package/cli/registry.json +1 -0
- package/dist/design-system/index.d.ts +1 -0
- package/dist/design-system/index.d.ts.map +1 -1
- package/dist/design-system/rating.d.ts +43 -0
- package/dist/design-system/rating.d.ts.map +1 -0
- package/dist/ui/rating/index.d.ts +4 -0
- package/dist/ui/rating/index.d.ts.map +1 -0
- package/dist/ui/rating/rating.d.ts +6 -0
- package/dist/ui/rating/rating.d.ts.map +1 -0
- package/dist/ui/rating/types.d.ts +25 -0
- package/dist/ui/rating/types.d.ts.map +1 -0
- package/dist/ui/rating/variants.d.ts +7 -0
- package/dist/ui/rating/variants.d.ts.map +1 -0
- package/dist/ui/rating.js +319 -0
- package/dist/ui/rating.js.map +1 -0
- package/dist/ui/rating.mjs +315 -0
- package/dist/ui/rating.mjs.map +1 -0
- package/package.json +1 -1
- package/src/design-system/index.ts +1 -0
- package/src/design-system/rating.ts +81 -0
- package/src/ui/rating/index.ts +10 -0
- package/src/ui/rating/rating.test.tsx +139 -0
- package/src/ui/rating/rating.tsx +305 -0
- package/src/ui/rating/types.ts +33 -0
- package/src/ui/rating/variants.ts +26 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { cn } from '../chunk-4D54YOL6.mjs';
|
|
3
|
+
import { useId, useState, useCallback } from 'react';
|
|
4
|
+
import { FaStar, FaThumbsUp, FaFire, FaHeart } from 'react-icons/fa';
|
|
5
|
+
import { cva } from 'class-variance-authority';
|
|
6
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
// src/design-system/rating.ts
|
|
9
|
+
var zuiRatingRootBase = "grid w-fit gap-2 text-[color:var(--zui-rating-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-label-fg-dark,oklch(98.4%_0.003_247.858))] data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50";
|
|
10
|
+
var zuiRatingLabelBase = "text-sm font-medium leading-6 text-[color:var(--zui-rating-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-label-fg-dark,oklch(98.4%_0.003_247.858))]";
|
|
11
|
+
var zuiRatingHintBase = "max-w-sm text-xs leading-5 text-[color:var(--zui-rating-hint-fg,oklch(55.4%_0.046_257.417))] dark:text-[color:var(--zui-rating-hint-fg-dark,oklch(70.4%_0.04_256.788))]";
|
|
12
|
+
var zuiRatingGroupBase = "flex w-fit flex-wrap items-center gap-[var(--zui-rating-gap,0.25rem)]";
|
|
13
|
+
var zuiRatingItemBase = "relative inline-grid shrink-0 place-items-center text-[color:var(--zui-rating-empty,oklch(86.9%_0.022_252.894))] transition-transform duration-200 data-[interactive=true]:hover:-translate-y-0.5 dark:text-[color:var(--zui-rating-empty-dark,oklch(37.2%_0.044_257.287))]";
|
|
14
|
+
var zuiRatingIconBase = "pointer-events-none col-start-1 row-start-1 transition-[clip-path,color,transform] duration-200 ease-out";
|
|
15
|
+
var zuiRatingControlBase = "absolute inset-y-0 z-[1] cursor-pointer rounded-md bg-transparent outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-[var(--zui-rating-ring-focus,oklch(54.6%_0.245_262.881_/_0.32))] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--zui-rating-ring-offset-focus,#ffffff)] disabled:cursor-not-allowed dark:focus-visible:ring-offset-[var(--zui-rating-ring-offset-focus-dark,oklch(12.9%_0.042_264.695))]";
|
|
16
|
+
var zuiRatingErrorBase = "text-sm leading-6 text-[color:var(--zui-rating-error-fg,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-error-fg-dark,oklch(71.2%_0.194_13.428))]";
|
|
17
|
+
var zuiRatingSizes = {
|
|
18
|
+
sm: "size-5 text-lg",
|
|
19
|
+
md: "size-7 text-2xl",
|
|
20
|
+
lg: "size-9 text-3xl"
|
|
21
|
+
};
|
|
22
|
+
var zuiRatingAppearances = {
|
|
23
|
+
default: "text-[color:var(--zui-rating-default-active,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-default-active-dark,oklch(98.4%_0.003_247.858))]",
|
|
24
|
+
secondary: "text-[color:var(--zui-rating-secondary-active,oklch(44.6%_0.043_257.281))] dark:text-[color:var(--zui-rating-secondary-active-dark,oklch(86.9%_0.022_252.894))]",
|
|
25
|
+
destructive: "text-[color:var(--zui-rating-destructive-active,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-destructive-active-dark,oklch(71.2%_0.194_13.428))]",
|
|
26
|
+
outline: "text-[color:var(--zui-rating-outline-active,oklch(44.6%_0.043_257.281))] dark:text-[color:var(--zui-rating-outline-active-dark,oklch(86.9%_0.022_252.894))]",
|
|
27
|
+
ghost: "text-[color:var(--zui-rating-ghost-active,oklch(37.2%_0.044_257.287))] dark:text-[color:var(--zui-rating-ghost-active-dark,oklch(92.9%_0.013_255.508))]",
|
|
28
|
+
glass: "text-[color:var(--zui-rating-glass-active,oklch(54.6%_0.245_262.881))] drop-shadow-[0_2px_12px_rgba(59,130,246,0.25)] dark:text-[color:var(--zui-rating-glass-active-dark,oklch(78.9%_0.154_211.53))]",
|
|
29
|
+
emerald: "text-[color:var(--zui-rating-emerald-active,oklch(59.6%_0.145_163.225))] dark:text-[color:var(--zui-rating-emerald-active-dark,oklch(77.7%_0.152_181.912))]",
|
|
30
|
+
indigo: "text-[color:var(--zui-rating-indigo-active,oklch(51.1%_0.262_276.966))] dark:text-[color:var(--zui-rating-indigo-active-dark,oklch(67.3%_0.182_276.935))]",
|
|
31
|
+
purple: "text-[color:var(--zui-rating-purple-active,oklch(55.8%_0.288_302.321))] dark:text-[color:var(--zui-rating-purple-active-dark,oklch(71.4%_0.203_305.504))]",
|
|
32
|
+
pink: "text-[color:var(--zui-rating-pink-active,oklch(59.2%_0.249_0.584))] dark:text-[color:var(--zui-rating-pink-active-dark,oklch(71.8%_0.202_349.761))]",
|
|
33
|
+
rose: "text-[color:var(--zui-rating-rose-active,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-rose-active-dark,oklch(71.2%_0.194_13.428))]",
|
|
34
|
+
sky: "text-[color:var(--zui-rating-sky-active,oklch(62.3%_0.214_259.815))] dark:text-[color:var(--zui-rating-sky-active-dark,oklch(74.6%_0.16_232.661))]",
|
|
35
|
+
teal: "text-[color:var(--zui-rating-teal-active,oklch(60%_0.118_184.704))] dark:text-[color:var(--zui-rating-teal-active-dark,oklch(77.7%_0.152_181.912))]",
|
|
36
|
+
yellow: "text-[color:var(--zui-rating-yellow-active,oklch(79.5%_0.184_86.047))] dark:text-[color:var(--zui-rating-yellow-active-dark,oklch(85.2%_0.199_91.936))]",
|
|
37
|
+
orange: "text-[color:var(--zui-rating-orange-active,oklch(64.6%_0.222_41.116))] dark:text-[color:var(--zui-rating-orange-active-dark,oklch(75%_0.183_55.934))]",
|
|
38
|
+
gray: "text-[color:var(--zui-rating-gray-active,oklch(55.1%_0.027_264.364))] dark:text-[color:var(--zui-rating-gray-active-dark,oklch(70.7%_0.022_261.325))]",
|
|
39
|
+
amber: "text-[color:var(--zui-rating-amber-active,oklch(76.9%_0.188_70.08))] dark:text-[color:var(--zui-rating-amber-active-dark,oklch(82.8%_0.189_84.429))]",
|
|
40
|
+
violet: "text-[color:var(--zui-rating-violet-active,oklch(54.1%_0.281_293.009))] dark:text-[color:var(--zui-rating-violet-active-dark,oklch(70.2%_0.183_293.541))]",
|
|
41
|
+
"gradient-blue": "text-[color:var(--zui-rating-gradient-blue-active,oklch(54.6%_0.245_262.881))] drop-shadow-[0_2px_12px_rgba(37,99,235,0.28)] dark:text-[color:var(--zui-rating-gradient-blue-active-dark,oklch(70.7%_0.165_254.624))]",
|
|
42
|
+
"gradient-green": "text-[color:var(--zui-rating-gradient-green-active,oklch(62.7%_0.194_149.214))] drop-shadow-[0_2px_12px_rgba(22,163,74,0.24)] dark:text-[color:var(--zui-rating-gradient-green-active-dark,oklch(79.2%_0.209_151.711))]",
|
|
43
|
+
"gradient-red": "text-[color:var(--zui-rating-gradient-red-active,oklch(57.7%_0.245_27.325))] drop-shadow-[0_2px_12px_rgba(220,38,38,0.24)] dark:text-[color:var(--zui-rating-gradient-red-active-dark,oklch(70.4%_0.191_22.216))]",
|
|
44
|
+
"gradient-yellow": "text-[color:var(--zui-rating-gradient-yellow-active,oklch(79.5%_0.184_86.047))] drop-shadow-[0_2px_12px_rgba(234,179,8,0.24)] dark:text-[color:var(--zui-rating-gradient-yellow-active-dark,oklch(85.2%_0.199_91.936))]",
|
|
45
|
+
"gradient-purple": "text-[color:var(--zui-rating-gradient-purple-active,oklch(62.7%_0.265_303.9))] drop-shadow-[0_2px_12px_rgba(147,51,234,0.24)] dark:text-[color:var(--zui-rating-gradient-purple-active-dark,oklch(71.4%_0.203_305.504))]",
|
|
46
|
+
"gradient-teal": "text-[color:var(--zui-rating-gradient-teal-active,oklch(60%_0.118_184.704))] drop-shadow-[0_2px_12px_rgba(13,148,136,0.24)] dark:text-[color:var(--zui-rating-gradient-teal-active-dark,oklch(77.7%_0.152_181.912))]",
|
|
47
|
+
"gradient-indigo": "text-[color:var(--zui-rating-gradient-indigo-active,oklch(51.1%_0.262_276.966))] drop-shadow-[0_2px_12px_rgba(79,70,229,0.24)] dark:text-[color:var(--zui-rating-gradient-indigo-active-dark,oklch(67.3%_0.182_276.935))]",
|
|
48
|
+
"gradient-pink": "text-[color:var(--zui-rating-gradient-pink-active,oklch(59.2%_0.249_0.584))] drop-shadow-[0_2px_12px_rgba(219,39,119,0.24)] dark:text-[color:var(--zui-rating-gradient-pink-active-dark,oklch(71.8%_0.202_349.761))]",
|
|
49
|
+
"gradient-orange": "text-[color:var(--zui-rating-gradient-orange-active,oklch(64.6%_0.222_41.116))] drop-shadow-[0_2px_12px_rgba(234,88,12,0.24)] dark:text-[color:var(--zui-rating-gradient-orange-active-dark,oklch(75%_0.183_55.934))]"
|
|
50
|
+
};
|
|
51
|
+
var ratingItemVariants = cva(zuiRatingItemBase, {
|
|
52
|
+
variants: {
|
|
53
|
+
size: zuiRatingSizes
|
|
54
|
+
},
|
|
55
|
+
defaultVariants: {
|
|
56
|
+
size: "md"
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
var ratingIconVariants = cva(zuiRatingIconBase, {
|
|
60
|
+
variants: {
|
|
61
|
+
appearance: zuiRatingAppearances
|
|
62
|
+
},
|
|
63
|
+
defaultVariants: {
|
|
64
|
+
appearance: "amber"
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
var PRESET_ICONS = {
|
|
68
|
+
star: FaStar,
|
|
69
|
+
heart: FaHeart,
|
|
70
|
+
flame: FaFire,
|
|
71
|
+
thumb: FaThumbsUp
|
|
72
|
+
};
|
|
73
|
+
function clamp(value, min, max) {
|
|
74
|
+
return Math.min(Math.max(value, min), max);
|
|
75
|
+
}
|
|
76
|
+
function normalizeMax(max) {
|
|
77
|
+
const resolved = Number.isFinite(max) ? Number(max) : 5;
|
|
78
|
+
return Math.max(1, Math.min(10, Math.floor(resolved)));
|
|
79
|
+
}
|
|
80
|
+
function normalizeValue(value, max, allowHalf) {
|
|
81
|
+
const resolved = Number.isFinite(value) ? Number(value) : 0;
|
|
82
|
+
const step = allowHalf ? 0.5 : 1;
|
|
83
|
+
return clamp(Math.round(resolved / step) * step, 0, max);
|
|
84
|
+
}
|
|
85
|
+
function defaultGetLabel(value, max) {
|
|
86
|
+
return `${value} of ${max}`;
|
|
87
|
+
}
|
|
88
|
+
function resolveIcon(icon) {
|
|
89
|
+
if (!icon) {
|
|
90
|
+
return PRESET_ICONS.star;
|
|
91
|
+
}
|
|
92
|
+
if (typeof icon === "string") {
|
|
93
|
+
return PRESET_ICONS[icon] ?? PRESET_ICONS.star;
|
|
94
|
+
}
|
|
95
|
+
return icon;
|
|
96
|
+
}
|
|
97
|
+
function Rating(props) {
|
|
98
|
+
const {
|
|
99
|
+
allowClear = false,
|
|
100
|
+
allowHalf = false,
|
|
101
|
+
appearance,
|
|
102
|
+
className,
|
|
103
|
+
defaultValue = 0,
|
|
104
|
+
disabled,
|
|
105
|
+
errorMessage,
|
|
106
|
+
getLabel = defaultGetLabel,
|
|
107
|
+
hint,
|
|
108
|
+
icon,
|
|
109
|
+
iconClassName,
|
|
110
|
+
id,
|
|
111
|
+
label,
|
|
112
|
+
max = 5,
|
|
113
|
+
name,
|
|
114
|
+
onValueChange,
|
|
115
|
+
readOnly,
|
|
116
|
+
ref,
|
|
117
|
+
size,
|
|
118
|
+
value,
|
|
119
|
+
...rest
|
|
120
|
+
} = props;
|
|
121
|
+
const generatedId = useId();
|
|
122
|
+
const rootId = id ?? generatedId;
|
|
123
|
+
const resolvedMax = normalizeMax(max);
|
|
124
|
+
const isControlled = value !== void 0;
|
|
125
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(
|
|
126
|
+
() => normalizeValue(defaultValue, resolvedMax, allowHalf)
|
|
127
|
+
);
|
|
128
|
+
const [hoverValue, setHoverValue] = useState();
|
|
129
|
+
const resolvedValue = normalizeValue(
|
|
130
|
+
isControlled ? value : uncontrolledValue,
|
|
131
|
+
resolvedMax,
|
|
132
|
+
allowHalf
|
|
133
|
+
);
|
|
134
|
+
const displayValue = hoverValue ?? resolvedValue;
|
|
135
|
+
const Icon = resolveIcon(icon);
|
|
136
|
+
const interactive = !disabled && !readOnly;
|
|
137
|
+
const controlsDisabled = disabled || readOnly;
|
|
138
|
+
const step = allowHalf ? 0.5 : 1;
|
|
139
|
+
const labelId = `${rootId}-label`;
|
|
140
|
+
const hintId = `${rootId}-hint`;
|
|
141
|
+
const errorId = `${rootId}-error`;
|
|
142
|
+
const describedBy = [
|
|
143
|
+
hint !== void 0 ? hintId : void 0,
|
|
144
|
+
errorMessage !== void 0 ? errorId : void 0
|
|
145
|
+
].filter(Boolean).join(" ");
|
|
146
|
+
const commitValue = useCallback(
|
|
147
|
+
(nextValue) => {
|
|
148
|
+
const normalized = normalizeValue(nextValue, resolvedMax, allowHalf);
|
|
149
|
+
const next = allowClear && normalized === resolvedValue ? 0 : normalized;
|
|
150
|
+
if (!isControlled) {
|
|
151
|
+
setUncontrolledValue(next);
|
|
152
|
+
}
|
|
153
|
+
onValueChange?.(next);
|
|
154
|
+
},
|
|
155
|
+
[
|
|
156
|
+
allowClear,
|
|
157
|
+
allowHalf,
|
|
158
|
+
isControlled,
|
|
159
|
+
onValueChange,
|
|
160
|
+
resolvedMax,
|
|
161
|
+
resolvedValue
|
|
162
|
+
]
|
|
163
|
+
);
|
|
164
|
+
const handleKeyDown = useCallback(
|
|
165
|
+
(event) => {
|
|
166
|
+
if (!interactive) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const root = event.currentTarget.closest('[data-slot="rating"]');
|
|
170
|
+
const focusValue = (nextValue) => {
|
|
171
|
+
const control = root?.querySelector(
|
|
172
|
+
`button[data-value="${nextValue}"]`
|
|
173
|
+
);
|
|
174
|
+
control?.focus();
|
|
175
|
+
};
|
|
176
|
+
if (event.key === "ArrowRight" || event.key === "ArrowUp") {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
const nextValue = clamp(resolvedValue + step, step, resolvedMax);
|
|
179
|
+
commitValue(nextValue);
|
|
180
|
+
focusValue(nextValue);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (event.key === "ArrowLeft" || event.key === "ArrowDown") {
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
const nextValue = clamp(resolvedValue - step, 0, resolvedMax);
|
|
186
|
+
commitValue(nextValue);
|
|
187
|
+
focusValue(nextValue === 0 ? step : nextValue);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (event.key === "Home") {
|
|
191
|
+
event.preventDefault();
|
|
192
|
+
commitValue(step);
|
|
193
|
+
focusValue(step);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (event.key === "End") {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
commitValue(resolvedMax);
|
|
199
|
+
focusValue(resolvedMax);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
[commitValue, interactive, resolvedMax, resolvedValue, step]
|
|
203
|
+
);
|
|
204
|
+
return /* @__PURE__ */ jsxs(
|
|
205
|
+
"div",
|
|
206
|
+
{
|
|
207
|
+
ref,
|
|
208
|
+
id: rootId,
|
|
209
|
+
className: cn(zuiRatingRootBase, className),
|
|
210
|
+
"data-disabled": disabled ? "true" : void 0,
|
|
211
|
+
"data-readonly": readOnly ? "true" : void 0,
|
|
212
|
+
"data-slot": "rating",
|
|
213
|
+
...rest,
|
|
214
|
+
children: [
|
|
215
|
+
label !== void 0 && /* @__PURE__ */ jsx("p", { id: labelId, className: zuiRatingLabelBase, children: label }),
|
|
216
|
+
hint !== void 0 && /* @__PURE__ */ jsx("p", { id: hintId, className: zuiRatingHintBase, children: hint }),
|
|
217
|
+
/* @__PURE__ */ jsx(
|
|
218
|
+
"div",
|
|
219
|
+
{
|
|
220
|
+
"aria-describedby": describedBy || void 0,
|
|
221
|
+
"aria-invalid": errorMessage !== void 0 ? true : void 0,
|
|
222
|
+
"aria-labelledby": label !== void 0 ? labelId : void 0,
|
|
223
|
+
"aria-label": label === void 0 ? "Rating" : void 0,
|
|
224
|
+
className: zuiRatingGroupBase,
|
|
225
|
+
"data-slot": "rating-group",
|
|
226
|
+
onPointerLeave: () => setHoverValue(void 0),
|
|
227
|
+
role: "radiogroup",
|
|
228
|
+
children: Array.from({ length: resolvedMax }, (_, index) => {
|
|
229
|
+
const fullValue = index + 1;
|
|
230
|
+
const fillAmount = clamp(displayValue - index, 0, 1);
|
|
231
|
+
const clipStyle = {
|
|
232
|
+
clipPath: `inset(0 ${100 - fillAmount * 100}% 0 0)`
|
|
233
|
+
};
|
|
234
|
+
const itemOptions = allowHalf ? [fullValue - 0.5, fullValue] : [fullValue];
|
|
235
|
+
return /* @__PURE__ */ jsxs(
|
|
236
|
+
"span",
|
|
237
|
+
{
|
|
238
|
+
className: ratingItemVariants({ size }),
|
|
239
|
+
"data-interactive": interactive ? "true" : void 0,
|
|
240
|
+
"data-slot": "rating-item",
|
|
241
|
+
children: [
|
|
242
|
+
/* @__PURE__ */ jsx(
|
|
243
|
+
Icon,
|
|
244
|
+
{
|
|
245
|
+
"aria-hidden": "true",
|
|
246
|
+
className: cn("col-start-1 row-start-1", iconClassName)
|
|
247
|
+
}
|
|
248
|
+
),
|
|
249
|
+
/* @__PURE__ */ jsx(
|
|
250
|
+
Icon,
|
|
251
|
+
{
|
|
252
|
+
"aria-hidden": "true",
|
|
253
|
+
className: cn(
|
|
254
|
+
ratingIconVariants({ appearance }),
|
|
255
|
+
iconClassName
|
|
256
|
+
),
|
|
257
|
+
"data-slot": "rating-icon-fill",
|
|
258
|
+
style: clipStyle
|
|
259
|
+
}
|
|
260
|
+
),
|
|
261
|
+
itemOptions.map((optionValue, optionIndex) => /* @__PURE__ */ jsx(
|
|
262
|
+
"button",
|
|
263
|
+
{
|
|
264
|
+
type: "button",
|
|
265
|
+
"aria-checked": resolvedValue === optionValue,
|
|
266
|
+
"aria-label": getLabel(optionValue, resolvedMax),
|
|
267
|
+
className: cn(
|
|
268
|
+
zuiRatingControlBase,
|
|
269
|
+
allowHalf ? optionIndex === 0 ? "left-0 w-1/2" : "right-0 w-1/2" : "inset-x-0"
|
|
270
|
+
),
|
|
271
|
+
"data-slot": "rating-control",
|
|
272
|
+
"data-value": optionValue,
|
|
273
|
+
disabled: controlsDisabled,
|
|
274
|
+
onClick: () => {
|
|
275
|
+
if (interactive) {
|
|
276
|
+
commitValue(optionValue);
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
onKeyDown: handleKeyDown,
|
|
280
|
+
onPointerEnter: () => {
|
|
281
|
+
if (interactive) {
|
|
282
|
+
setHoverValue(optionValue);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
role: "radio",
|
|
286
|
+
tabIndex: resolvedValue === optionValue || resolvedValue === 0 && optionValue === step ? 0 : -1
|
|
287
|
+
},
|
|
288
|
+
optionValue
|
|
289
|
+
))
|
|
290
|
+
]
|
|
291
|
+
},
|
|
292
|
+
fullValue
|
|
293
|
+
);
|
|
294
|
+
})
|
|
295
|
+
}
|
|
296
|
+
),
|
|
297
|
+
name !== void 0 && /* @__PURE__ */ jsx(
|
|
298
|
+
"input",
|
|
299
|
+
{
|
|
300
|
+
type: "hidden",
|
|
301
|
+
name,
|
|
302
|
+
value: resolvedValue,
|
|
303
|
+
disabled
|
|
304
|
+
}
|
|
305
|
+
),
|
|
306
|
+
errorMessage !== void 0 && /* @__PURE__ */ jsx("p", { id: errorId, className: zuiRatingErrorBase, children: errorMessage })
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
Rating.displayName = "Rating";
|
|
312
|
+
|
|
313
|
+
export { Rating, ratingIconVariants, ratingItemVariants };
|
|
314
|
+
//# sourceMappingURL=rating.mjs.map
|
|
315
|
+
//# sourceMappingURL=rating.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/design-system/rating.ts","../../src/ui/rating/variants.ts","../../src/ui/rating/rating.tsx"],"names":[],"mappings":";;;;;;;AAAO,IAAM,iBAAA,GACX,0OAAA;AAEK,IAAM,kBAAA,GACX,+KAAA;AAEK,IAAM,iBAAA,GACX,yKAAA;AAEK,IAAM,kBAAA,GACX,uEAAA;AAEK,IAAM,iBAAA,GACX,6QAAA;AAEK,IAAM,iBAAA,GACX,0GAAA;AAEK,IAAM,oBAAA,GACX,gbAAA;AAEK,IAAM,kBAAA,GACX,iKAAA;AAEK,IAAM,cAAA,GAAiB;AAAA,EAC5B,EAAA,EAAI,gBAAA;AAAA,EACJ,EAAA,EAAI,iBAAA;AAAA,EACJ,EAAA,EAAI;AACN,CAAA;AAEO,IAAM,oBAAA,GAAuB;AAAA,EAClC,OAAA,EACE,6JAAA;AAAA,EACF,SAAA,EACE,iKAAA;AAAA,EACF,WAAA,EACE,mKA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AA;AAAA,0BACzB;AAAA,wBACF,CAAA;AAAA,wBACA,SAAA,EAAW,aAAA;AAAA,wBACX,gBAAgB,MAAM;AACpB,0BAAA,IAAI,WAAA,EAAa;AACf,4BAAA,aAAA,CAAc,WAAW,CAAA;AAAA,0BAC3B;AAAA,wBACF,CAAA;AAAA,wBACA,IAAA,EAAK,OAAA;AAAA,wBACL,UACE,aAAA,KAAkB,WAAA,IACjB,kBAAkB,CAAA,IAAK,WAAA,KAAgB,OACpC,CAAA,GACA;AAAA,uBAAA;AAAA,sBA/BD;AAAA,qBAkCR;AAAA;AAAA,iBAAA;AAAA,gBAtDI;AAAA,eAuDP;AAAA,YAEJ,CAAC;AAAA;AAAA,SACH;AAAA,QACC,SAAS,MAAA,oBACR,GAAA;AAAA,UAAC,OAAA;AAAA,UAAA;AAAA,YACC,IAAA,EAAK,QAAA;AAAA,YACL,IAAA;AAAA,YACA,KAAA,EAAO,aAAA;AAAA,YACP;AAAA;AAAA,SACF;AAAA,QAED,YAAA,KAAiB,0BAChB,GAAA,CAAC,GAAA,EAAA,EAAE,IAAI,OAAA,EAAS,SAAA,EAAW,oBACxB,QAAA,EAAA,YAAA,EACH;AAAA;AAAA;AAAA,GAEJ;AAEJ;AAEA,MAAA,CAAO,WAAA,GAAc,QAAA","file":"rating.mjs","sourcesContent":["export const zuiRatingRootBase =\n \"grid w-fit gap-2 text-[color:var(--zui-rating-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-label-fg-dark,oklch(98.4%_0.003_247.858))] data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50\";\n\nexport const zuiRatingLabelBase =\n \"text-sm font-medium leading-6 text-[color:var(--zui-rating-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-label-fg-dark,oklch(98.4%_0.003_247.858))]\";\n\nexport const zuiRatingHintBase =\n \"max-w-sm text-xs leading-5 text-[color:var(--zui-rating-hint-fg,oklch(55.4%_0.046_257.417))] dark:text-[color:var(--zui-rating-hint-fg-dark,oklch(70.4%_0.04_256.788))]\";\n\nexport const zuiRatingGroupBase =\n \"flex w-fit flex-wrap items-center gap-[var(--zui-rating-gap,0.25rem)]\";\n\nexport const zuiRatingItemBase =\n \"relative inline-grid shrink-0 place-items-center text-[color:var(--zui-rating-empty,oklch(86.9%_0.022_252.894))] transition-transform duration-200 data-[interactive=true]:hover:-translate-y-0.5 dark:text-[color:var(--zui-rating-empty-dark,oklch(37.2%_0.044_257.287))]\";\n\nexport const zuiRatingIconBase =\n \"pointer-events-none col-start-1 row-start-1 transition-[clip-path,color,transform] duration-200 ease-out\";\n\nexport const zuiRatingControlBase =\n \"absolute inset-y-0 z-[1] cursor-pointer rounded-md bg-transparent outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-[var(--zui-rating-ring-focus,oklch(54.6%_0.245_262.881_/_0.32))] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--zui-rating-ring-offset-focus,#ffffff)] disabled:cursor-not-allowed dark:focus-visible:ring-offset-[var(--zui-rating-ring-offset-focus-dark,oklch(12.9%_0.042_264.695))]\";\n\nexport const zuiRatingErrorBase =\n \"text-sm leading-6 text-[color:var(--zui-rating-error-fg,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-error-fg-dark,oklch(71.2%_0.194_13.428))]\";\n\nexport const zuiRatingSizes = {\n sm: \"size-5 text-lg\",\n md: \"size-7 text-2xl\",\n lg: \"size-9 text-3xl\",\n} as const;\n\nexport const zuiRatingAppearances = {\n default:\n \"text-[color:var(--zui-rating-default-active,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-default-active-dark,oklch(98.4%_0.003_247.858))]\",\n secondary:\n \"text-[color:var(--zui-rating-secondary-active,oklch(44.6%_0.043_257.281))] dark:text-[color:var(--zui-rating-secondary-active-dark,oklch(86.9%_0.022_252.894))]\",\n destructive:\n \"text-[color:var(--zui-rating-destructive-active,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-destructive-active-dark,oklch(71.2%_0.194_13.428))]\",\n outline:\n \"text-[color:var(--zui-rating-outline-active,oklch(44.6%_0.043_257.281))] dark:text-[color:var(--zui-rating-outline-active-dark,oklch(86.9%_0.022_252.894))]\",\n ghost:\n \"text-[color:var(--zui-rating-ghost-active,oklch(37.2%_0.044_257.287))] dark:text-[color:var(--zui-rating-ghost-active-dark,oklch(92.9%_0.013_255.508))]\",\n glass:\n \"text-[color:var(--zui-rating-glass-active,oklch(54.6%_0.245_262.881))] drop-shadow-[0_2px_12px_rgba(59,130,246,0.25)] dark:text-[color:var(--zui-rating-glass-active-dark,oklch(78.9%_0.154_211.53))]\",\n emerald:\n \"text-[color:var(--zui-rating-emerald-active,oklch(59.6%_0.145_163.225))] dark:text-[color:var(--zui-rating-emerald-active-dark,oklch(77.7%_0.152_181.912))]\",\n indigo:\n \"text-[color:var(--zui-rating-indigo-active,oklch(51.1%_0.262_276.966))] dark:text-[color:var(--zui-rating-indigo-active-dark,oklch(67.3%_0.182_276.935))]\",\n purple:\n \"text-[color:var(--zui-rating-purple-active,oklch(55.8%_0.288_302.321))] dark:text-[color:var(--zui-rating-purple-active-dark,oklch(71.4%_0.203_305.504))]\",\n pink: \"text-[color:var(--zui-rating-pink-active,oklch(59.2%_0.249_0.584))] dark:text-[color:var(--zui-rating-pink-active-dark,oklch(71.8%_0.202_349.761))]\",\n rose: \"text-[color:var(--zui-rating-rose-active,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-rose-active-dark,oklch(71.2%_0.194_13.428))]\",\n sky: \"text-[color:var(--zui-rating-sky-active,oklch(62.3%_0.214_259.815))] dark:text-[color:var(--zui-rating-sky-active-dark,oklch(74.6%_0.16_232.661))]\",\n teal: \"text-[color:var(--zui-rating-teal-active,oklch(60%_0.118_184.704))] dark:text-[color:var(--zui-rating-teal-active-dark,oklch(77.7%_0.152_181.912))]\",\n yellow:\n \"text-[color:var(--zui-rating-yellow-active,oklch(79.5%_0.184_86.047))] dark:text-[color:var(--zui-rating-yellow-active-dark,oklch(85.2%_0.199_91.936))]\",\n orange:\n \"text-[color:var(--zui-rating-orange-active,oklch(64.6%_0.222_41.116))] dark:text-[color:var(--zui-rating-orange-active-dark,oklch(75%_0.183_55.934))]\",\n gray: \"text-[color:var(--zui-rating-gray-active,oklch(55.1%_0.027_264.364))] dark:text-[color:var(--zui-rating-gray-active-dark,oklch(70.7%_0.022_261.325))]\",\n amber:\n \"text-[color:var(--zui-rating-amber-active,oklch(76.9%_0.188_70.08))] dark:text-[color:var(--zui-rating-amber-active-dark,oklch(82.8%_0.189_84.429))]\",\n violet:\n \"text-[color:var(--zui-rating-violet-active,oklch(54.1%_0.281_293.009))] dark:text-[color:var(--zui-rating-violet-active-dark,oklch(70.2%_0.183_293.541))]\",\n \"gradient-blue\":\n \"text-[color:var(--zui-rating-gradient-blue-active,oklch(54.6%_0.245_262.881))] drop-shadow-[0_2px_12px_rgba(37,99,235,0.28)] dark:text-[color:var(--zui-rating-gradient-blue-active-dark,oklch(70.7%_0.165_254.624))]\",\n \"gradient-green\":\n \"text-[color:var(--zui-rating-gradient-green-active,oklch(62.7%_0.194_149.214))] drop-shadow-[0_2px_12px_rgba(22,163,74,0.24)] dark:text-[color:var(--zui-rating-gradient-green-active-dark,oklch(79.2%_0.209_151.711))]\",\n \"gradient-red\":\n \"text-[color:var(--zui-rating-gradient-red-active,oklch(57.7%_0.245_27.325))] drop-shadow-[0_2px_12px_rgba(220,38,38,0.24)] dark:text-[color:var(--zui-rating-gradient-red-active-dark,oklch(70.4%_0.191_22.216))]\",\n \"gradient-yellow\":\n \"text-[color:var(--zui-rating-gradient-yellow-active,oklch(79.5%_0.184_86.047))] drop-shadow-[0_2px_12px_rgba(234,179,8,0.24)] dark:text-[color:var(--zui-rating-gradient-yellow-active-dark,oklch(85.2%_0.199_91.936))]\",\n \"gradient-purple\":\n \"text-[color:var(--zui-rating-gradient-purple-active,oklch(62.7%_0.265_303.9))] drop-shadow-[0_2px_12px_rgba(147,51,234,0.24)] dark:text-[color:var(--zui-rating-gradient-purple-active-dark,oklch(71.4%_0.203_305.504))]\",\n \"gradient-teal\":\n \"text-[color:var(--zui-rating-gradient-teal-active,oklch(60%_0.118_184.704))] drop-shadow-[0_2px_12px_rgba(13,148,136,0.24)] dark:text-[color:var(--zui-rating-gradient-teal-active-dark,oklch(77.7%_0.152_181.912))]\",\n \"gradient-indigo\":\n \"text-[color:var(--zui-rating-gradient-indigo-active,oklch(51.1%_0.262_276.966))] drop-shadow-[0_2px_12px_rgba(79,70,229,0.24)] dark:text-[color:var(--zui-rating-gradient-indigo-active-dark,oklch(67.3%_0.182_276.935))]\",\n \"gradient-pink\":\n \"text-[color:var(--zui-rating-gradient-pink-active,oklch(59.2%_0.249_0.584))] drop-shadow-[0_2px_12px_rgba(219,39,119,0.24)] dark:text-[color:var(--zui-rating-gradient-pink-active-dark,oklch(71.8%_0.202_349.761))]\",\n \"gradient-orange\":\n \"text-[color:var(--zui-rating-gradient-orange-active,oklch(64.6%_0.222_41.116))] drop-shadow-[0_2px_12px_rgba(234,88,12,0.24)] dark:text-[color:var(--zui-rating-gradient-orange-active-dark,oklch(75%_0.183_55.934))]\",\n} as const;\n","import { cva } from \"class-variance-authority\";\n\nimport {\n zuiRatingAppearances,\n zuiRatingIconBase,\n zuiRatingItemBase,\n zuiRatingSizes,\n} from \"../../design-system/rating\";\n\nexport const ratingItemVariants = cva(zuiRatingItemBase, {\n variants: {\n size: zuiRatingSizes,\n },\n defaultVariants: {\n size: \"md\",\n },\n});\n\nexport const ratingIconVariants = cva(zuiRatingIconBase, {\n variants: {\n appearance: zuiRatingAppearances,\n },\n defaultVariants: {\n appearance: \"amber\",\n },\n});\n","\"use client\";\n\nimport {\n type CSSProperties,\n type KeyboardEvent,\n useCallback,\n useId,\n useState,\n} from \"react\";\nimport { FaFire, FaHeart, FaStar, FaThumbsUp } from \"react-icons/fa\";\nimport type { IconType } from \"react-icons\";\n\nimport {\n zuiRatingControlBase,\n zuiRatingErrorBase,\n zuiRatingGroupBase,\n zuiRatingHintBase,\n zuiRatingLabelBase,\n zuiRatingRootBase,\n} from \"../../design-system/rating\";\nimport { cn } from \"../../lib/utils\";\n\nimport type { RatingPresetIcon, RatingProps } from \"./types\";\nimport { ratingIconVariants, ratingItemVariants } from \"./variants\";\n\nconst PRESET_ICONS: Record<RatingPresetIcon, IconType> = {\n star: FaStar,\n heart: FaHeart,\n flame: FaFire,\n thumb: FaThumbsUp,\n};\n\nfunction clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max);\n}\n\nfunction normalizeMax(max: number | undefined): number {\n const resolved = Number.isFinite(max) ? Number(max) : 5;\n return Math.max(1, Math.min(10, Math.floor(resolved)));\n}\n\nfunction normalizeValue(\n value: number | undefined,\n max: number,\n allowHalf: boolean,\n): number {\n const resolved = Number.isFinite(value) ? Number(value) : 0;\n const step = allowHalf ? 0.5 : 1;\n return clamp(Math.round(resolved / step) * step, 0, max);\n}\n\nfunction defaultGetLabel(value: number, max: number): string {\n return `${value} of ${max}`;\n}\n\nfunction resolveIcon(icon: RatingProps[\"icon\"]): IconType {\n if (!icon) {\n return PRESET_ICONS.star;\n }\n\n if (typeof icon === \"string\") {\n return PRESET_ICONS[icon as RatingPresetIcon] ?? PRESET_ICONS.star;\n }\n\n return icon;\n}\n\nexport function Rating(props: RatingProps) {\n const {\n allowClear = false,\n allowHalf = false,\n appearance,\n className,\n defaultValue = 0,\n disabled,\n errorMessage,\n getLabel = defaultGetLabel,\n hint,\n icon,\n iconClassName,\n id,\n label,\n max = 5,\n name,\n onValueChange,\n readOnly,\n ref,\n size,\n value,\n ...rest\n } = props;\n\n const generatedId = useId();\n const rootId = id ?? generatedId;\n const resolvedMax = normalizeMax(max);\n const isControlled = value !== undefined;\n const [uncontrolledValue, setUncontrolledValue] = useState(() =>\n normalizeValue(defaultValue, resolvedMax, allowHalf),\n );\n const [hoverValue, setHoverValue] = useState<number | undefined>();\n const resolvedValue = normalizeValue(\n isControlled ? value : uncontrolledValue,\n resolvedMax,\n allowHalf,\n );\n const displayValue = hoverValue ?? resolvedValue;\n const Icon = resolveIcon(icon);\n const interactive = !disabled && !readOnly;\n const controlsDisabled = disabled || readOnly;\n const step = allowHalf ? 0.5 : 1;\n const labelId = `${rootId}-label`;\n const hintId = `${rootId}-hint`;\n const errorId = `${rootId}-error`;\n const describedBy = [\n hint !== undefined ? hintId : undefined,\n errorMessage !== undefined ? errorId : undefined,\n ]\n .filter(Boolean)\n .join(\" \");\n\n const commitValue = useCallback(\n (nextValue: number) => {\n const normalized = normalizeValue(nextValue, resolvedMax, allowHalf);\n const next = allowClear && normalized === resolvedValue ? 0 : normalized;\n\n if (!isControlled) {\n setUncontrolledValue(next);\n }\n onValueChange?.(next);\n },\n [\n allowClear,\n allowHalf,\n isControlled,\n onValueChange,\n resolvedMax,\n resolvedValue,\n ],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLButtonElement>) => {\n if (!interactive) {\n return;\n }\n\n const root = event.currentTarget.closest('[data-slot=\"rating\"]');\n const focusValue = (nextValue: number) => {\n const control = root?.querySelector(\n `button[data-value=\"${nextValue}\"]`,\n ) as HTMLButtonElement | null;\n control?.focus();\n };\n\n if (event.key === \"ArrowRight\" || event.key === \"ArrowUp\") {\n event.preventDefault();\n const nextValue = clamp(resolvedValue + step, step, resolvedMax);\n commitValue(nextValue);\n focusValue(nextValue);\n return;\n }\n\n if (event.key === \"ArrowLeft\" || event.key === \"ArrowDown\") {\n event.preventDefault();\n const nextValue = clamp(resolvedValue - step, 0, resolvedMax);\n commitValue(nextValue);\n focusValue(nextValue === 0 ? step : nextValue);\n return;\n }\n\n if (event.key === \"Home\") {\n event.preventDefault();\n commitValue(step);\n focusValue(step);\n return;\n }\n\n if (event.key === \"End\") {\n event.preventDefault();\n commitValue(resolvedMax);\n focusValue(resolvedMax);\n }\n },\n [commitValue, interactive, resolvedMax, resolvedValue, step],\n );\n\n return (\n <div\n ref={ref}\n id={rootId}\n className={cn(zuiRatingRootBase, className)}\n data-disabled={disabled ? \"true\" : undefined}\n data-readonly={readOnly ? \"true\" : undefined}\n data-slot=\"rating\"\n {...rest}\n >\n {label !== undefined && (\n <p id={labelId} className={zuiRatingLabelBase}>\n {label}\n </p>\n )}\n {hint !== undefined && (\n <p id={hintId} className={zuiRatingHintBase}>\n {hint}\n </p>\n )}\n <div\n aria-describedby={describedBy || undefined}\n aria-invalid={errorMessage !== undefined ? true : undefined}\n aria-labelledby={label !== undefined ? labelId : undefined}\n aria-label={label === undefined ? \"Rating\" : undefined}\n className={zuiRatingGroupBase}\n data-slot=\"rating-group\"\n onPointerLeave={() => setHoverValue(undefined)}\n role=\"radiogroup\"\n >\n {Array.from({ length: resolvedMax }, (_, index) => {\n const fullValue = index + 1;\n const fillAmount = clamp(displayValue - index, 0, 1);\n const clipStyle = {\n clipPath: `inset(0 ${100 - fillAmount * 100}% 0 0)`,\n } satisfies CSSProperties;\n const itemOptions = allowHalf\n ? [fullValue - 0.5, fullValue]\n : [fullValue];\n\n return (\n <span\n key={fullValue}\n className={ratingItemVariants({ size })}\n data-interactive={interactive ? \"true\" : undefined}\n data-slot=\"rating-item\"\n >\n <Icon\n aria-hidden=\"true\"\n className={cn(\"col-start-1 row-start-1\", iconClassName)}\n />\n <Icon\n aria-hidden=\"true\"\n className={cn(\n ratingIconVariants({ appearance }),\n iconClassName,\n )}\n data-slot=\"rating-icon-fill\"\n style={clipStyle}\n />\n {itemOptions.map((optionValue, optionIndex) => (\n <button\n key={optionValue}\n type=\"button\"\n aria-checked={resolvedValue === optionValue}\n aria-label={getLabel(optionValue, resolvedMax)}\n className={cn(\n zuiRatingControlBase,\n allowHalf\n ? optionIndex === 0\n ? \"left-0 w-1/2\"\n : \"right-0 w-1/2\"\n : \"inset-x-0\",\n )}\n data-slot=\"rating-control\"\n data-value={optionValue}\n disabled={controlsDisabled}\n onClick={() => {\n if (interactive) {\n commitValue(optionValue);\n }\n }}\n onKeyDown={handleKeyDown}\n onPointerEnter={() => {\n if (interactive) {\n setHoverValue(optionValue);\n }\n }}\n role=\"radio\"\n tabIndex={\n resolvedValue === optionValue ||\n (resolvedValue === 0 && optionValue === step)\n ? 0\n : -1\n }\n />\n ))}\n </span>\n );\n })}\n </div>\n {name !== undefined && (\n <input\n type=\"hidden\"\n name={name}\n value={resolvedValue}\n disabled={disabled}\n />\n )}\n {errorMessage !== undefined && (\n <p id={errorId} className={zuiRatingErrorBase}>\n {errorMessage}\n </p>\n )}\n </div>\n );\n}\n\nRating.displayName = \"Rating\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zentauri-ui/zentauri-components",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.8",
|
|
4
4
|
"description": "React + Tailwind UI kit with charts, ESM/CJS builds, per-entry exports, and a zentauri-components / zentauri-ui CLI to vendor UI or hook source into your app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const zuiRatingRootBase =
|
|
2
|
+
"grid w-fit gap-2 text-[color:var(--zui-rating-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-label-fg-dark,oklch(98.4%_0.003_247.858))] data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50";
|
|
3
|
+
|
|
4
|
+
export const zuiRatingLabelBase =
|
|
5
|
+
"text-sm font-medium leading-6 text-[color:var(--zui-rating-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-label-fg-dark,oklch(98.4%_0.003_247.858))]";
|
|
6
|
+
|
|
7
|
+
export const zuiRatingHintBase =
|
|
8
|
+
"max-w-sm text-xs leading-5 text-[color:var(--zui-rating-hint-fg,oklch(55.4%_0.046_257.417))] dark:text-[color:var(--zui-rating-hint-fg-dark,oklch(70.4%_0.04_256.788))]";
|
|
9
|
+
|
|
10
|
+
export const zuiRatingGroupBase =
|
|
11
|
+
"flex w-fit flex-wrap items-center gap-[var(--zui-rating-gap,0.25rem)]";
|
|
12
|
+
|
|
13
|
+
export const zuiRatingItemBase =
|
|
14
|
+
"relative inline-grid shrink-0 place-items-center text-[color:var(--zui-rating-empty,oklch(86.9%_0.022_252.894))] transition-transform duration-200 data-[interactive=true]:hover:-translate-y-0.5 dark:text-[color:var(--zui-rating-empty-dark,oklch(37.2%_0.044_257.287))]";
|
|
15
|
+
|
|
16
|
+
export const zuiRatingIconBase =
|
|
17
|
+
"pointer-events-none col-start-1 row-start-1 transition-[clip-path,color,transform] duration-200 ease-out";
|
|
18
|
+
|
|
19
|
+
export const zuiRatingControlBase =
|
|
20
|
+
"absolute inset-y-0 z-[1] cursor-pointer rounded-md bg-transparent outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-[var(--zui-rating-ring-focus,oklch(54.6%_0.245_262.881_/_0.32))] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--zui-rating-ring-offset-focus,#ffffff)] disabled:cursor-not-allowed dark:focus-visible:ring-offset-[var(--zui-rating-ring-offset-focus-dark,oklch(12.9%_0.042_264.695))]";
|
|
21
|
+
|
|
22
|
+
export const zuiRatingErrorBase =
|
|
23
|
+
"text-sm leading-6 text-[color:var(--zui-rating-error-fg,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-error-fg-dark,oklch(71.2%_0.194_13.428))]";
|
|
24
|
+
|
|
25
|
+
export const zuiRatingSizes = {
|
|
26
|
+
sm: "size-5 text-lg",
|
|
27
|
+
md: "size-7 text-2xl",
|
|
28
|
+
lg: "size-9 text-3xl",
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export const zuiRatingAppearances = {
|
|
32
|
+
default:
|
|
33
|
+
"text-[color:var(--zui-rating-default-active,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-rating-default-active-dark,oklch(98.4%_0.003_247.858))]",
|
|
34
|
+
secondary:
|
|
35
|
+
"text-[color:var(--zui-rating-secondary-active,oklch(44.6%_0.043_257.281))] dark:text-[color:var(--zui-rating-secondary-active-dark,oklch(86.9%_0.022_252.894))]",
|
|
36
|
+
destructive:
|
|
37
|
+
"text-[color:var(--zui-rating-destructive-active,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-destructive-active-dark,oklch(71.2%_0.194_13.428))]",
|
|
38
|
+
outline:
|
|
39
|
+
"text-[color:var(--zui-rating-outline-active,oklch(44.6%_0.043_257.281))] dark:text-[color:var(--zui-rating-outline-active-dark,oklch(86.9%_0.022_252.894))]",
|
|
40
|
+
ghost:
|
|
41
|
+
"text-[color:var(--zui-rating-ghost-active,oklch(37.2%_0.044_257.287))] dark:text-[color:var(--zui-rating-ghost-active-dark,oklch(92.9%_0.013_255.508))]",
|
|
42
|
+
glass:
|
|
43
|
+
"text-[color:var(--zui-rating-glass-active,oklch(54.6%_0.245_262.881))] drop-shadow-[0_2px_12px_rgba(59,130,246,0.25)] dark:text-[color:var(--zui-rating-glass-active-dark,oklch(78.9%_0.154_211.53))]",
|
|
44
|
+
emerald:
|
|
45
|
+
"text-[color:var(--zui-rating-emerald-active,oklch(59.6%_0.145_163.225))] dark:text-[color:var(--zui-rating-emerald-active-dark,oklch(77.7%_0.152_181.912))]",
|
|
46
|
+
indigo:
|
|
47
|
+
"text-[color:var(--zui-rating-indigo-active,oklch(51.1%_0.262_276.966))] dark:text-[color:var(--zui-rating-indigo-active-dark,oklch(67.3%_0.182_276.935))]",
|
|
48
|
+
purple:
|
|
49
|
+
"text-[color:var(--zui-rating-purple-active,oklch(55.8%_0.288_302.321))] dark:text-[color:var(--zui-rating-purple-active-dark,oklch(71.4%_0.203_305.504))]",
|
|
50
|
+
pink: "text-[color:var(--zui-rating-pink-active,oklch(59.2%_0.249_0.584))] dark:text-[color:var(--zui-rating-pink-active-dark,oklch(71.8%_0.202_349.761))]",
|
|
51
|
+
rose: "text-[color:var(--zui-rating-rose-active,oklch(58.6%_0.253_17.585))] dark:text-[color:var(--zui-rating-rose-active-dark,oklch(71.2%_0.194_13.428))]",
|
|
52
|
+
sky: "text-[color:var(--zui-rating-sky-active,oklch(62.3%_0.214_259.815))] dark:text-[color:var(--zui-rating-sky-active-dark,oklch(74.6%_0.16_232.661))]",
|
|
53
|
+
teal: "text-[color:var(--zui-rating-teal-active,oklch(60%_0.118_184.704))] dark:text-[color:var(--zui-rating-teal-active-dark,oklch(77.7%_0.152_181.912))]",
|
|
54
|
+
yellow:
|
|
55
|
+
"text-[color:var(--zui-rating-yellow-active,oklch(79.5%_0.184_86.047))] dark:text-[color:var(--zui-rating-yellow-active-dark,oklch(85.2%_0.199_91.936))]",
|
|
56
|
+
orange:
|
|
57
|
+
"text-[color:var(--zui-rating-orange-active,oklch(64.6%_0.222_41.116))] dark:text-[color:var(--zui-rating-orange-active-dark,oklch(75%_0.183_55.934))]",
|
|
58
|
+
gray: "text-[color:var(--zui-rating-gray-active,oklch(55.1%_0.027_264.364))] dark:text-[color:var(--zui-rating-gray-active-dark,oklch(70.7%_0.022_261.325))]",
|
|
59
|
+
amber:
|
|
60
|
+
"text-[color:var(--zui-rating-amber-active,oklch(76.9%_0.188_70.08))] dark:text-[color:var(--zui-rating-amber-active-dark,oklch(82.8%_0.189_84.429))]",
|
|
61
|
+
violet:
|
|
62
|
+
"text-[color:var(--zui-rating-violet-active,oklch(54.1%_0.281_293.009))] dark:text-[color:var(--zui-rating-violet-active-dark,oklch(70.2%_0.183_293.541))]",
|
|
63
|
+
"gradient-blue":
|
|
64
|
+
"text-[color:var(--zui-rating-gradient-blue-active,oklch(54.6%_0.245_262.881))] drop-shadow-[0_2px_12px_rgba(37,99,235,0.28)] dark:text-[color:var(--zui-rating-gradient-blue-active-dark,oklch(70.7%_0.165_254.624))]",
|
|
65
|
+
"gradient-green":
|
|
66
|
+
"text-[color:var(--zui-rating-gradient-green-active,oklch(62.7%_0.194_149.214))] drop-shadow-[0_2px_12px_rgba(22,163,74,0.24)] dark:text-[color:var(--zui-rating-gradient-green-active-dark,oklch(79.2%_0.209_151.711))]",
|
|
67
|
+
"gradient-red":
|
|
68
|
+
"text-[color:var(--zui-rating-gradient-red-active,oklch(57.7%_0.245_27.325))] drop-shadow-[0_2px_12px_rgba(220,38,38,0.24)] dark:text-[color:var(--zui-rating-gradient-red-active-dark,oklch(70.4%_0.191_22.216))]",
|
|
69
|
+
"gradient-yellow":
|
|
70
|
+
"text-[color:var(--zui-rating-gradient-yellow-active,oklch(79.5%_0.184_86.047))] drop-shadow-[0_2px_12px_rgba(234,179,8,0.24)] dark:text-[color:var(--zui-rating-gradient-yellow-active-dark,oklch(85.2%_0.199_91.936))]",
|
|
71
|
+
"gradient-purple":
|
|
72
|
+
"text-[color:var(--zui-rating-gradient-purple-active,oklch(62.7%_0.265_303.9))] drop-shadow-[0_2px_12px_rgba(147,51,234,0.24)] dark:text-[color:var(--zui-rating-gradient-purple-active-dark,oklch(71.4%_0.203_305.504))]",
|
|
73
|
+
"gradient-teal":
|
|
74
|
+
"text-[color:var(--zui-rating-gradient-teal-active,oklch(60%_0.118_184.704))] drop-shadow-[0_2px_12px_rgba(13,148,136,0.24)] dark:text-[color:var(--zui-rating-gradient-teal-active-dark,oklch(77.7%_0.152_181.912))]",
|
|
75
|
+
"gradient-indigo":
|
|
76
|
+
"text-[color:var(--zui-rating-gradient-indigo-active,oklch(51.1%_0.262_276.966))] drop-shadow-[0_2px_12px_rgba(79,70,229,0.24)] dark:text-[color:var(--zui-rating-gradient-indigo-active-dark,oklch(67.3%_0.182_276.935))]",
|
|
77
|
+
"gradient-pink":
|
|
78
|
+
"text-[color:var(--zui-rating-gradient-pink-active,oklch(59.2%_0.249_0.584))] drop-shadow-[0_2px_12px_rgba(219,39,119,0.24)] dark:text-[color:var(--zui-rating-gradient-pink-active-dark,oklch(71.8%_0.202_349.761))]",
|
|
79
|
+
"gradient-orange":
|
|
80
|
+
"text-[color:var(--zui-rating-gradient-orange-active,oklch(64.6%_0.222_41.116))] drop-shadow-[0_2px_12px_rgba(234,88,12,0.24)] dark:text-[color:var(--zui-rating-gradient-orange-active-dark,oklch(75%_0.183_55.934))]",
|
|
81
|
+
} as const;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createRef } from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { Rating } from "./rating";
|
|
7
|
+
|
|
8
|
+
describe("Rating", () => {
|
|
9
|
+
it("should expose displayName", () => {
|
|
10
|
+
expect(Rating.displayName).toBe("Rating");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should stamp data slots and render the requested number of controls", () => {
|
|
14
|
+
render(<Rating label="Product score" max={4} />);
|
|
15
|
+
|
|
16
|
+
expect(document.querySelector('[data-slot="rating"]')).toBeTruthy();
|
|
17
|
+
expect(screen.getByRole("radiogroup")).toBeInTheDocument();
|
|
18
|
+
expect(screen.getAllByRole("radio")).toHaveLength(4);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should render half-step radio options when allowHalf is enabled", () => {
|
|
22
|
+
render(<Rating allowHalf label="Product score" max={3} />);
|
|
23
|
+
|
|
24
|
+
expect(screen.getAllByRole("radio")).toHaveLength(6);
|
|
25
|
+
expect(screen.getByLabelText("2.5 of 3")).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should support uncontrolled value changes", async () => {
|
|
29
|
+
const user = userEvent.setup();
|
|
30
|
+
const onValueChange = vi.fn();
|
|
31
|
+
render(<Rating label="Product score" onValueChange={onValueChange} />);
|
|
32
|
+
|
|
33
|
+
await user.click(screen.getByLabelText("4 of 5"));
|
|
34
|
+
|
|
35
|
+
expect(screen.getByLabelText("4 of 5")).toHaveAttribute(
|
|
36
|
+
"aria-checked",
|
|
37
|
+
"true",
|
|
38
|
+
);
|
|
39
|
+
expect(onValueChange).toHaveBeenLastCalledWith(4);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should support controlled state", async () => {
|
|
43
|
+
const user = userEvent.setup();
|
|
44
|
+
const onValueChange = vi.fn();
|
|
45
|
+
render(
|
|
46
|
+
<Rating label="Product score" value={2} onValueChange={onValueChange} />,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
await user.click(screen.getByLabelText("5 of 5"));
|
|
50
|
+
|
|
51
|
+
expect(screen.getByLabelText("2 of 5")).toHaveAttribute(
|
|
52
|
+
"aria-checked",
|
|
53
|
+
"true",
|
|
54
|
+
);
|
|
55
|
+
expect(onValueChange).toHaveBeenLastCalledWith(5);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should clear the current value when allowClear is enabled", async () => {
|
|
59
|
+
const user = userEvent.setup();
|
|
60
|
+
render(<Rating allowClear defaultValue={3} label="Product score" />);
|
|
61
|
+
|
|
62
|
+
await user.click(screen.getByLabelText("3 of 5"));
|
|
63
|
+
|
|
64
|
+
expect(screen.getByLabelText("1 of 5")).toHaveAttribute("tabindex", "0");
|
|
65
|
+
expect(screen.getByLabelText("3 of 5")).toHaveAttribute(
|
|
66
|
+
"aria-checked",
|
|
67
|
+
"false",
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should step with arrow keys", async () => {
|
|
72
|
+
const user = userEvent.setup();
|
|
73
|
+
const onValueChange = vi.fn();
|
|
74
|
+
render(
|
|
75
|
+
<Rating
|
|
76
|
+
allowHalf
|
|
77
|
+
defaultValue={2}
|
|
78
|
+
label="Product score"
|
|
79
|
+
onValueChange={onValueChange}
|
|
80
|
+
/>,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
screen.getByLabelText("2 of 5").focus();
|
|
84
|
+
await user.keyboard("{ArrowRight}");
|
|
85
|
+
|
|
86
|
+
expect(onValueChange).toHaveBeenLastCalledWith(2.5);
|
|
87
|
+
expect(screen.getByLabelText("2.5 of 5")).toHaveAttribute(
|
|
88
|
+
"aria-checked",
|
|
89
|
+
"true",
|
|
90
|
+
);
|
|
91
|
+
expect(screen.getByLabelText("2.5 of 5")).toHaveFocus();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should fall back to the star icon for unknown icon preset strings", () => {
|
|
95
|
+
render(
|
|
96
|
+
<Rating
|
|
97
|
+
icon={"unknown" as never}
|
|
98
|
+
defaultValue={3}
|
|
99
|
+
label="Product score"
|
|
100
|
+
/>,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(screen.getByRole("radiogroup")).toBeInTheDocument();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("should not change when disabled", async () => {
|
|
107
|
+
const user = userEvent.setup();
|
|
108
|
+
const onValueChange = vi.fn();
|
|
109
|
+
render(
|
|
110
|
+
<Rating
|
|
111
|
+
disabled
|
|
112
|
+
defaultValue={2}
|
|
113
|
+
label="Product score"
|
|
114
|
+
onValueChange={onValueChange}
|
|
115
|
+
/>,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
await user.click(screen.getByLabelText("4 of 5"));
|
|
119
|
+
|
|
120
|
+
expect(onValueChange).not.toHaveBeenCalled();
|
|
121
|
+
expect(screen.getByLabelText("2 of 5")).toHaveAttribute(
|
|
122
|
+
"aria-checked",
|
|
123
|
+
"true",
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should render a hidden input when name is provided", () => {
|
|
128
|
+
render(<Rating defaultValue={3.5} allowHalf label="Score" name="score" />);
|
|
129
|
+
|
|
130
|
+
expect(document.querySelector('input[name="score"]')).toHaveValue("3.5");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should forward ref to the root", () => {
|
|
134
|
+
const ref = createRef<HTMLDivElement>();
|
|
135
|
+
render(<Rating ref={ref} label="Product score" />);
|
|
136
|
+
|
|
137
|
+
expect(ref.current?.getAttribute("data-slot")).toBe("rating");
|
|
138
|
+
});
|
|
139
|
+
});
|