@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.
@@ -2,7 +2,7 @@ import { extendTailwindMerge, twJoin } from "tailwind-merge";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
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
@@ -6223,46 +6223,43 @@ function Input({ children, className, description, descriptionProps: { className
6223
6223
  }
6224
6224
  //#endregion
6225
6225
  //#region src/hooks/create-fast-context.tsx
6226
- function createFastContext(defaultInitialState) {
6227
- function useStoreData(initialState = defaultInitialState) {
6228
- const store = useRef(initialState), get = () => store.current, subscribers = useRef(/* @__PURE__ */ new Set());
6229
- const set = (value) => {
6230
- if (typeof value === "function") store.current = value(store.current);
6231
- else store.current = value;
6232
- subscribers.current.forEach((callback) => callback());
6233
- };
6234
- const subscribe = (callback) => {
6235
- subscribers.current.add(callback);
6236
- return () => subscribers.current.delete(callback);
6237
- };
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());
6238
6231
  return {
6239
6232
  get,
6240
- set,
6241
- subscribe
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
+ }, [])
6242
6244
  };
6243
6245
  }
6244
6246
  const StoreContext = createContext(null);
6245
- function Provider({ initialValue = defaultInitialState, ...props }) {
6247
+ function Provider({ children }) {
6246
6248
  return /* @__PURE__ */ jsx(StoreContext.Provider, {
6247
- value: useStoreData(initialValue),
6248
- ...props
6249
+ value: useStoreData(),
6250
+ children
6249
6251
  });
6250
6252
  }
6251
- function useStore(selector, initialValue) {
6253
+ function useStore(selector) {
6252
6254
  const store = useContext(StoreContext);
6253
- if (!store) {
6254
- const selectedValue = selector(initialValue !== void 0 ? initialValue : defaultInitialState);
6255
- const noOpSet = () => console.warn("Attempting to set store value outside of Provider");
6256
- return [selectedValue, noOpSet];
6257
- }
6258
- 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];
6259
6257
  }
6260
6258
  return {
6261
6259
  Provider,
6262
6260
  useStore
6263
6261
  };
6264
6262
  }
6265
- const { Provider, useStore } = createFastContext("incomplete");
6266
6263
  //#endregion
6267
6264
  //#region src/hooks/use-mobile-device.ts
