@helpwave/hightide
Version:
helpwave's component and theming library
153 lines (150 loc) • 6.94 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-input/Select.tsx
var Select_exports = {};
__export(Select_exports, {
Select: () => Select
});
module.exports = __toCommonJS(Select_exports);
var import_react = require("@headlessui/react");
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/Select.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var Select = ({
value,
label,
options,
onChange,
isHidingCurrentValue = true,
hintText = "",
showDisabledOptions = true,
isDisabled,
className,
textColor = "text-menu-text",
hoverColor = "hover:brightness-90",
additionalItems,
selectedDisplayOverwrite
}) => {
let filteredOptions = isHidingCurrentValue ? options.filter((option) => option.value !== value) : options;
if (!showDisabledOptions) {
filteredOptions = filteredOptions.filter((value2) => !value2.disabled);
}
const selectedOption = options.find((option) => option.value === value);
if (value !== void 0 && selectedOption === void 0 && selectedDisplayOverwrite === void 0) {
console.warn("The selected value is not found in the options list. This might be an error on your part or default behavior if it is complex data type on which === does not work. In case of the latter use selectedDisplayOverwrite to set your selected text or component");
}
const borderColor = "border-menu-border";
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: (0, import_clsx.default)(className), children: [
label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { ...label, labelType: label.labelType ?? "labelBig", className: (0, import_clsx.default)("mb-1", label.className) }),
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Menu, { as: "div", className: "relative text-menu-text", children: ({ open }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
import_react.Menu.Button,
{
className: (0, import_clsx.default)(
"inline-flex w-full justify-between items-center rounded-t-lg border-2 px-4 py-2 font-medium bg-menu-background text-menu-text",
textColor,
borderColor,
{
"rounded-b-lg": !open,
[hoverColor]: !isDisabled,
"bg-disabled-background cursor-not-allowed text-disabled": isDisabled
}
),
disabled: isDisabled,
children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: selectedDisplayOverwrite ?? selectedOption?.label ?? hintText }),
open ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.ChevronUp, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_lucide_react.ChevronDown, {})
]
}
),
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
import_react.Menu.Items,
{
className: "absolute w-full z-10 rounded-b-lg bg-menu-background text-menu-text shadow-lg max-h-[500px] overflow-y-auto",
children: [
(additionalItems ?? []).map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
className: (0, import_clsx.default)(borderColor, "px-4 py-2 overflow-hidden whitespace-nowrap text-ellipsis border-2 border-t-0", {
"border-b-0 rounded-b-lg": filteredOptions.length === 0 && index === (additionalItems?.length ?? 1) - 1
}),
children: item
},
`additionalItems${index}`
)),
filteredOptions.map((option, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react.Menu.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
className: (0, import_clsx.default)(
"px-4 py-2 overflow-hidden whitespace-nowrap text-ellipsis border-2 border-t-0 cursor-pointer",
option.className,
borderColor,
{
"brightness-90": option.value === value,
"brightness-95": index % 2 === 1,
"text-disabled bg-disabled-background cursor-not-allowed": !!option.disabled,
"bg-menu-background text-menu-text hover:brightness-90 cursor-pointer": !option.disabled,
"rounded-b-lg": index === filteredOptions.length - 1
}
),
onClick: () => {
if (!option.disabled) {
onChange(option.value);
}
},
children: option.label
}
) }, `item${index}`))
]
}
)
] }) })
] });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Select
});
//# sourceMappingURL=Select.js.map