@kloudlite/design-system
Version:
A design system for building ambitious products.
150 lines (144 loc) • 4.58 kB
JavaScript
"use client";
// components/atoms/checkbox.tsx
import { useId } from "react";
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
// components/bounce-it.tsx
import { motion } from "framer-motion";
// components/utils.tsx
import classNames from "classnames";
import { useMemo } from "react";
import { v4 } from "uuid";
var cn = (...props) => {
return classNames(...props);
};
// components/bounce-it.tsx
import { jsx } from "react/jsx-runtime";
var BounceIt = ({
disable = false,
onClick = (_) => {
},
className = "",
...etc
}) => {
if (disable) {
return /* @__PURE__ */ jsx("div", { children: etc.children });
}
return /* @__PURE__ */ jsx(
motion.div,
{
tabIndex: -1,
className: cn("kl-inline-block", className),
initial: { y: 0 },
whileTap: { y: 0.5 },
transition: { ease: "anticipate", duration: 0.1 },
onClick,
...etc
}
);
};
// components/atoms/checkbox.tsx
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
var Checkbox = ({
checked,
onChange = () => {
},
disabled = false,
error = false,
indeterminate = false,
label,
withBounceEffect
}) => {
const id = useId();
const rend = () => {
return /* @__PURE__ */ jsxs("div", { className: cn("kl-flex kl-items-center kl-justify-center kl-w-fit"), children: [
/* @__PURE__ */ jsx2(
CheckboxPrimitive.Root,
{
className: cn(
"kl-rounded kl-flex kl-flex-row kl-items-center kl-justify-center kl-border kl-w-2xl kl-h-2xl kl-outline-none kl-transition-all kl-cursor-pointer",
"kl-ring-border-focus kl-ring-offset-1 focus:kl-ring-2",
{
"kl-border-border-disabled !kl-cursor-default": disabled
},
{
"kl-bg-surface-basic-default kl-border-border-default": !checked && !disabled && !error,
"kl-bg-surface-critical-subdued kl-border-border-critical": !checked && !disabled && error,
"kl-bg-surface-primary-default kl-border-border-primary": !!checked && !error && !disabled,
"kl-bg-surface-critical-default kl-border-border-critical": !!checked && error && !disabled,
"hover:kl-bg-surface-basic-hovered": !checked && !disabled
}
),
defaultChecked: true,
id,
checked: !!checked,
onCheckedChange: (e) => {
let c = checked;
if (indeterminate) {
if (checked === "indeterminate")
c = false;
c = "indeterminate";
}
c = e;
onChange?.(c);
},
disabled,
children: /* @__PURE__ */ jsx2(CheckboxPrimitive.Indicator, { children: /* @__PURE__ */ jsxs(
"svg",
{
width: "14",
height: "14",
viewBox: "0 0 14 14",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
children: [
checked === true && /* @__PURE__ */ jsx2(
"path",
{
d: "M12.25 3.50017L5.25 10.4999L1.75 7.00017",
strokeLinecap: "round",
strokeLinejoin: "round",
className: cn({
"kl-stroke-text-disabled": disabled,
"kl-stroke-text-on-primary": !disabled
})
}
),
checked === "indeterminate" && /* @__PURE__ */ jsx2(
"path",
{
d: "M1.75 7H12.25",
strokeLinecap: "round",
strokeLinejoin: "round",
className: cn({
"kl-stroke-text-disabled": disabled,
"kl-stroke-text-on-primary": !disabled
})
}
)
]
}
) })
}
),
label && /* @__PURE__ */ jsx2(
"label",
{
className: cn(
{
"kl-text-text-disabled": disabled,
"kl-text-text-default kl-cursor-pointer": !disabled && !error,
"kl-text-text-critical kl-cursor-pointer": !disabled && error
},
"kl-bodyMd kl-pl-lg kl-select-none"
),
htmlFor: id,
children: label
}
)
] });
};
return withBounceEffect ? /* @__PURE__ */ jsx2(BounceIt, { children: rend() }) : rend();
};
export {
Checkbox
};