6268
6265
  function useMobileDevice() {
@@ -6396,17 +6393,11 @@ function ModalDialog({ dialogPanelProps: { className: dialogPanelClassName, styl
6396
6393
  if (!setModalControls) return;
6397
6394
  if (progressY >= DRAG_TO_CLOSE_PROGRESS && !readyToCloseRef.current) {
6398
6395
  readyToCloseRef.current = true;
6399
- setModalControls((prev) => ({
6400
- ...prev,
6401
- readyToClose: true
6402
- }));
6396
+ setModalControls({ readyToClose: true });
6403
6397
  }
6404
6398
  if (progressY < DRAG_TO_CLOSE_PROGRESS && readyToCloseRef.current) {
6405
6399
  readyToCloseRef.current = false;
6406
- setModalControls((prev) => ({
6407
- ...prev,
6408
- readyToClose: false
6409
- }));
6400
+ setModalControls({ readyToClose: false });
6410
6401
  }
6411
6402
  },
6412
6403
  trigger: draggableTrigger
@@ -6543,11 +6534,10 @@ function ModalDisplay({ children, className, onClose, onOpen, place = "bottom" }
6543
6534
  const closeFunctions = () => {
6544
6535
  onClose?.();
6545
6536
  modalControls?.pseudoContainerRef?.current?.remove();
6546
- setModalControls?.((previous) => ({
6547
- ...previous,
6537
+ setModalControls?.({
6548
6538
  pseudoContainerRef: { current: null },
6549
6539
  readyToClose: false
6550
- }));
6540
+ });
6551
6541
  };
6552
6542
  const mobileAnimation = {
6553
6543
  y: "100%",
@@ -6576,15 +6566,14 @@ function ModalDisplay({ children, className, onClose, onOpen, place = "bottom" }
6576
6566
  });
6577
6567
  };
6578
6568
  useEffect(() => {
6579
- setModalControls?.((previous) => ({
6580
- ...previous,
6569
+ setModalControls?.({
6581
6570
  isOpen,
6582
6571
  place,
6583
6572
  className,
6584
6573
  openModal,
6585
6574
  closeModal,
6586
6575
  dialogPanelRef: localDialogPanelRef
6587
- }));
6576
+ });
6588
6577
  }, [
6589
6578
  className,
6590
6579
  closeModal,
@@ -6651,6 +6640,10 @@ function ChevronUpChevronDown({ weight = "regular", ...props }) {
6651
6640
  }
6652
6641
  //#endregion
6653
6642
  //#region src/components/select.tsx
6643
+ const { Provider: SelectContextProvider, useStore: useSelectContext } = createFastContext({
6644
+ multiple: false,
6645
+ selectedOptionDisplayProps: {}
6646
+ });
6654
6647
  /**
6655
6648
  * ## Select Section Title
6656
6649
  *
@@ -6665,48 +6658,32 @@ function SelectSectionTitle({ className, ...props }) {
6665
6658
  /**
6666
6659
  * ## SelectOption
6667
6660
  *
6668
- * @prop children - This is what is displayed in the drop down menu
6669
- * @prop name - This is displayed in the trigger button
6670
- * @prop value - This is used for FormData
6671
- */
6672
- function SelectOption({ children, className, name, ...props }) {
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 || {};
6673
6669
  return /* @__PURE__ */ jsx(ListboxOption, {
6674
6670
  className: "group/option contents",
6675
6671
  ...props,
6676
6672
  children: (bag) => bag.selectedOption ? /* @__PURE__ */ jsx("span", {
6677
- className: `mr-3 before:absolute before:-left-3 before:content-[',_']`,
6678
- children: name
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
6679
6677
  }) : /* @__PURE__ */ jsxs("div", {
6680
- 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),
6681
- children: [/* @__PURE__ */ jsx(Checkmark, { className: "invisible size-3.5 group-data-selected/option:visible" }), typeof children === "function" ? children(bag) : children]
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]
6682
6680
  })
6683
6681
  });
6684
6682
  }
6685
- /**
6686
- * # Select
6687
- *
6688
- * A customizable select component intended to work very similar to HTML's `<select>` element.
6689
- *
6690
- * Use the `SelectOption` component to define the options.
6691
- *
6692
- * Use the `SelectSectionTitle` component to define titles.
6693
- *
6694
- * @prop label - The label for the select component.
6695
- * @prop description - The description for the select component.
6696
- * @prop placeholder - The placeholder for the select component.
6697
- * @prop required - Whether the select component is required.
6698
- * @prop invalid - Whether the select component is invalid.
6699
- * @prop multiple - Whether the select component allows multiple selections.
6700
- * @prop optionsProps - The props to be passed to each SelectOption component.
6701
- * @prop selectedOptionProps - The props to be passed to the selected option component.
6702
- * @prop fieldProps - The props to be passed to the parent field component.
6703
- * @prop labelProps - The props to be passed to the label component.
6704
- * @prop descriptionProps - The props to be passed to the description component.
6705
- * @prop anchor - The anchor point for the drop down menu.
6706
- */
6707
- 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 }) {
6708
6684
  const uniqueId = useId();
6709
- const multiple = props.multiple;
6685
+ const multiple = Boolean(props.multiple);
6686
+ const [, setSelectContext] = useSelectContext((store) => store);
6710
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);
6711
6688
  const listboxButtonRef = useRef(null);
6712
6689
  const [isInvalid, setIsInvalid] = useState(invalid);
@@ -6718,6 +6695,15 @@ function Select({ buttonProps, children, className, description, descriptionProp
6718
6695
  };
6719
6696
  const handleInvalid = () => setIsInvalid(true);
6720
6697
  const refocus = () => listboxButtonRef.current?.focus();
6698
+ const onVisible = useEffectEvent(() => {
6699
+ setSelectContext?.({
6700
+ multiple,
6701
+ selectedOptionDisplayProps
6702
+ });
6703
+ });
6704
+ useEffect(() => {
6705
+ onVisible();
6706
+ }, []);
6721
6707
  return /* @__PURE__ */ jsxs(Field, {
6722
6708
  ...fieldProps,
6723
6709
  className: (bag) => twMerge("grid gap-1", typeof fieldClassName === "function" ? fieldClassName(bag) : fieldClassName),
@@ -6774,6 +6760,32 @@ function Select({ buttonProps, children, className, description, descriptionProp
6774
6760
  ]
6775
6761
  });
6776
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
+ }
6777
6789
  //#endregion
6778
6790
  //#region src/symbols/plus.tsx
6779
6791
  function Plus({ weight = "regular", ...props }) {
@@ -6827,6 +6839,23 @@ function Plus({ weight = "regular", ...props }) {
6827
6839
  }
6828
6840
  //#endregion
6829
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
+ }
6830
6859
  /**
6831
6860
  * ## SearchOption
6832
6861
  *
@@ -6834,8 +6863,17 @@ function Plus({ weight = "regular", ...props }) {
6834
6863
  * @prop name - This is used for filtering by default
6835
6864
  * @prop value - This is used as selected value and for FormData
6836
6865
  */
6837
- function SearchOption({ children, className, name, value, ...props }) {
6838
- return /* @__PURE__ */ jsx(ComboboxOption, {
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, {
6839
6877
  className: "group/option contents",
6840
6878
  value: {
6841
6879
  id: value,
@@ -6843,46 +6881,130 @@ function SearchOption({ children, className, name, value, ...props }) {
6843
6881
  },
6844
6882
  ...props,
6845
6883
  children: (bag) => /* @__PURE__ */ jsxs("div", {
6846
- 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),
6847
- children: [/* @__PURE__ */ jsx(Checkmark, { className: "invisible size-3.5 group-data-selected/option:visible" }), typeof children === "function" ? children(bag) : children ?? name]
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]
6848
6886
  })
6849
6887
  });
6850
6888
  }
6851
- /**
6852
- * # Search
6853
- *
6854
- * A searchable select component built on top of Headless UI's `Combobox`.
6855
- *
6856
- * Use the `SearchOption` component to define options.
6857
- */
6858
- 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 }) {
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 }) {
6859
6898
  const uniqueId = useId();
6860
- const options = Children.toArray(children).flatMap((child) => {
6861
- if (!isValidElement(child)) return [];
6862
- const candidate = child;
6863
- if (typeof candidate.props?.name !== "string") return [];
6864
- if (typeof candidate.props?.value !== "string") return [];
6865
- return [{
6866
- name: candidate.props.name,
6867
- value: candidate.props.value,
6868
- element: child
6869
- }];
6870
- });
6871
- const [query, setQuery] = useState("");
6899
+ const [searchContext, setSearchContext] = useSearchContext((store) => store), { query } = searchContext || {};
6872
6900
  const [isInvalid, setIsInvalid] = useState(invalid);
6873
6901
  const [selectedOptionSync, setSelectedOptionSync] = useState(() => {
6874
6902
  if (multiple) return Array.isArray(defaultValue) ? defaultValue : [];
6875
6903
  return typeof defaultValue === "string" ? defaultValue : null;
6876
6904
  });
6877
6905
  const comboboxInputRef = useRef(null);
6878
- const filteredOptions = query.trim() === "" ? options : options.filter((option) => option.name.toLowerCase().includes(query.toLowerCase()));
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
+ });
6879
6938
  const handleChange = (selected) => {
6880
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
+ }
6881
6962
  setSelectedOptionSync(selected);
