@zentauri-ui/zentauri-components 1.7.0 → 1.7.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/README.md +9 -5
- package/cli/index.mjs +1 -0
- package/cli/registry.json +2 -0
- package/dist/chunk-6QQUQLPB.js +107 -0
- package/dist/chunk-6QQUQLPB.js.map +1 -0
- package/dist/chunk-K6IZANTI.mjs +80 -0
- package/dist/chunk-K6IZANTI.mjs.map +1 -0
- package/dist/chunk-MTTXLC2V.mjs +100 -0
- package/dist/chunk-MTTXLC2V.mjs.map +1 -0
- package/dist/chunk-PHEUJ4EF.js +84 -0
- package/dist/chunk-PHEUJ4EF.js.map +1 -0
- package/dist/design-system/checkbox.d.ts +32 -0
- package/dist/design-system/checkbox.d.ts.map +1 -0
- package/dist/design-system/index.d.ts +2 -0
- package/dist/design-system/index.d.ts.map +1 -1
- package/dist/design-system/radio-group.d.ts +37 -0
- package/dist/design-system/radio-group.d.ts.map +1 -0
- package/dist/ui/checkbox/animated/animations.d.ts +32 -0
- package/dist/ui/checkbox/animated/animations.d.ts.map +1 -0
- package/dist/ui/checkbox/animated/checkbox-animated.d.ts +6 -0
- package/dist/ui/checkbox/animated/checkbox-animated.d.ts.map +1 -0
- package/dist/ui/checkbox/animated/index.d.ts +4 -0
- package/dist/ui/checkbox/animated/index.d.ts.map +1 -0
- package/dist/ui/checkbox/animated/types.d.ts +8 -0
- package/dist/ui/checkbox/animated/types.d.ts.map +1 -0
- package/dist/ui/checkbox/animated.js +153 -0
- package/dist/ui/checkbox/animated.js.map +1 -0
- package/dist/ui/checkbox/animated.mjs +150 -0
- package/dist/ui/checkbox/animated.mjs.map +1 -0
- package/dist/ui/checkbox/checkbox-base.d.ts +6 -0
- package/dist/ui/checkbox/checkbox-base.d.ts.map +1 -0
- package/dist/ui/checkbox/checkbox.d.ts +6 -0
- package/dist/ui/checkbox/checkbox.d.ts.map +1 -0
- package/dist/ui/checkbox/index.d.ts +4 -0
- package/dist/ui/checkbox/index.d.ts.map +1 -0
- package/dist/ui/checkbox/types.d.ts +19 -0
- package/dist/ui/checkbox/types.d.ts.map +1 -0
- package/dist/ui/checkbox/variants.d.ts +11 -0
- package/dist/ui/checkbox/variants.d.ts.map +1 -0
- package/dist/ui/checkbox.js +150 -0
- package/dist/ui/checkbox.js.map +1 -0
- package/dist/ui/checkbox.mjs +137 -0
- package/dist/ui/checkbox.mjs.map +1 -0
- package/dist/ui/radio-group/animated/animations.d.ts +32 -0
- package/dist/ui/radio-group/animated/animations.d.ts.map +1 -0
- package/dist/ui/radio-group/animated/index.d.ts +4 -0
- package/dist/ui/radio-group/animated/index.d.ts.map +1 -0
- package/dist/ui/radio-group/animated/radio-group-animated.d.ts +10 -0
- package/dist/ui/radio-group/animated/radio-group-animated.d.ts.map +1 -0
- package/dist/ui/radio-group/animated/types.d.ts +11 -0
- package/dist/ui/radio-group/animated/types.d.ts.map +1 -0
- package/dist/ui/radio-group/animated.js +177 -0
- package/dist/ui/radio-group/animated.js.map +1 -0
- package/dist/ui/radio-group/animated.mjs +173 -0
- package/dist/ui/radio-group/animated.mjs.map +1 -0
- package/dist/ui/radio-group/index.d.ts +4 -0
- package/dist/ui/radio-group/index.d.ts.map +1 -0
- package/dist/ui/radio-group/radio-group-context.d.ts +13 -0
- package/dist/ui/radio-group/radio-group-context.d.ts.map +1 -0
- package/dist/ui/radio-group/radio-group.d.ts +10 -0
- package/dist/ui/radio-group/radio-group.d.ts.map +1 -0
- package/dist/ui/radio-group/types.d.ts +26 -0
- package/dist/ui/radio-group/types.d.ts.map +1 -0
- package/dist/ui/radio-group/variants.d.ts +14 -0
- package/dist/ui/radio-group/variants.d.ts.map +1 -0
- package/dist/ui/radio-group.js +171 -0
- package/dist/ui/radio-group.js.map +1 -0
- package/dist/ui/radio-group.mjs +153 -0
- package/dist/ui/radio-group.mjs.map +1 -0
- package/package.json +1 -1
- package/src/design-system/checkbox.ts +47 -0
- package/src/design-system/index.ts +2 -0
- package/src/design-system/radio-group.ts +54 -0
- package/src/ui/checkbox/animated/animations.ts +12 -0
- package/src/ui/checkbox/animated/checkbox-animated.tsx +145 -0
- package/src/ui/checkbox/animated/index.ts +9 -0
- package/src/ui/checkbox/animated/types.ts +9 -0
- package/src/ui/checkbox/checkbox-base.tsx +134 -0
- package/src/ui/checkbox/checkbox.test.tsx +53 -0
- package/src/ui/checkbox/checkbox.tsx +8 -0
- package/src/ui/checkbox/index.ts +15 -0
- package/src/ui/checkbox/types.ts +40 -0
- package/src/ui/checkbox/variants.ts +50 -0
- package/src/ui/radio-group/animated/animations.ts +12 -0
- package/src/ui/radio-group/animated/index.ts +10 -0
- package/src/ui/radio-group/animated/radio-group-animated.tsx +173 -0
- package/src/ui/radio-group/animated/types.ts +13 -0
- package/src/ui/radio-group/index.ts +19 -0
- package/src/ui/radio-group/radio-group-context.ts +23 -0
- package/src/ui/radio-group/radio-group.test.tsx +61 -0
- package/src/ui/radio-group/radio-group.tsx +159 -0
- package/src/ui/radio-group/types.ts +62 -0
- package/src/ui/radio-group/variants.ts +61 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const zuiCheckboxRootBase =
|
|
2
|
+
"group inline-flex w-fit items-start gap-2.5 text-sm font-medium text-[color:var(--zui-checkbox-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-checkbox-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 zuiCheckboxControlBase =
|
|
5
|
+
"grid shrink-0 place-items-center rounded-md border-2 border-[color:var(--zui-checkbox-border,#0000004d)] bg-[var(--zui-checkbox-bg,transparent)] text-[color:var(--zui-checkbox-fg,oklch(44.6%_0.043_257.281))] transition-[background-color,border-color,color,box-shadow] peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--zui-checkbox-ring-focus,oklch(44.6%_0.043_257.281_/_0.7))] peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-[var(--zui-checkbox-ring-offset-focus,oklch(98.4%_0.003_247.858))] dark:border-[color:var(--zui-checkbox-border-dark,#ffffff4d)] dark:text-[color:var(--zui-checkbox-fg-dark,oklch(92.9%_0.013_255.508))] dark:peer-focus-visible:ring-[var(--zui-checkbox-ring-focus-dark,oklch(86.9%_0.022_252.894_/_0.7))] dark:peer-focus-visible:ring-offset-[var(--zui-checkbox-ring-offset-focus-dark,oklch(12.9%_0.042_264.695))] group-data-[disabled=true]:cursor-not-allowed";
|
|
6
|
+
|
|
7
|
+
export const zuiCheckboxIndicatorBase =
|
|
8
|
+
"pointer-events-none opacity-0 transition-opacity duration-150 stroke-white group-data-[state=checked]:opacity-100 group-data-[state=indeterminate]:opacity-100";
|
|
9
|
+
|
|
10
|
+
export const zuiCheckboxSizes = {
|
|
11
|
+
sm: {
|
|
12
|
+
root: "text-xs",
|
|
13
|
+
control: "mt-0.5 size-4 rounded-[0.35rem]",
|
|
14
|
+
indicator: "size-3",
|
|
15
|
+
},
|
|
16
|
+
md: {
|
|
17
|
+
root: "text-sm",
|
|
18
|
+
control: "mt-0.5 size-5",
|
|
19
|
+
indicator: "size-3.5",
|
|
20
|
+
},
|
|
21
|
+
lg: {
|
|
22
|
+
root: "text-base",
|
|
23
|
+
control: "mt-0.5 size-6",
|
|
24
|
+
indicator: "size-4",
|
|
25
|
+
},
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
export const zuiCheckboxAppearances = {
|
|
29
|
+
default:
|
|
30
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-default-border-checked,oklch(44.6%_0.043_257.281))] group-data-[state=checked]:bg-[var(--zui-checkbox-default-bg-checked,oklch(44.6%_0.043_257.281))] group-data-[state=checked]:text-[color:var(--zui-checkbox-default-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-default-border-checked,oklch(44.6%_0.043_257.281))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-default-bg-checked,oklch(44.6%_0.043_257.281))] group-data-[state=indeterminate]:text-[color:var(--zui-checkbox-default-fg-checked,#ffffff)]",
|
|
31
|
+
success:
|
|
32
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-success-border-checked,oklch(59.6%_0.145_163.225))] group-data-[state=checked]:bg-[var(--zui-checkbox-success-bg-checked,oklch(59.6%_0.145_163.225))] group-data-[state=checked]:text-[color:var(--zui-checkbox-success-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-success-border-checked,oklch(59.6%_0.145_163.225))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-success-bg-checked,oklch(59.6%_0.145_163.225))]",
|
|
33
|
+
warning:
|
|
34
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-warning-border-checked,oklch(68.1%_0.162_75.834))] group-data-[state=checked]:bg-[var(--zui-checkbox-warning-bg-checked,oklch(68.1%_0.162_75.834))] group-data-[state=checked]:text-[color:var(--zui-checkbox-warning-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-warning-border-checked,oklch(68.1%_0.162_75.834))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-warning-bg-checked,oklch(68.1%_0.162_75.834))]",
|
|
35
|
+
error:
|
|
36
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-error-border-checked,oklch(58.6%_0.253_17.585))] group-data-[state=checked]:bg-[var(--zui-checkbox-error-bg-checked,oklch(58.6%_0.253_17.585))] group-data-[state=checked]:text-[color:var(--zui-checkbox-error-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-error-border-checked,oklch(58.6%_0.253_17.585))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-error-bg-checked,oklch(58.6%_0.253_17.585))]",
|
|
37
|
+
info:
|
|
38
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-info-border-checked,oklch(54.6%_0.245_262.881))] group-data-[state=checked]:bg-[var(--zui-checkbox-info-bg-checked,oklch(54.6%_0.245_262.881))] group-data-[state=checked]:text-[color:var(--zui-checkbox-info-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-info-border-checked,oklch(54.6%_0.245_262.881))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-info-bg-checked,oklch(54.6%_0.245_262.881))]",
|
|
39
|
+
violet:
|
|
40
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-violet-border-checked,oklch(54.1%_0.281_293.009))] group-data-[state=checked]:bg-[var(--zui-checkbox-violet-bg-checked,oklch(54.1%_0.281_293.009))] group-data-[state=checked]:text-[color:var(--zui-checkbox-violet-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-violet-border-checked,oklch(54.1%_0.281_293.009))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-violet-bg-checked,oklch(54.1%_0.281_293.009))]",
|
|
41
|
+
amber:
|
|
42
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-amber-border-checked,oklch(66.6%_0.179_58.318))] group-data-[state=checked]:bg-[var(--zui-checkbox-amber-bg-checked,oklch(66.6%_0.179_58.318))] group-data-[state=checked]:text-[color:var(--zui-checkbox-amber-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-amber-border-checked,oklch(66.6%_0.179_58.318))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-amber-bg-checked,oklch(66.6%_0.179_58.318))]",
|
|
43
|
+
pink:
|
|
44
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-pink-border-checked,oklch(59.2%_0.249_0.584))] group-data-[state=checked]:bg-[var(--zui-checkbox-pink-bg-checked,oklch(59.2%_0.249_0.584))] group-data-[state=checked]:text-[color:var(--zui-checkbox-pink-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-pink-border-checked,oklch(59.2%_0.249_0.584))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-pink-bg-checked,oklch(59.2%_0.249_0.584))]",
|
|
45
|
+
indigo:
|
|
46
|
+
"group-data-[state=checked]:border-[color:var(--zui-checkbox-indigo-border-checked,oklch(51.1%_0.262_276.966))] group-data-[state=checked]:bg-[var(--zui-checkbox-indigo-bg-checked,oklch(51.1%_0.262_276.966))] group-data-[state=checked]:text-[color:var(--zui-checkbox-indigo-fg-checked,#ffffff)] group-data-[state=indeterminate]:border-[color:var(--zui-checkbox-indigo-border-checked,oklch(51.1%_0.262_276.966))] group-data-[state=indeterminate]:bg-[var(--zui-checkbox-indigo-bg-checked,oklch(51.1%_0.262_276.966))]",
|
|
47
|
+
} as const;
|
|
@@ -5,6 +5,7 @@ export * from "./badge";
|
|
|
5
5
|
export * from "./breadcrumb";
|
|
6
6
|
export * from "./button";
|
|
7
7
|
export * from "./card";
|
|
8
|
+
export * from "./checkbox";
|
|
8
9
|
export * from "./divider";
|
|
9
10
|
export * from "./drawer";
|
|
10
11
|
export * from "./dropdown";
|
|
@@ -15,6 +16,7 @@ export * from "./inputs";
|
|
|
15
16
|
export * from "./modal";
|
|
16
17
|
export * from "./pagination";
|
|
17
18
|
export * from "./progress";
|
|
19
|
+
export * from "./radio-group";
|
|
18
20
|
export * from "./select";
|
|
19
21
|
export * from "./skeleton";
|
|
20
22
|
export * from "./slider";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export const zuiRadioGroupRootBase = "grid gap-2";
|
|
2
|
+
|
|
3
|
+
export const zuiRadioGroupItemBase =
|
|
4
|
+
"group inline-flex w-fit items-start gap-2.5 text-sm font-medium text-[color:var(--zui-radio-label-fg,oklch(20.8%_0.042_265.755))] dark:text-[color:var(--zui-radio-label-fg-dark,oklch(98.4%_0.003_247.858))] data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50";
|
|
5
|
+
|
|
6
|
+
export const zuiRadioGroupControlBase =
|
|
7
|
+
"grid shrink-0 place-items-center rounded-full border-2 border-[color:var(--zui-radio-border,#0000004d)] bg-[var(--zui-radio-bg,transparent)] transition-[background-color,border-color,box-shadow] peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-[var(--zui-radio-ring-focus,oklch(44.6%_0.043_257.281_/_0.7))] peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-[var(--zui-radio-ring-offset-focus,oklch(98.4%_0.003_247.858))] dark:border-[color:var(--zui-radio-border-dark,#ffffff4d)] dark:peer-focus-visible:ring-[var(--zui-radio-ring-focus-dark,oklch(86.9%_0.022_252.894_/_0.7))] dark:peer-focus-visible:ring-offset-[var(--zui-radio-ring-offset-focus-dark,oklch(12.9%_0.042_264.695))] group-data-[disabled=true]:cursor-not-allowed";
|
|
8
|
+
|
|
9
|
+
export const zuiRadioGroupIndicatorBase =
|
|
10
|
+
"pointer-events-none block rounded-full opacity-0 transition-opacity duration-150 group-data-[state=checked]:opacity-100";
|
|
11
|
+
|
|
12
|
+
export const zuiRadioGroupSizes = {
|
|
13
|
+
sm: {
|
|
14
|
+
item: "text-xs",
|
|
15
|
+
control: "mt-0.5 size-4",
|
|
16
|
+
indicator: "size-1.5",
|
|
17
|
+
},
|
|
18
|
+
md: {
|
|
19
|
+
item: "text-sm",
|
|
20
|
+
control: "mt-0.5 size-5",
|
|
21
|
+
indicator: "size-2",
|
|
22
|
+
},
|
|
23
|
+
lg: {
|
|
24
|
+
item: "text-base",
|
|
25
|
+
control: "mt-0.5 size-6",
|
|
26
|
+
indicator: "size-2.5",
|
|
27
|
+
},
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
export const zuiRadioGroupAppearances = {
|
|
31
|
+
default:
|
|
32
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-default-border-checked,oklch(44.6%_0.043_257.281))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-default-indicator-bg,oklch(44.6%_0.043_257.281))]",
|
|
33
|
+
success:
|
|
34
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-success-border-checked,oklch(59.6%_0.145_163.225))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-success-indicator-bg,oklch(59.6%_0.145_163.225))]",
|
|
35
|
+
warning:
|
|
36
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-warning-border-checked,oklch(68.1%_0.162_75.834))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-warning-indicator-bg,oklch(68.1%_0.162_75.834))]",
|
|
37
|
+
error:
|
|
38
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-error-border-checked,oklch(58.6%_0.253_17.585))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-error-indicator-bg,oklch(58.6%_0.253_17.585))]",
|
|
39
|
+
info:
|
|
40
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-info-border-checked,oklch(54.6%_0.245_262.881))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-info-indicator-bg,oklch(54.6%_0.245_262.881))]",
|
|
41
|
+
violet:
|
|
42
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-violet-border-checked,oklch(54.1%_0.281_293.009))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-violet-indicator-bg,oklch(54.1%_0.281_293.009))]",
|
|
43
|
+
amber:
|
|
44
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-amber-border-checked,oklch(66.6%_0.179_58.318))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-amber-indicator-bg,oklch(66.6%_0.179_58.318))]",
|
|
45
|
+
pink:
|
|
46
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-pink-border-checked,oklch(59.2%_0.249_0.584))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-pink-indicator-bg,oklch(59.2%_0.249_0.584))]",
|
|
47
|
+
indigo:
|
|
48
|
+
"group-data-[state=checked]:border-[color:var(--zui-radio-indigo-border-checked,oklch(51.1%_0.262_276.966))] [&_[data-slot=radio-group-indicator]]:bg-[var(--zui-radio-indigo-indicator-bg,oklch(51.1%_0.262_276.966))]",
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
export const zuiRadioGroupOrientations = {
|
|
52
|
+
vertical: "grid gap-2",
|
|
53
|
+
horizontal: "flex flex-wrap gap-x-5 gap-y-2",
|
|
54
|
+
} as const;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const checkboxAnimationPresets = {
|
|
2
|
+
draw: {
|
|
3
|
+
initial: { pathLength: 0, opacity: 0 },
|
|
4
|
+
animate: { pathLength: 1, opacity: 1 },
|
|
5
|
+
transition: { duration: 0.2, ease: "easeOut" },
|
|
6
|
+
},
|
|
7
|
+
spring: {
|
|
8
|
+
initial: { scale: 0.7, opacity: 0 },
|
|
9
|
+
animate: { scale: 1, opacity: 1 },
|
|
10
|
+
transition: { type: "spring", stiffness: 520, damping: 30 },
|
|
11
|
+
},
|
|
12
|
+
} as const;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { motion } from "framer-motion";
|
|
4
|
+
import { useCallback, useId, useState } from "react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../../lib/utils";
|
|
7
|
+
|
|
8
|
+
import { checkboxAnimationPresets } from "./animations";
|
|
9
|
+
import type { CheckboxAnimatedProps } from "./types";
|
|
10
|
+
import type { CheckboxState } from "../types";
|
|
11
|
+
import {
|
|
12
|
+
checkboxControlVariants,
|
|
13
|
+
checkboxIndicatorVariants,
|
|
14
|
+
checkboxRootVariants,
|
|
15
|
+
} from "../variants";
|
|
16
|
+
|
|
17
|
+
function resolveCheckboxState(
|
|
18
|
+
checked: boolean,
|
|
19
|
+
indeterminate: boolean | undefined,
|
|
20
|
+
): CheckboxState {
|
|
21
|
+
if (indeterminate) {
|
|
22
|
+
return "indeterminate";
|
|
23
|
+
}
|
|
24
|
+
return checked ? "checked" : "unchecked";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function CheckboxAnimated(props: CheckboxAnimatedProps) {
|
|
28
|
+
const {
|
|
29
|
+
className,
|
|
30
|
+
rootClassName,
|
|
31
|
+
controlClassName,
|
|
32
|
+
indicatorClassName,
|
|
33
|
+
appearance,
|
|
34
|
+
size,
|
|
35
|
+
checked,
|
|
36
|
+
defaultChecked = false,
|
|
37
|
+
indeterminate,
|
|
38
|
+
onCheckedChange,
|
|
39
|
+
disabled,
|
|
40
|
+
children,
|
|
41
|
+
label,
|
|
42
|
+
id,
|
|
43
|
+
ref,
|
|
44
|
+
"aria-label": ariaLabel,
|
|
45
|
+
animation = "draw",
|
|
46
|
+
...rest
|
|
47
|
+
} = props;
|
|
48
|
+
const generatedId = useId();
|
|
49
|
+
const controlId = id ?? generatedId;
|
|
50
|
+
const isControlled = checked !== undefined;
|
|
51
|
+
const [uncontrolled, setUncontrolled] = useState(defaultChecked);
|
|
52
|
+
const resolvedChecked = isControlled ? Boolean(checked) : uncontrolled;
|
|
53
|
+
const state = resolveCheckboxState(resolvedChecked, indeterminate);
|
|
54
|
+
const labelContent = label ?? children;
|
|
55
|
+
const hasVisibleLabel =
|
|
56
|
+
labelContent !== undefined && labelContent !== null && labelContent !== false;
|
|
57
|
+
const motionPreset = checkboxAnimationPresets[animation];
|
|
58
|
+
const svgMotionProps = animation === "spring" ? motionPreset : undefined;
|
|
59
|
+
const pathMotionProps = animation === "draw" ? motionPreset : undefined;
|
|
60
|
+
|
|
61
|
+
const setChecked = useCallback(
|
|
62
|
+
(next: boolean) => {
|
|
63
|
+
if (!isControlled) {
|
|
64
|
+
setUncontrolled(next);
|
|
65
|
+
}
|
|
66
|
+
onCheckedChange?.(next);
|
|
67
|
+
},
|
|
68
|
+
[isControlled, onCheckedChange],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<label
|
|
73
|
+
className={cn(checkboxRootVariants({ size }), rootClassName, className)}
|
|
74
|
+
data-disabled={disabled ? "true" : undefined}
|
|
75
|
+
data-state={state}
|
|
76
|
+
htmlFor={controlId}
|
|
77
|
+
>
|
|
78
|
+
<input
|
|
79
|
+
ref={ref}
|
|
80
|
+
id={controlId}
|
|
81
|
+
type="checkbox"
|
|
82
|
+
data-slot="checkbox"
|
|
83
|
+
className="peer sr-only"
|
|
84
|
+
checked={resolvedChecked}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
aria-checked={indeterminate ? "mixed" : resolvedChecked}
|
|
87
|
+
aria-label={ariaLabel ?? (hasVisibleLabel ? undefined : "Checkbox")}
|
|
88
|
+
onChange={(event) => setChecked(event.currentTarget.checked)}
|
|
89
|
+
{...rest}
|
|
90
|
+
/>
|
|
91
|
+
<span
|
|
92
|
+
aria-hidden="true"
|
|
93
|
+
className={cn(
|
|
94
|
+
checkboxControlVariants({ appearance, size }),
|
|
95
|
+
controlClassName,
|
|
96
|
+
)}
|
|
97
|
+
data-slot="checkbox-control"
|
|
98
|
+
>
|
|
99
|
+
{state !== "unchecked" && (
|
|
100
|
+
<motion.svg
|
|
101
|
+
key={state}
|
|
102
|
+
viewBox="0 0 16 16"
|
|
103
|
+
fill="none"
|
|
104
|
+
className={cn(
|
|
105
|
+
checkboxIndicatorVariants({ size }),
|
|
106
|
+
"opacity-100",
|
|
107
|
+
indicatorClassName,
|
|
108
|
+
)}
|
|
109
|
+
initial={svgMotionProps?.initial}
|
|
110
|
+
animate={svgMotionProps?.animate}
|
|
111
|
+
transition={svgMotionProps?.transition}
|
|
112
|
+
>
|
|
113
|
+
{state === "indeterminate" ? (
|
|
114
|
+
<motion.path
|
|
115
|
+
d="M3.5 8H12.5"
|
|
116
|
+
strokeWidth="2.4"
|
|
117
|
+
strokeLinecap="round"
|
|
118
|
+
initial={pathMotionProps?.initial}
|
|
119
|
+
animate={pathMotionProps?.animate}
|
|
120
|
+
transition={pathMotionProps?.transition}
|
|
121
|
+
/>
|
|
122
|
+
) : (
|
|
123
|
+
<motion.path
|
|
124
|
+
d="M3.2 8.4L6.5 11.5L12.8 4.5"
|
|
125
|
+
strokeWidth="2.2"
|
|
126
|
+
strokeLinecap="round"
|
|
127
|
+
strokeLinejoin="round"
|
|
128
|
+
initial={pathMotionProps?.initial}
|
|
129
|
+
animate={pathMotionProps?.animate}
|
|
130
|
+
transition={pathMotionProps?.transition}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
</motion.svg>
|
|
134
|
+
)}
|
|
135
|
+
</span>
|
|
136
|
+
{hasVisibleLabel && (
|
|
137
|
+
<span className="min-w-0 leading-6" data-slot="checkbox-label">
|
|
138
|
+
{labelContent}
|
|
139
|
+
</span>
|
|
140
|
+
)}
|
|
141
|
+
</label>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
CheckboxAnimated.displayName = "Checkbox";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CheckboxProps } from "../types";
|
|
2
|
+
import type { checkboxAnimationPresets } from "./animations";
|
|
3
|
+
|
|
4
|
+
export type CheckboxAnimation = keyof typeof checkboxAnimationPresets;
|
|
5
|
+
export type CheckboxAnimationPresets = typeof checkboxAnimationPresets;
|
|
6
|
+
|
|
7
|
+
export type CheckboxAnimatedProps = CheckboxProps & {
|
|
8
|
+
animation?: CheckboxAnimation;
|
|
9
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useId, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils";
|
|
6
|
+
|
|
7
|
+
import type { CheckboxProps, CheckboxState } from "./types";
|
|
8
|
+
import {
|
|
9
|
+
checkboxControlVariants,
|
|
10
|
+
checkboxIndicatorVariants,
|
|
11
|
+
checkboxRootVariants,
|
|
12
|
+
} from "./variants";
|
|
13
|
+
|
|
14
|
+
function resolveCheckboxState(
|
|
15
|
+
checked: boolean,
|
|
16
|
+
indeterminate: boolean | undefined,
|
|
17
|
+
): CheckboxState {
|
|
18
|
+
if (indeterminate) {
|
|
19
|
+
return "indeterminate";
|
|
20
|
+
}
|
|
21
|
+
return checked ? "checked" : "unchecked";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function CheckboxBase(props: CheckboxProps) {
|
|
25
|
+
const {
|
|
26
|
+
className,
|
|
27
|
+
rootClassName,
|
|
28
|
+
controlClassName,
|
|
29
|
+
indicatorClassName,
|
|
30
|
+
appearance,
|
|
31
|
+
size,
|
|
32
|
+
checked,
|
|
33
|
+
defaultChecked = false,
|
|
34
|
+
indeterminate,
|
|
35
|
+
onCheckedChange,
|
|
36
|
+
disabled,
|
|
37
|
+
children,
|
|
38
|
+
label,
|
|
39
|
+
id,
|
|
40
|
+
ref,
|
|
41
|
+
"aria-label": ariaLabel,
|
|
42
|
+
...rest
|
|
43
|
+
} = props;
|
|
44
|
+
const generatedId = useId();
|
|
45
|
+
const controlId = id ?? generatedId;
|
|
46
|
+
const isControlled = checked !== undefined;
|
|
47
|
+
const [uncontrolled, setUncontrolled] = useState(defaultChecked);
|
|
48
|
+
const resolvedChecked = isControlled ? Boolean(checked) : uncontrolled;
|
|
49
|
+
const state = resolveCheckboxState(resolvedChecked, indeterminate);
|
|
50
|
+
const labelContent = label ?? children;
|
|
51
|
+
const hasVisibleLabel =
|
|
52
|
+
labelContent !== undefined && labelContent !== null && labelContent !== false;
|
|
53
|
+
|
|
54
|
+
const setChecked = useCallback(
|
|
55
|
+
(next: boolean) => {
|
|
56
|
+
if (!isControlled) {
|
|
57
|
+
setUncontrolled(next);
|
|
58
|
+
}
|
|
59
|
+
onCheckedChange?.(next);
|
|
60
|
+
},
|
|
61
|
+
[isControlled, onCheckedChange],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<label
|
|
66
|
+
className={cn(checkboxRootVariants({ size }), rootClassName, className)}
|
|
67
|
+
data-disabled={disabled ? "true" : undefined}
|
|
68
|
+
data-state={state}
|
|
69
|
+
htmlFor={controlId}
|
|
70
|
+
>
|
|
71
|
+
<input
|
|
72
|
+
ref={ref}
|
|
73
|
+
id={controlId}
|
|
74
|
+
type="checkbox"
|
|
75
|
+
data-slot="checkbox"
|
|
76
|
+
className="peer sr-only"
|
|
77
|
+
checked={resolvedChecked}
|
|
78
|
+
disabled={disabled}
|
|
79
|
+
aria-checked={indeterminate ? "mixed" : resolvedChecked}
|
|
80
|
+
aria-label={ariaLabel ?? (hasVisibleLabel ? undefined : "Checkbox")}
|
|
81
|
+
onChange={(event) => setChecked(event.currentTarget.checked)}
|
|
82
|
+
{...rest}
|
|
83
|
+
/>
|
|
84
|
+
<span
|
|
85
|
+
aria-hidden="true"
|
|
86
|
+
className={cn(
|
|
87
|
+
checkboxControlVariants({ appearance, size }),
|
|
88
|
+
controlClassName,
|
|
89
|
+
)}
|
|
90
|
+
data-slot="checkbox-control"
|
|
91
|
+
>
|
|
92
|
+
{state === "indeterminate" ? (
|
|
93
|
+
<svg
|
|
94
|
+
viewBox="0 0 16 16"
|
|
95
|
+
fill="none"
|
|
96
|
+
className={cn(
|
|
97
|
+
checkboxIndicatorVariants({ size }),
|
|
98
|
+
indicatorClassName,
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
<path
|
|
102
|
+
d="M3.5 8H12.5"
|
|
103
|
+
strokeWidth="2.4"
|
|
104
|
+
strokeLinecap="round"
|
|
105
|
+
/>
|
|
106
|
+
</svg>
|
|
107
|
+
) : (
|
|
108
|
+
<svg
|
|
109
|
+
viewBox="0 0 16 16"
|
|
110
|
+
fill="none"
|
|
111
|
+
className={cn(
|
|
112
|
+
checkboxIndicatorVariants({ size }),
|
|
113
|
+
indicatorClassName,
|
|
114
|
+
)}
|
|
115
|
+
>
|
|
116
|
+
<path
|
|
117
|
+
d="M3.2 8.4L6.5 11.5L12.8 4.5"
|
|
118
|
+
strokeWidth="2.2"
|
|
119
|
+
strokeLinecap="round"
|
|
120
|
+
strokeLinejoin="round"
|
|
121
|
+
/>
|
|
122
|
+
</svg>
|
|
123
|
+
)}
|
|
124
|
+
</span>
|
|
125
|
+
{hasVisibleLabel && (
|
|
126
|
+
<span className="min-w-0 leading-6" data-slot="checkbox-label">
|
|
127
|
+
{labelContent}
|
|
128
|
+
</span>
|
|
129
|
+
)}
|
|
130
|
+
</label>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
CheckboxBase.displayName = "Checkbox";
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { Checkbox } from "./checkbox";
|
|
7
|
+
|
|
8
|
+
describe("Checkbox", () => {
|
|
9
|
+
it("should expose displayName", () => {
|
|
10
|
+
expect(Checkbox.displayName).toBe("Checkbox");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("should stamp data-slot", () => {
|
|
14
|
+
render(<Checkbox aria-label="Accept" />);
|
|
15
|
+
expect(document.querySelector('[data-slot="checkbox"]')).toBeTruthy();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should use accessible label content", () => {
|
|
19
|
+
render(<Checkbox>Accept terms</Checkbox>);
|
|
20
|
+
expect(
|
|
21
|
+
screen.getByRole("checkbox", { name: "Accept terms" }),
|
|
22
|
+
).toBeInTheDocument();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should call onCheckedChange when toggled", async () => {
|
|
26
|
+
const user = userEvent.setup();
|
|
27
|
+
const onCheckedChange = vi.fn();
|
|
28
|
+
render(
|
|
29
|
+
<Checkbox defaultChecked={false} onCheckedChange={onCheckedChange}>
|
|
30
|
+
Marketing emails
|
|
31
|
+
</Checkbox>,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
await user.click(screen.getByRole("checkbox", { name: "Marketing emails" }));
|
|
35
|
+
expect(onCheckedChange).toHaveBeenLastCalledWith(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should expose mixed state when indeterminate", () => {
|
|
39
|
+
render(
|
|
40
|
+
<Checkbox indeterminate aria-label="Select partial group" />,
|
|
41
|
+
);
|
|
42
|
+
expect(screen.getByRole("checkbox")).toHaveAttribute(
|
|
43
|
+
"aria-checked",
|
|
44
|
+
"mixed",
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should forward ref to the input", () => {
|
|
49
|
+
const ref = createRef<HTMLInputElement>();
|
|
50
|
+
render(<Checkbox ref={ref} aria-label="Remember me" />);
|
|
51
|
+
expect(ref.current?.getAttribute("data-slot")).toBe("checkbox");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export { Checkbox } from "./checkbox";
|
|
4
|
+
export type {
|
|
5
|
+
CheckboxControlVariantProps,
|
|
6
|
+
CheckboxIndicatorVariantProps,
|
|
7
|
+
CheckboxProps,
|
|
8
|
+
CheckboxRootVariantProps,
|
|
9
|
+
CheckboxState,
|
|
10
|
+
} from "./types";
|
|
11
|
+
export {
|
|
12
|
+
checkboxControlVariants,
|
|
13
|
+
checkboxIndicatorVariants,
|
|
14
|
+
checkboxRootVariants,
|
|
15
|
+
} from "./variants";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { VariantProps } from "class-variance-authority";
|
|
2
|
+
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
checkboxControlVariants,
|
|
6
|
+
checkboxIndicatorVariants,
|
|
7
|
+
checkboxRootVariants,
|
|
8
|
+
} from "./variants";
|
|
9
|
+
|
|
10
|
+
export type CheckboxState = "checked" | "unchecked" | "indeterminate";
|
|
11
|
+
|
|
12
|
+
export type CheckboxRootVariantProps = VariantProps<typeof checkboxRootVariants>;
|
|
13
|
+
export type CheckboxControlVariantProps = VariantProps<
|
|
14
|
+
typeof checkboxControlVariants
|
|
15
|
+
>;
|
|
16
|
+
export type CheckboxIndicatorVariantProps = VariantProps<
|
|
17
|
+
typeof checkboxIndicatorVariants
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export type CheckboxProps = CheckboxRootVariantProps &
|
|
21
|
+
CheckboxControlVariantProps &
|
|
22
|
+
Omit<
|
|
23
|
+
ComponentPropsWithRef<"input">,
|
|
24
|
+
| "type"
|
|
25
|
+
| "size"
|
|
26
|
+
| "checked"
|
|
27
|
+
| "defaultChecked"
|
|
28
|
+
| "onChange"
|
|
29
|
+
| "children"
|
|
30
|
+
> & {
|
|
31
|
+
checked?: boolean;
|
|
32
|
+
defaultChecked?: boolean;
|
|
33
|
+
indeterminate?: boolean;
|
|
34
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
35
|
+
children?: ReactNode;
|
|
36
|
+
label?: ReactNode;
|
|
37
|
+
rootClassName?: string;
|
|
38
|
+
controlClassName?: string;
|
|
39
|
+
indicatorClassName?: string;
|
|
40
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { cva } from "class-variance-authority";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
zuiCheckboxAppearances,
|
|
5
|
+
zuiCheckboxControlBase,
|
|
6
|
+
zuiCheckboxIndicatorBase,
|
|
7
|
+
zuiCheckboxRootBase,
|
|
8
|
+
zuiCheckboxSizes,
|
|
9
|
+
} from "../../design-system/checkbox";
|
|
10
|
+
|
|
11
|
+
export const checkboxRootVariants = cva(zuiCheckboxRootBase, {
|
|
12
|
+
variants: {
|
|
13
|
+
size: {
|
|
14
|
+
sm: zuiCheckboxSizes.sm.root,
|
|
15
|
+
md: zuiCheckboxSizes.md.root,
|
|
16
|
+
lg: zuiCheckboxSizes.lg.root,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
size: "md",
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const checkboxControlVariants = cva(zuiCheckboxControlBase, {
|
|
25
|
+
variants: {
|
|
26
|
+
appearance: zuiCheckboxAppearances,
|
|
27
|
+
size: {
|
|
28
|
+
sm: zuiCheckboxSizes.sm.control,
|
|
29
|
+
md: zuiCheckboxSizes.md.control,
|
|
30
|
+
lg: zuiCheckboxSizes.lg.control,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
defaultVariants: {
|
|
34
|
+
appearance: "default",
|
|
35
|
+
size: "md",
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const checkboxIndicatorVariants = cva(zuiCheckboxIndicatorBase, {
|
|
40
|
+
variants: {
|
|
41
|
+
size: {
|
|
42
|
+
sm: zuiCheckboxSizes.sm.indicator,
|
|
43
|
+
md: zuiCheckboxSizes.md.indicator,
|
|
44
|
+
lg: zuiCheckboxSizes.lg.indicator,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
defaultVariants: {
|
|
48
|
+
size: "md",
|
|
49
|
+
},
|
|
50
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const radioGroupAnimationPresets = {
|
|
2
|
+
pop: {
|
|
3
|
+
initial: { scale: 0.35, opacity: 0 },
|
|
4
|
+
animate: { scale: 1, opacity: 1 },
|
|
5
|
+
transition: { type: "spring", stiffness: 520, damping: 28 },
|
|
6
|
+
},
|
|
7
|
+
fade: {
|
|
8
|
+
initial: { scale: 0.85, opacity: 0 },
|
|
9
|
+
animate: { scale: 1, opacity: 1 },
|
|
10
|
+
transition: { duration: 0.16, ease: "easeOut" },
|
|
11
|
+
},
|
|
12
|
+
} as const;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export { RadioGroupAnimated, RadioGroupItemAnimated } from "./radio-group-animated";
|
|
4
|
+
export type {
|
|
5
|
+
RadioGroupAnimatedProps,
|
|
6
|
+
RadioGroupAnimation,
|
|
7
|
+
RadioGroupAnimationPresets,
|
|
8
|
+
RadioGroupItemAnimatedProps,
|
|
9
|
+
} from "./types";
|
|
10
|
+
export { radioGroupAnimationPresets } from "./animations";
|