@andrilla/mado-ui 1.0.11 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/components/index.js +478 -102
- package/dist/client.js +467 -107
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +478 -102
- package/dist/components/modal.d.ts +6 -2
- package/dist/components/search.d.ts +129 -0
- package/dist/components/select.d.ts +17 -7
- package/dist/hooks/create-fast-context.d.ts +8 -9
- package/dist/hooks/index.js +30 -35
- package/dist/hooks/use-form-status.d.ts +8 -10
- package/dist/index.js +467 -107
- package/package.json +1 -1
package/dist/components/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { extendTailwindMerge, twJoin } from "tailwind-merge";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Button as Button$1, Checkbox as Checkbox$1, Description, Dialog, DialogBackdrop, DialogPanel, DialogTitle, Disclosure, DisclosureButton, DisclosurePanel, Field, Fieldset as Fieldset$1, Input as Input$1, Label, Legend, Listbox, ListboxButton, ListboxOption, ListboxOptions, ListboxSelectedOption, Menu, MenuButton, MenuHeading, MenuItem, MenuItems, MenuSection, MenuSeparator, Textarea as Textarea$1 } from "@headlessui/react";
|
|
3
|
+
import { Button as Button$1, Checkbox as Checkbox$1, Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions, Description, Dialog, DialogBackdrop, DialogPanel, DialogTitle, Disclosure, DisclosureButton, DisclosurePanel, Field, Fieldset as Fieldset$1, Input as Input$1, Label, Legend, Listbox, ListboxButton, ListboxOption, ListboxOptions, ListboxSelectedOption, Menu, MenuButton, MenuHeading, MenuItem, MenuItems, MenuSection, MenuSeparator, Textarea as Textarea$1 } from "@headlessui/react";
|
|
4
4
|
import * as React from "react";
|
|
5
|
-
import { Children, cloneElement, createContext, isValidElement, useContext, useEffect, useEffectEvent, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
5
|
+
import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useEffectEvent, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
6
6
|
import * as ReactDOM from "react-dom";
|
|
7
7
|
import { createPortal } from "react-dom";
|
|
8
8
|
//#region src/utils/custom-tailwind-merge.ts
|
|
@@ -1251,7 +1251,7 @@ if (isBrowser) {
|
|
|
1251
1251
|
* @param {String} str
|
|
1252
1252
|
* @return {String}
|
|
1253
1253
|
*/
|
|
1254
|
-
const toLowerCase = (str) => str.replace(lowerCaseRgx, "$1-$2").toLowerCase();
|
|
1254
|
+
const toLowerCase$1 = (str) => str.replace(lowerCaseRgx, "$1-$2").toLowerCase();
|
|
1255
1255
|
/**
|
|
1256
1256
|
* Prioritize this method instead of regex when possible
|
|
1257
1257
|
* @param {String} str
|
|
@@ -1889,7 +1889,7 @@ const sanitizePropertyName = (propertyName, target, tweenType) => {
|
|
|
1889
1889
|
const cachedPropertyName = propertyNamesCache[propertyName];
|
|
1890
1890
|
if (cachedPropertyName) return cachedPropertyName;
|
|
1891
1891
|
else {
|
|
1892
|
-
const lowerCaseName = propertyName ? toLowerCase(propertyName) : propertyName;
|
|
1892
|
+
const lowerCaseName = propertyName ? toLowerCase$1(propertyName) : propertyName;
|
|
1893
1893
|
propertyNamesCache[propertyName] = lowerCaseName;
|
|
1894
1894
|
return lowerCaseName;
|
|
1895
1895
|
}
|
|
@@ -1922,7 +1922,7 @@ const cleanInlineStyles = (renderable) => {
|
|
|
1922
1922
|
for (let key in cachedTransforms) str += transformsFragmentStrings[key] + cachedTransforms[key] + ") ";
|
|
1923
1923
|
targetStyle.transform = str;
|
|
1924
1924
|
}
|
|
1925
|
-
} else if (tweenHadNoInlineValue) targetStyle.removeProperty(toLowerCase(tweenProperty));
|
|
1925
|
+
} else if (tweenHadNoInlineValue) targetStyle.removeProperty(toLowerCase$1(tweenProperty));
|
|
1926
1926
|
else targetStyle[tweenProperty] = originalInlinedValue;
|
|
1927
1927
|
if (animation._tail === tween) animation.targets.forEach((t) => {
|
|
1928
1928
|
if (t.getAttribute && t.getAttribute("style") === "") t.removeAttribute("style");
|
|
@@ -3970,6 +3970,20 @@ function getWeekdayName(weekday = d) {
|
|
|
3970
3970
|
return weekdayNamesList[weekday.getDay()];
|
|
3971
3971
|
}
|
|
3972
3972
|
//#endregion
|
|
3973
|
+
//#region src/utils/string-manipulation.ts
|
|
3974
|
+
/**
|
|
3975
|
+
* # To Lower Case
|
|
3976
|
+
* Converts a string to lowercase, and offers easy string replacements for creating snake case, kebab case, or your own.
|
|
3977
|
+
* @param str - The string to convert to lowercase.
|
|
3978
|
+
* @param options - Configuration options.
|
|
3979
|
+
* @param options[0] - The delimiter to split the string. Defaults to space.
|
|
3980
|
+
* @param options[1] - The string to join the parts back together. Defaults to space.
|
|
3981
|
+
* @returns The lowercase version of the input string, with the replacements, if provided.
|
|
3982
|
+
*/
|
|
3983
|
+
function toLowerCase(str, [delimiter, joiner]) {
|
|
3984
|
+
return str.toLowerCase().replaceAll(delimiter || " ", joiner || " ");
|
|
3985
|
+
}
|
|
3986
|
+
//#endregion
|
|
3973
3987
|
//#region src/components/chevron-up-down-anime.tsx
|
|
3974
3988
|
function ChevronUpDownAnime({ className, isUp = false }) {
|
|
3975
3989
|
const firstLoadRef = useRef(true);
|
|
@@ -6209,46 +6223,43 @@ function Input({ children, className, description, descriptionProps: { className
|
|
|
6209
6223
|
}
|
|
6210
6224
|
//#endregion
|
|
6211
6225
|
//#region src/hooks/create-fast-context.tsx
|
|
6212
|
-
function createFastContext(
|
|
6213
|
-
function useStoreData(
|
|
6214
|
-
const store = useRef(initialState)
|
|
6215
|
-
const
|
|
6216
|
-
|
|
6217
|
-
else store.current = value;
|
|
6218
|
-
subscribers.current.forEach((callback) => callback());
|
|
6219
|
-
};
|
|
6220
|
-
const subscribe = (callback) => {
|
|
6221
|
-
subscribers.current.add(callback);
|
|
6222
|
-
return () => subscribers.current.delete(callback);
|
|
6223
|
-
};
|
|
6226
|
+
function createFastContext(initialState) {
|
|
6227
|
+
function useStoreData() {
|
|
6228
|
+
const store = useRef(initialState);
|
|
6229
|
+
const get = useCallback(() => store.current, []);
|
|
6230
|
+
const subscribers = useRef(/* @__PURE__ */ new Set());
|
|
6224
6231
|
return {
|
|
6225
6232
|
get,
|
|
6226
|
-
set
|
|
6227
|
-
|
|
6233
|
+
set: useCallback((value) => {
|
|
6234
|
+
store.current = {
|
|
6235
|
+
...store.current,
|
|
6236
|
+
...value
|
|
6237
|
+
};
|
|
6238
|
+
subscribers.current.forEach((callback) => callback());
|
|
6239
|
+
}, []),
|
|
6240
|
+
subscribe: useCallback((callback) => {
|
|
6241
|
+
subscribers.current.add(callback);
|
|
6242
|
+
return () => subscribers.current.delete(callback);
|
|
6243
|
+
}, [])
|
|
6228
6244
|
};
|
|
6229
6245
|
}
|
|
6230
6246
|
const StoreContext = createContext(null);
|
|
6231
|
-
function Provider({
|
|
6247
|
+
function Provider({ children }) {
|
|
6232
6248
|
return /* @__PURE__ */ jsx(StoreContext.Provider, {
|
|
6233
|
-
value: useStoreData(
|
|
6234
|
-
|
|
6249
|
+
value: useStoreData(),
|
|
6250
|
+
children
|
|
6235
6251
|
});
|
|
6236
6252
|
}
|
|
6237
|
-
function useStore(selector
|
|
6253
|
+
function useStore(selector) {
|
|
6238
6254
|
const store = useContext(StoreContext);
|
|
6239
|
-
if (!store)
|
|
6240
|
-
|
|
6241
|
-
const noOpSet = () => console.warn("Attempting to set store value outside of Provider");
|
|
6242
|
-
return [selectedValue, noOpSet];
|
|
6243
|
-
}
|
|
6244
|
-
return [useSyncExternalStore(store.subscribe, () => selector(store.get()), () => selector(initialValue !== void 0 ? initialValue : defaultInitialState)), store.set];
|
|
6255
|
+
if (!store) throw new Error("Store not found");
|
|
6256
|
+
return [useSyncExternalStore(store.subscribe, () => selector(store.get()), () => selector(initialState)), store.set];
|
|
6245
6257
|
}
|
|
6246
6258
|
return {
|
|
6247
6259
|
Provider,
|
|
6248
6260
|
useStore
|
|
6249
6261
|
};
|
|
6250
6262
|
}
|
|
6251
|
-
const { Provider, useStore } = createFastContext("incomplete");
|
|
6252
6263
|
//#endregion
|
|
6253
6264
|
//#region src/hooks/use-mobile-device.ts
|
|
6254
6265
|
function useMobileDevice() {
|
|
@@ -6346,7 +6357,7 @@ function ModalTitle({ as, ref, ...props }) {
|
|
|
6346
6357
|
ref
|
|
6347
6358
|
});
|
|
6348
6359
|
}
|
|
6349
|
-
function ModalDialog(props) {
|
|
6360
|
+
function ModalDialog({ dialogPanelProps: { className: dialogPanelClassName, style: dialogPanelStyle, ...dialogPanelProps } = {}, modalScrollContainerProps: { className: modalScrollContainerClassName, ...modalScrollContainerProps } = {}, ...props }) {
|
|
6350
6361
|
const [modalControls, setModalControls] = useModalControls((store) => store), isMobileDevice = useMobileDevice();
|
|
6351
6362
|
const { className, closeModal, dialogPanelRef, isOpen, place, pseudoContainerRef, readyToClose } = modalControls || {};
|
|
6352
6363
|
const [dialogPanelEl, setDialogPanelEl] = useState(null);
|
|
@@ -6382,17 +6393,11 @@ function ModalDialog(props) {
|
|
|
6382
6393
|
if (!setModalControls) return;
|
|
6383
6394
|
if (progressY >= DRAG_TO_CLOSE_PROGRESS && !readyToCloseRef.current) {
|
|
6384
6395
|
readyToCloseRef.current = true;
|
|
6385
|
-
setModalControls(
|
|
6386
|
-
...prev,
|
|
6387
|
-
readyToClose: true
|
|
6388
|
-
}));
|
|
6396
|
+
setModalControls({ readyToClose: true });
|
|
6389
6397
|
}
|
|
6390
6398
|
if (progressY < DRAG_TO_CLOSE_PROGRESS && readyToCloseRef.current) {
|
|
6391
6399
|
readyToCloseRef.current = false;
|
|
6392
|
-
setModalControls(
|
|
6393
|
-
...prev,
|
|
6394
|
-
readyToClose: false
|
|
6395
|
-
}));
|
|
6400
|
+
setModalControls({ readyToClose: false });
|
|
6396
6401
|
}
|
|
6397
6402
|
},
|
|
6398
6403
|
trigger: draggableTrigger
|
|
@@ -6409,7 +6414,6 @@ function ModalDialog(props) {
|
|
|
6409
6414
|
pseudoContainer.style.width = `${width}px`;
|
|
6410
6415
|
pseudoContainer.style.height = `100dvh`;
|
|
6411
6416
|
pseudoContainer.style.zIndex = "-1";
|
|
6412
|
-
pseudoContainer.style.border = "2px solid blue";
|
|
6413
6417
|
document.body.appendChild(pseudoContainer);
|
|
6414
6418
|
animate(dialogPanel, {
|
|
6415
6419
|
...isMobileDevice ? {
|
|
@@ -6477,8 +6481,12 @@ function ModalDialog(props) {
|
|
|
6477
6481
|
})
|
|
6478
6482
|
}), /* @__PURE__ */ jsxs(DialogPanel, {
|
|
6479
6483
|
ref: setDialogPanelRef,
|
|
6480
|
-
|
|
6481
|
-
|
|
6484
|
+
...dialogPanelProps,
|
|
6485
|
+
className: twMerge("fixed left-1/2 w-screen -translate-x-1/2 bg-neutral-50 shadow-[0_-15px_50px_-12px] shadow-neutral-950/25 ease-exponential sm:w-[calc(100vw-2rem)] sm:max-w-fit sm:shadow-2xl dark:bg-neutral-900", place === "center" ? "top-1/2 -translate-y-1/2 rounded-2xl" : "bottom-0 h-fit max-h-[calc(100dvh-4rem)] translate-y-0 rounded-ss-4xl rounded-se-4xl after:absolute after:inset-x-0 after:-bottom-64 after:h-64 after:bg-inherit sm:top-1/2 sm:bottom-auto sm:-translate-y-1/2 sm:rounded-ee-4xl sm:rounded-es-4xl sm:after:hidden pointer-fine:top-1/2 pointer-fine:bottom-auto pointer-fine:-translate-y-1/2 pointer-fine:rounded-3xl", dialogPanelClassName),
|
|
6486
|
+
style: {
|
|
6487
|
+
...dialogPanelStyle,
|
|
6488
|
+
...isMobileDevice ? {} : { opacity: 0 }
|
|
6489
|
+
},
|
|
6482
6490
|
children: [/* @__PURE__ */ jsx("button", {
|
|
6483
6491
|
className: "absolute inset-x-0 top-0 z-10 flex h-6 cursor-grab items-center justify-center after:h-1 after:w-8 after:rounded-full after:bg-neutral-500/50 after:transition-[scale,background-color] after:duration-500 after:ease-exponential active:cursor-grabbing active:after:scale-x-150 active:after:scale-y-125 active:after:bg-neutral-500 data-ready:after:scale-x-200 data-ready:after:scale-y-200 data-ready:after:bg-(--base-theme-color) pointer-fine:hover:after:scale-x-125 pointer-fine:hover:after:bg-neutral-500/75 pointer-fine:active:after:scale-x-150 pointer-fine:active:after:bg-neutral-500 data-ready:pointer-fine:hover:after:scale-x-200 data-ready:pointer-fine:hover:after:scale-y-200 data-ready:pointer-fine:hover:after:bg-(--base-theme-color) data-ready:pointer-fine:active:after:scale-x-200 data-ready:pointer-fine:active:after:scale-y-200 data-ready:pointer-fine:active:after:bg-(--base-theme-color)",
|
|
6484
6492
|
...readyToClose ? { "data-ready": "" } : {},
|
|
@@ -6489,10 +6497,11 @@ function ModalDialog(props) {
|
|
|
6489
6497
|
children: "Drag down to close"
|
|
6490
6498
|
})
|
|
6491
6499
|
}), /* @__PURE__ */ jsx("div", {
|
|
6492
|
-
|
|
6500
|
+
...modalScrollContainerProps,
|
|
6501
|
+
className: twMerge("h-fit max-h-[calc(100dvh-4rem)] overflow-y-scroll px-4 sm:px-6 lg:px-8", modalScrollContainerClassName),
|
|
6493
6502
|
children: /* @__PURE__ */ jsx("div", {
|
|
6494
6503
|
...props,
|
|
6495
|
-
className: "py-
|
|
6504
|
+
className: twMerge("h-full py-3 sm:py-5 lg:py-7", className)
|
|
6496
6505
|
})
|
|
6497
6506
|
})]
|
|
6498
6507
|
})]
|
|
@@ -6525,11 +6534,10 @@ function ModalDisplay({ children, className, onClose, onOpen, place = "bottom" }
|
|
|
6525
6534
|
const closeFunctions = () => {
|
|
6526
6535
|
onClose?.();
|
|
6527
6536
|
modalControls?.pseudoContainerRef?.current?.remove();
|
|
6528
|
-
setModalControls?.(
|
|
6529
|
-
...previous,
|
|
6537
|
+
setModalControls?.({
|
|
6530
6538
|
pseudoContainerRef: { current: null },
|
|
6531
6539
|
readyToClose: false
|
|
6532
|
-
})
|
|
6540
|
+
});
|
|
6533
6541
|
};
|
|
6534
6542
|
const mobileAnimation = {
|
|
6535
6543
|
y: "100%",
|
|
@@ -6558,15 +6566,14 @@ function ModalDisplay({ children, className, onClose, onOpen, place = "bottom" }
|
|
|
6558
6566
|
});
|
|
6559
6567
|
};
|
|
6560
6568
|
useEffect(() => {
|
|
6561
|
-
setModalControls?.(
|
|
6562
|
-
...previous,
|
|
6569
|
+
setModalControls?.({
|
|
6563
6570
|
isOpen,
|
|
6564
6571
|
place,
|
|
6565
6572
|
className,
|
|
6566
6573
|
openModal,
|
|
6567
6574
|
closeModal,
|
|
6568
6575
|
dialogPanelRef: localDialogPanelRef
|
|
6569
|
-
})
|
|
6576
|
+
});
|
|
6570
6577
|
}, [
|
|
6571
6578
|
className,
|
|
6572
6579
|
closeModal,
|
|
@@ -6633,6 +6640,10 @@ function ChevronUpChevronDown({ weight = "regular", ...props }) {
|
|
|
6633
6640
|
}
|
|
6634
6641
|
//#endregion
|
|
6635
6642
|
//#region src/components/select.tsx
|
|
6643
|
+
const { Provider: SelectContextProvider, useStore: useSelectContext } = createFastContext({
|
|
6644
|
+
multiple: false,
|
|
6645
|
+
selectedOptionDisplayProps: {}
|
|
6646
|
+
});
|
|
6636
6647
|
/**
|
|
6637
6648
|
* ## Select Section Title
|
|
6638
6649
|
*
|
|
@@ -6647,48 +6658,32 @@ function SelectSectionTitle({ className, ...props }) {
|
|
|
6647
6658
|
/**
|
|
6648
6659
|
* ## SelectOption
|
|
6649
6660
|
*
|
|
6650
|
-
* @prop children - This is what is displayed in the drop down menu
|
|
6651
|
-
* @prop name - This is displayed in the trigger button
|
|
6652
|
-
* @prop value - This is used for FormData
|
|
6653
|
-
|
|
6654
|
-
|
|
6661
|
+
* @prop children - This is what is displayed in the drop down menu.
|
|
6662
|
+
* @prop name - This is displayed in the trigger button.
|
|
6663
|
+
* @prop value - This is used for FormData.
|
|
6664
|
+
* @prop selectedDisplayProps - This is used to customize the display of the selected option (takes priority over selectedOptionDisplayProps).
|
|
6665
|
+
*/
|
|
6666
|
+
function SelectOption({ children, className, name, selectedDisplayProps: { children: selectedDisplayChildren, className: selectedDisplayClassName, ...selectedDisplayProps } = {}, ...props }) {
|
|
6667
|
+
const [selectContext] = useSelectContext((store) => store), { multiple, selectedOptionDisplayProps } = selectContext || {};
|
|
6668
|
+
const { children: selectedOptionDisplayChildren, className: selectedOptionDisplayClassName } = selectedOptionDisplayProps || {};
|
|
6655
6669
|
return /* @__PURE__ */ jsx(ListboxOption, {
|
|
6656
6670
|
className: "group/option contents",
|
|
6657
6671
|
...props,
|
|
6658
6672
|
children: (bag) => bag.selectedOption ? /* @__PURE__ */ jsx("span", {
|
|
6659
|
-
|
|
6660
|
-
|
|
6673
|
+
...selectedOptionDisplayProps,
|
|
6674
|
+
...selectedDisplayProps,
|
|
6675
|
+
className: twMerge(!selectedDisplayClassName && !selectedOptionDisplayClassName && multiple && `before:content-[',_'] group-first-of-type/option:before:content-['']`, selectedOptionDisplayClassName, selectedDisplayClassName),
|
|
6676
|
+
children: selectedDisplayChildren ? typeof selectedDisplayChildren === "function" ? selectedDisplayChildren(name) : selectedDisplayChildren : selectedOptionDisplayChildren ? typeof selectedOptionDisplayChildren === "function" ? selectedOptionDisplayChildren(name) : selectedOptionDisplayChildren : name
|
|
6661
6677
|
}) : /* @__PURE__ */ jsxs("div", {
|
|
6662
|
-
className: twMerge("flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 transition-[background-color] duration-200 ease-exponential select-none [--theme-color:var(--base-theme-color)] corner-super-1.5 group-disabled/option:opacity-50 group-data-focus/option:bg-(--theme-color)/15 group-data-selected/option:
|
|
6663
|
-
children: [/* @__PURE__ */ jsx(Checkmark, { className: "
|
|
6678
|
+
className: twMerge("flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 transition-[background-color,color] duration-200 ease-exponential select-none [--theme-color:var(--base-theme-color)] corner-super-1.5 group-disabled/option:opacity-50 group-data-focus/option:bg-(--theme-color)/15 group-data-selected/option:text-(--theme-color) dark:group-data-focus/option:bg-(--theme-color)/15", !multiple && "group-data-selected/option:cursor-default group-data-focus/option:group-data-selected/option:bg-transparent", className),
|
|
6679
|
+
children: [/* @__PURE__ */ jsx(Checkmark, { className: "size-3.5 scale-70 opacity-0 transition-[opacity,scale] duration-200 ease-exponential group-data-selected/option:scale-100 group-data-selected/option:opacity-100" }), typeof children === "function" ? children(bag) : children]
|
|
6664
6680
|
})
|
|
6665
6681
|
});
|
|
6666
6682
|
}
|
|
6667
|
-
|
|
6668
|
-
* # Select
|
|
6669
|
-
*
|
|
6670
|
-
* A customizable select component intended to work very similar to HTML's `<select>` element.
|
|
6671
|
-
*
|
|
6672
|
-
* Use the `SelectOption` component to define the options.
|
|
6673
|
-
*
|
|
6674
|
-
* Use the `SelectSectionTitle` component to define titles.
|
|
6675
|
-
*
|
|
6676
|
-
* @prop label - The label for the select component.
|
|
6677
|
-
* @prop description - The description for the select component.
|
|
6678
|
-
* @prop placeholder - The placeholder for the select component.
|
|
6679
|
-
* @prop required - Whether the select component is required.
|
|
6680
|
-
* @prop invalid - Whether the select component is invalid.
|
|
6681
|
-
* @prop multiple - Whether the select component allows multiple selections.
|
|
6682
|
-
* @prop optionsProps - The props to be passed to each SelectOption component.
|
|
6683
|
-
* @prop selectedOptionProps - The props to be passed to the selected option component.
|
|
6684
|
-
* @prop fieldProps - The props to be passed to the parent field component.
|
|
6685
|
-
* @prop labelProps - The props to be passed to the label component.
|
|
6686
|
-
* @prop descriptionProps - The props to be passed to the description component.
|
|
6687
|
-
* @prop anchor - The anchor point for the drop down menu.
|
|
6688
|
-
*/
|
|
6689
|
-
function Select({ buttonProps, children, className, description, descriptionProps: { className: descriptionClassName, ...descriptionProps } = {}, fieldProps: { className: fieldClassName, ...fieldProps } = {}, invalid, label, labelProps: { className: labelClassName, ...labelProps } = {}, onChange, optionsProps: { anchor, className: optionsClassName, transition, ...optionsProps } = {}, placeholder, required, selectedOptionProps: { ...selectedOptionProps } = {}, ...props }) {
|
|
6683
|
+
function SelectField({ buttonProps, children, className, description, descriptionProps: { className: descriptionClassName, ...descriptionProps } = {}, fieldProps: { className: fieldClassName, ...fieldProps } = {}, invalid, label, labelProps: { className: labelClassName, ...labelProps } = {}, onChange, optionsProps: { anchor, className: optionsClassName, transition, ...optionsProps } = {}, placeholder, required, selectedOptionProps, selectedOptionDisplayProps, ...props }) {
|
|
6690
6684
|
const uniqueId = useId();
|
|
6691
|
-
const multiple = props.multiple;
|
|
6685
|
+
const multiple = Boolean(props.multiple);
|
|
6686
|
+
const [, setSelectContext] = useSelectContext((store) => store);
|
|
6692
6687
|
const selectOptionList = Children.toArray(children).filter((child) => isValidElement(child) && child.props && typeof child.props === "object" && "name" in child.props && "value" in child.props && "children" in child.props);
|
|
6693
6688
|
const listboxButtonRef = useRef(null);
|
|
6694
6689
|
const [isInvalid, setIsInvalid] = useState(invalid);
|
|
@@ -6700,6 +6695,15 @@ function Select({ buttonProps, children, className, description, descriptionProp
|
|
|
6700
6695
|
};
|
|
6701
6696
|
const handleInvalid = () => setIsInvalid(true);
|
|
6702
6697
|
const refocus = () => listboxButtonRef.current?.focus();
|
|
6698
|
+
const onVisible = useEffectEvent(() => {
|
|
6699
|
+
setSelectContext?.({
|
|
6700
|
+
multiple,
|
|
6701
|
+
selectedOptionDisplayProps
|
|
6702
|
+
});
|
|
6703
|
+
});
|
|
6704
|
+
useEffect(() => {
|
|
6705
|
+
onVisible();
|
|
6706
|
+
}, []);
|
|
6703
6707
|
return /* @__PURE__ */ jsxs(Field, {
|
|
6704
6708
|
...fieldProps,
|
|
6705
6709
|
className: (bag) => twMerge("grid gap-1", typeof fieldClassName === "function" ? fieldClassName(bag) : fieldClassName),
|
|
@@ -6756,6 +6760,382 @@ function Select({ buttonProps, children, className, description, descriptionProp
|
|
|
6756
6760
|
]
|
|
6757
6761
|
});
|
|
6758
6762
|
}
|
|
6763
|
+
/**
|
|
6764
|
+
* # Select
|
|
6765
|
+
*
|
|
6766
|
+
* A customizable select component intended to work very similar to HTML's `<select>` element.
|
|
6767
|
+
*
|
|
6768
|
+
* Use the `SelectOption` component to define the options.
|
|
6769
|
+
*
|
|
6770
|
+
* Use the `SelectSectionTitle` component to define titles.
|
|
6771
|
+
*
|
|
6772
|
+
* @prop label - The label for the select component.
|
|
6773
|
+
* @prop description - The description for the select component.
|
|
6774
|
+
* @prop placeholder - The placeholder for the select component.
|
|
6775
|
+
* @prop required - Whether the select component is required.
|
|
6776
|
+
* @prop invalid - Whether the select component is invalid.
|
|
6777
|
+
* @prop multiple - Whether the select component allows multiple selections.
|
|
6778
|
+
* @prop optionsProps - The props to be passed to each SelectOption component.
|
|
6779
|
+
* @prop selectedOptionProps - The props to be passed to the selected option component.
|
|
6780
|
+
* @prop selectedOptionDisplayProps - The props to be passed to each selected option in the selected option component.
|
|
6781
|
+
* @prop fieldProps - The props to be passed to the parent field component.
|
|
6782
|
+
* @prop labelProps - The props to be passed to the label component.
|
|
6783
|
+
* @prop descriptionProps - The props to be passed to the description component.
|
|
6784
|
+
* @prop anchor - The anchor point for the drop down menu.
|
|
6785
|
+
*/
|
|
6786
|
+
function Select(props) {
|
|
6787
|
+
return /* @__PURE__ */ jsx(SelectContextProvider, { children: /* @__PURE__ */ jsx(SelectField, { ...props }) });
|
|
6788
|
+
}
|
|
6789
|
+
//#endregion
|
|
6790
|
+
//#region src/symbols/plus.tsx
|
|
6791
|
+
function Plus({ weight = "regular", ...props }) {
|
|
6792
|
+
switch (weight) {
|
|
6793
|
+
case "ultralight": return /* @__PURE__ */ jsx("svg", {
|
|
6794
|
+
viewBox: "9.76562 -65.2349 59.96 59.96",
|
|
6795
|
+
...props,
|
|
6796
|
+
children: /* @__PURE__ */ jsx("path", { d: "M40.8828-6.4126L40.8828-64.0952C40.8828-64.7417 40.3511-65.2349 39.7466-65.2349C39.1421-65.2349 38.6069-64.7417 38.6069-64.0952L38.6069-6.4126C38.6069-5.76611 39.1421-5.27293 39.7466-5.27293C40.3511-5.27293 40.8828-5.76611 40.8828-6.4126ZM10.9053-34.1142L68.5879-34.1142C69.2344-34.1142 69.7242-34.6494 69.7242-35.2539C69.7242-35.8584 69.2344-36.3936 68.5879-36.3936L10.9053-36.3936C10.2554-36.3936 9.76562-35.8584 9.76562-35.2539C9.76562-34.6494 10.2554-34.1142 10.9053-34.1142Z" })
|
|
6797
|
+
});
|
|
6798
|
+
case "thin": return /* @__PURE__ */ jsx("svg", {
|
|
6799
|
+
viewBox: "9.76562 -65.6758 60.83 60.84",
|
|
6800
|
+
...props,
|
|
6801
|
+
children: /* @__PURE__ */ jsx("path", { d: "M41.9492-6.60743L41.9492-63.9004C41.9492-64.875 41.1406-65.6758 40.1875-65.6758C39.2344-65.6758 38.4121-64.875 38.4121-63.9004L38.4121-6.60743C38.4121-5.63281 39.2344-4.83202 40.1875-4.83202C41.1406-4.83202 41.9492-5.63281 41.9492-6.60743ZM11.541-33.4785L68.834-33.4785C69.8086-33.4785 70.5957-34.3008 70.5957-35.2539C70.5957-36.207 69.8086-37.0293 68.834-37.0293L11.541-37.0293C10.5527-37.0293 9.76562-36.207 9.76562-35.2539C9.76562-34.3008 10.5527-33.4785 11.541-33.4785Z" })
|
|
6802
|
+
});
|
|
6803
|
+
case "light": return /* @__PURE__ */ jsx("svg", {
|
|
6804
|
+
viewBox: "9.76562 -66.5366 62.53 62.57",
|
|
6805
|
+
...props,
|
|
6806
|
+
children: /* @__PURE__ */ jsx("path", { d: "M44.0313-6.9878L44.0313-63.52C44.0313-65.1353 42.6821-66.5366 41.0483-66.5366C39.4146-66.5366 38.0317-65.1353 38.0317-63.52L38.0317-6.9878C38.0317-5.37256 39.4146-3.97119 41.0483-3.97119C42.6821-3.97119 44.0313-5.37256 44.0313-6.9878ZM12.7822-32.2373L69.3145-32.2373C70.9297-32.2373 72.2974-33.6201 72.2974-35.2539C72.2974-36.8877 70.9297-38.2705 69.3145-38.2705L12.7822-38.2705C11.1333-38.2705 9.76562-36.8877 9.76562-35.2539C9.76562-33.6201 11.1333-32.2373 12.7822-32.2373Z" })
|
|
6807
|
+
});
|
|
6808
|
+
case "regular": return /* @__PURE__ */ jsx("svg", {
|
|
6809
|
+
viewBox: "9.76562 -67.1875 63.82 63.87",
|
|
6810
|
+
...props,
|
|
6811
|
+
children: /* @__PURE__ */ jsx("path", { d: "M45.6055-7.27539L45.6055-63.2324C45.6055-65.332 43.8477-67.1875 41.6992-67.1875C39.5508-67.1875 37.7441-65.332 37.7441-63.2324L37.7441-7.27539C37.7441-5.17578 39.5508-3.32031 41.6992-3.32031C43.8477-3.32031 45.6055-5.17578 45.6055-7.27539ZM13.7207-31.2988L69.6777-31.2988C71.7773-31.2988 73.584-33.1055 73.584-35.2539C73.584-37.4023 71.7773-39.209 69.6777-39.209L13.7207-39.209C11.5723-39.209 9.76562-37.4023 9.76562-35.2539C9.76562-33.1055 11.5723-31.2988 13.7207-31.2988Z" })
|
|
6812
|
+
});
|
|
6813
|
+
case "medium": return /* @__PURE__ */ jsx("svg", {
|
|
6814
|
+
viewBox: "9.76562 -67.6006 64.67 64.71",
|
|
6815
|
+
...props,
|
|
6816
|
+
children: /* @__PURE__ */ jsx("path", { d: "M46.8623-7.6709L46.8623-62.8193C46.8623-65.3936 44.7354-67.6006 42.1211-67.6006C39.5068-67.6006 37.3398-65.3936 37.3398-62.8193L37.3398-7.6709C37.3398-5.09668 39.5068-2.88965 42.1211-2.88965C44.7354-2.88965 46.8623-5.09668 46.8623-7.6709ZM14.5469-30.4639L69.6953-30.4639C72.2695-30.4639 74.4365-32.6309 74.4365-35.2451C74.4365-37.8594 72.2695-40.0264 69.6953-40.0264L14.5469-40.0264C11.9326-40.0264 9.76562-37.8594 9.76562-35.2451C9.76562-32.6309 11.9326-30.4639 14.5469-30.4639Z" })
|
|
6817
|
+
});
|
|
6818
|
+
case "semibold": return /* @__PURE__ */ jsx("svg", {
|
|
6819
|
+
viewBox: "9.76562 -67.9173 65.32 65.36",
|
|
6820
|
+
...props,
|
|
6821
|
+
children: /* @__PURE__ */ jsx("path", { d: "M47.8259-7.97412L47.8259-62.5026C47.8259-65.4407 45.4159-67.9173 42.4445-67.9173C39.4731-67.9173 37.0299-65.4407 37.0299-62.5026L37.0299-7.97412C37.0299-5.03604 39.4731-2.55947 42.4445-2.55947C45.4159-2.55947 47.8259-5.03604 47.8259-7.97412ZM15.1803-29.8237L69.7088-29.8237C72.6469-29.8237 75.0901-32.267 75.0901-35.2384C75.0901-38.2098 72.6469-40.653 69.7088-40.653L15.1803-40.653C12.2089-40.653 9.76562-38.2098 9.76562-35.2384C9.76562-32.267 12.2089-29.8237 15.1803-29.8237Z" })
|
|
6822
|
+
});
|
|
6823
|
+
case "bold": return /* @__PURE__ */ jsx("svg", {
|
|
6824
|
+
viewBox: "9.76562 -68.335 66.19 66.21",
|
|
6825
|
+
...props,
|
|
6826
|
+
children: /* @__PURE__ */ jsx("path", { d: "M49.0967-8.37402L49.0967-62.085C49.0967-65.5029 46.3135-68.335 42.8711-68.335C39.4287-68.335 36.6211-65.5029 36.6211-62.085L36.6211-8.37402C36.6211-4.95605 39.4287-2.12402 42.8711-2.12402C46.3135-2.12402 49.0967-4.95605 49.0967-8.37402ZM16.0156-28.9795L69.7266-28.9795C73.1445-28.9795 75.9521-31.7871 75.9521-35.2295C75.9521-38.6719 73.1445-41.4795 69.7266-41.4795L16.0156-41.4795C12.5732-41.4795 9.76562-38.6719 9.76562-35.2295C9.76562-31.7871 12.5732-28.9795 16.0156-28.9795Z" })
|
|
6827
|
+
});
|
|
6828
|
+
case "heavy": return /* @__PURE__ */ jsx("svg", {
|
|
6829
|
+
viewBox: "9.76562 -68.9408 67.44 67.45",
|
|
6830
|
+
...props,
|
|
6831
|
+
children: /* @__PURE__ */ jsx("path", { d: "M50.9399-8.95406L50.9399-61.4791C50.9399-65.5932 47.6153-68.9408 43.4898-68.9408C39.3643-68.9408 36.0282-65.5932 36.0282-61.4791L36.0282-8.95406C36.0282-4.84005 39.3643-1.49243 43.4898-1.49243C47.6153-1.49243 50.9399-4.84005 50.9399-8.95406ZM17.2272-27.755L69.7523-27.755C73.8663-27.755 77.2024-31.0911 77.2024-35.2166C77.2024-39.3421 73.8663-42.6782 69.7523-42.6782L17.2272-42.6782C13.1017-42.6782 9.76562-39.3421 9.76562-35.2166C9.76562-31.0911 13.1017-27.755 17.2272-27.755Z" })
|
|
6832
|
+
});
|
|
6833
|
+
case "black": return /* @__PURE__ */ jsx("svg", {
|
|
6834
|
+
viewBox: "9.76562 -69.4824 68.55 68.55",
|
|
6835
|
+
...props,
|
|
6836
|
+
children: /* @__PURE__ */ jsx("path", { d: "M52.5879-9.47266L52.5879-60.9375C52.5879-65.6738 48.7793-69.4824 44.043-69.4824C39.3066-69.4824 35.498-65.6738 35.498-60.9375L35.498-9.47266C35.498-4.73633 39.3066-0.927734 44.043-0.927734C48.7793-0.927734 52.5879-4.73633 52.5879-9.47266ZM18.3105-26.6602L69.7754-26.6602C74.5117-26.6602 78.3203-30.4688 78.3203-35.2051C78.3203-39.9414 74.5117-43.75 69.7754-43.75L18.3105-43.75C13.5742-43.75 9.76562-39.9414 9.76562-35.2051C9.76562-30.4688 13.5742-26.6602 18.3105-26.6602Z" })
|
|
6837
|
+
});
|
|
6838
|
+
}
|
|
6839
|
+
}
|
|
6840
|
+
//#endregion
|
|
6841
|
+
//#region src/components/search.tsx
|
|
6842
|
+
const { Provider: SearchContextProvider, useStore: useSearchContext } = createFastContext({
|
|
6843
|
+
multiple: false,
|
|
6844
|
+
query: "",
|
|
6845
|
+
selectedOptionDisplayProps: {},
|
|
6846
|
+
selectedOptionList: []
|
|
6847
|
+
});
|
|
6848
|
+
/**
|
|
6849
|
+
* ## Search Section Title
|
|
6850
|
+
*
|
|
6851
|
+
* Displays a simple title.
|
|
6852
|
+
*/
|
|
6853
|
+
function SearchSectionTitle({ className, ...props }) {
|
|
6854
|
+
return /* @__PURE__ */ jsx("div", {
|
|
6855
|
+
className: twMerge("sticky -top-1 z-10 -mx-1 bg-inherit mask-t-from-transparent mask-t-from-0 mask-t-to-white mask-t-to-1.5 pl-2 font-bold text-neutral-500/50 backdrop-blur-[2px] backdrop-brightness-101", className),
|
|
6856
|
+
...props
|
|
6857
|
+
});
|
|
6858
|
+
}
|
|
6859
|
+
/**
|
|
6860
|
+
* ## SearchOption
|
|
6861
|
+
*
|
|
6862
|
+
* @prop children - This is what is displayed in the drop down menu
|
|
6863
|
+
* @prop name - This is used for filtering by default
|
|
6864
|
+
* @prop value - This is used as selected value and for FormData
|
|
6865
|
+
*/
|
|
6866
|
+
function SearchOption({ children, className, isInDisplay, name, selectedDisplayProps: { children: selectedDisplayChildren, className: selectedDisplayClassName, ...selectedDisplayProps } = {}, value, ...props }) {
|
|
6867
|
+
const [searchContext] = useSearchContext((store) => store);
|
|
6868
|
+
const { multiple, query, selectedOptionDisplayProps } = searchContext || {};
|
|
6869
|
+
if (!((query || "").trim() === "" || name.toLowerCase().includes((query || "").toLowerCase()) || isInDisplay)) return /* @__PURE__ */ jsx(Fragment, {});
|
|
6870
|
+
const { children: selectedOptionDisplayChildren, className: selectedOptionDisplayClassName } = selectedOptionDisplayProps || {};
|
|
6871
|
+
return isInDisplay ? /* @__PURE__ */ jsx("span", {
|
|
6872
|
+
...selectedOptionDisplayProps,
|
|
6873
|
+
...selectedDisplayProps,
|
|
6874
|
+
className: twMerge(!selectedDisplayClassName && !selectedOptionDisplayClassName && multiple && `after:content-[',_'] last-of-type:after:content-['']`, selectedOptionDisplayClassName, selectedDisplayClassName),
|
|
6875
|
+
children: selectedDisplayChildren ? typeof selectedDisplayChildren === "function" ? selectedDisplayChildren(name) : selectedDisplayChildren : selectedOptionDisplayChildren ? typeof selectedOptionDisplayChildren === "function" ? selectedOptionDisplayChildren(name) : selectedOptionDisplayChildren : name
|
|
6876
|
+
}) : /* @__PURE__ */ jsx(ComboboxOption, {
|
|
6877
|
+
className: "group/option contents",
|
|
6878
|
+
value: {
|
|
6879
|
+
id: value,
|
|
6880
|
+
name
|
|
6881
|
+
},
|
|
6882
|
+
...props,
|
|
6883
|
+
children: (bag) => /* @__PURE__ */ jsxs("div", {
|
|
6884
|
+
className: twMerge("flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 transition-[background-color,color] duration-200 ease-exponential select-none [--theme-color:var(--base-theme-color)] corner-super-1.5 group-disabled/option:opacity-50 group-data-focus/option:bg-(--theme-color)/15 group-data-selected/option:text-(--theme-color) dark:group-data-focus/option:bg-(--theme-color)/15", !multiple && "group-data-selected/option:cursor-default group-data-focus/option:group-data-selected/option:bg-transparent", className),
|
|
6885
|
+
children: [/* @__PURE__ */ jsx(Checkmark, { className: "size-3.5 scale-70 opacity-0 transition-[opacity,scale] duration-200 ease-exponential group-data-selected/option:scale-100 group-data-selected/option:opacity-100" }), typeof children === "function" ? children(bag) : children ?? name]
|
|
6886
|
+
})
|
|
6887
|
+
});
|
|
6888
|
+
}
|
|
6889
|
+
function checkEquality(aOptionList, bOptionList) {
|
|
6890
|
+
if (aOptionList.length !== bOptionList.length) return false;
|
|
6891
|
+
for (let i = 0; i < aOptionList.length; i += 1) {
|
|
6892
|
+
const aOption = aOptionList[i], bOption = bOptionList[i];
|
|
6893
|
+
if (aOption?.id !== bOption?.id || aOption?.name !== bOption?.name) return false;
|
|
6894
|
+
}
|
|
6895
|
+
return true;
|
|
6896
|
+
}
|
|
6897
|
+
function SearchField({ allowCustom, buttonProps, children, className, defaultValue, description, descriptionProps: { className: descriptionClassName, ...descriptionProps } = {}, fieldProps: { className: fieldClassName, ...fieldProps } = {}, inputProps, invalid, label, labelProps: { className: labelClassName, ...labelProps } = {}, multiple, onChange, optionsProps: { anchor, className: optionsClassName, transition, ...optionsProps } = {}, placeholder, required = true, shelfProps: { className: shelfClassName, ...shelfProps } = {}, selectedOptionDisplayProps, singleDisplay, ...props }) {
|
|
6898
|
+
const uniqueId = useId();
|
|
6899
|
+
const [searchContext, setSearchContext] = useSearchContext((store) => store), { query } = searchContext || {};
|
|
6900
|
+
const [isInvalid, setIsInvalid] = useState(invalid);
|
|
6901
|
+
const [selectedOptionSync, setSelectedOptionSync] = useState(() => {
|
|
6902
|
+
if (multiple) return Array.isArray(defaultValue) ? defaultValue : [];
|
|
6903
|
+
return typeof defaultValue === "string" ? defaultValue : null;
|
|
6904
|
+
});
|
|
6905
|
+
const comboboxInputRef = useRef(null);
|
|
6906
|
+
const childOptionList = useMemo(() => Children.toArray(children).filter((child) => isValidElement(child) && !!child.props && "value" in child.props && "name" in child.props), [children]);
|
|
6907
|
+
const staticOptionList = useMemo(() => childOptionList.map((child) => ({
|
|
6908
|
+
id: child.props.value,
|
|
6909
|
+
name: child.props.name,
|
|
6910
|
+
selectedDisplayProps: child.props.selectedDisplayProps
|
|
6911
|
+
})), [childOptionList]);
|
|
6912
|
+
const [addedOptionList, setAddedOptionList] = useState([]);
|
|
6913
|
+
const customOptionFromQuery = useMemo(() => {
|
|
6914
|
+
const trimmedQuery = query.trim();
|
|
6915
|
+
if (!allowCustom || trimmedQuery.length === 0) return null;
|
|
6916
|
+
return {
|
|
6917
|
+
id: props.customOptionParams?.formatID?.(trimmedQuery) ?? toLowerCase(trimmedQuery, [" ", "_"]),
|
|
6918
|
+
name: trimmedQuery
|
|
6919
|
+
};
|
|
6920
|
+
}, [
|
|
6921
|
+
allowCustom,
|
|
6922
|
+
props.customOptionParams,
|
|
6923
|
+
query
|
|
6924
|
+
]);
|
|
6925
|
+
const optionLookupMap = useMemo(() => {
|
|
6926
|
+
const lookupMap = /* @__PURE__ */ new Map();
|
|
6927
|
+
for (const option of staticOptionList) lookupMap.set(option.id, option.name);
|
|
6928
|
+
for (const option of addedOptionList) lookupMap.set(option.id, option.name);
|
|
6929
|
+
return lookupMap;
|
|
6930
|
+
}, [addedOptionList, staticOptionList]);
|
|
6931
|
+
const saveCustomOption = useEffectEvent((option) => {
|
|
6932
|
+
if (!multiple) return;
|
|
6933
|
+
setAddedOptionList((prevOptionList) => {
|
|
6934
|
+
if (prevOptionList.some((prevOption) => prevOption.id === option.id)) return prevOptionList;
|
|
6935
|
+
return [...prevOptionList, option];
|
|
6936
|
+
});
|
|
6937
|
+
});
|
|
6938
|
+
const handleChange = (selected) => {
|
|
6939
|
+
setIsInvalid(false);
|
|
6940
|
+
if (multiple && Array.isArray(selected)) {
|
|
6941
|
+
const selectedValueList = selected.map((selectedValue) => {
|
|
6942
|
+
if (selectedValue && typeof selectedValue === "object" && "id" in selectedValue && "name" in selectedValue) {
|
|
6943
|
+
const option = {
|
|
6944
|
+
id: String(selectedValue.id),
|
|
6945
|
+
name: String(selectedValue.name)
|
|
6946
|
+
};
|
|
6947
|
+
saveCustomOption(option);
|
|
6948
|
+
return option.id;
|
|
6949
|
+
}
|
|
6950
|
+
return String(selectedValue);
|
|
6951
|
+
});
|
|
6952
|
+
setSelectedOptionSync(selectedValueList);
|
|
6953
|
+
onChange?.(selectedValueList);
|
|
6954
|
+
return;
|
|
6955
|
+
}
|
|
6956
|
+
if (!multiple) {
|
|
6957
|
+
const normalizedSelected = selected && typeof selected === "object" && !Array.isArray(selected) ? String(selected.id) : selected;
|
|
6958
|
+
setSelectedOptionSync(normalizedSelected);
|
|
6959
|
+
onChange?.(normalizedSelected);
|
|
6960
|
+
return;
|
|
6961
|
+
}
|
|
6962
|
+
setSelectedOptionSync(selected);
|
|
6963
|
+
};
|
|
6964
|
+
const formatSelectedDisplay = (name) => {
|
|
6965
|
+
const selectedOptionDisplayChildren = selectedOptionDisplayProps?.children;
|
|
6966
|
+
if (!selectedOptionDisplayChildren) return name;
|
|
6967
|
+
const selectedOptionDisplayValue = typeof selectedOptionDisplayChildren === "function" ? selectedOptionDisplayChildren(name) : selectedOptionDisplayChildren;
|
|
6968
|
+
return typeof selectedOptionDisplayValue === "string" ? selectedOptionDisplayValue : name;
|
|
6969
|
+
};
|
|
6970
|
+
const handleInvalid = () => setIsInvalid(true);
|
|
6971
|
+
const refocus = () => comboboxInputRef.current?.focus();
|
|
6972
|
+
const onVisible = useEffectEvent(() => {
|
|
6973
|
+
setSearchContext?.({
|
|
6974
|
+
multiple,
|
|
6975
|
+
query: "",
|
|
6976
|
+
selectedOptionDisplayProps
|
|
6977
|
+
});
|
|
6978
|
+
});
|
|
6979
|
+
useEffect(() => {
|
|
6980
|
+
onVisible();
|
|
6981
|
+
}, []);
|
|
6982
|
+
useEffect(() => {
|
|
6983
|
+
const selectedOptionList = (Array.isArray(selectedOptionSync) ? selectedOptionSync : typeof selectedOptionSync === "string" ? [selectedOptionSync] : []).map((selectedId) => ({
|
|
6984
|
+
id: selectedId,
|
|
6985
|
+
name: optionLookupMap.get(selectedId) ?? selectedId
|
|
6986
|
+
}));
|
|
6987
|
+
if (!checkEquality(searchContext?.selectedOptionList ?? [], selectedOptionList)) setSearchContext?.({ selectedOptionList });
|
|
6988
|
+
}, [
|
|
6989
|
+
optionLookupMap,
|
|
6990
|
+
searchContext?.selectedOptionList,
|
|
6991
|
+
selectedOptionSync,
|
|
6992
|
+
setSearchContext
|
|
6993
|
+
]);
|
|
6994
|
+
const queryChange = (e) => {
|
|
6995
|
+
const { currentTarget } = e, { value } = currentTarget;
|
|
6996
|
+
setSearchContext?.({ query: value });
|
|
6997
|
+
};
|
|
6998
|
+
const handleClose = () => {
|
|
6999
|
+
setSearchContext?.({ query: "" });
|
|
7000
|
+
};
|
|
7001
|
+
const updateDisplayValue = (value) => {
|
|
7002
|
+
if (multiple && Array.isArray(value)) {
|
|
7003
|
+
if (singleDisplay) return value.map((v) => formatSelectedDisplay(v.name)).join(", ");
|
|
7004
|
+
}
|
|
7005
|
+
if (!multiple && value) return formatSelectedDisplay(value.name);
|
|
7006
|
+
return "";
|
|
7007
|
+
};
|
|
7008
|
+
return /* @__PURE__ */ jsxs(Field, {
|
|
7009
|
+
...fieldProps,
|
|
7010
|
+
className: (bag) => twMerge("grid gap-1", typeof fieldClassName === "function" ? fieldClassName(bag) : fieldClassName),
|
|
7011
|
+
children: [
|
|
7012
|
+
label && /* @__PURE__ */ jsx(Label, {
|
|
7013
|
+
...labelProps,
|
|
7014
|
+
className: (bag) => twMerge("text-sm font-medium", required ? `after:text-red-700 after:content-['_*']` : "", typeof labelClassName === "function" ? labelClassName(bag) : labelClassName),
|
|
7015
|
+
children: label
|
|
7016
|
+
}),
|
|
7017
|
+
/* @__PURE__ */ jsxs(Combobox, {
|
|
7018
|
+
...props,
|
|
7019
|
+
invalid: isInvalid || invalid,
|
|
7020
|
+
multiple,
|
|
7021
|
+
onChange: handleChange,
|
|
7022
|
+
onClose: handleClose,
|
|
7023
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
7024
|
+
...multiple ? { "data-multiple": "" } : {},
|
|
7025
|
+
className: "isolate contents data-multiple:grid",
|
|
7026
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
7027
|
+
className: "relative",
|
|
7028
|
+
children: [
|
|
7029
|
+
/* @__PURE__ */ jsx(ComboboxInput, {
|
|
7030
|
+
...inputProps,
|
|
7031
|
+
"aria-label": typeof label === "string" ? label : props.name,
|
|
7032
|
+
className: (bag) => twMerge("inline-block w-full overflow-clip rounded-xl border border-neutral-500/50 bg-neutral-100 py-1 pr-8 pl-2 text-left text-neutral-950 outline-offset-1 outline-blue-400/95 transition-[background-color] duration-300 ease-exponential corner-super-1.5 dark:bg-neutral-700 dark:text-neutral-50", "focus:outline-3 focus-visible:bg-neutral-50 focus-visible:outline-3 active:bg-neutral-200 dark:focus-visible:bg-neutral-600 dark:active:bg-neutral-800 pointer-fine:hover:bg-neutral-50 pointer-fine:active:bg-neutral-200 dark:pointer-fine:hover:bg-neutral-600 dark:pointer-fine:active:bg-neutral-800", "data-invalid:border-red-500 data-invalid:bg-[color-mix(in_oklch,var(--color-red-500)_5%,var(--color-neutral-100)_5%)] data-invalid:focus-visible:bg-[color-mix(in_oklch,var(--color-red-500)_1%,var(--color-neutral-100))] data-invalid:active:bg-[color-mix(in_oklch,var(--color-red-500)_5%,var(--color-neutral-100))] dark:data-invalid:bg-[color-mix(in_oklch,var(--color-red-500)_5%,var(--color-neutral-800)_5%)] dark:data-invalid:focus-visible:bg-[color-mix(in_oklch,var(--color-red-500)_1%,var(--color-neutral-800))] dark:data-invalid:active:bg-[color-mix(in_oklch,var(--color-red-500)_5%,var(--color-neutral-800)_5%)] data-invalid:pointer-fine:hover:bg-[color-mix(in_oklch,var(--color-red-500)_10%,var(--color-neutral-500)_5%)] data-invalid:pointer-fine:focus-visible:bg-[color-mix(in_oklch,var(--color-red-500)_1%,var(--color-neutral-100))] data-invalid:pointer-fine:active:bg-[color-mix(in_oklch,var(--color-red-500)_5%,var(--color-neutral-100))] dark:data-invalid:pointer-fine:hover:bg-[color-mix(in_oklch,var(--color-red-500)_10%,var(--color-neutral-800)_5%)] dark:data-invalid:pointer-fine:focus-visible:bg-[color-mix(in_oklch,var(--color-red-500)_1%,var(--color-neutral-800))] dark:data-invalid:pointer-fine:active:bg-[color-mix(in_oklch,var(--color-red-500)_5%,var(--color-neutral-800)_5%)]", typeof className === "function" ? className(bag) : className),
|
|
7033
|
+
displayValue: updateDisplayValue,
|
|
7034
|
+
name: props.name,
|
|
7035
|
+
onChange: queryChange,
|
|
7036
|
+
placeholder: placeholder || `${multiple ? "Choose Any" : "Choose One"}${allowCustom ? " or Create Your Own" : ""}`,
|
|
7037
|
+
ref: comboboxInputRef,
|
|
7038
|
+
required
|
|
7039
|
+
}),
|
|
7040
|
+
/* @__PURE__ */ jsx("input", {
|
|
7041
|
+
"aria-hidden": "true",
|
|
7042
|
+
className: "sr-only top-0 left-1/2",
|
|
7043
|
+
id: props.name + ":input:id" + uniqueId,
|
|
7044
|
+
name: props.name,
|
|
7045
|
+
onChange: () => {},
|
|
7046
|
+
onFocus: refocus,
|
|
7047
|
+
onInvalid: handleInvalid,
|
|
7048
|
+
required,
|
|
7049
|
+
tabIndex: -1,
|
|
7050
|
+
value: Array.isArray(selectedOptionSync) ? selectedOptionSync.join(", ") : selectedOptionSync ?? ""
|
|
7051
|
+
}),
|
|
7052
|
+
/* @__PURE__ */ jsx(ComboboxButton, {
|
|
7053
|
+
...buttonProps,
|
|
7054
|
+
className: "absolute top-1/2 right-1.5 -translate-y-1/2 rounded p-0.5",
|
|
7055
|
+
children: /* @__PURE__ */ jsx(ChevronUpChevronDown, { className: "size-3 fill-current/50" })
|
|
7056
|
+
})
|
|
7057
|
+
]
|
|
7058
|
+
}), multiple && !singleDisplay && /* @__PURE__ */ jsx("div", {
|
|
7059
|
+
...shelfProps,
|
|
7060
|
+
className: twMerge("flex min-h-8 flex-wrap gap-1 p-2 before:absolute before:inset-x-0 before:-top-4 before:bottom-0 before:-z-10 before:rounded-b-xl before:border before:border-t-0 before:border-neutral-500/50", shelfClassName),
|
|
7061
|
+
children: searchContext?.selectedOptionList?.length > 0 && [...staticOptionList, ...addedOptionList].filter((option, optionIndex, optionList) => {
|
|
7062
|
+
return optionList.findIndex((innerOption) => innerOption.id === option.id) === optionIndex;
|
|
7063
|
+
}).map((option) => {
|
|
7064
|
+
if (!searchContext.selectedOptionList.some(({ id }) => id === option.id)) return null;
|
|
7065
|
+
return /* @__PURE__ */ jsx(SearchOption, {
|
|
7066
|
+
name: option.name,
|
|
7067
|
+
value: option.id,
|
|
7068
|
+
selectedDisplayProps: option.selectedDisplayProps,
|
|
7069
|
+
isInDisplay: true,
|
|
7070
|
+
children: option.name
|
|
7071
|
+
}, option.id);
|
|
7072
|
+
}).filter(Boolean)
|
|
7073
|
+
})]
|
|
7074
|
+
}), /* @__PURE__ */ jsxs(ComboboxOptions, {
|
|
7075
|
+
...optionsProps,
|
|
7076
|
+
anchor: anchor || "bottom start",
|
|
7077
|
+
className: (bag) => twMerge("z-50 w-(--input-width) origin-top rounded-xl border border-neutral-500/50 bg-neutral-50/95 p-1 backdrop-blur-sm backdrop-brightness-110 transition-[opacity,scale,translate] duration-300 ease-exponential corner-super-1.5 empty:invisible focus:outline-none data-closed:-translate-y-0.5 data-closed:scale-y-0 data-closed:opacity-0 data-[anchor*=top]:origin-bottom dark:bg-neutral-800/95", multiple && !singleDisplay ? "[--anchor-gap:--spacing(8)]" : "[--anchor-gap:--spacing(1)]", typeof optionsClassName === "function" ? optionsClassName(bag) : optionsClassName),
|
|
7078
|
+
transition: transition ?? true,
|
|
7079
|
+
children: [
|
|
7080
|
+
allowCustom && query.length > 0 && customOptionFromQuery && !addedOptionList.some((addedOption) => addedOption.id === customOptionFromQuery.id) && /* @__PURE__ */ jsx(ComboboxOption, {
|
|
7081
|
+
value: customOptionFromQuery,
|
|
7082
|
+
className: "group/option contents",
|
|
7083
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
7084
|
+
className: "flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 transition-[background-color] duration-200 ease-exponential select-none [--theme-color:var(--base-theme-color)] corner-super-1.5 group-disabled/option:opacity-50 group-data-focus/option:bg-(--theme-color)/15 dark:group-data-focus/option:bg-(--theme-color)/15",
|
|
7085
|
+
children: [
|
|
7086
|
+
/* @__PURE__ */ jsx(Plus, { className: "size-3.5" }),
|
|
7087
|
+
"Use ",
|
|
7088
|
+
/* @__PURE__ */ jsxs("b", { children: [
|
|
7089
|
+
"\"",
|
|
7090
|
+
query,
|
|
7091
|
+
"\""
|
|
7092
|
+
] })
|
|
7093
|
+
]
|
|
7094
|
+
})
|
|
7095
|
+
}),
|
|
7096
|
+
children,
|
|
7097
|
+
multiple && addedOptionList.filter((addedOption) => !staticOptionList.some((staticOption) => staticOption.id === addedOption.id)).map((addedOption) => /* @__PURE__ */ jsx(SearchOption, {
|
|
7098
|
+
name: addedOption.name,
|
|
7099
|
+
value: addedOption.id,
|
|
7100
|
+
selectedDisplayProps: addedOption.selectedDisplayProps,
|
|
7101
|
+
children: addedOption.name
|
|
7102
|
+
}, "added:" + addedOption.id))
|
|
7103
|
+
]
|
|
7104
|
+
})]
|
|
7105
|
+
}),
|
|
7106
|
+
description && /* @__PURE__ */ jsx(Description, {
|
|
7107
|
+
...descriptionProps,
|
|
7108
|
+
className: (bag) => twMerge("text-xs text-current/60", typeof descriptionClassName === "function" ? descriptionClassName(bag) : descriptionClassName),
|
|
7109
|
+
children: description
|
|
7110
|
+
})
|
|
7111
|
+
]
|
|
7112
|
+
});
|
|
7113
|
+
}
|
|
7114
|
+
/**
|
|
7115
|
+
* # Search
|
|
7116
|
+
*
|
|
7117
|
+
* A searchable select component built on top of Headless UI's `Combobox`.
|
|
7118
|
+
*
|
|
7119
|
+
* Use the `SearchOption` component to define options.
|
|
7120
|
+
*
|
|
7121
|
+
* Use the `SearchSectionTitle` component to define titles.
|
|
7122
|
+
*
|
|
7123
|
+
* @prop label - The label for the select component.
|
|
7124
|
+
* @prop description - The description for the select component.
|
|
7125
|
+
* @prop placeholder - The placeholder for the select component.
|
|
7126
|
+
* @prop required - Whether the select component is required.
|
|
7127
|
+
* @prop invalid - Whether the select component is invalid.
|
|
7128
|
+
* @prop multiple - Whether the select component allows multiple selections.
|
|
7129
|
+
* @prop optionsProps - The props to be passed to each SearchOption component.
|
|
7130
|
+
* @prop selectedOptionDisplayProps - The props to be passed to each selected option in the selected option component.
|
|
7131
|
+
* @prop fieldProps - The props to be passed to the parent field component.
|
|
7132
|
+
* @prop labelProps - The props to be passed to the label component.
|
|
7133
|
+
* @prop descriptionProps - The props to be passed to the description component.
|
|
7134
|
+
* @prop anchor - The anchor point for the drop down menu.
|
|
7135
|
+
*/
|
|
7136
|
+
function Search(props) {
|
|
7137
|
+
return /* @__PURE__ */ jsx(SearchContextProvider, { children: /* @__PURE__ */ jsx(SearchField, { ...props }) });
|
|
7138
|
+
}
|
|
6759
7139
|
//#endregion
|
|
6760
7140
|
//#region src/symbols/circle.fill.tsx
|
|
6761
7141
|
function CircleFill({ weight = "regular", ...props }) {
|
|
@@ -8758,25 +9138,21 @@ function TooltipDisplay({ anchor = "top", arrow: arrow$4, arrowClassName, childr
|
|
|
8758
9138
|
clearTimeout(timeoutRef.current);
|
|
8759
9139
|
};
|
|
8760
9140
|
}, []);
|
|
8761
|
-
const [, setTooltipContext] = useTooltipContext(() =>
|
|
9141
|
+
const [tooltipContext, setTooltipContext] = useTooltipContext(() => defaultTooltipContext);
|
|
8762
9142
|
useEffect(() => {
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
arrowRef,
|
|
8777
|
-
arrow: nextArrow,
|
|
8778
|
-
arrowClassName: nextArrowClassName
|
|
8779
|
-
};
|
|
9143
|
+
const nextArrow = arrow$4 || false, nextArrowClassName = arrowClassName || "";
|
|
9144
|
+
if (tooltipContext && tooltipContext.isOpen !== isOpen || tooltipContext.openTooltip !== openTooltip || tooltipContext.closeTooltip !== closeTooltip || tooltipContext.refs !== refs || tooltipContext.floatingStyles !== floatingStyles || tooltipContext.isPositioned !== isPositioned || tooltipContext.placement !== placement || tooltipContext.middlewareData !== middlewareData || tooltipContext.arrowRef !== arrowRef || tooltipContext.arrow !== nextArrow || tooltipContext.arrowClassName !== nextArrowClassName) setTooltipContext?.({
|
|
9145
|
+
isOpen,
|
|
9146
|
+
openTooltip,
|
|
9147
|
+
closeTooltip,
|
|
9148
|
+
refs,
|
|
9149
|
+
floatingStyles,
|
|
9150
|
+
isPositioned,
|
|
9151
|
+
placement,
|
|
9152
|
+
middlewareData,
|
|
9153
|
+
arrowRef,
|
|
9154
|
+
arrow: nextArrow,
|
|
9155
|
+
arrowClassName: nextArrowClassName
|
|
8780
9156
|
});
|
|
8781
9157
|
}, [
|
|
8782
9158
|
arrow$4,
|
|
@@ -8837,4 +9213,4 @@ function ArrowSvg({ className, ...props }) {
|
|
|
8837
9213
|
});
|
|
8838
9214
|
}
|
|
8839
9215
|
//#endregion
|
|
8840
|
-
export { Anchor, Button, Checkbox, Details, DetailsBody, DetailsSummary, DropDown, DropDownButton, DropDownItem, DropDownItems, DropDownSection, DropDownSeparator, Fieldset, Form, Ghost, Heading, HumanVerification, IFrame, Input, Link, Modal, ModalClose, ModalDialog, ModalTitle, ModalTrigger, Select, SelectOption, SelectSectionTitle, SubmitButton, Textarea, Time, Tooltip, TooltipPanel, TooltipTrigger, generateHumanValidationToken, getLinkClasses, validateHuman };
|
|
9216
|
+
export { Anchor, Button, Checkbox, Details, DetailsBody, DetailsSummary, DropDown, DropDownButton, DropDownItem, DropDownItems, DropDownSection, DropDownSeparator, Fieldset, Form, Ghost, Heading, HumanVerification, IFrame, Input, Link, Modal, ModalClose, ModalDialog, ModalTitle, ModalTrigger, Search, SearchOption, SearchSectionTitle, Select, SelectOption, SelectSectionTitle, SubmitButton, Textarea, Time, Tooltip, TooltipPanel, TooltipTrigger, generateHumanValidationToken, getLinkClasses, validateHuman };
|