UNPKG

@sikka/hawa

Version:

Modern UI Kit made with Tailwind

469 lines (460 loc) • 19.2 kB
"use client"; "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); // elements/radio/index.ts var radio_exports = {}; __export(radio_exports, { Radio: () => Radio }); module.exports = __toCommonJS(radio_exports); // elements/radio/Radio.tsx var import_react3 = __toESM(require("react")); // util/index.ts var import_clsx = require("clsx"); var import_tailwind_merge = require("tailwind-merge"); function cn(...inputs) { return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs)); } // elements/helperText/HelperText.tsx var import_react = __toESM(require("react")); var HelperText = ({ helperText }) => /* @__PURE__ */ import_react.default.createElement( "p", { className: cn( "hawa-my-0 hawa-text-start hawa-text-xs hawa-text-helper-color hawa-transition-all", helperText ? "hawa-h-4 hawa-opacity-100" : "hawa-h-0 hawa-opacity-0" ) }, helperText ); // elements/label/Label.tsx var React3 = __toESM(require("react")); // elements/tooltip/Tooltip.tsx var import_react2 = __toESM(require("react")); var TooltipPrimitive = __toESM(require("@radix-ui/react-tooltip")); var TooltipContent = import_react2.default.forwardRef(({ className, sideOffset = 4, size = "default", ...props }, ref) => /* @__PURE__ */ import_react2.default.createElement( TooltipPrimitive.Content, { ref, sideOffset, className: cn( "hawa-z-50 hawa-overflow-hidden hawa-rounded-md hawa-border hawa-bg-popover hawa-px-3 hawa-py-1.5 hawa-text-sm hawa-text-popover-foreground hawa-shadow-md hawa-animate-in hawa-fade-in-0 hawa-zoom-in-95 data-[state=closed]:hawa-animate-out data-[state=closed]:hawa-fade-out-0 data-[state=closed]:hawa-zoom-out-95 data-[side=bottom]:hawa-slide-in-from-top-2 data-[side=left]:hawa-slide-in-from-right-2 data-[side=right]:hawa-slide-in-from-left-2 data-[side=top]:hawa-slide-in-from-bottom-2", { "hawa-text-xs": size === "small", "hawa-text-xl": size === "large" }, className ), ...props } )); TooltipContent.displayName = TooltipPrimitive.Content.displayName; var TooltipArrow = import_react2.default.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ import_react2.default.createElement(TooltipPrimitive.Arrow, { ref, className: cn(className), ...props })); TooltipArrow.displayName = TooltipPrimitive.Arrow.displayName; var Tooltip = ({ side, size, open, content, children, disabled, defaultOpen, onOpenChange, triggerProps, contentProps, providerProps, delayDuration = 300, ...props }) => { return /* @__PURE__ */ import_react2.default.createElement( TooltipPrimitive.TooltipProvider, { delayDuration, ...providerProps }, /* @__PURE__ */ import_react2.default.createElement( TooltipPrimitive.Root, { open: !disabled && open, defaultOpen, onOpenChange, ...props }, /* @__PURE__ */ import_react2.default.createElement(TooltipPrimitive.Trigger, { ...triggerProps }, children), /* @__PURE__ */ import_react2.default.createElement( TooltipContent, { size, side, align: "center", ...contentProps, style: { ...contentProps == null ? void 0 : contentProps.style, maxWidth: "var(--radix-tooltip-content-available-width)", maxHeight: "var(--radix-tooltip-content-available-height)" } }, content ) ) ); }; // elements/label/Label.tsx var Label = React3.forwardRef(({ className, hint, hintSide, required, children, ...props }, ref) => /* @__PURE__ */ React3.createElement("div", { className: "hawa-flex hawa-flex-row hawa-items-center hawa-gap-1 hawa-transition-all" }, /* @__PURE__ */ React3.createElement( "label", { ref, className: cn( "hawa-text-sm hawa-font-medium hawa-leading-none peer-disabled:hawa-cursor-not-allowed peer-disabled:hawa-opacity-70", className ), ...props }, children, required && /* @__PURE__ */ React3.createElement("span", { className: "hawa-mx-0.5 hawa-text-red-500" }, "*") ), hint && /* @__PURE__ */ React3.createElement( Tooltip, { content: hint, side: hintSide, triggerProps: { tabIndex: -1, onClick: (event) => event.preventDefault() } }, /* @__PURE__ */ React3.createElement("div", null, /* @__PURE__ */ React3.createElement( "svg", { xmlns: "http://www.w3.org/2000/svg", className: "hawa-h-[14px] hawa-w-[14px] hawa-cursor-help", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }, /* @__PURE__ */ React3.createElement("circle", { cx: "12", cy: "12", r: "10" }), /* @__PURE__ */ React3.createElement("path", { d: "M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3" }), /* @__PURE__ */ React3.createElement("path", { d: "M12 17h.01" }) )) ))); Label.displayName = "Label"; // elements/popover/Popover.tsx var React4 = __toESM(require("react")); var PopoverPrimitive = __toESM(require("@radix-ui/react-popover")); var PopoverContent = React4.forwardRef( ({ className, align = "center", sideOffset = 4, container, ...props }, ref) => /* @__PURE__ */ React4.createElement(PopoverPrimitive.Portal, { container }, /* @__PURE__ */ React4.createElement( PopoverPrimitive.Content, { ref, align, sideOffset, className: cn( "dark:dark-shadow hawa-z-50 hawa-rounded hawa-border hawa-bg-popover hawa-text-popover-foreground hawa-shadow-md hawa-outline-none data-[state=open]:hawa-animate-in data-[state=closed]:hawa-animate-out data-[state=closed]:hawa-fade-out-0 data-[state=open]:hawa-fade-in-0 data-[state=closed]:hawa-zoom-out-95 data-[state=open]:hawa-zoom-in-95 data-[side=bottom]:hawa-slide-in-from-top-2 data-[side=left]:hawa-slide-in-from-right-2 data-[side=right]:hawa-slide-in-from-left-2 data-[side=top]:hawa-slide-in-from-bottom-2", className ), ...props } )) ); PopoverContent.displayName = PopoverPrimitive.Content.displayName; var PopoverTrigger = PopoverPrimitive.Trigger; var PopoverRoot = PopoverPrimitive.Root; // elements/radio/Radio.tsx var Radio = (0, import_react3.forwardRef)( ({ design = "default", width = "default", size = "default", orientation = "horizontal", name, labelProps, tabsContainerClassName, forceHideHelperText = false, onChange, containerClassNames, ...props }, ref) => { var _a, _b, _c; let activeTabStyle = "hawa-inline-block hawa-w-full hawa-text-primary-foreground hawa-bg-primary hawa-active dark:hawa-bg-primary"; let inactiveTabStyle = `hawa-inline-block hawa-w-full hawa-transition-all hawa-bg-primary-foreground dark:hover:hawa-text-white ${props.disabled ? "" : "hover:hawa-bg-muted"}`; let orientationStyle = { horizontal: "hawa-flex hawa-flex-row", vertical: "hawa-flex hawa-flex-col" }; let tabSizeStyle = { default: "hawa-py-2 hawa-px-4 hawa-text-sm", lg: "hawa-py-2 hawa-px-4", sm: "hawa-p-1.5 hawa-text-xs", xs: "hawa-p-1 hawa-text-[10px]" }; let widthStyle = { none: "", default: "hawa-max-w-fit", full: "hawa-w-full" }; const [parentDirection, setParentDirection] = import_react3.default.useState( null ); const [selectedOption, setSelectedOption] = (0, import_react3.useState)( props.defaultValue || props.value ); const [openTooltip, setOpenTooltip] = (0, import_react3.useState)(null); const parentRef = (0, import_react3.useRef)(null); (0, import_react3.useEffect)(() => { var _a2; const parentNode = (_a2 = parentRef.current) == null ? void 0 : _a2.parentNode; if (parentNode) { const dir = window.getComputedStyle(parentNode).direction; setParentDirection(dir); } }); const handleChange = (opt) => { setSelectedOption(opt.value); if (onChange) { onChange(opt.value); } else { console.log("onChange was not provided"); } }; const radio_option_tabs_styling = [ "hawa-w-full hawa-last hawa-flex hawa-flex-row hawa-items-center hawa-justify-center hawa-gap-2 ", !props.disabled && "hawa-cursor-pointer", orientation === "horizontal" && parentDirection === "ltr" && "hawa-rounded-none first:hawa-rounded-l last:hawa-rounded-r", orientation === "horizontal" && parentDirection === "rtl" && "hawa-rounded-none first:hawa-rounded-r last:hawa-rounded-l", orientation === "vertical" && "hawa-rounded-none first:hawa-rounded-t last:hawa-rounded-b", tabSizeStyle[size] ]; switch (design) { case "tabs": return /* @__PURE__ */ import_react3.default.createElement( "div", { className: cn( "hawa-gap-2 hawa-flex hawa-flex-col", containerClassNames == null ? void 0 : containerClassNames.tabs ) }, props.label && /* @__PURE__ */ import_react3.default.createElement(Label, { ...labelProps }, props.label), /* @__PURE__ */ import_react3.default.createElement( "ul", { ref: parentRef, className: cn( props.options && ((_a = props.options) == null ? void 0 : _a.length) > 2 ? "hawa-flex-wrap xs:hawa-max-w-full xs:hawa-flex-nowrap" : "", "hawa-select-none hawa-whitespace-nowrap hawa-rounded hawa-border hawa-text-center hawa-font-medium hawa-h-[40px]", orientationStyle[orientation], widthStyle[width], tabsContainerClassName ) }, (_b = props.options) == null ? void 0 : _b.map((opt, o) => { return opt.tooltip ? /* @__PURE__ */ import_react3.default.createElement( PopoverRoot, { key: o, open: o === openTooltip, onOpenChange: (bool) => setOpenTooltip(bool ? o : null) }, /* @__PURE__ */ import_react3.default.createElement( PopoverTrigger, { onMouseEnter: () => setOpenTooltip(o), onMouseLeave: () => setOpenTooltip(null), asChild: true }, /* @__PURE__ */ import_react3.default.createElement( "li", { "aria-current": "page", onClick: () => { if (props.disabled || opt.disabled) return; handleChange(opt); }, className: cn( ...radio_option_tabs_styling, selectedOption === opt.value ? activeTabStyle : inactiveTabStyle ) }, opt.icon && opt.icon, opt.label ) ), /* @__PURE__ */ import_react3.default.createElement(PopoverContent, { ...opt.tooltipContentProps }, opt.tooltip) ) : /* @__PURE__ */ import_react3.default.createElement( "li", { key: o, "aria-current": "page", onClick: () => { if (props.disabled || opt.disabled) return; handleChange(opt); }, className: cn( ...radio_option_tabs_styling, selectedOption === opt.value ? activeTabStyle : inactiveTabStyle ) }, opt.icon && opt.icon, opt.label ); }) ), !forceHideHelperText && /* @__PURE__ */ import_react3.default.createElement(HelperText, { helperText: props.helperText }) ); case "bordered": return /* @__PURE__ */ import_react3.default.createElement( "div", { className: cn( orientationStyle[orientation], "hawa-gap-4", containerClassNames == null ? void 0 : containerClassNames.bordered ) }, props.options && props.options.map((opt, i) => /* @__PURE__ */ import_react3.default.createElement("div", { key: i, className: "hawa-w-full hawa-rounded hawa-border" }, /* @__PURE__ */ import_react3.default.createElement( "div", { className: cn( "radio-item radio-item-bordered hawa-flex hawa-items-center hawa-transition-all", props.direction === "rtl" ? "margin-left right-19px" : "margin-right left-23px" ), key: i + 1 }, /* @__PURE__ */ import_react3.default.createElement( "input", { disabled: opt.disabled, id: opt.value.toString(), type: "radio", value: opt.value, name, onChange: () => handleChange(opt) } ), /* @__PURE__ */ import_react3.default.createElement( "label", { htmlFor: opt.value.toString(), className: cn( "hawa-ml-2 hawa-w-full hawa-select-none hawa-p-4 hawa-pl-3 hawa-text-sm hawa-font-medium hawa-text-black dark:hawa-text-white", opt.disabled ? "hawa-opacity-50" : "hawa-cursor-pointer hawa-text-gray-900" ) }, opt.label ) ))) ); case "cards": return /* @__PURE__ */ import_react3.default.createElement( "ul", { className: cn( orientationStyle[orientation], "hawa-gap-4", containerClassNames == null ? void 0 : containerClassNames.cards ) }, (_c = props.options) == null ? void 0 : _c.map((opt, o) => /* @__PURE__ */ import_react3.default.createElement("li", { key: o, onClick: () => handleChange(opt) }, /* @__PURE__ */ import_react3.default.createElement( "input", { type: "radio", id: opt.value.toString(), name, value: opt.value.toString(), className: "hawa-peer hawa-hidden", required: true, disabled: opt.disabled } ), /* @__PURE__ */ import_react3.default.createElement( "label", { htmlFor: opt.value.toString(), className: cn( "hawa-inline-flex hawa-h-full hawa-w-full hawa-transition-all hawa-items-center hawa-justify-between hawa-rounded-lg hawa-border hawa-border-foreground/10 hawa-bg-background hawa-p-5 hawa-text-gray-500 peer-checked:hawa-border-primary peer-checked:hawa-text-primary dark:hawa-border-foreground/10 dark:hawa-bg-foreground/5 dark:hawa-text-gray-400 dark:peer-checked:hawa-text-primary", opt.disabled ? "hawa-opacity-50" : "hawa-cursor-pointer hover:hawa-bg-foreground/10 hover:hawa-text-gray-600 dark:hover:hawa-bg-foreground/20 dark:hover:hawa-text-gray-300" ) }, /* @__PURE__ */ import_react3.default.createElement("div", { className: "hawa-block hawa-h-full hawa-w-full" }, /* @__PURE__ */ import_react3.default.createElement("div", { className: "hawa-w-full hawa-text-lg hawa-font-semibold" }, opt.label), /* @__PURE__ */ import_react3.default.createElement("div", { className: "hawa-w-full" }, opt.sublabel)) ))) ); default: return /* @__PURE__ */ import_react3.default.createElement( "div", { className: cn( "hawa-flex hawa-flex-col hawa-gap-2", containerClassNames == null ? void 0 : containerClassNames.default ) }, props.label && /* @__PURE__ */ import_react3.default.createElement(Label, { ...labelProps }, props.label), /* @__PURE__ */ import_react3.default.createElement("div", { className: cn(orientationStyle[orientation], "hawa-gap-2") }, props.options && props.options.map((opt, i) => /* @__PURE__ */ import_react3.default.createElement( "div", { className: cn( "radio-item radio-item-default hawa-flex hawa-items-center hawa-transition-all", props.direction === "rtl" ? "margin-left right-3px" : "margin-right left-3px" ), key: i + 1 }, /* @__PURE__ */ import_react3.default.createElement( "input", { disabled: opt.disabled, id: opt.value.toString(), type: "radio", value: opt.value, name, onChange: () => handleChange(opt) } ), /* @__PURE__ */ import_react3.default.createElement( "label", { htmlFor: opt.value.toString(), className: cn( "hawa-text-sm hawa-font-medium dark:hawa-text-white", opt.disabled ? "hawa-text-gray-400" : "hawa-cursor-pointer hawa-text-gray-900" ) }, opt.label ) ))), /* @__PURE__ */ import_react3.default.createElement(HelperText, { helperText: props.helperText }) ); } } ); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Radio }); //# sourceMappingURL=index.js.map