@helpwave/hightide
Version:
helpwave's component and theming library
816 lines (792 loc) • 27.7 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/properties/MultiSelectProperty.tsx
var MultiSelectProperty_exports = {};
__export(MultiSelectProperty_exports, {
MultiSelectProperty: () => MultiSelectProperty
});
module.exports = __toCommonJS(MultiSelectProperty_exports);
var import_lucide_react4 = require("lucide-react");
var import_clsx8 = __toESM(require("clsx"));
// src/hooks/useLanguage.tsx
var import_react2 = require("react");
// src/hooks/useLocalStorage.tsx
var import_react = require("react");
// src/hooks/useLanguage.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var DEFAULT_LANGUAGE = "en";
var LanguageContext = (0, import_react2.createContext)({ language: DEFAULT_LANGUAGE, setLanguage: (v) => v });
var useLanguage = () => (0, import_react2.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/user-input/MultiSelect.tsx
var import_react9 = require("react");
var import_lucide_react2 = require("lucide-react");
// src/util/simpleSearch.ts
var MultiSearchWithMapping = (search, objects, mapping) => {
return objects.filter((object) => {
const mappedSearchKeywords = mapping(object).map((value) => value.toLowerCase().trim());
return !!mappedSearchKeywords.find((value) => value.includes(search.toLowerCase().trim()));
});
};
// src/components/user-input/MultiSelect.tsx
var import_clsx4 = __toESM(require("clsx"));
// src/components/user-input/Menu.tsx
var import_react5 = require("react");
var import_clsx = __toESM(require("clsx"));
// src/hooks/useOutsideClick.ts
var import_react3 = require("react");
var useOutsideClick = (refs, handler) => {
(0, import_react3.useEffect)(() => {
const listener = (event) => {
if (event.target === null) return;
if (refs.some((ref) => !ref.current || ref.current.contains(event.target))) {
return;
}
handler();
};
document.addEventListener("mousedown", listener);
document.addEventListener("touchstart", listener);
return () => {
document.removeEventListener("mousedown", listener);
document.removeEventListener("touchstart", listener);
};
}, [refs, handler]);
};
// src/hooks/useHoverState.ts
var import_react4 = require("react");
var defaultUseHoverStateProps = {
closingDelay: 200,
isDisabled: false
};
var useHoverState = (props = void 0) => {
const { closingDelay, isDisabled } = { ...defaultUseHoverStateProps, ...props };
const [isHovered, setIsHovered] = (0, import_react4.useState)(false);
const [timer, setTimer] = (0, import_react4.useState)();
const onMouseEnter = () => {
if (isDisabled) {
return;
}
clearTimeout(timer);
setIsHovered(true);
};
const onMouseLeave = () => {
if (isDisabled) {
return;
}
setTimer(setTimeout(() => {
setIsHovered(false);
}, closingDelay));
};
(0, import_react4.useEffect)(() => {
if (timer) {
return () => {
clearTimeout(timer);
};
}
});
(0, import_react4.useEffect)(() => {
if (timer) {
clearTimeout(timer);
}
}, [isDisabled]);
return {
isHovered,
setIsHovered,
handlers: { onMouseEnter, onMouseLeave }
};
};
// src/components/user-input/Menu.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var MenuItem = ({
children,
onClick,
alignment = "left",
className
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
className: (0, import_clsx.default)("block px-3 py-1 bg-menu-background text-menu-text hover:brightness-90", {
"text-right": alignment === "right",
"text-left": alignment === "left"
}, className),
onClick,
children
}
);
var Menu = ({
trigger,
children,
alignment = "tl",
showOnHover = false,
menuClassName = ""
}) => {
const { isHovered: isOpen, setIsHovered: setIsOpen, handlers } = useHoverState({ isDisabled: !showOnHover });
const triggerRef = (0, import_react5.useRef)(null);
const menuRef = (0, import_react5.useRef)(null);
useOutsideClick([triggerRef, menuRef], () => setIsOpen(false));
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
"div",
{
className: "relative",
...handlers,
children: [
trigger(() => setIsOpen(!isOpen), triggerRef),
isOpen ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
ref: menuRef,
onClick: (e) => e.stopPropagation(),
className: (0, import_clsx.default)("absolute top-full mt-1 py-2 w-60 rounded-lg bg-menu-background text-menu-text ring-1 ring-slate-900/5 text-sm leading-6 font-semibold shadow-md z-[1]", {
" top-[8px]": alignment[0] === "t",
" bottom-[8px]": alignment[0] === "b",
" left-[-8px]": alignment[1] === "l",
" right-[-8px]": alignment[1] === "r"
}, menuClassName),
children
}
) : null
]
}
);
};
// src/components/user-input/Input.tsx
var import_react7 = require("react");
var import_clsx2 = __toESM(require("clsx"));
// src/hooks/useSaveDelay.ts
var import_react6 = require("react");
function useSaveDelay(setNotificationStatus, delay) {
const [updateTimer, setUpdateTimer] = (0, import_react6.useState)(void 0);
const [notificationTimer, setNotificationTimer] = (0, import_react6.useState)(void 0);
const restartTimer = (onSave) => {
clearTimeout(updateTimer);
setUpdateTimer(setTimeout(() => {
onSave();
setNotificationStatus(true);
clearTimeout(notificationTimer);
setNotificationTimer(setTimeout(() => {
setNotificationStatus(false);
clearTimeout(notificationTimer);
}, delay));
clearTimeout(updateTimer);
}, delay));
};
const clearUpdateTimer = (hasSaved = true) => {
clearTimeout(updateTimer);
if (hasSaved) {
setNotificationStatus(true);
clearTimeout(notificationTimer);
setNotificationTimer(setTimeout(() => {
setNotificationStatus(false);
clearTimeout(notificationTimer);
}, delay));
} else {
setNotificationStatus(false);
}
};
(0, import_react6.useEffect)(() => {
return () => {
clearTimeout(updateTimer);
clearTimeout(notificationTimer);
};
}, []);
return { restartTimer, clearUpdateTimer };
}
// src/util/noop.ts
var noop = () => void 0;
// src/components/user-input/Label.tsx
var import_jsx_runtime3 = 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_runtime3.jsx)("label", { ...props, children: children ? children : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: styleMapping[labelType], children: name }) });
};
// src/components/user-input/Input.tsx
var import_jsx_runtime4 = require("react/jsx-runtime");
var ControlledInput = ({
id,
type = "text",
value,
label,
onChange = noop,
onChangeEvent = noop,
className = "",
onEditCompleted,
expanded = true,
onBlur,
containerClassName,
...restProps
}) => {
const {
restartTimer,
clearUpdateTimer
} = useSaveDelay(() => void 0, 3e3);
const ref = (0, import_react7.useRef)(null);
(0, import_react7.useEffect)(() => {
if (restProps.autoFocus) {
ref.current?.focus();
}
}, [restProps.autoFocus]);
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: (0, import_clsx2.default)({ "w-full": expanded }, containerClassName), children: [
label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Label, { ...label, htmlFor: id, className: (0, import_clsx2.default)("mb-1", label.className) }),
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"input",
{
ref,
value,
id,
type,
className: (0, import_clsx2.default)("block bg-surface text-on-surface px-3 py-2 rounded-md w-full border-2 border-gray-200 hover:border-primary focus:outline-none focus:border-primary focus:ring-primary", className),
onBlur: (event) => {
if (onBlur) {
onBlur(event);
}
if (onEditCompleted) {
onEditCompleted(event.target.value, event);
clearUpdateTimer();
}
},
onChange: (e) => {
const value2 = e.target.value;
if (onEditCompleted) {
restartTimer(() => {
onEditCompleted(value2, e);
clearUpdateTimer();
});
}
onChange(value2, e);
onChangeEvent(e);
},
...restProps
}
)
] });
};
var FormInput = (0, import_react7.forwardRef)(function FormInput2({
id,
labelText,
errorText,
className,
labelClassName,
errorClassName,
containerClassName,
required,
...restProps
}, ref) {
const input = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"input",
{
ref,
id,
...restProps,
className: (0, import_clsx2.default)(
"block bg-surface text-on-surface px-3 py-2 rounded-md w-full border-2 border-gray-200 hover:border-primary focus:outline-none focus:border-primary focus:ring-primary",
{
"focus:border-primary focus:ring-primary": !errorText,
"focus:border-negative focus:ring-negative text-negative": !!errorText
},
className
)
}
);
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: (0, import_clsx2.default)("flex flex-col gap-y-1", containerClassName), children: [
labelText && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { htmlFor: id, className: (0, import_clsx2.default)("textstyle-label-md", labelClassName), children: [
labelText,
required && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-primary font-bold", children: "*" })
] }),
input,
errorText && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: id, className: (0, import_clsx2.default)("text-negative", errorClassName), children: errorText })
] });
});
// src/components/user-input/Checkbox.tsx
var import_react8 = require("react");
var CheckboxPrimitive = __toESM(require("@radix-ui/react-checkbox"));
var import_lucide_react = require("lucide-react");
var import_clsx3 = __toESM(require("clsx"));
var import_jsx_runtime5 = 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_runtime5.jsxs)("div", { className: (0, import_clsx3.default)("row justify-center items-center", containerClassName), children: [
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
CheckboxPrimitive.Root,
{
onCheckedChange: propagateChange,
checked,
disabled,
id,
className: (0, import_clsx3.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_runtime5.jsxs)(CheckboxPrimitive.Indicator, { children: [
checked === true && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.Check, { className: innerIconSize }),
checked === "indeterminate" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.Minus, { className: innerIconSize })
] })
}
),
label && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Label, { ...label, className: (0, import_clsx3.default)("cursor-pointer", label.className), htmlFor: id, onClick: changeValue })
] });
};
// src/components/user-input/MultiSelect.tsx
var import_jsx_runtime6 = require("react/jsx-runtime");
var defaultMultiSelectTranslation = {
en: {
select: "Select",
search: "Search",
selected: "selected"
},
de: {
select: "Ausw\xE4hlen",
search: "Suche",
selected: "ausgew\xE4hlt"
}
};
var MultiSelect = ({
overwriteTranslation,
options,
onChange,
search,
disabled = false,
selectedDisplay,
label,
hintText,
showDisabledOptions = true,
className = "",
triggerClassName = ""
}) => {
const translation = useTranslation(defaultMultiSelectTranslation, overwriteTranslation);
const [searchText, setSearchText] = (0, import_react9.useState)(search?.initialSearch ?? "");
let filteredOptions = options;
const enableSearch = !!search;
if (enableSearch && !!searchText) {
filteredOptions = MultiSearchWithMapping(
searchText,
filteredOptions,
(value) => search.searchMapping(value)
);
}
if (!showDisabledOptions) {
filteredOptions = filteredOptions.filter((value) => !value.disabled);
}
const selectedItems = options.filter((value) => value.selected);
const menuButtonText = selectedItems.length === 0 ? hintText ?? translation.select : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: `${selectedItems.length} ${translation.selected}` });
const borderColor = "border-menu-border";
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: (0, import_clsx4.default)(className), children: [
label && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
Label,
{
...label,
htmlFor: label.name,
className: (0, import_clsx4.default)(" mb-1", label.className),
labelType: label.labelType ?? "labelBig"
}
),
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
Menu,
{
alignment: "t_",
trigger: (onClick, ref) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
"div",
{
ref,
onClick: disabled ? void 0 : onClick,
className: (0, import_clsx4.default)(
borderColor,
"bg-menu-background text-menu-text inline-w-full justify-between items-center rounded-lg border-2 px-4 py-2 font-medium",
{
"hover:brightness-90 hover:border-primary cursor-pointer": !disabled,
"bg-disabled-background text-disabled cursor-not-allowed": disabled
},
triggerClassName
),
children: selectedDisplay ? selectedDisplay({ items: options, disabled }) : menuButtonText
}
),
menuClassName: (0, import_clsx4.default)(
"!rounded-lg !shadow-lg !max-h-[500px] !min-w-[400px] !max-w-[70vh] !overflow-y-auto !border !border-2",
borderColor,
{ "!py-0": !enableSearch, "!pb-0": enableSearch }
),
children: [
enableSearch && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "row gap-x-2 items-center px-2 py-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ControlledInput, { autoFocus: true, value: searchText, onChange: setSearchText }),
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_lucide_react2.Search, {})
] }, "selectSearch"),
filteredOptions.map((option, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
MenuItem,
{
className: (0, import_clsx4.default)({
"cursor-not-allowed !bg-disabled-background !text-disabled-text hover:brightness-100": !!option.disabled,
"cursor-pointer": !option.disabled
}),
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
"div",
{
className: (0, import_clsx4.default)("overflow-hidden whitespace-nowrap text-ellipsis row items-center gap-x-2", option.className),
onClick: () => {
if (!option.disabled) {
onChange(options.map((value) => value.value === option.value ? {
...option,
selected: !value.selected
} : value));
}
},
children: [
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ControlledCheckbox, { checked: option.selected, disabled: option.disabled, size: "small" }),
option.label
]
}
)
},
`item${index}`
))
]
}
)
] });
};
// src/components/ChipList.tsx
var import_clsx5 = __toESM(require("clsx"));
var import_jsx_runtime7 = require("react/jsx-runtime");
var Chip = ({
children,
trailingIcon,
color = "default",
variant = "normal",
className = "",
...restProps
}) => {
const colorMapping = {
default: "text-tag-default-text bg-tag-default-background",
dark: "text-tag-dark-text bg-tag-dark-background",
red: "text-tag-red-text bg-tag-red-background",
yellow: "text-tag-yellow-text bg-tag-yellow-background",
green: "text-tag-green-text bg-tag-green-background",
blue: "text-tag-blue-text bg-tag-blue-background",
pink: "text-tag-pink-text bg-tag-pink-background"
}[color];
const colorMappingIcon = {
default: "text-tag-default-icon",
dark: "text-tag-dark-icon",
red: "text-tag-red-icon",
yellow: "text-tag-yellow-icon",
green: "text-tag-green-icon",
blue: "text-tag-blue-icon",
pink: "text-tag-pink-icon"
}[color];
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
"div",
{
...restProps,
className: (0, import_clsx5.default)(
`row w-fit px-2 py-1`,
colorMapping,
{
"rounded-md": variant === "normal",
"rounded-full": variant === "fullyRounded"
},
className
),
children: [
children,
trailingIcon && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: colorMappingIcon, children: trailingIcon })
]
}
);
};
var ChipList = ({
list,
className = ""
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: (0, import_clsx5.default)("flex flex-wrap gap-x-4 gap-y-2", className), children: list.map((value, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
Chip,
{
...value,
color: value.color ?? "dark",
variant: value.variant ?? "normal",
children: value.children
},
index
)) });
};
// src/components/properties/PropertyBase.tsx
var import_lucide_react3 = require("lucide-react");
var import_clsx7 = __toESM(require("clsx"));
// src/components/Button.tsx
var import_clsx6 = __toESM(require("clsx"));
var import_jsx_runtime8 = 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_runtime8.jsxs)(
"button",
{
onClick: disabled ? void 0 : onClick,
disabled: disabled || onClick === void 0,
className: (0, import_clsx6.default)(
className,
{
"text-disabled-text": disabled,
[(0, import_clsx6.default)(colorClasses, "hover:bg-button-text-hover-background rounded-full")]: !disabled
},
ButtonSizePaddings[size]
),
...restProps,
children: [
startIcon && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"span",
{
className: (0, import_clsx6.default)({
[iconColorClasses]: !disabled,
[`text-disabled-icon`]: disabled
}),
children: startIcon
}
),
children,
endIcon && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"span",
{
className: (0, import_clsx6.default)({
[iconColorClasses]: !disabled,
[`text-disabled-icon`]: disabled
}),
children: endIcon
}
)
]
}
);
};
// src/components/properties/PropertyBase.tsx
var import_jsx_runtime9 = 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_runtime9.jsxs)("div", { className: (0, import_clsx7.default)("row gap-x-0 group", className), children: [
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
"div",
{
className: (0, import_clsx7.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_runtime9.jsxs)(
"div",
{
className: (0, import_clsx7.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_runtime9.jsx)("div", { className: "text-warning pr-4", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_lucide_react3.AlertTriangle, { size: 24 }) }),
onRemove && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
TextButton,
{
onClick: onRemove,
color: "negative",
className: (0, import_clsx7.default)("pr-4 items-center", { "!text-transparent": !hasValue || readOnly }),
disabled: !hasValue || readOnly,
children: translation.remove
}
)
]
}
)
] });
};
// src/components/properties/MultiSelectProperty.tsx
var import_jsx_runtime10 = require("react/jsx-runtime");
var defaultMultiSelectPropertyTranslation = {
en: {
select: "Select"
},
de: {
select: "Ausw\xE4hlen"
}
};
var MultiSelectProperty = ({
overwriteTranslation,
options,
name,
readOnly = false,
softRequired,
onRemove,
...multiSelectProps
}) => {
const translation = useTranslation(defaultMultiSelectPropertyTranslation, overwriteTranslation);
const hasValue = options.some((value) => value.selected);
let triggerClassName;
if (softRequired && !hasValue) {
triggerClassName = "border-warning hover:brightness-90";
}
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
PropertyBase,
{
name,
onRemove,
readOnly,
softRequired,
hasValue,
icon: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_lucide_react4.List, { size: 16 }),
input: ({ softRequired: softRequired2 }) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
"div",
{
className: (0, import_clsx8.default)("row grow py-2 px-4 cursor-pointer", { "text-warning": softRequired2 && !hasValue }),
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
MultiSelect,
{
...multiSelectProps,
className: (0, import_clsx8.default)("w-full", { "bg-surface-warning": softRequired2 && !hasValue }),
triggerClassName,
selectedDisplay: ({ items }) => {
const selected = items.filter((value) => value.selected);
if (selected.length === 0) {
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "Select" });
}
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
ChipList,
{
list: selected.map((value) => ({ children: value.label }))
}
);
},
options,
disabled: readOnly,
hintText: `${translation.select}...`
}
)
}
)
}
);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
MultiSelectProperty
});
//# sourceMappingURL=MultiSelectProperty.js.map