@kloudlite/design-system
Version:
A design system for building ambitious products.
124 lines (120 loc) • 4.61 kB
JavaScript
;
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// components/atoms/switch.tsx
var switch_exports = {};
__export(switch_exports, {
Switch: () => Switch
});
module.exports = __toCommonJS(switch_exports);
var import_react2 = require("react");
var SwitchPrimitive = __toESM(require("@radix-ui/react-switch"), 1);
// components/utils.tsx
var import_classnames = __toESM(require("classnames"), 1);
var import_react = require("react");
var import_uuid = require("uuid");
var cn = (...props) => {
return (0, import_classnames.default)(...props);
};
// components/atoms/switch.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var Switch = ({
checked: c = false,
onChange = () => {
},
disabled = false,
label
}) => {
const id = (0, import_react2.useId)();
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "kl-flex kl-gap-lg kl-items-center kl-w-fit", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
SwitchPrimitive.Root,
{
className: cn(
"kl-transition-all kl-w-7xl kl-rounded-full kl-border kl-flex kl-items-center kl-p-sm kl-cursor-pointer",
"kl-ring-border-focus kl-ring-offset-1 focus:kl-ring-2 kl-outline-none",
{
"data-[state=unchecked]:kl-bg-surface-basic-default data-[state=unchecked]:kl-border-border-default": !disabled
},
{
"data-[state=checked]:kl-bg-surface-primary-default data-[state=checked]:kl-border-border-primary": !disabled
},
{
"data-[disabled]:kl-bg-surface-basic-default data-[disabled]:kl-border-border-disabled data-[disabled]:!kl-cursor-default": disabled
}
),
id,
disabled,
checked: c,
onCheckedChange: onChange,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
SwitchPrimitive.Thumb,
{
className: cn(
"kl-group kl-rounded-full kl-translate-x-0 kl-transition-all kl-duration-200 data-[state=checked]:kl-translate-x-full"
),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"svg",
{
width: "21",
height: "21",
viewBox: "0 0 22 22",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
className: cn(
{
"group-data-[disabled]:kl-fill-icon-disabled": disabled
},
{
"group-data-[state=unchecked]:kl-fill-surface-primary-default group-data-[state=checked]:kl-fill-surface-basic-default": !disabled
}
),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "11", cy: "11", r: "10.5" })
}
)
}
)
}
),
label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"label",
{
className: cn(
{
"kl-text-text-disabled": disabled,
"kl-text-text-default kl-cursor-pointer": !disabled
},
"kl-bodyMd-medium kl-select-none"
),
htmlFor: id,
children: label
}
)
] });
};