UNPKG

@trail-ui/react

Version:
1,410 lines (1,385 loc) 94.4 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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); 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/editable-table/table-body/editable-table-body.tsx var editable_table_body_exports = {}; __export(editable_table_body_exports, { default: () => EditableTableBody }); module.exports = __toCommonJS(editable_table_body_exports); // src/spinner/spinner.tsx var import_theme = require("@trail-ui/theme"); var import_react = require("react"); // src/spinner/spinners/bars.tsx var import_jsx_runtime = require("react/jsx-runtime"); var Bars = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { viewBox: "0 0 135 140", xmlns: "http://www.w3.org/2000/svg", fill: "currentColor", ...props, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("rect", { y: "10", width: "15", height: "120", rx: "6", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "height", begin: "0.5s", dur: "1s", values: "120;110;100;90;80;70;60;50;40;140;120", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "y", begin: "0.5s", dur: "1s", values: "10;15;20;25;30;35;40;45;50;0;10", calcMode: "linear", repeatCount: "indefinite" } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("rect", { x: "30", y: "10", width: "15", height: "120", rx: "6", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "height", begin: "0.25s", dur: "1s", values: "120;110;100;90;80;70;60;50;40;140;120", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "y", begin: "0.25s", dur: "1s", values: "10;15;20;25;30;35;40;45;50;0;10", calcMode: "linear", repeatCount: "indefinite" } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("rect", { x: "60", width: "15", height: "140", rx: "6", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "height", begin: "0s", dur: "1s", values: "120;110;100;90;80;70;60;50;40;140;120", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "y", begin: "0s", dur: "1s", values: "10;15;20;25;30;35;40;45;50;0;10", calcMode: "linear", repeatCount: "indefinite" } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("rect", { x: "90", y: "10", width: "15", height: "120", rx: "6", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "height", begin: "0.25s", dur: "1s", values: "120;110;100;90;80;70;60;50;40;140;120", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "y", begin: "0.25s", dur: "1s", values: "10;15;20;25;30;35;40;45;50;0;10", calcMode: "linear", repeatCount: "indefinite" } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("rect", { x: "120", y: "10", width: "15", height: "120", rx: "6", children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "height", begin: "0.5s", dur: "1s", values: "120;110;100;90;80;70;60;50;40;140;120", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "animate", { attributeName: "y", begin: "0.5s", dur: "1s", values: "10;15;20;25;30;35;40;45;50;0;10", calcMode: "linear", repeatCount: "indefinite" } ) ] }) ] }); // src/spinner/spinners/dots.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var Dots = (props) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { viewBox: "0 0 120 30", xmlns: "http://www.w3.org/2000/svg", fill: "currentColor", ...props, children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("circle", { cx: "15", cy: "15", r: "15", children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "animate", { attributeName: "r", from: "15", to: "15", begin: "0s", dur: "0.8s", values: "15;9;15", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "animate", { attributeName: "fill-opacity", from: "1", to: "1", begin: "0s", dur: "0.8s", values: "1;.5;1", calcMode: "linear", repeatCount: "indefinite" } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("circle", { cx: "60", cy: "15", r: "9", fillOpacity: "0.3", children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "animate", { attributeName: "r", from: "9", to: "9", begin: "0s", dur: "0.8s", values: "9;15;9", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "animate", { attributeName: "fill-opacity", from: "0.5", to: "0.5", begin: "0s", dur: "0.8s", values: ".5;1;.5", calcMode: "linear", repeatCount: "indefinite" } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("circle", { cx: "105", cy: "15", r: "15", children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "animate", { attributeName: "r", from: "15", to: "15", begin: "0s", dur: "0.8s", values: "15;9;15", calcMode: "linear", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "animate", { attributeName: "fill-opacity", from: "1", to: "1", begin: "0s", dur: "0.8s", values: "1;.5;1", calcMode: "linear", repeatCount: "indefinite" } ) ] }) ] }); // src/spinner/spinners/ring.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); var Ring = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( "svg", { fill: "none", stroke: "currentColor", viewBox: "0 0 38 38", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("g", { fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("g", { transform: "translate(2.5 2.5)", strokeWidth: "5", children: [ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { strokeOpacity: ".5", cx: "16", cy: "16", r: "16" }), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M32 16c0-9.94-8.06-16-16-16", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( "animateTransform", { attributeName: "transform", type: "rotate", from: "0 16 16", to: "360 16 16", dur: "1s", repeatCount: "indefinite" } ) }) ] }) }) } ); // src/spinner/spinners/spin.tsx var import_jsx_runtime4 = require("react/jsx-runtime"); var Spin = (props) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { stroke: "currentColor", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("g", { children: [ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("circle", { cx: "12", cy: "12", r: "9.5", fill: "none", strokeWidth: "3", strokeLinecap: "round", children: [ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( "animate", { attributeName: "stroke-dasharray", dur: "1.5s", calcMode: "spline", values: "0 150;42 150;42 150;42 150", keyTimes: "0;0.475;0.95;1", keySplines: "0.42,0,0.58,1;0.42,0,0.58,1;0.42,0,0.58,1", repeatCount: "indefinite" } ), /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( "animate", { attributeName: "stroke-dashoffset", dur: "1.5s", calcMode: "spline", values: "0;-16;-59;-59", keyTimes: "0;0.475;0.95;1", keySplines: "0.42,0,0.58,1;0.42,0,0.58,1;0.42,0,0.58,1", repeatCount: "indefinite" } ) ] }), /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( "animateTransform", { attributeName: "transform", type: "rotate", dur: "2s", values: "0 12 12;360 12 12", repeatCount: "indefinite" } ) ] }) }); // src/spinner/spinner.tsx var import_jsx_runtime5 = require("react/jsx-runtime"); var SPINNERS = { bars: Bars, dots: Dots, ring: Ring, spin: Spin }; var DEFAULT_SPINNER = "spin"; function Spinner(props, ref) { const { className, variant = DEFAULT_SPINNER, color, size, ...spinnerProps } = props; const defaultSpinner = variant in SPINNERS ? variant : DEFAULT_SPINNER; const SpinnerComponent = SPINNERS[defaultSpinner]; const styles = (0, import_react.useMemo)( () => (0, import_theme.spinner)({ color, size, className }), [className, color, size] ); return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SpinnerComponent, { "aria-hidden": true, className: styles, ref, ...spinnerProps }); } var _Spinner = (0, import_react.forwardRef)(Spinner); // src/editable-table/editable-table-cell.tsx var import_react22 = require("react"); var import_icons5 = require("@trail-ui/icons"); var import_react_table3 = require("@tanstack/react-table"); // src/editable-table/editable-components/select.tsx var import_react13 = require("react"); // src/toast/index.ts var toast_exports = {}; __export(toast_exports, { customToast: () => customToast }); // src/flag/flag.tsx var import_react4 = require("react"); var import_theme4 = require("@trail-ui/theme"); var import_icons = require("@trail-ui/icons"); // src/button/button.tsx var import_react2 = require("react"); var import_react_aria_components = require("react-aria-components"); var import_theme2 = require("@trail-ui/theme"); var import_jsx_runtime6 = require("react/jsx-runtime"); function Button(props, ref) { const { appearance, // size = 'md', spacing = "default", fullWidth, isLoading, spinner: spinner2 = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(_Spinner, { color: "current", size: "sm", ...props.spinnerProps }), spinnerPlacement = "start", startContent: startContentProp, endContent: endContentProp, disableAnimation, className, children, ...otherProps } = props; const styles = (0, import_react2.useMemo)( () => (0, import_theme2.button)({ // size, isLoading, spinnerPlacement, startContentProp: !!startContentProp, endContentProp: !!endContentProp, appearance, spacing, fullWidth, disableAnimation, className }), [ isLoading, spinnerPlacement, startContentProp, endContentProp, appearance, spacing, fullWidth, disableAnimation, className ] ); const getIconClone = (icon) => (0, import_react2.isValidElement)(icon) ? (0, import_react2.cloneElement)(icon, { "aria-hidden": true, focusable: false, tabIndex: -1 }) : null; const startContent = getIconClone(startContentProp); const endContent = getIconClone(endContentProp); return ( // @ts-ignore /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_aria_components.Button, { ref, className: styles, ...otherProps, children: () => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [ !isLoading && startContent, isLoading && spinnerPlacement === "start" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "shrink-0", children: [ spinner2, /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { "aria-atomic": "true", "aria-live": "polite", className: "sr-only", children: [ "Loading", " " ] }) ] }), children, isLoading && spinnerPlacement === "end" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "shrink-0", children: [ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { "aria-atomic": "true", "aria-live": "polite", className: "sr-only", children: [ "Loading", " " ] }), spinner2 ] }), !isLoading && endContent ] }) }) ); } var _Button = (0, import_react2.forwardRef)(Button); // src/button/icon-button.tsx var import_theme3 = require("@trail-ui/theme"); var import_react3 = require("react"); var import_react_aria_components2 = require("react-aria-components"); var import_jsx_runtime7 = require("react/jsx-runtime"); function IconButton(props, ref) { const { appearance, spacing, disableAnimation, className, children, ...otherProps } = props; const styles = (0, import_react3.useMemo)( () => (0, import_theme3.button)({ isIconOnly: true, appearance, spacing, disableAnimation, className }), [className, disableAnimation, appearance, spacing] ); const element = children; const _children = (0, import_react3.isValidElement)(element) ? (0, import_react3.cloneElement)(element, { "aria-hidden": true, focusable: false }) : null; return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_aria_components2.Button, { ref, className: styles, ...otherProps, children: _children }); } var _IconButton = (0, import_react3.forwardRef)(IconButton); // src/flag/flag.tsx var import_jsx_runtime8 = require("react/jsx-runtime"); function Flag(props) { let flagIcon; const { title, desc, variant, hasActionBtn, actionBtnText, isClosable, onActionClick, onClose } = props; const variantProps = (0, import_theme4.filterVariantProps)(props, import_theme4.flag.variantKeys); const styles = (0, import_react4.useMemo)( () => (0, import_theme4.flag)({ ...variantProps, variant }), [variantProps, variant] ); switch (variant) { case "default": flagIcon = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons.SettingsIcon, { height: 24, width: 24 }); break; case "success": flagIcon = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons.CheckCircleIcon, { height: 24, width: 24 }); break; case "error": flagIcon = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons.ErrorIcon, { height: 24, width: 24 }); break; case "warning": flagIcon = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons.WarningIcon, { height: 24, width: 24 }); break; case "info": flagIcon = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons.InfoIcon, { height: 24, width: 24 }); break; default: break; } return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "shadow-medium flex w-full gap-1.5 rounded text-base", children: [ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `${styles} flex w-12 min-w-12 items-center justify-center rounded-l`, children: flagIcon }), /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex w-full items-center p-2", children: [ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "flex w-full flex-col", children: [ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "font-semibold text-neutral-900", children: title }), /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { className: "text-sm font-normal text-neutral-700", children: desc }) ] }), hasActionBtn && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(_Button, { appearance: "link", onPress: onActionClick, children: actionBtnText || "Action" }), isClosable && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)( _IconButton, { spacing: "compact", appearance: "transparent", onPress: onClose, "aria-label": "Close", className: "ml-auto h-auto p-2.5", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons.CloseIcon, { height: 24, width: 24, className: "text-neutral-600" }) } ) ] }) ] }) }); } // src/toast/toast.tsx var import_react_toastify = require("react-toastify"); var import_jsx_runtime9 = require("react/jsx-runtime"); function capitalizeText(text) { return (text == null ? void 0 : text.split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ")) || ""; } function customToast(message, type, title, options = {}) { (0, import_react_toastify.toast)( /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "w-full overflow-hidden rounded", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Flag, { variant: type, title: title != null ? title : capitalizeText(type), desc: message }) }), { delay: 1e3, ...options } ); } // src/toast/index.ts __reExport(toast_exports, require("react-toastify")); // src/editable-table/table-context/table-context-provider.tsx var import_react5 = require("react"); var import_jsx_runtime10 = require("react/jsx-runtime"); var EditableTableContext = (0, import_react5.createContext)({ handleSaveData: () => { }, idSelector: () => { }, table: {}, tableName: "", groupData: [], allowBulkGroupSelection: false, doesRowHeaderExist: false }); function useTableContext(cell) { const { handleSaveData, ...rest } = (0, import_react5.useContext)(EditableTableContext); function updateData(value) { var _a, _b; if (cell) { const accessorKey = cell.column.columnDef.accessorKey; const groupId = (_a = cell.row.original) == null ? void 0 : _a.editableTableGroupId; handleSaveData({ accessorKey, columnId: cell.column.id, rowId: rest.idSelector(cell.row.original), value, ...groupId ? { groupId } : {} }); (_b = rest.table.options.meta) == null ? void 0 : _b.updateData(cell.row.id, accessorKey, value); } } return { ...cell ? { updateData } : {}, ...rest }; } // src/editable-table/focus-handler/focus-handler-provider.tsx var import_react6 = require("react"); var import_jsx_runtime11 = require("react/jsx-runtime"); var FocusDataContext = (0, import_react6.createContext)({ columnIndex: 0, rowId: null, cellType: "headerCell" /* headerCell */, groupId: null, rowIndex: 0 }); var FocusDispatchContext = (0, import_react6.createContext)(() => { }); function useFocusHandler({ cellType, columnIndex, groupId, rowId, rowIndex }) { var _a; const focusedCell = (0, import_react6.useContext)(FocusDataContext); const setFocusedCell = (0, import_react6.useContext)(FocusDispatchContext); const { allowBulkGroupSelection, tableRef, table, serverPagination } = useTableContext(); const filteredRows = (_a = table == null ? void 0 : table.getRowModel().rows) != null ? _a : []; const localRowIndex = filteredRows.findIndex((row) => row.id === rowId); const isCurrentCellFocused = (0, import_react6.useMemo)(() => { var _a2; const isFocused = ((_a2 = tableRef.current) == null ? void 0 : _a2.contains(document.activeElement)) && focusedCell.cellType === cellType; switch (cellType) { case "headerCell" /* headerCell */: case "footerCell" /* footerCell */: return isFocused && focusedCell.columnIndex === columnIndex; case "groupHeaderCell" /* groupHeaderCell */: { let isGroup = focusedCell.groupId === groupId; if (allowBulkGroupSelection) { isGroup && (isGroup = columnIndex === 0 ? focusedCell.columnIndex === 0 : focusedCell.columnIndex > 0); } return isFocused && isGroup; } case "dataCell" /* dataCell */: return isFocused && focusedCell.rowIndex === localRowIndex && focusedCell.columnIndex === columnIndex; default: return false; } }, [focusedCell, columnIndex, cellType, groupId, localRowIndex, allowBulkGroupSelection]); const focusCurrentCell = (0, import_react6.useCallback)(() => { setFocusedCell == null ? void 0 : setFocusedCell({ columnIndex, rowId, cellType, groupId, rowIndex }); }, [columnIndex, rowId, cellType, groupId, rowIndex]); const resetFocus = (0, import_react6.useCallback)(() => { setFocusedCell == null ? void 0 : setFocusedCell({ cellType: "headerCell" /* headerCell */, rowId: null, groupId: null, rowIndex: -1, columnIndex: 0 }); }, []); return { isCurrentCellFocused, focusCurrentCell, resetFocus }; } // src/_utils/utils.tsx var import_utils = require("@react-aria/utils"); var import_react7 = __toESM(require("react")); var import_react_aria = require("react-aria"); var import_react_dom = __toESM(require("react-dom")); var import_jsx_runtime12 = require("react/jsx-runtime"); if (typeof HTMLTemplateElement !== "undefined") { const getFirstChild = Object.getOwnPropertyDescriptor(Node.prototype, "firstChild").get; Object.defineProperty(HTMLTemplateElement.prototype, "firstChild", { configurable: true, enumerable: true, get: function() { if (this.dataset.reactAriaHidden) { return this.content.firstChild; } else { return getFirstChild.call(this); } } }); } var HiddenContext = (0, import_react7.createContext)(false); var hiddenFragment = typeof DocumentFragment !== "undefined" ? new DocumentFragment() : null; function useDOMRef(ref) { const domRef = (0, import_react7.useRef)(null); (0, import_react7.useImperativeHandle)(ref, () => domRef.current); return domRef; } function replaceSpacesWithHyphens(str) { return str.toLowerCase().trim().replace(/\s+/g, "-"); } // src/select/customSelect.tsx var import_theme5 = require("@trail-ui/theme"); var import_react12 = __toESM(require("react")); var import_icons2 = require("@trail-ui/icons"); // src/overlay/overlay.tsx var import_react8 = __toESM(require("react")); var import_react9 = require("react"); var import_jsx_runtime13 = require("react/jsx-runtime"); var Positions = { top: "top", topLeft: "topLeft", topRight: "topRight", bottom: "bottom", bottomLeft: "bottomLeft", bottomRight: "bottomRight", left: "left", leftTop: "leftTop", leftBottom: "leftBottom", right: "right", rightTop: "rightTop", rightBottom: "rightBottom" }; function Overlay(props) { var _a, _b, _c; const [style, setStyle] = (0, import_react9.useState)({ top: 0, left: 0, transform: "", position: "fixed" }); const elementRef = (0, import_react9.useRef)(null); const getContainingBlockOffset = () => { const probe = document.createElement("div"); probe.style.cssText = "position:fixed;top:0;left:0;width:1px;height:1px;pointer-events:none;visibility:hidden;"; document.body.appendChild(probe); const rect = probe.getBoundingClientRect(); document.body.removeChild(probe); return { top: rect.top, left: rect.left }; }; const getMaxHeight = () => { var _a2, _b2, _c2; const refEl = props.referenceElement.current; if (!refEl) { return; } const refRect = refEl.getBoundingClientRect(); let maxAvailableHeight = 0; const windowHeight = window.innerHeight; const offsetY = ((_a2 = props.offset) == null ? void 0 : _a2.y) || 0; switch (props.position) { case Positions.bottom: case Positions.bottomLeft: case Positions.bottomRight: maxAvailableHeight = windowHeight - refRect.bottom - offsetY * 2; break; case Positions.top: case Positions.topLeft: case Positions.topRight: maxAvailableHeight = refRect.top - offsetY * 2; break; default: maxAvailableHeight = Math.min( windowHeight - offsetY * 2, ((_b2 = props.style) == null ? void 0 : _b2.maxHeight) || Number.POSITIVE_INFINITY ); } if ((_c2 = props.style) == null ? void 0 : _c2.maxHeight) { maxAvailableHeight = Math.min(maxAvailableHeight, props.style.maxHeight); } return maxAvailableHeight; }; const getMaxWidth = () => { var _a2, _b2, _c2; const refEl = props.referenceElement.current; if (!refEl) { return; } const refRect = refEl.getBoundingClientRect(); let maxAvailableWidth = 0; const windowWidth = window.innerWidth; const offsetX = ((_a2 = props.offset) == null ? void 0 : _a2.x) || 0; switch (props.position) { case Positions.right: case Positions.rightBottom: case Positions.rightTop: maxAvailableWidth = windowWidth - refRect.right - offsetX * 2; break; case Positions.left: case Positions.leftBottom: case Positions.leftTop: maxAvailableWidth = refRect.left - offsetX * 2; break; default: maxAvailableWidth = Math.min( windowWidth - offsetX * 2, ((_b2 = props.style) == null ? void 0 : _b2.maxWidth) || Number.POSITIVE_INFINITY ); } if ((_c2 = props.style) == null ? void 0 : _c2.maxWidth) { maxAvailableWidth = Math.min(maxAvailableWidth, props.style.maxWidth); } return maxAvailableWidth; }; const getUpdatedPositions = () => { var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l; const refEl = props.referenceElement.current; if (!refEl) { return; } const refRect = refEl.getBoundingClientRect(); const cbOffset = getContainingBlockOffset(); let top = 0; let left = 0; let transform = ""; switch (props.position) { case Positions.top: top = refRect.top - (((_a2 = props.offset) == null ? void 0 : _a2.y) || 0) - cbOffset.top; left = refRect.left + refRect.width / 2 - cbOffset.left; transform = "translate(-50%, -100%)"; break; case Positions.topLeft: top = refRect.top - (((_b2 = props.offset) == null ? void 0 : _b2.y) || 0) - cbOffset.top; left = refRect.left - cbOffset.left; transform = "translateY(-100%)"; break; case Positions.topRight: top = refRect.top - (((_c2 = props.offset) == null ? void 0 : _c2.y) || 0) - cbOffset.top; left = refRect.right - cbOffset.left; transform = "translate(-100%, -100%)"; break; case Positions.bottom: top = refRect.bottom + (((_d = props.offset) == null ? void 0 : _d.y) || 0) - cbOffset.top; left = refRect.left + refRect.width / 2 - cbOffset.left; transform = "translateX(-50%)"; break; case Positions.bottomLeft: top = refRect.bottom + (((_e = props.offset) == null ? void 0 : _e.y) || 0) - cbOffset.top; left = refRect.left - cbOffset.left; break; case Positions.bottomRight: top = refRect.bottom + (((_f = props.offset) == null ? void 0 : _f.y) || 0) - cbOffset.top; left = refRect.right - cbOffset.left; transform = "translateX(-100%)"; break; case Positions.left: top = refRect.top + refRect.height / 2 - cbOffset.top; left = refRect.left - (((_g = props.offset) == null ? void 0 : _g.x) || 0) - cbOffset.left; transform = "translate(-100%, -50%)"; break; case Positions.leftTop: top = refRect.top - cbOffset.top; left = refRect.left - (((_h = props.offset) == null ? void 0 : _h.x) || 0) - cbOffset.left; transform = "translateX(-100%)"; break; case Positions.leftBottom: top = refRect.bottom - cbOffset.top; left = refRect.left - (((_i = props.offset) == null ? void 0 : _i.x) || 0) - cbOffset.left; transform = "translate(-100%, -100%)"; break; case Positions.right: top = refRect.top + refRect.height / 2 - cbOffset.top; left = refRect.right + (((_j = props.offset) == null ? void 0 : _j.x) || 0) - cbOffset.left; transform = "translateY(-50%)"; break; case Positions.rightTop: top = refRect.top - cbOffset.top; left = refRect.right + (((_k = props.offset) == null ? void 0 : _k.x) || 0) - cbOffset.left; break; case Positions.rightBottom: top = refRect.bottom - cbOffset.top; left = refRect.right + (((_l = props.offset) == null ? void 0 : _l.x) || 0) - cbOffset.left; transform = "translateY(-100%)"; break; } const maxHeight = getMaxHeight(); const maxWidth = getMaxWidth(); setStyle((prevState) => ({ ...prevState, top, left, transform, ...maxHeight && { maxHeight }, ...maxWidth && { maxWidth } })); }; (0, import_react9.useLayoutEffect)(() => { if (!props.referenceElement.current) { return; } getUpdatedPositions(); const updatePositions = () => getUpdatedPositions(); window.addEventListener("resize", updatePositions); window.addEventListener("scroll", updatePositions, true); return () => { window.removeEventListener("resize", updatePositions); window.removeEventListener("scroll", updatePositions, true); }; }, [props.referenceElement, props.isOpen]); if ((0, import_react9.isValidElement)(props.children)) { return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [ props.onOverlayClick && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)( "div", { role: "button", className: "z-2 fixed left-[0] top-[0] h-[100vh] w-[100vw]", onClick: props.onOverlayClick, onKeyDown: props.onOverlayClick, "aria-label": "Close dropdown", tabIndex: -1 } ), /* @__PURE__ */ (0, import_jsx_runtime13.jsx)( "div", { style: { ...style, overflow: "auto", width: ((_a = props.style) == null ? void 0 : _a.width) || ((_b = props.referenceElement.current) == null ? void 0 : _b.getBoundingClientRect().width), height: ((_c = props.style) == null ? void 0 : _c.height) || "fit-content", zIndex: 30 }, children: import_react8.default.cloneElement(props.children, { ref: elementRef }) } ) ] }); } return props.children; } // src/multiselect/tw-field.tsx var import_react11 = __toESM(require("react")); var import_react_aria_components3 = require("react-aria-components"); var import_tailwind_merge2 = require("tailwind-merge"); // src/multiselect/tw-text.tsx var import_tailwind_merge = require("tailwind-merge"); var import_react10 = __toESM(require("react")); var import_jsx_runtime14 = require("react/jsx-runtime"); function Text({ className, elementType, children, ...props }) { return import_react10.default.createElement( elementType != null ? elementType : "p", { ...props, className: (0, import_tailwind_merge.twMerge)("flex gap-1 pt-1.5 text-xs text-neutral-700", className) }, children ); } // src/multiselect/tw-field.tsx var import_jsx_runtime15 = require("react/jsx-runtime"); var LabeledGroup = import_react11.default.forwardRef(function(props, ref) { const labelId = import_react11.default.useId(); return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_aria_components3.LabelContext.Provider, { value: { id: labelId, elementType: "span" }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_aria_components3.GroupContext.Provider, { value: { "aria-labelledby": labelId }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)( import_react_aria_components3.Group, { ...props, ref, className: (0, import_react_aria_components3.composeRenderProps)(props.className, (className) => { return (0, import_tailwind_merge2.twMerge)("relative flex flex-col", className); }) } ) }) }); }); function Label({ requiredHint, isDisabled, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)( import_react_aria_components3.Label, { ...props, "data-slot": "label", className: (0, import_tailwind_merge2.twMerge)( requiredHint && "after:ml-0.5 after:text-red-800 after:content-['*']", isDisabled && "opacity-50", props.className ) } ); } var DescriptionContext = import_react11.default.createContext(null); var InputFieldGroup = import_react11.default.forwardRef( function InputFieldGroup2(props, ref) { return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)( import_react_aria_components3.Group, { ...props, "data-slot": "control", ref, className: (0, import_react_aria_components3.composeRenderProps)(props.className, (className) => { return (0, import_tailwind_merge2.twMerge)( "group relative flex w-full items-center overflow-hidden rounded-md border bg-inherit shadow-sm", "[&_svg]:text-muted", "group-invalid:border-destructive", // Disabled and readonly style "[&:has(_[data-disabled=true])]:opacity-50", "[&:has([readonly])]:opacity-50", // Prevent double opacity "[&:has(_[data-disabled=true])_[class*=opacity-]]:opacity-100", "[&:has([readonly])_[class*=opacity-]]:opacity-100", // Remove inside input/data-input border style "[&_:is(input,[data-slot=control])]:border-none", "[&_:is(input,[data-slot=control])]:shadow-none", "[&_:is(input,[data-slot=control])]:ring-0", className ); }) } ); } ); var Input = import_react11.default.forwardRef(function Input2(props, ref) { return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)( import_react_aria_components3.Input, { ...props, ref, className: (0, import_react_aria_components3.composeRenderProps)(props.className, (className, { isDisabled, isInvalid }) => { return (0, import_tailwind_merge2.twMerge)( "flex w-full rounded-md border-none bg-inherit px-2 py-[5px] shadow-none outline-none", "text-sm placeholder:text-neutral-600", "[&[readonly]]:opacity-50", isInvalid && "border-destructive", isDisabled && "opacity-50", className ); }) } ); }); // src/select/customSelect.tsx var import_react_aria_components4 = require("react-aria-components"); var import_shared_utils = require("@trail-ui/shared-utils"); var import_jsx_runtime16 = require("react/jsx-runtime"); var Keys = { Backspace: "Backspace", Clear: "Clear", Down: "ArrowDown", End: "End", Enter: "Enter", Escape: "Escape", Home: "Home", Left: "ArrowLeft", PageDown: "PageDown", PageUp: "PageUp", Right: "ArrowRight", Space: " ", Tab: "Tab", Up: "ArrowUp" }; var MenuActions = { Close: "Close", CloseSelect: "CloseSelect", First: "First", Last: "Last", Next: "Next", Open: "Open", Previous: "Previous", Select: "Select", Space: "Space", Type: "Type" }; function getActionFromKey(key, menuOpen) { if (!menuOpen && key === Keys.Down) return MenuActions.Open; if (!menuOpen && key === Keys.Enter) return MenuActions.Open; if (key === Keys.Down) return MenuActions.Next; if (key === Keys.Up) return MenuActions.Previous; if (key === Keys.Home) return MenuActions.First; if (key === Keys.End) return MenuActions.Last; if (key === Keys.Escape) return MenuActions.Close; if (key === Keys.Enter) return MenuActions.CloseSelect; if (key === Keys.Backspace || key === Keys.Clear || key.length === 1) return MenuActions.Type; return void 0; } var CustomSelect = (0, import_react12.forwardRef)( ({ options, label, labelKey, valueKey, id: userProvidedId, onChange, onTriggerBlur, onBlur, classNames, errorMessage, description, errorIcon = /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( import_icons2.ErrorIcon, { className: "h-4 w-4 text-red-800 dark:text-red-600", role: "img", "aria-label": "Error", "aria-hidden": false } ), errorId: eID, isRequired, isDisabled, isInvalid, placeholder = "Select items", value: selectedValue, form, name, maxOptionsBeforeConversionToComboBox = 6, isCombobox, position = Positions.bottom, popover = { maxHeight: 240 }, onKeyDown, onInputChange, isLoading = false, allowCustomInput = false, renderCustomLabel, ariaLabelledBy, baseRef, allowDeselection = true, ...otherprops }, ref) => { const [isOpen, setIsOpen] = (0, import_react12.useState)(false); const [searchValue, setSearchValue] = (0, import_react12.useState)(""); const [activeIndex, setActiveIndex] = (0, import_react12.useState)(-1); const [value, setValue] = (0, import_react12.useState)({ label: "", value: "" }); const listboxRef = (0, import_react12.useRef)(null); const inputRef = (0, import_react12.useRef)(null); const localRef = (0, import_react12.useRef)(null); const buttonRef = (0, import_react12.useRef)(null); const optionRefs = (0, import_react12.useRef)([]); const noSearchResultsRef = (0, import_react12.useRef)(null); const hiddenInputRef = (0, import_react12.useRef)(null); const refElementForOverlay = (0, import_react12.useRef)(null); const uuid = (0, import_react12.useId)(); const uuid2 = (0, import_react12.useId)(); const id = userProvidedId != null ? userProvidedId : uuid; const errorId = eID || uuid2; const slots = (0, import_react12.useMemo)(() => (0, import_theme5.multiselect)(), []); const isComponentCombobox = (0, import_react12.useMemo)(() => { if (isCombobox !== void 0) { return isCombobox; } else { return options.length > maxOptionsBeforeConversionToComboBox; } }, [isCombobox, options, maxOptionsBeforeConversionToComboBox]); const labelId = `${id}-select-label`; const optionBoxId = `${id}-select-${isComponentCombobox ? "combobox" : "listbox"}`; function getOptionLabel(option, isView) { if (isView && renderCustomLabel && option.value) { return renderCustomLabel == null ? void 0 : renderCustomLabel(option); } return (option == null ? void 0 : option[labelKey != null ? labelKey : "label"]) || ""; } const getOptionValue = (option) => { return (option == null ? void 0 : option[valueKey != null ? valueKey : "value"]) || ""; }; const resetIndex = () => setActiveIndex(-1); const filteredOptions = (0, import_react12.useMemo)(() => { const optList = []; if (allowCustomInput) { if (searchValue && options.findIndex( (o) => getOptionLabel(o, false).toLowerCase() === searchValue.toLowerCase() ) === -1) { optList.push({ label: searchValue, value: searchValue, isItalic: true }); } else if (selectedValue && options.findIndex((o) => o.value === selectedValue) === -1) { optList.push({ label: selectedValue, value: selectedValue, isItalic: true }); } } return [ ...optList, ...options.filter((option) => { return getOptionLabel(option, false).toString().toLowerCase().includes(searchValue.toLowerCase()); }) ]; }, [searchValue, options, selectedValue]); const activedescendant = isOpen ? filteredOptions.length > 0 && activeIndex >= 0 ? `${id}-option-${activeIndex}` : `${id}-option-no-data` : ""; const toggleDropdown = () => setIsOpen((prevState) => !prevState); const toggleItem = (option) => { if (isDisabled) return; let newOption = option; if (option.value === selectedValue && allowDeselection) { newOption = { label: "", value: "" }; } onChange(newOption.value); setSearchValue(""); toggleDropdown(); if (inputRef.current) { inputRef.current.focus(); inputRef.current.value = getOptionLabel(newOption, false); } if (buttonRef.current) { buttonRef.current.focus(); } if (hiddenInputRef.current) { hiddenInputRef.current.value = getOptionLabel(newOption, false); } }; const handleInputChange = (e) => { if (isDisabled) return; setSearchValue(e.target.value); if (!isOpen) toggleDropdown(); if (activeIndex === -1) { setActiveIndex(0); } }; function getUpdatedIndex(current, action) { switch (action) { case MenuActions.First: return 0; case MenuActions.Last: return filteredOptions.length; case MenuActions.Previous: return (activeIndex - 1 + filteredOptions.length) % filteredOptions.length; case MenuActions.Next: return (activeIndex + 1) % filteredOptions.length; default: return current; } } const handleKeyDown = (e) => { var _a, _b; const action = getActionFromKey(e.key, isOpen); if (isDisabled) { e.preventDefault(); return; } if (e.key === Keys.Tab) { if (isOpen) { toggleDropdown(); resetIndex(); setSearchValue(""); } return; } if (!action) return; if (MenuActions.Type !== action) e.preventDefault(); switch (action) { case MenuActions.Next: case MenuActions.Last: case MenuActions.First: case MenuActions.Previous: const nextIndex = getUpdatedIndex(activeIndex, action); setActiveIndex(nextIndex); (_a = noSearchResultsRef.current) == null ? void 0 : _a.focus(); break; case MenuActions.Type: if (inputRef.current) inputRef.current.focus(); break; case MenuActions.CloseSelect: if (activeIndex >= 0) { (_b = optionRefs.current[activeIndex].current) == null ? void 0 : _b.click(); } break; case MenuActions.Close: setSearchValue(""); setIsOpen(false); resetIndex(); break; case MenuActions.Open: handleOnClick({ detail: 1 }); break; } }; const handleOnClick = (e) => { if (!isDisabled && (e == null ? void 0 : e.detail) === 1) { toggleDropdown(); if (isOpen) { resetIndex(); } } }; function mergeRefs(...refs) { return (value2) => { for (const ref2 of refs) { if (!ref2) continue; if (typeof ref2 === "function") { ref2(value2); } else { ref2.current = value2; } } }; } function onComponentBlur(e) { var _a; const selectedOption = filteredOptions.find((o) => o.value === selectedValue); if (e.relatedTarget && !((_a = localRef.current) == null ? void 0 : _a.contains(e.relatedTarget))) { if (selectedOption) { if (inputRef.current) { inputRef.current.value = getOptionLabel(selectedOption, false); } if (hiddenInputRef.current) { hiddenInputRef.current.value = getOptionLabel(selectedOption, false); } } onBlur == null ? void 0 : onBlur(e); } } function announceToScreenReader(message) { const announcer = document.createElement("div"); announcer.setAttribute("role", "alert"); announcer.setAttribute("aria-live", "polite"); announcer.classList.add("sr-only"); document.body.appendChild(announcer); setTimeout(() => { announcer.textContent = message; }, 100); setTimeout(() => { document.body.removeChild(announcer); }, 1e3); } (0, import_react12.useEffect)(() => { const handleClickOutside = (event) => { if (localRef.current && !localRef.current.contains(event.target)) { setIsOpen(false); } }; document.addEventListener("mousedown", handleClickOutside, true); return () => document.removeEventListener("mousedown", handleClickOutside, true); }, []); (0, import_react12.useEffect)(() => { const index = options.findIndex((item) => item.value === selectedValue); const newValue = index === -1 ? allowCustomInput ? { label: selectedValue, value: selectedValue, isItalic: true } : { label: "", value: "" } : options[index]; setValue(newValue); if (inputRef.current) { inputRef.current.value = getOptionLabel(newValue, false); } if (hiddenInputRef.current) { hiddenInputRef.current.value = getOptionLabel(newValue, false); } }, [selectedValue, options]); (0, import_react12.useEffect)(() => { var _a; if (isOpen) { optionRefs.current = filteredOptions.map( (_, i) => optionRefs.current[i] || import_react12.default.createRef() ); if (filteredOptions.length > 1 && !isCombobox) { setActiveIndex(0); } if (!isLoading) announceToScreenReader(`${filteredOptions.length} results found`); } (_a = buttonRef.current) == null ? void 0 : _a.setAttribute("role", "combobox"); }, [isOpen, filteredOptions]); (0, import_react12.useEffect)(() => { var _a; if (filteredOptions.length > 0) { resetIndex(); } if (isRequired) { (_a = buttonRef.current) == null ? void 0 : _a.setAttribute("aria-required", String(isRequired)); } }, [filteredOptions]); (0, import_react12.useEffect)(() => { var _a; if (isOpen && activeIndex >= 0) { requestAnimationFrame(() => { var _a2, _b; (_b = (_a2 = optionRefs.current[activeIndex]) == null ? void 0 : _a2.current) == null ? void 0 : _b.scrollIntoView({ block: "nearest" }); }); } (_a = buttonRef.current) == null ? void 0 : _a.setAttribute( "aria-activedescendant", isOpen ? `${id}-option-${activeIndex}` : "" ); }, [activeIndex]); (0, import_react12.useEffect)(() => { var _a; (_a = buttonRef.current) == null ? void 0 : _a.setAttribute("data-invalid", `${isInvalid}`); }, [isInvalid, options]); return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)( "div", { ref: mergeRefs(localRef, baseRef), className: slots.base({ class: classNames == null ? void 0 : classNames.base }), onBlur: onComponentBlur, children: [ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( Label, { id: labelId, isDisabled, requiredHint: isRequired, className: slots.label({ class: classNames == null ? void 0 : classNames.label }), children: label } ), /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( "input", { ref: hiddenInputRef, type: "hidden", name, value: getOptionValue(value), form, required: isRequired } ), /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)( "div", { ref: refElementForOverlay, className: slots.inputWrapper({ className: classNames == null ? void 0 : classNames.inputWrapper }), children: [ isComponentCombobox ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)( Input, { id, ref: mergeRefs(inputRef, ref), autoComplete: "off", "aria-busy": isLoading, "aria-autocomplete": "list", "aria-labelledby": ariaLabelledBy != null ? ariaLabelledBy : labelId, onBlur: onTriggerBlur, className: slo