UNPKG

@helpwave/hightide

Version:

helpwave's component and theming library

326 lines (313 loc) 11.2 kB
"use strict"; 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/properties/CheckboxProperty.tsx var CheckboxProperty_exports = {}; __export(CheckboxProperty_exports, { CheckboxProperty: () => CheckboxProperty }); module.exports = __toCommonJS(CheckboxProperty_exports); var import_lucide_react3 = require("lucide-react"); // src/util/noop.ts var noop = () => void 0; // src/components/user-input/Checkbox.tsx var import_react = require("react"); var CheckboxPrimitive = __toESM(require("@radix-ui/react-checkbox")); var import_lucide_react = require("lucide-react"); var import_clsx = __toESM(require("clsx")); // src/components/user-input/Label.tsx 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", ...props }) => { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { ...props, children: children ? children : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: styleMapping[labelType], children: name }) }); }; // src/components/user-input/Checkbox.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var checkboxSizeMapping = { small: "size-4", medium: "size-6", large: "size-8" }; var checkboxIconSizeMapping = { small: "size-3", medium: "size-5", large: "size-7" }; var ControlledCheckbox = ({ 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 = () => { const newValue = checked === "indeterminate" ? false : !checked; propagateChange(newValue); }; return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: (0, import_clsx.default)("row justify-center items-center", containerClassName), children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( CheckboxPrimitive.Root, { onCheckedChange: propagateChange, checked, disabled, id, className: (0, import_clsx.default)(usedSizeClass, `items-center border-2 rounded outline-none focus:border-primary`, { "text-disabled-text border-disabled-text": disabled, "border-on-background": !disabled, "bg-primary/30 border-primary text-primary": checked === true || checked === "indeterminate", "hover:border-gray-400 focus:hover:border-primary": !checked }, 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_clsx.default)("cursor-pointer", label.className), htmlFor: id, onClick: changeValue }) ] }); }; // src/hooks/useLanguage.tsx var import_react3 = require("react"); // src/hooks/useLocalStorage.tsx var import_react2 = require("react"); // src/hooks/useLanguage.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); var DEFAULT_LANGUAGE = "en"; var LanguageContext = (0, import_react3.createContext)({ language: DEFAULT_LANGUAGE, setLanguage: (v) => v }); var useLanguage = () => (0, import_react3.useContext)(LanguageContext); // src/hooks/useTranslation.ts var useTranslation = (defaults, translationOverwrite = {}) => { const { language: languageProp, translation: overwrite } = translationOverwrite; const { language: inferredLanguage } = useLanguage(); const usedLanguage = languageProp ?? inferredLanguage; let defaultValues = defaults[usedLanguage]; if (overwrite && overwrite[usedLanguage]) { defaultValues = { ...defaultValues, ...overwrite[usedLanguage] }; } return defaultValues; }; // src/components/properties/PropertyBase.tsx var import_lucide_react2 = require("lucide-react"); var import_clsx3 = __toESM(require("clsx")); // src/components/Button.tsx var import_clsx2 = __toESM(require("clsx")); var import_jsx_runtime4 = require("react/jsx-runtime"); var ButtonSizePaddings = { small: "btn-sm", medium: "btn-md", large: "btn-lg" }; var TextButton = ({ children, disabled = false, color = "neutral", size = "medium", startIcon, endIcon, onClick, className, ...restProps }) => { const colorClasses = { negative: "bg-transparent text-button-text-negative-text", neutral: "bg-transparent text-button-text-neutral-text" }[color]; const iconColorClasses = { negative: "text-button-text-negative-icon", neutral: "text-button-text-neutral-icon" }[color]; return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)( "button", { onClick: disabled ? void 0 : onClick, disabled: disabled || onClick === void 0, className: (0, import_clsx2.default)( className, { "text-disabled-text": disabled, [(0, import_clsx2.default)(colorClasses, "hover:bg-button-text-hover-background rounded-full")]: !disabled }, ButtonSizePaddings[size] ), ...restProps, children: [ startIcon && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( "span", { className: (0, import_clsx2.default)({ [iconColorClasses]: !disabled, [`text-disabled-icon`]: disabled }), children: startIcon } ), children, endIcon && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( "span", { className: (0, import_clsx2.default)({ [iconColorClasses]: !disabled, [`text-disabled-icon`]: disabled }), children: endIcon } ) ] } ); }; // src/components/properties/PropertyBase.tsx var import_jsx_runtime5 = require("react/jsx-runtime"); var defaultPropertyBaseTranslation = { en: { remove: "Remove" }, de: { remove: "Entfernen" } }; var PropertyBase = ({ overwriteTranslation, name, input, softRequired = false, hasValue, icon, readOnly, onRemove, className = "" }) => { const translation = useTranslation(defaultPropertyBaseTranslation, overwriteTranslation); const requiredAndNoValue = softRequired && !hasValue; return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: (0, import_clsx3.default)("row gap-x-0 group", className), children: [ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)( "div", { className: (0, import_clsx3.default)("row gap-x-2 !w-[200px] px-4 py-2 items-center rounded-l-xl border-2 border-r-0", { "bg-gray-100 text-black group-hover:border-primary border-gray-400": !requiredAndNoValue, "bg-warning text-surface-warning group-hover:border-warning border-warning/90": requiredAndNoValue }, className), children: [ icon, name ] } ), /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)( "div", { className: (0, import_clsx3.default)("row grow justify-between items-center rounded-r-xl border-2 border-l-0", { "bg-white group-hover:border-primary border-gray-400": !requiredAndNoValue, "bg-surface-warning group-hover:border-warning border-warning/90": requiredAndNoValue }, className), children: [ input({ softRequired, hasValue }), requiredAndNoValue && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "text-warning pr-4", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.AlertTriangle, { size: 24 }) }), onRemove && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( TextButton, { onClick: onRemove, color: "negative", className: (0, import_clsx3.default)("pr-4 items-center", { "!text-transparent": !hasValue || readOnly }), disabled: !hasValue || readOnly, children: translation.remove } ) ] } ) ] }); }; // src/components/properties/CheckboxProperty.tsx var import_jsx_runtime6 = require("react/jsx-runtime"); var defaultCheckboxPropertyTranslation = { en: { yes: "Yes", no: "No" }, de: { yes: "Ja", no: "Nein" } }; var CheckboxProperty = ({ overwriteTranslation, value, onChange = noop, readOnly, ...baseProps }) => { const translation = useTranslation(defaultCheckboxPropertyTranslation, overwriteTranslation); return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( PropertyBase, { ...baseProps, hasValue: true, readOnly, icon: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react3.Check, { size: 16 }), input: () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "row py-2 px-4 items-center", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( ControlledCheckbox, { checked: value ?? true, disabled: readOnly, onChange, label: { name: `${translation.yes}/${translation.no}`, labelType: "labelMedium" } } ) }) } ); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { CheckboxProperty }); //# sourceMappingURL=CheckboxProperty.js.map