@andrilla/mado-ui 1.1.0 → 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.
@@ -3,7 +3,7 @@ import { extendTailwindMerge, twJoin } from "tailwind-merge";
3
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
4
  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";
5
5
  import * as React from "react";
6
- import { Children, cloneElement, createContext, isValidElement, useContext, useEffect, useEffectEvent, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
6
+ import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useEffectEvent, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
7
7
  import * as ReactDOM from "react-dom";
8
8
  import { createPortal } from "react-dom";
9
9
  //#region src/utils/custom-tailwind-merge.ts
@@ -6224,46 +6224,43 @@ function Input({ children, className, description, descriptionProps: { className
6224
6224
  }
6225
6225
  //#endregion
6226
6226
  //#region src/hooks/create-fast-context.tsx
6227
- function createFastContext(defaultInitialState) {
6228
- function useStoreData(initialState = defaultInitialState) {
6229
- const store = useRef(initialState), get = () => store.current, subscribers = useRef(/* @__PURE__ */ new Set());
6230
- const set = (value) => {
6231
- if (typeof value === "function") store.current = value(store.current);
6232
- else store.current = value;
6233
- subscribers.current.forEach((callback) => callback());
6234
- };
6235
- const subscribe = (callback) => {
6236
- subscribers.current.add(callback);
6237
- return () => subscribers.current.delete(callback);
6238
- };
6227
+ function createFastContext(initialState) {
6228
+ function useStoreData() {
6229
+ const store = useRef(initialState);
6230
+ const get = useCallback(() => store.current, []);
6231
+ const subscribers = useRef(/* @__PURE__ */ new Set());
6239
6232
  return {
6240
6233
  get,
6241
- set,
6242
- subscribe
6234
+ set: useCallback((value) => {
6235
+ store.current = {
6236
+ ...store.current,
6237
+ ...value
6238
+ };
6239
+ subscribers.current.forEach((callback) => callback());
6240
+ }, []),
6241
+ subscribe: useCallback((callback) => {
6242
+ subscribers.current.add(callback);
6243
+ return () => subscribers.current.delete(callback);
6244
+ }, [])
6243
6245
  };
6244
6246
  }
6245
6247
  const StoreContext = createContext(null);
6246
- function Provider({ initialValue = defaultInitialState, ...props }) {
6248
+ function Provider({ children }) {
6247
6249
  return /* @__PURE__ */ jsx(StoreContext.Provider, {
6248
- value: useStoreData(initialValue),
6249
- ...props
6250
+ value: useStoreData(),
6251
+ children
6250
6252
  });
6251
6253
  }
6252
- function useStore(selector, initialValue) {
6254
+ function useStore(selector) {
6253
6255
  const store = useContext(StoreContext);
6254
- if (!store) {
6255
- const selectedValue = selector(initialValue !== void 0 ? initialValue : defaultInitialState);
6256
- const noOpSet = () => console.warn("Attempting to set store value outside of Provider");
6257
- return [selectedValue, noOpSet];
6258
- }
6259
- return [useSyncExternalStore(store.subscribe, () => selector(store.get()), () => selector(initialValue !== void 0 ? initialValue : defaultInitialState)), store.set];
6256
+ if (!store) throw new Error("Store not found");
6257
+ return [useSyncExternalStore(store.subscribe, () => selector(store.get()), () => selector(initialState)), store.set];
6260
6258
  }
6261
6259
  return {
6262
6260
  Provider,
6263
6261
  useStore
6264
6262
  };
6265
6263
  }
6266
- const { Provider, useStore } = createFastContext("incomplete");
6267
6264
  //#endregion
6268
6265
  //#region src/hooks/use-mobile-device.ts
6269
6266
  function useMobileDevice() {
@@ -6397,17 +6394,11 @@ function ModalDialog({ dialogPanelProps: { className: dialogPanelClassName, styl
6397
6394
  if (!setModalControls) return;
6398
6395
  if (progressY >= DRAG_TO_CLOSE_PROGRESS && !readyToCloseRef.current) {
6399
6396
  readyToCloseRef.current = true;
6400
- setModalControls((prev) => ({
6401
- ...prev,
6402
- readyToClose: true
6403
- }));
6397
+ setModalControls({ readyToClose: true });
6404
6398
  }
6405
6399
  if (progressY < DRAG_TO_CLOSE_PROGRESS && readyToCloseRef.current) {
6406
6400
  readyToCloseRef.current = false;
6407
- setModalControls((prev) => ({
6408
- ...prev,
6409
- readyToClose: false
6410
- }));
6401
+ setModalControls({ readyToClose: false });
6411
6402
  }
6412
6403
  },
6413
6404
  trigger: draggableTrigger
@@ -6544,11 +6535,10 @@ function ModalDisplay({ children, className, onClose, onOpen, place = "bottom" }
6544
6535
  const closeFunctions = () => {
6545
6536
  onClose?.();
6546
6537
  modalControls?.pseudoContainerRef?.current?.remove();
6547
- setModalControls?.((previous) => ({
6548
- ...previous,
6538
+ setModalControls?.({
6549
6539
  pseudoContainerRef: { current: null },
6550
6540
  readyToClose: false
6551
- }));
6541
+ });
6552
6542
  };
6553
6543
  const mobileAnimation = {
6554
6544
  y: "100%",
@@ -6577,15 +6567,14 @@ function ModalDisplay({ children, className, onClose, onOpen, place = "bottom" }
6577
6567
  });
6578
6568
  };
6579
6569
  useEffect(() => {
6580
- setModalControls?.((previous) => ({
6581
- ...previous,
6570
+ setModalControls?.({
6582
6571
  isOpen,
6583
6572
  place,
6584
6573
  className,
6585
6574
  openModal,
6586
6575
  closeModal,
6587
6576
  dialogPanelRef: localDialogPanelRef
6588
- }));
6577
+ });
6589
6578
  }, [
6590
6579
  className,
6591
6580
  closeModal,
@@ -6652,6 +6641,10 @@ function ChevronUpChevronDown({ weight = "regular", ...props }) {
6652
6641
  }
6653
6642
  //#endregion
6654
6643
  //#region src/components/select.tsx
6644
+ const { Provider: SelectContextProvider, useStore: useSelectContext } = createFastContext({
6645
+ multiple: false,
6646
+ selectedOptionDisplayProps: {}
6647
+ });
6655
6648
  /**
6656
6649
  * ## Select Section Title
6657
6650
  *
@@ -6666,48 +6659,32 @@ function SelectSectionTitle({ className, ...props }) {
6666
6659
  /**
6667
6660
  * ## SelectOption
6668
6661
  *
6669
- * @prop children - This is what is displayed in the drop down menu
6670
- * @prop name - This is displayed in the trigger button
6671
- * @prop value - This is used for FormData
6672
- */
6673
- function SelectOption({ children, className, name, ...props }) {
6662
+ * @prop children - This is what is displayed in the drop down menu.
6663
+ * @prop name - This is displayed in the trigger button.
6664
+ * @prop value - This is used for FormData.
6665
+ * @prop selectedDisplayProps - This is used to customize the display of the selected option (takes priority over selectedOptionDisplayProps).
6666
+ */
6667
+ function SelectOption({ children, className, name, selectedDisplayProps: { children: selectedDisplayChildren, className: selectedDisplayClassName, ...selectedDisplayProps } = {}, ...props }) {
6668
+ const [selectContext] = useSelectContext((store) => store), { multiple, selectedOptionDisplayProps } = selectContext || {};
6669
+ const { children: selectedOptionDisplayChildren, className: selectedOptionDisplayClassName } = selectedOptionDisplayProps || {};
6674
6670
  return /* @__PURE__ */ jsx(ListboxOption, {
6675
6671
  className: "group/option contents",
6676
6672
  ...props,
6677
6673
  children: (bag) => bag.selectedOption ? /* @__PURE__ */ jsx("span", {
6678
- className: `mr-3 before:absolute before:-left-3 before:content-[',_']`,
6679
- children: name
6674
+ ...selectedOptionDisplayProps,
6675
+ ...selectedDisplayProps,
6676
+ className: twMerge(!selectedDisplayClassName && !selectedOptionDisplayClassName && multiple && `before:content-[',_'] group-first-of-type/option:before:content-['']`, selectedOptionDisplayClassName, selectedDisplayClassName),
6677
+ children: selectedDisplayChildren ? typeof selectedDisplayChildren === "function" ? selectedDisplayChildren(name) : selectedDisplayChildren : selectedOptionDisplayChildren ? typeof selectedOptionDisplayChildren === "function" ? selectedOptionDisplayChildren(name) : selectedOptionDisplayChildren : name
6680
6678
  }) : /* @__PURE__ */ jsxs("div", {
6681
- 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:cursor-default group-data-selected/option:text-(--theme-color) group-data-focus/option:group-data-selected/option:bg-transparent dark:group-data-focus/option:bg-(--theme-color)/15", className),
6682
- children: [/* @__PURE__ */ jsx(Checkmark, { className: "invisible size-3.5 group-data-selected/option:visible" }), typeof children === "function" ? children(bag) : children]
6679
+ 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),
6680
+ 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]
6683
6681
  })
6684
6682
  });
6685
6683
  }
6686
- /**
6687
- * # Select
6688
- *
6689
- * A customizable select component intended to work very similar to HTML's `<select>` element.
6690
- *
6691
- * Use the `SelectOption` component to define the options.
6692
- *
6693
- * Use the `SelectSectionTitle` component to define titles.
6694
- *
6695
- * @prop label - The label for the select component.
6696
- * @prop description - The description for the select component.
6697
- * @prop placeholder - The placeholder for the select component.
6698
- * @prop required - Whether the select component is required.
6699
- * @prop invalid - Whether the select component is invalid.
6700
- * @prop multiple - Whether the select component allows multiple selections.
6701
- * @prop optionsProps - The props to be passed to each SelectOption component.
6702
- * @prop selectedOptionProps - The props to be passed to the selected option component.
6703
- * @prop fieldProps - The props to be passed to the parent field component.
6704
- * @prop labelProps - The props to be passed to the label component.
6705
- * @prop descriptionProps - The props to be passed to the description component.
6706
- * @prop anchor - The anchor point for the drop down menu.
6707
- */
6708
- 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 }) {
6684
+ 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 }) {
6709
6685
  const uniqueId = useId();
6710
- const multiple = props.multiple;
6686
+ const multiple = Boolean(props.multiple);
6687
+ const [, setSelectContext] = useSelectContext((store) => store);
6711
6688
  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);
6712
6689
  const listboxButtonRef = useRef(null);
6713
6690
  const [isInvalid, setIsInvalid] = useState(invalid);
@@ -6719,6 +6696,15 @@ function Select({ buttonProps, children, className, description, descriptionProp
6719
6696
  };
6720
6697
  const handleInvalid = () => setIsInvalid(true);
6721
6698
  const refocus = () => listboxButtonRef.current?.focus();
6699
+ const onVisible = useEffectEvent(() => {
6700
+ setSelectContext?.({
6701
+ multiple,
6702
+ selectedOptionDisplayProps
6703
+ });
6704
+ });
6705
+ useEffect(() => {
6706
+ onVisible();
6707
+ }, []);
6722
6708
  return /* @__PURE__ */ jsxs(Field, {
6723
6709
  ...fieldProps,
6724
6710
  className: (bag) => twMerge("grid gap-1", typeof fieldClassName === "function" ? fieldClassName(bag) : fieldClassName),
@@ -6775,6 +6761,32 @@ function Select({ buttonProps, children, className, description, descriptionProp
6775
6761
  ]
6776
6762
  });
6777
6763
  }
6764
+ /**
6765
+ * # Select
6766
+ *
6767
+ * A customizable select component intended to work very similar to HTML's `<select>` element.
6768
+ *
6769
+ * Use the `SelectOption` component to define the options.
6770
+ *
6771
+ * Use the `SelectSectionTitle` component to define titles.
6772
+ *
6773
+ * @prop label - The label for the select component.
6774
+ * @prop description - The description for the select component.
6775
+ * @prop placeholder - The placeholder for the select component.
6776
+ * @prop required - Whether the select component is required.
6777
+ * @prop invalid - Whether the select component is invalid.
6778
+ * @prop multiple - Whether the select component allows multiple selections.
6779
+ * @prop optionsProps - The props to be passed to each SelectOption component.
6780
+ * @prop selectedOptionProps - The props to be passed to the selected option component.
6781
+ * @prop selectedOptionDisplayProps - The props to be passed to each selected option in the selected option component.
6782
+ * @prop fieldProps - The props to be passed to the parent field component.
6783
+ * @prop labelProps - The props to be passed to the label component.
6784
+ * @prop descriptionProps - The props to be passed to the description component.
6785
+ * @prop anchor - The anchor point for the drop down menu.
6786
+ */
6787
+ function Select(props) {
6788
+ return /* @__PURE__ */ jsx(SelectContextProvider, { children: /* @__PURE__ */ jsx(SelectField, { ...props }) });
6789
+ }
6778
6790
  //#endregion
6779
6791
  //#region src/symbols/plus.tsx
6780
6792
  function Plus({ weight = "regular", ...props }) {
@@ -6828,6 +6840,23 @@ function Plus({ weight = "regular", ...props }) {
6828
6840
  }
6829
6841
  //#endregion
6830
6842
  //#region src/components/search.tsx
6843
+ const { Provider: SearchContextProvider, useStore: useSearchContext } = createFastContext({
6844
+ multiple: false,
6845
+ query: "",
6846
+ selectedOptionDisplayProps: {},
6847
+ selectedOptionList: []
6848
+ });
6849
+ /**
6850
+ * ## Search Section Title
6851
+ *
6852
+ * Displays a simple title.
6853
+ */
6854
+ function SearchSectionTitle({ className, ...props }) {
6855
+ return /* @__PURE__ */ jsx("div", {
6856
+ 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),
6857
+ ...props
6858
+ });
6859
+ }
6831
6860
  /**
6832
6861
  * ## SearchOption
6833
6862
  *
@@ -6835,8 +6864,17 @@ function Plus({ weight = "regular", ...props }) {
6835
6864
  * @prop name - This is used for filtering by default
6836
6865
  * @prop value - This is used as selected value and for FormData
6837
6866
  */
6838
- function SearchOption({ children, className, name, value, ...props }) {
6839
- return /* @__PURE__ */ jsx(ComboboxOption, {
6867
+ function SearchOption({ children, className, isInDisplay, name, selectedDisplayProps: { children: selectedDisplayChildren, className: selectedDisplayClassName, ...selectedDisplayProps } = {}, value, ...props }) {
6868
+ const [searchContext] = useSearchContext((store) => store);
6869
+ const { multiple, query, selectedOptionDisplayProps } = searchContext || {};
6870
+ if (!((query || "").trim() === "" || name.toLowerCase().includes((query || "").toLowerCase()) || isInDisplay)) return /* @__PURE__ */ jsx(Fragment, {});
6871
+ const { children: selectedOptionDisplayChildren, className: selectedOptionDisplayClassName } = selectedOptionDisplayProps || {};
6872
+ return isInDisplay ? /* @__PURE__ */ jsx("span", {
6873
+ ...selectedOptionDisplayProps,
6874
+ ...selectedDisplayProps,
6875
+ className: twMerge(!selectedDisplayClassName && !selectedOptionDisplayClassName && multiple && `after:content-[',_'] last-of-type:after:content-['']`, selectedOptionDisplayClassName, selectedDisplayClassName),
6876
+ children: selectedDisplayChildren ? typeof selectedDisplayChildren === "function" ? selectedDisplayChildren(name) : selectedDisplayChildren : selectedOptionDisplayChildren ? typeof selectedOptionDisplayChildren === "function" ? selectedOptionDisplayChildren(name) : selectedOptionDisplayChildren : name
6877
+ }) : /* @__PURE__ */ jsx(ComboboxOption, {
6840
6878
  className: "group/option contents",
6841
6879
  value: {
6842
6880
  id: value,
@@ -6844,46 +6882,130 @@ function SearchOption({ children, className, name, value, ...props }) {
6844
6882
  },
6845
6883
  ...props,
6846
6884
  children: (bag) => /* @__PURE__ */ jsxs("div", {
6847
- 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:cursor-default group-data-selected/option:text-(--theme-color) group-data-focus/option:group-data-selected/option:bg-transparent dark:group-data-focus/option:bg-(--theme-color)/15", className),
6848
- children: [/* @__PURE__ */ jsx(Checkmark, { className: "invisible size-3.5 group-data-selected/option:visible" }), typeof children === "function" ? children(bag) : children ?? name]
6885
+ 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),
6886
+ 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]
6849
6887
  })
6850
6888
  });
6851
6889
  }
6852
- /**
6853
- * # Search
6854
- *
6855
- * A searchable select component built on top of Headless UI's `Combobox`.
6856
- *
6857
- * Use the `SearchOption` component to define options.
6858
- */
6859
- function Search({ 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, ...props }) {
6890
+ function checkEquality(aOptionList, bOptionList) {
6891
+ if (aOptionList.length !== bOptionList.length) return false;
6892
+ for (let i = 0; i < aOptionList.length; i += 1) {
6893
+ const aOption = aOptionList[i], bOption = bOptionList[i];
6894
+ if (aOption?.id !== bOption?.id || aOption?.name !== bOption?.name) return false;
6895
+ }
6896
+ return true;
6897
+ }
6898
+ 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 }) {
6860
6899
  const uniqueId = useId();
6861
- const options = Children.toArray(children).flatMap((child) => {
6862
- if (!isValidElement(child)) return [];
6863
- const candidate = child;
6864
- if (typeof candidate.props?.name !== "string") return [];
6865
- if (typeof candidate.props?.value !== "string") return [];
6866
- return [{
6867
- name: candidate.props.name,
6868
- value: candidate.props.value,
6869
- element: child
6870
- }];
6871
- });
6872
- const [query, setQuery] = useState("");
6900
+ const [searchContext, setSearchContext] = useSearchContext((store) => store), { query } = searchContext || {};
6873
6901
  const [isInvalid, setIsInvalid] = useState(invalid);
6874
6902
  const [selectedOptionSync, setSelectedOptionSync] = useState(() => {
6875
6903
  if (multiple) return Array.isArray(defaultValue) ? defaultValue : [];
6876
6904
  return typeof defaultValue === "string" ? defaultValue : null;
6877
6905
  });
6878
6906
  const comboboxInputRef = useRef(null);
6879
- const filteredOptions = query.trim() === "" ? options : options.filter((option) => option.name.toLowerCase().includes(query.toLowerCase()));
6907
+ const childOptionList = useMemo(() => Children.toArray(children).filter((child) => isValidElement(child) && !!child.props && "value" in child.props && "name" in child.props), [children]);
6908
+ const staticOptionList = useMemo(() => childOptionList.map((child) => ({
6909
+ id: child.props.value,
6910
+ name: child.props.name,
6911
+ selectedDisplayProps: child.props.selectedDisplayProps
6912
+ })), [childOptionList]);
6913
+ const [addedOptionList, setAddedOptionList] = useState([]);
6914
+ const customOptionFromQuery = useMemo(() => {
6915
+ const trimmedQuery = query.trim();
6916
+ if (!allowCustom || trimmedQuery.length === 0) return null;
6917
+ return {
6918
+ id: props.customOptionParams?.formatID?.(trimmedQuery) ?? toLowerCase(trimmedQuery, [" ", "_"]),
6919
+ name: trimmedQuery
6920
+ };
6921
+ }, [
6922
+ allowCustom,
6923
+ props.customOptionParams,
6924
+ query
6925
+ ]);
6926
+ const optionLookupMap = useMemo(() => {
6927
+ const lookupMap = /* @__PURE__ */ new Map();
6928
+ for (const option of staticOptionList) lookupMap.set(option.id, option.name);
6929
+ for (const option of addedOptionList) lookupMap.set(option.id, option.name);
6930
+ return lookupMap;
6931
+ }, [addedOptionList, staticOptionList]);
6932
+ const saveCustomOption = useEffectEvent((option) => {
6933
+ if (!multiple) return;
6934
+ setAddedOptionList((prevOptionList) => {
6935
+ if (prevOptionList.some((prevOption) => prevOption.id === option.id)) return prevOptionList;
6936
+ return [...prevOptionList, option];
6937
+ });
6938
+ });
6880
6939
  const handleChange = (selected) => {
6881
6940
  setIsInvalid(false);
6941
+ if (multiple && Array.isArray(selected)) {
6942
+ const selectedValueList = selected.map((selectedValue) => {
6943
+ if (selectedValue && typeof selectedValue === "object" && "id" in selectedValue && "name" in selectedValue) {
6944
+ const option = {
6945
+ id: String(selectedValue.id),
6946
+ name: String(selectedValue.name)
6947
+ };
6948
+ saveCustomOption(option);
6949
+ return option.id;
6950
+ }
6951
+ return String(selectedValue);
6952
+ });
6953
+ setSelectedOptionSync(selectedValueList);
6954
+ onChange?.(selectedValueList);
6955
+ return;
6956
+ }
6957
+ if (!multiple) {
6958
+ const normalizedSelected = selected && typeof selected === "object" && !Array.isArray(selected) ? String(selected.id) : selected;
6959
+ setSelectedOptionSync(normalizedSelected);
6960
+ onChange?.(normalizedSelected);
6961
+ return;
6962
+ }
6882
6963
  setSelectedOptionSync(selected);
6883
- onChange?.(selected);
6964
+ };
6965
+ const formatSelectedDisplay = (name) => {
6966
+ const selectedOptionDisplayChildren = selectedOptionDisplayProps?.children;
6967
+ if (!selectedOptionDisplayChildren) return name;
6968
+ const selectedOptionDisplayValue = typeof selectedOptionDisplayChildren === "function" ? selectedOptionDisplayChildren(name) : selectedOptionDisplayChildren;
6969
+ return typeof selectedOptionDisplayValue === "string" ? selectedOptionDisplayValue : name;
6884
6970
  };
6885
6971
  const handleInvalid = () => setIsInvalid(true);
6886
6972
  const refocus = () => comboboxInputRef.current?.focus();
6973
+ const onVisible = useEffectEvent(() => {
6974
+ setSearchContext?.({
6975
+ multiple,
6976
+ query: "",
6977
+ selectedOptionDisplayProps
6978
+ });
6979
+ });
6980
+ useEffect(() => {
6981
+ onVisible();
6982
+ }, []);
6983
+ useEffect(() => {
6984
+ const selectedOptionList = (Array.isArray(selectedOptionSync) ? selectedOptionSync : typeof selectedOptionSync === "string" ? [selectedOptionSync] : []).map((selectedId) => ({
6985
+ id: selectedId,
6986
+ name: optionLookupMap.get(selectedId) ?? selectedId
6987
+ }));
6988
+ if (!checkEquality(searchContext?.selectedOptionList ?? [], selectedOptionList)) setSearchContext?.({ selectedOptionList });
6989
+ }, [
6990
+ optionLookupMap,
6991
+ searchContext?.selectedOptionList,
6992
+ selectedOptionSync,
6993
+ setSearchContext
6994
+ ]);
6995
+ const queryChange = (e) => {
6996
+ const { currentTarget } = e, { value } = currentTarget;
6997
+ setSearchContext?.({ query: value });
6998
+ };
6999
+ const handleClose = () => {
7000
+ setSearchContext?.({ query: "" });
7001
+ };
7002
+ const updateDisplayValue = (value) => {
7003
+ if (multiple && Array.isArray(value)) {
7004
+ if (singleDisplay) return value.map((v) => formatSelectedDisplay(v.name)).join(", ");
7005
+ }
7006
+ if (!multiple && value) return formatSelectedDisplay(value.name);
7007
+ return "";
7008
+ };
6887
7009
  return /* @__PURE__ */ jsxs(Field, {
6888
7010
  ...fieldProps,
6889
7011
  className: (bag) => twMerge("grid gap-1", typeof fieldClassName === "function" ? fieldClassName(bag) : fieldClassName),
@@ -6898,64 +7020,88 @@ function Search({ allowCustom, buttonProps, children, className, defaultValue, d
6898
7020
  invalid: isInvalid || invalid,
6899
7021
  multiple,
6900
7022
  onChange: handleChange,
6901
- onClose: () => setQuery(""),
6902
- value: selectedOptionSync || "",
7023
+ onClose: handleClose,
6903
7024
  children: [/* @__PURE__ */ jsxs("div", {
6904
- className: "relative",
6905
- children: [
6906
- /* @__PURE__ */ jsx(ComboboxInput, {
6907
- ...inputProps,
6908
- "aria-label": typeof label === "string" ? label : props.name,
6909
- 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),
6910
- displayValue: (value) => Array.isArray(value) ? value.map((v) => v.name).join(", ") : value?.name ?? "",
6911
- name: props.name,
6912
- onChange: (event) => setQuery(event.target.value),
6913
- placeholder: placeholder || (multiple ? "Choose Any" : "Choose One"),
6914
- ref: comboboxInputRef,
6915
- required
6916
- }),
6917
- /* @__PURE__ */ jsx("input", {
6918
- "aria-hidden": "true",
6919
- className: "sr-only top-0 left-1/2",
6920
- id: props.name + ":input:id" + uniqueId,
6921
- name: props.name,
6922
- onChange: () => {},
6923
- onFocus: refocus,
6924
- onInvalid: handleInvalid,
6925
- required,
6926
- tabIndex: -1,
6927
- value: Array.isArray(selectedOptionSync) ? selectedOptionSync.join(", ") : selectedOptionSync ?? ""
6928
- }),
6929
- /* @__PURE__ */ jsx(ComboboxButton, {
6930
- ...buttonProps,
6931
- className: "absolute top-1/2 right-1.5 -translate-y-1/2 rounded p-0.5",
6932
- children: /* @__PURE__ */ jsx(ChevronUpChevronDown, { className: "size-3 fill-current/50" })
6933
- })
6934
- ]
7025
+ ...multiple ? { "data-multiple": "" } : {},
7026
+ className: "isolate contents data-multiple:grid",
7027
+ children: [/* @__PURE__ */ jsxs("div", {
7028
+ className: "relative",
7029
+ children: [
7030
+ /* @__PURE__ */ jsx(ComboboxInput, {
7031
+ ...inputProps,
7032
+ "aria-label": typeof label === "string" ? label : props.name,
7033
+ 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),
7034
+ displayValue: updateDisplayValue,
7035
+ name: props.name,
7036
+ onChange: queryChange,
7037
+ placeholder: placeholder || `${multiple ? "Choose Any" : "Choose One"}${allowCustom ? " or Create Your Own" : ""}`,
7038
+ ref: comboboxInputRef,
7039
+ required
7040
+ }),
7041
+ /* @__PURE__ */ jsx("input", {
7042
+ "aria-hidden": "true",
7043
+ className: "sr-only top-0 left-1/2",
7044
+ id: props.name + ":input:id" + uniqueId,
7045
+ name: props.name,
7046
+ onChange: () => {},
7047
+ onFocus: refocus,
7048
+ onInvalid: handleInvalid,
7049
+ required,
7050
+ tabIndex: -1,
7051
+ value: Array.isArray(selectedOptionSync) ? selectedOptionSync.join(", ") : selectedOptionSync ?? ""
7052
+ }),
7053
+ /* @__PURE__ */ jsx(ComboboxButton, {
7054
+ ...buttonProps,
7055
+ className: "absolute top-1/2 right-1.5 -translate-y-1/2 rounded p-0.5",
7056
+ children: /* @__PURE__ */ jsx(ChevronUpChevronDown, { className: "size-3 fill-current/50" })
7057
+ })
7058
+ ]
7059
+ }), multiple && !singleDisplay && /* @__PURE__ */ jsx("div", {
7060
+ ...shelfProps,
7061
+ 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),
7062
+ children: searchContext?.selectedOptionList?.length > 0 && [...staticOptionList, ...addedOptionList].filter((option, optionIndex, optionList) => {
7063
+ return optionList.findIndex((innerOption) => innerOption.id === option.id) === optionIndex;
7064
+ }).map((option) => {
7065
+ if (!searchContext.selectedOptionList.some(({ id }) => id === option.id)) return null;
7066
+ return /* @__PURE__ */ jsx(SearchOption, {
7067
+ name: option.name,
7068
+ value: option.id,
7069
+ selectedDisplayProps: option.selectedDisplayProps,
7070
+ isInDisplay: true,
7071
+ children: option.name
7072
+ }, option.id);
7073
+ }).filter(Boolean)
7074
+ })]
6935
7075
  }), /* @__PURE__ */ jsxs(ComboboxOptions, {
6936
7076
  ...optionsProps,
6937
7077
  anchor: anchor || "bottom start",
6938
- 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 [--anchor-gap:--spacing(1)] 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", typeof optionsClassName === "function" ? optionsClassName(bag) : optionsClassName),
7078
+ 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),
6939
7079
  transition: transition ?? true,
6940
- children: [allowCustom && query.length > 0 && /* @__PURE__ */ jsx(ComboboxOption, {
6941
- value: {
6942
- id: props.customOptionParams?.formatID?.(query) ?? toLowerCase(query, [" ", "_"]),
6943
- name: query
6944
- },
6945
- className: "group/option contents",
6946
- children: ({ selected }) => /* @__PURE__ */ jsx("div", {
6947
- 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 group-data-selected/option:cursor-default group-data-selected/option:text-(--theme-color) group-data-focus/option:group-data-selected/option:bg-transparent dark:group-data-focus/option:bg-(--theme-color)/15",
6948
- children: selected ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Checkmark, { className: "size-3.5" }), query] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
6949
- /* @__PURE__ */ jsx(Plus, { className: "size-3.5" }),
6950
- "Use ",
6951
- /* @__PURE__ */ jsxs("b", { children: [
6952
- "\"",
6953
- query,
6954
- "\""
6955
- ] })
6956
- ] })
6957
- })
6958
- }), filteredOptions.map((option) => option.element)]
7080
+ children: [
7081
+ allowCustom && query.length > 0 && customOptionFromQuery && !addedOptionList.some((addedOption) => addedOption.id === customOptionFromQuery.id) && /* @__PURE__ */ jsx(ComboboxOption, {
7082
+ value: customOptionFromQuery,
7083
+ className: "group/option contents",
7084
+ children: /* @__PURE__ */ jsxs("div", {
7085
+ 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",
7086
+ children: [
7087
+ /* @__PURE__ */ jsx(Plus, { className: "size-3.5" }),
7088
+ "Use ",
7089
+ /* @__PURE__ */ jsxs("b", { children: [
7090
+ "\"",
7091
+ query,
7092
+ "\""
7093
+ ] })
7094
+ ]
7095
+ })
7096
+ }),
7097
+ children,
7098
+ multiple && addedOptionList.filter((addedOption) => !staticOptionList.some((staticOption) => staticOption.id === addedOption.id)).map((addedOption) => /* @__PURE__ */ jsx(SearchOption, {
7099
+ name: addedOption.name,
7100
+ value: addedOption.id,
7101
+ selectedDisplayProps: addedOption.selectedDisplayProps,
7102
+ children: addedOption.name
7103
+ }, "added:" + addedOption.id))
7104
+ ]
6959
7105
  })]
6960
7106
  }),
6961
7107
  description && /* @__PURE__ */ jsx(Description, {
@@ -6966,6 +7112,31 @@ function Search({ allowCustom, buttonProps, children, className, defaultValue, d
6966
7112
  ]
6967
7113
  });
6968
7114
  }
7115
+ /**
7116
+ * # Search
7117
+ *
7118
+ * A searchable select component built on top of Headless UI's `Combobox`.
7119
+ *
7120
+ * Use the `SearchOption` component to define options.
7121
+ *
7122
+ * Use the `SearchSectionTitle` component to define titles.
7123
+ *
7124
+ * @prop label - The label for the select component.
7125
+ * @prop description - The description for the select component.
7126
+ * @prop placeholder - The placeholder for the select component.
7127
+ * @prop required - Whether the select component is required.
7128
+ * @prop invalid - Whether the select component is invalid.
7129
+ * @prop multiple - Whether the select component allows multiple selections.
7130
+ * @prop optionsProps - The props to be passed to each SearchOption component.
7131
+ * @prop selectedOptionDisplayProps - The props to be passed to each selected option in the selected option component.
7132
+ * @prop fieldProps - The props to be passed to the parent field component.
7133
+ * @prop labelProps - The props to be passed to the label component.
7134
+ * @prop descriptionProps - The props to be passed to the description component.
7135
+ * @prop anchor - The anchor point for the drop down menu.
7136
+ */
7137
+ function Search(props) {
7138
+ return /* @__PURE__ */ jsx(SearchContextProvider, { children: /* @__PURE__ */ jsx(SearchField, { ...props }) });
7139
+ }
6969
7140
  //#endregion
6970
7141
  //#region src/symbols/circle.fill.tsx
6971
7142
  function CircleFill({ weight = "regular", ...props }) {
@@ -8968,25 +9139,21 @@ function TooltipDisplay({ anchor = "top", arrow: arrow$4, arrowClassName, childr
8968
9139
  clearTimeout(timeoutRef.current);
8969
9140
  };
8970
9141
  }, []);
8971
- const [, setTooltipContext] = useTooltipContext(() => void 0, defaultTooltipContext);
9142
+ const [tooltipContext, setTooltipContext] = useTooltipContext(() => defaultTooltipContext);
8972
9143
  useEffect(() => {
8973
- setTooltipContext?.((previous) => {
8974
- const nextArrow = arrow$4 || false, nextArrowClassName = arrowClassName || "";
8975
- if (previous.isOpen === isOpen && previous.openTooltip === openTooltip && previous.closeTooltip === closeTooltip && previous.refs === refs && previous.floatingStyles === floatingStyles && previous.isPositioned === isPositioned && previous.placement === placement && previous.middlewareData === middlewareData && previous.arrowRef === arrowRef && previous.arrow === nextArrow && previous.arrowClassName === nextArrowClassName) return previous;
8976
- return {
8977
- ...previous,
8978
- isOpen,
8979
- openTooltip,
8980
- closeTooltip,
8981
- refs,
8982
- floatingStyles,
8983
- isPositioned,
8984
- placement,
8985
- middlewareData,
8986
- arrowRef,
8987
- arrow: nextArrow,
8988
- arrowClassName: nextArrowClassName
8989
- };
9144
+ const nextArrow = arrow$4 || false, nextArrowClassName = arrowClassName || "";
9145
+ 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?.({
9146
+ isOpen,
9147
+ openTooltip,
9148
+ closeTooltip,
9149
+ refs,
9150
+ floatingStyles,
9151
+ isPositioned,
9152
+ placement,
9153
+ middlewareData,
9154
+ arrowRef,
9155
+ arrow: nextArrow,
9156
+ arrowClassName: nextArrowClassName
8990
9157
  });
8991
9158
  }, [
8992
9159
  arrow$4,
@@ -9047,4 +9214,4 @@ function ArrowSvg({ className, ...props }) {
9047
9214
  });
9048
9215
  }
9049
9216
  //#endregion
9050
- 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, Select, SelectOption, SelectSectionTitle, SubmitButton, Textarea, Time, Tooltip, TooltipPanel, TooltipTrigger, generateHumanValidationToken, getLinkClasses, validateHuman };
9217
+ 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 };