UNPKG

@kloudlite/design-system

Version:

A design system for building ambitious products.

163 lines (157 loc) 4.24 kB
"use client"; // components/atoms/radio.tsx import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"; import React, { cloneElement, useId } from "react"; // 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/radio.tsx import { jsx as jsx2, jsxs } from "react/jsx-runtime"; var Item2 = ({ disabled = false, value = "", children, className = "", withBounceEffect = true, labelPlacement = "right" }) => { const id = useId(); const rend = () => { return /* @__PURE__ */ jsxs( "label", { htmlFor: id, className: cn( "kl-flex kl-items-center kl-w-fit", { "kl-cursor-pointer": !disabled, "kl-flex-row-reverse": labelPlacement === "left", "kl-flex-row": labelPlacement === "right" }, className ), "aria-label": value, children: [ /* @__PURE__ */ jsx2( RadioGroupPrimitive.Item, { className: cn( "kl-w-2xl kl-h-2xl kl-outline-none kl-rounded-full kl-border pulsable pulsable-hidden kl-ring-border-focus focus:kl-ring-2 kl-transition-all kl-flex kl-items-center kl-justify-center kl-border-border-default", { "hover:kl-bg-surface-basic-hovered": !disabled, "data-[state=checked]:kl-border-border-primary": !disabled, "data-[disabled]:kl-border-border-disabled": disabled } ), value, id, disabled, "aria-label": value, children: /* @__PURE__ */ jsx2( RadioGroupPrimitive.Indicator, { className: cn("kl-block kl-w-lg kl-h-lg kl-rounded-full", { "kl-bg-icon-disabled": disabled, "kl-bg-surface-primary-default": !disabled }) } ) } ), /* @__PURE__ */ jsx2( "div", { className: cn( { "kl-text-text-disabled": disabled, "kl-text-text-default kl-cursor-pointer": !disabled }, "kl-bodyMd-medium kl-pl-lg kl-select-none kl-flex-1" ), children } ) ] } ); }; return withBounceEffect ? /* @__PURE__ */ jsx2(BounceIt, { children: rend() }) : rend(); }; var Root2 = ({ value, onChange = () => { }, label, disabled = false, children, className = "", labelPlacement = "right", withBounceEffect = true, direction = "vertical" }) => { return /* @__PURE__ */ jsxs( RadioGroupPrimitive.Root, { className: cn( "flex ", { "kl-flex-row kl-gap-x-xl": direction === "horizontal", "kl-flex-col kl-gap-y-xl": direction === "vertical" }, className ), value, "aria-label": label || "Radio choice", disabled, onValueChange: onChange, children: [ label && /* @__PURE__ */ jsx2("span", { className: "kl-bodyMd-medium", children: label }), React.Children.map( children, (child) => cloneElement(child, { labelPlacement, withBounceEffect }) ) ] } ); }; var Radio = { Root: Root2, Item: Item2 }; var radio_default = Radio; export { Item2 as Item, Root2 as Root, radio_default as default };