@kloudlite/design-system
Version:
A design system for building ambitious products.
151 lines (147 loc) • 4.23 kB
JavaScript
"use client";
// components/atoms/action-list.tsx
import { LayoutGroup, motion } from "framer-motion";
import React, { useId, useMemo as useMemo2 } from "react";
// components/utils.tsx
import classNames from "classnames";
import { useMemo } from "react";
import { v4 } from "uuid";
var cn = (...props) => {
return classNames(...props);
};
// components/atoms/action-list.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var Item = ({
children,
disabled = false,
critical = false,
active = false,
onClick = () => {
},
to = "",
prefix,
suffix,
LinkComponent = "div",
// eslint-disable-next-line no-unused-vars
showIndicator = true
}) => {
let Component = LinkComponent;
if (to) {
if (LinkComponent === "div") {
Component = "a";
} else {
Component = LinkComponent;
}
}
return /* @__PURE__ */ jsxs("div", { className: cn("kl-w-full kl-flex kl-flex-row kl-gap-x-md"), children: [
active && showIndicator && /* @__PURE__ */ jsx(
motion.div,
{
layoutId: "line",
className: "kl-w-sm kl-bg-icon-primary kl-rounded"
}
),
!active && showIndicator && /* @__PURE__ */ jsx(
motion.div,
{
layoutId: "line_1",
className: "kl-w-sm kl-bg-transparent kl-rounded"
}
),
/* @__PURE__ */ jsxs(
Component,
{
...Component === "a" ? { href: to } : { to },
className: cn(
"kl-transition-all kl-w-[inherit] kl-rounded kl-border kl-flex kl-gap-lg kl-items-center kl-justify-between kl-cursor-pointer kl-outline-none kl-border-none kl-py-lg kl-ring-offset-1 focus-visible:kl-ring-2 focus:kl-ring-border-focus",
{
"kl-px-2xl": showIndicator,
"kl-text-text-soft hover:kl-text-text-default": !active && !disabled && !critical && showIndicator,
"kl-text-text-primary kl-bodyMd-medium": active && showIndicator,
bodyMd: !active || !showIndicator,
"kl-text-text-default kl-px-xl": !showIndicator,
"kl-text-text-disabled": disabled,
"kl-text-text-critical hover:kl-text-text-on-primary active:kl-text-text-on-primary": critical
},
{
"kl-pointer-events-none": disabled
},
{
"kl-bg-none hover:kl-bg-surface-basic-hovered active:kl-bg-surface-basic-pressed": !active && !disabled && !critical,
"kl-bg-none hover:kl-bg-surface-critical-hovered active:kl-bg-surface-critical-pressed": !active && !disabled && critical,
"kl-bg-none": disabled,
"kl-bg-surface-basic-active": !critical && active
}
),
onClick: !critical ? onClick : null,
children: [
/* @__PURE__ */ jsxs("div", { className: "kl-flex kl-flex-row kl-items-center kl-gap-lg", children: [
!!prefix && React.cloneElement(prefix, { size: 16, color: "currentColor" }),
children
] }),
suffix && React.cloneElement(suffix, { size: 16, color: "currentColor" })
]
}
)
] });
};
var ItemBase = ({
children,
prefix,
suffix,
value,
to,
disabled,
critical
}) => {
return /* @__PURE__ */ jsx(
Item,
{
prefix,
suffix,
value,
to,
disabled,
critical,
children
}
);
};
var Root = ({
children,
value,
onChange = () => {
},
LinkComponent,
showIndicator = true,
onClick,
className
}) => {
const props = { children, value, onChange, LinkComponent };
let id = useId();
id = useMemo2(() => id, [props]);
return /* @__PURE__ */ jsx("div", { className: cn("kl-flex kl-flex-col kl-gap-y-md", className), children: /* @__PURE__ */ jsx(LayoutGroup, { id, children: React.Children.map(children, (child) => /* @__PURE__ */ jsx(
Item,
{
...child.props,
LinkComponent,
onClick: (e) => {
if (onChange)
onChange(child.props?.value);
onClick?.(e, child.props.to);
},
active: child.props.value === value,
showIndicator
}
)) }) });
};
var ActionList = {
Root,
Item: ItemBase
};
var action_list_default = ActionList;
export {
Item,
Root,
action_list_default as default
};