6882
- onChange?.(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;
6883
6969
  };
6884
6970
  const handleInvalid = () => setIsInvalid(true);
6885
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
+ };
6886
7008
  return /* @__PURE__ */ jsxs(Field, {
6887
7009
  ...fieldProps,
6888
7010
  className: (bag) => twMerge("grid gap-1", typeof fieldClassName === "function" ? fieldClassName(bag) : fieldClassName),
@@ -6897,64 +7019,88 @@ function Search({ allowCustom, buttonProps, children, className, defaultValue, d
6897
7019
  invalid: isInvalid || invalid,
6898
7020
  multiple,
6899
7021
  onChange: handleChange,
6900
- onClose: () => setQuery(""),
6901
- value: selectedOptionSync || "",
7022
+ onClose: handleClose,
6902
7023
  children: [/* @__PURE__ */ jsxs("div", {
6903
- className: "relative",
6904
- children: [
6905
- /* @__PURE__ */ jsx(ComboboxInput, {
6906
- ...inputProps,
6907
- "aria-label": typeof label === "string" ? label : props.name,
6908
- 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),
6909
- displayValue: (value) => Array.isArray(value) ? value.map((v) => v.name).join(", ") : value?.name ?? "",
6910
- name: props.name,
6911
- onChange: (event) => setQuery(event.target.value),
6912
- placeholder: placeholder || (multiple ? "Choose Any" : "Choose One"),
6913
- ref: comboboxInputRef,
6914
- required
6915
- }),
6916
- /* @__PURE__ */ jsx("input", {
6917
- "aria-hidden": "true",
6918
- className: "sr-only top-0 left-1/2",
6919
- id: props.name + ":input:id" + uniqueId,
6920
- name: props.name,
6921
- onChange: () => {},
6922
- onFocus: refocus,
6923
- onInvalid: handleInvalid,
6924
- required,
6925
- tabIndex: -1,
6926
- value: Array.isArray(selectedOptionSync) ? selectedOptionSync.join(", ") : selectedOptionSync ?? ""
6927
- }),
6928
- /* @__PURE__ */ jsx(ComboboxButton, {
6929
- ...buttonProps,
6930
- className: "absolute top-1/2 right-1.5 -translate-y-1/2 rounded p-0.5",
6931
- children: /* @__PURE__ */ jsx(ChevronUpChevronDown, { className: "size-3 fill-current/50" })
6932
- })
6933
- ]
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
+ })]
6934
7074
  }), /* @__PURE__ */ jsxs(ComboboxOptions, {
6935
7075
  ...optionsProps,
6936
7076
  anchor: anchor || "bottom start",
6937
- 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),
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),
6938
7078
  transition: transition ?? true,
6939
- children: [allowCustom && query.length > 0 && /* @__PURE__ */ jsx(ComboboxOption, {
6940
- value: {
6941
- id: props.customOptionParams?.formatID?.(query) ?? toLowerCase(query, [" ", "_"]),
6942
- name: query
6943
- },
6944
- className: "group/option contents",
6945
- children: ({ selected }) => /* @__PURE__ */ jsx("div", {
6946
- 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",
6947
- children: selected ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Checkmark, { className: "size-3.5" }), query] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
6948
- /* @__PURE__ */ jsx(Plus, { className: "size-3.5" }),
6949
- "Use ",
6950
- /* @__PURE__ */ jsxs("b", { children: [
6951
- "\"",
6952
- query,
6953
- "\""
6954
- ] })
6955
- ] })
6956
- })
6957
- }), filteredOptions.map((option) => option.element)]
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
+ ]
6958
7104
  })]
