@motor-hero/ui-kit 0.51.1 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/rating.d.ts.map +1 -1
- package/dist/index.cjs +30 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +148 -129
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/rating.tsx +30 -13
package/package.json
CHANGED
|
@@ -19,9 +19,12 @@ export interface RatingProps {
|
|
|
19
19
|
"aria-label"?: string
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const formatNote = (value: number) =>
|
|
23
|
+
value.toLocaleString("pt-BR", { maximumFractionDigits: 1 })
|
|
24
|
+
|
|
22
25
|
function defaultLabel(value: number) {
|
|
23
26
|
return value > 0
|
|
24
|
-
? `
|
|
27
|
+
? `Nota ${formatNote(value)} de ${MAX_STARS}`
|
|
25
28
|
: "Avaliação: sem nota"
|
|
26
29
|
}
|
|
27
30
|
|
|
@@ -43,18 +46,32 @@ export function Rating({
|
|
|
43
46
|
aria-label={label}
|
|
44
47
|
className={cn("inline-flex items-center gap-0.5", className)}
|
|
45
48
|
>
|
|
46
|
-
{Array.from({ length: MAX_STARS }, (_, index) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
className=
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
{Array.from({ length: MAX_STARS }, (_, index) => {
|
|
50
|
+
// Média 4,3 pinta 30% da quinta estrela: a fração é a nota, não um arredondamento.
|
|
51
|
+
const fill = Math.min(1, Math.max(0, clamped - index))
|
|
52
|
+
return (
|
|
53
|
+
<span key={index} className="relative inline-flex">
|
|
54
|
+
<Star
|
|
55
|
+
aria-hidden
|
|
56
|
+
className={cn(sizeClasses[size], "text-muted-foreground")}
|
|
57
|
+
/>
|
|
58
|
+
{fill > 0 && (
|
|
59
|
+
<span
|
|
60
|
+
className="absolute inset-y-0 left-0 overflow-hidden"
|
|
61
|
+
style={{ width: `${fill * 100}%` }}
|
|
62
|
+
>
|
|
63
|
+
<Star
|
|
64
|
+
aria-hidden
|
|
65
|
+
className={cn(
|
|
66
|
+
sizeClasses[size],
|
|
67
|
+
"max-w-none fill-amber-400 text-amber-400",
|
|
68
|
+
)}
|
|
69
|
+
/>
|
|
70
|
+
</span>
|
|
71
|
+
)}
|
|
72
|
+
</span>
|
|
73
|
+
)
|
|
74
|
+
})}
|
|
58
75
|
</div>
|
|
59
76
|
)
|
|
60
77
|
}
|