@helpwave/hightide
Version:
helpwave's component and theming library
175 lines (172 loc) • 5.88 kB
JavaScript
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);
// src/components/user-action/Checkbox.tsx
var Checkbox_exports = {};
__export(Checkbox_exports, {
Checkbox: () => Checkbox,
CheckboxUncontrolled: () => CheckboxUncontrolled
});
module.exports = __toCommonJS(Checkbox_exports);
var import_react = require("react");
var CheckboxPrimitive = __toESM(require("@radix-ui/react-checkbox"));
var import_lucide_react = require("lucide-react");
var import_clsx2 = __toESM(require("clsx"));
// src/components/user-action/Label.tsx
var import_clsx = __toESM(require("clsx"));
var import_jsx_runtime = require("react/jsx-runtime");
var styleMapping = {
labelSmall: "textstyle-label-sm",
labelMedium: "textstyle-label-md",
labelBig: "textstyle-label-lg"
};
var Label = ({
children,
name,
labelType = "labelSmall",
className,
...props
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { ...props, className: (0, import_clsx.default)(styleMapping[labelType], className), children: children ? children : name });
};
// src/components/user-action/Checkbox.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var checkboxSizeMapping = {
small: "size-5",
medium: "size-6",
large: "size-8"
};
var checkboxIconSizeMapping = {
small: "size-4",
medium: "size-5",
large: "size-7"
};
var Checkbox = ({
id,
label,
checked,
disabled,
onChange,
onChangeTristate,
size = "medium",
className = "",
containerClassName
}) => {
const usedSizeClass = checkboxSizeMapping[size];
const innerIconSize = checkboxIconSizeMapping[size];
const propagateChange = (checked2) => {
if (onChangeTristate) {
onChangeTristate(checked2);
}
if (onChange) {
onChange(checked2 === "indeterminate" ? false : checked2);
}
};
const changeValue = () => {
if (disabled) {
return;
}
const newValue = checked === "indeterminate" ? false : !checked;
propagateChange(newValue);
};
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
"div",
{
className: (0, import_clsx2.default)("group flex-row-2 items-center", {
"cursor-pointer": !disabled,
"cursor-not-allowed": disabled
}, containerClassName),
onClick: changeValue,
children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
CheckboxPrimitive.Root,
{
onCheckedChange: propagateChange,
checked,
disabled,
id,
className: (0, import_clsx2.default)(usedSizeClass, `items-center border-2 rounded outline-none `, {
"text-disabled-text border-disabled-outline bg-disabled-background cursor-not-allowed": disabled,
"focus:border-primary group-hover:border-primary ": !disabled,
"bg-input-background": !disabled && !checked,
"bg-primary/30 border-primary text-primary": !disabled && checked === true || checked === "indeterminate"
}, className),
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(CheckboxPrimitive.Indicator, { children: [
checked === true && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.Check, { className: innerIconSize }),
checked === "indeterminate" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.Minus, { className: innerIconSize })
] })
}
),
label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Label,
{
...label,
className: (0, import_clsx2.default)(
label.className,
{
"cursor-pointer": !disabled,
"cursor-not-allowed": disabled
}
),
htmlFor: id
}
)
]
}
);
};
var CheckboxUncontrolled = ({
onChange,
onChangeTristate,
defaultValue = false,
...props
}) => {
const [checked, setChecked] = (0, import_react.useState)(defaultValue);
const handleChange = (checked2) => {
if (onChangeTristate) {
onChangeTristate(checked2);
}
if (onChange) {
onChange(checked2 === "indeterminate" ? false : checked2);
}
setChecked(checked2);
};
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Checkbox,
{
...props,
checked,
onChangeTristate: handleChange
}
);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Checkbox,
CheckboxUncontrolled
});
//# sourceMappingURL=Checkbox.js.map