6959
7105
  }),
6960
7106
  description && /* @__PURE__ */ jsx(Description, {
@@ -6965,6 +7111,31 @@ function Search({ allowCustom, buttonProps, children, className, defaultValue, d
6965
7111
  ]
6966
7112
  });
6967
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
+ }
6968
7139
  //#endregion
6969
7140
  //#region src/symbols/circle.fill.tsx
6970
7141
  function CircleFill({ weight = "regular", ...props }) {
@@ -8967,25 +9138,21 @@ function TooltipDisplay({ anchor = "top", arrow: arrow$4, arrowClassName, childr
8967
9138
  clearTimeout(timeoutRef.current);
8968
9139
  };
8969
9140
  }, []);
8970
- const [, setTooltipContext] = useTooltipContext(() => void 0, defaultTooltipContext);
9141
+ const [tooltipContext, setTooltipContext] = useTooltipContext(() => defaultTooltipContext);
8971
9142
  useEffect(() => {
8972
- setTooltipContext?.((previous) => {
8973
- const nextArrow = arrow$4 || false, nextArrowClassName = arrowClassName || "";
8974
- 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;
8975
- return {
8976
- ...previous,
8977
- isOpen,
8978
- openTooltip,
8979
- closeTooltip,
8980
- refs,
8981
- floatingStyles,
8982
- isPositioned,
8983
- placement,
8984
- middlewareData,
8985
- arrowRef,
8986
- arrow: nextArrow,
8987
- arrowClassName: nextArrowClassName
8988
- };
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
8989
9156
  });
8990
9157
  }, [
8991
9158
  arrow$4,
@@ -9046,4 +9213,4 @@ function ArrowSvg({ className, ...props }) {
9046
9213
  });
9047
9214
  }
9048
9215
  //#endregion
9049
- 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 };
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 };