@andrilla/mado-ui 1.1.0 → 1.1.2

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.
@@ -1,4 +1,16 @@
1
1
  import type { OneOf } from '../types';
2
+ type MultipleShelf = OneOf<[
3
+ {
4
+ /** When true, disables the shelf display, displaying all selected options in the input */
5
+ singleDisplay?: true;
6
+ },
7
+ {
8
+ /** When true, disables the shelf display, displaying all selected options in the input */
9
+ singleDisplay?: false | never;
10
+ /** Props to pass to the shelf div element */
11
+ shelfProps?: ComponentPropsWithRef<'div'>;
12
+ }
13
+ ]>;
2
14
  type MultipleType = OneOf<[
3
15
  {
4
16
  defaultValue?: string;
@@ -9,7 +21,7 @@ type MultipleType = OneOf<[
9
21
  defaultValue?: string[];
10
22
  multiple?: true;
11
23
  onChange?: (selected: string[]) => void;
12
- }
24
+ } & MultipleShelf
13
25
  ]>;
14
26
  type CustomOption = OneOf<[
15
27
  {
@@ -59,15 +71,30 @@ export type SearchProps = Omit<ComboboxProps<string, boolean>, 'children' | 'def
59
71
  placeholder?: string;
60
72
  ref?: RefObject<HTMLElement | null>;
61
73
  required?: boolean;
74
+ selectedOptionDisplayProps?: Omit<ComponentPropsWithoutRef<'span'>, 'children'> & {
75
+ children?: ReactNode | ((name: string) => ReactNode);
76
+ };
62
77
  } & MultipleType & CustomOption;
63
78
  export type SearchOptionProps = Omit<ComboboxOptionProps<'div', string>, 'className' | 'value'> & {
64
79
  className?: string;
80
+ /** @ignore This is an internal prop used to determine if the option is selected. */
81
+ isInDisplay?: boolean;
65
82
  name: string;
66
83
  ref?: RefObject<HTMLElement | null>;
84
+ selectedDisplayProps?: Omit<ComponentPropsWithoutRef<'span'>, 'children'> & {
85
+ /** Use the function `(name: string) => ReactNode` to use the option name as the display value. */
86
+ children?: ReactNode | ((name: string) => ReactNode);
87
+ };
67
88
  value: string;
68
89
  };
69
- import { type JSX, type ReactNode, type RefObject } from 'react';
90
+ import { type JSX, type ReactNode, type RefObject, type ComponentPropsWithRef, type ComponentPropsWithoutRef } from 'react';
70
91
  import { type ComboboxButtonProps, type ComboboxInputProps, type ComboboxOptionProps, type ComboboxOptionsProps, type ComboboxProps, type DescriptionProps, type FieldProps, type LabelProps } from '@headlessui/react';
92
+ /**
93
+ * ## Search Section Title
94
+ *
95
+ * Displays a simple title.
96
+ */
97
+ export declare function SearchSectionTitle({ className, ...props }: ComponentPropsWithRef<'div'>): JSX.Element;
71
98
  /**
72
99
  * ## SearchOption
73
100
  *
@@ -75,13 +102,28 @@ import { type ComboboxButtonProps, type ComboboxInputProps, type ComboboxOptionP
75
102
  * @prop name - This is used for filtering by default
76
103
  * @prop value - This is used as selected value and for FormData
77
104
  */
78
- export declare function SearchOption({ children, className, name, value, ...props }: SearchOptionProps): JSX.Element;
105
+ export declare function SearchOption({ children, className, isInDisplay, name, selectedDisplayProps: { children: selectedDisplayChildren, className: selectedDisplayClassName, ...selectedDisplayProps }, value, ...props }: SearchOptionProps): JSX.Element;
79
106
  /**
80
107
  * # Search
81
108
  *
82
109
  * A searchable select component built on top of Headless UI's `Combobox`.
83
110
  *
84
111
  * Use the `SearchOption` component to define options.
112
+ *
113
+ * Use the `SearchSectionTitle` component to define titles.
114
+ *
115
+ * @prop label - The label for the select component.
116
+ * @prop description - The description for the select component.
117
+ * @prop placeholder - The placeholder for the select component.
118
+ * @prop required - Whether the select component is required.
119
+ * @prop invalid - Whether the select component is invalid.
120
+ * @prop multiple - Whether the select component allows multiple selections.
121
+ * @prop optionsProps - The props to be passed to each SearchOption component.
122
+ * @prop selectedOptionDisplayProps - The props to be passed to each selected option in the selected option component.
123
+ * @prop fieldProps - The props to be passed to the parent field component.
124
+ * @prop labelProps - The props to be passed to the label component.
125
+ * @prop descriptionProps - The props to be passed to the description component.
126
+ * @prop anchor - The anchor point for the drop down menu.
85
127
  */
86
- export declare 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, ...props }: SearchProps): JSX.Element;
128
+ export declare function Search(props: SearchProps): JSX.Element;
87
129
  export {};
@@ -28,9 +28,12 @@ export type SelectProps = Omit<ListboxProps, 'children' | 'defaultValue' | 'mult
28
28
  placeholder?: ListboxSelectedOptionProps['placeholder'];
29
29
  ref?: RefObject<HTMLElement | null>;
30
30
  required?: boolean;
31
- selectedOptionProps?: Omit<ListboxSelectedOptionProps, 'options' | 'placeholder'> & {
31
+ selectedOptionProps?: AnyElementProps<ElementType, Omit<Omit<ListboxSelectedOptionProps, 'as'>, 'options' | 'placeholder'> & {
32
32
  /** @deprecated use `placeholder` prop instead */
33
33
  placeholder?: never;
34
+ }>;
35
+ selectedOptionDisplayProps?: Omit<ComponentPropsWithoutRef<'span'>, 'children'> & {
36
+ children?: ReactNode | ((name: string) => ReactNode);
34
37
  };
35
38
  } & ({
36
39
  defaultValue?: string;
@@ -45,9 +48,14 @@ export type SelectOptionProps = Omit<ListboxOptionProps, 'className'> & {
45
48
  className?: string;
46
49
  name: string;
47
50
  ref?: RefObject<HTMLElement | null>;
51
+ selectedDisplayProps?: Omit<ComponentPropsWithoutRef<'span'>, 'children'> & {
52
+ /** Use the function `(name: string) => ReactNode` to use the option name as the display value. */
53
+ children?: ReactNode | ((name: string) => ReactNode);
54
+ };
48
55
  };
49
- import { type ComponentPropsWithRef, type JSX, type ReactNode, type RefObject } from 'react';
56
+ import { type ComponentPropsWithRef, type JSX, type ReactNode, type RefObject, type ComponentPropsWithoutRef, type ElementType } from 'react';
50
57
  import { type DescriptionProps, type FieldProps, type LabelProps, type ListboxButtonProps, type ListboxOptionProps, type ListboxOptionsProps, type ListboxProps, type ListboxSelectedOptionProps } from '@headlessui/react';
58
+ import type { AnyElementProps } from '../types';
51
59
  /**
52
60
  * ## Select Section Title
53
61
  *
@@ -57,11 +65,12 @@ export declare function SelectSectionTitle({ className, ...props }: ComponentPro
57
65
  /**
58
66
  * ## SelectOption
59
67
  *
60
- * @prop children - This is what is displayed in the drop down menu
61
- * @prop name - This is displayed in the trigger button
62
- * @prop value - This is used for FormData
68
+ * @prop children - This is what is displayed in the drop down menu.
69
+ * @prop name - This is displayed in the trigger button.
70
+ * @prop value - This is used for FormData.
71
+ * @prop selectedDisplayProps - This is used to customize the display of the selected option (takes priority over selectedOptionDisplayProps).
63
72
  */
64
- export declare function SelectOption({ children, className, name, ...props }: SelectOptionProps): JSX.Element;
73
+ export declare function SelectOption({ children, className, name, selectedDisplayProps: { children: selectedDisplayChildren, className: selectedDisplayClassName, ...selectedDisplayProps }, ...props }: SelectOptionProps): JSX.Element;
65
74
  /**
66
75
  * # Select
67
76
  *
@@ -79,9 +88,10 @@ export declare function SelectOption({ children, className, name, ...props }: Se
79
88
  * @prop multiple - Whether the select component allows multiple selections.
80
89
  * @prop optionsProps - The props to be passed to each SelectOption component.
81
90
  * @prop selectedOptionProps - The props to be passed to the selected option component.
91
+ * @prop selectedOptionDisplayProps - The props to be passed to each selected option in the selected option component.
82
92
  * @prop fieldProps - The props to be passed to the parent field component.
83
93
  * @prop labelProps - The props to be passed to the label component.
84
94
  * @prop descriptionProps - The props to be passed to the description component.
85
95
  * @prop anchor - The anchor point for the drop down menu.
86
96
  */
87
- export declare 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 }: SelectProps): JSX.Element;
97
+ export declare function Select(props: SelectProps): JSX.Element;
@@ -1,10 +1,9 @@
1
- import { type HTMLAttributes, type JSX } from 'react';
2
- export declare function createFastContext<Store>(defaultInitialState: Store): {
3
- Provider: ({ initialValue, ...props }: Pick<HTMLAttributes<HTMLElement>, 'children'> & {
4
- initialValue?: Store;
5
- }) => JSX.Element;
6
- useStore: <SelectorOutput>(selector: (store: Store) => SelectorOutput, initialValue?: Store) => [
7
- SelectorOutput | undefined,
8
- ((value: Store | ((prevState: Store) => Store)) => void) | undefined
9
- ];
1
+ import { type JSX, type ReactNode } from 'react';
2
+ export type FastContextProvider = ({ children, }: {
3
+ children: ReactNode;
4
+ }) => JSX.Element;
5
+ export type FastContextUseStore<TStore> = <SelectorOutput>(selector: (store: TStore) => SelectorOutput) => [SelectorOutput, (value: Partial<TStore>) => void];
6
+ export declare function createFastContext<TStore>(initialState: TStore): {
7
+ Provider: FastContextProvider;
8
+ useStore: FastContextUseStore<TStore>;
10
9
  };
@@ -1,39 +1,37 @@
1
- import { Suspense, createContext, useCallback, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
1
+ import { createContext, useCallback, useContext, useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  //#region src/hooks/create-fast-context.tsx
4
- function createFastContext(defaultInitialState) {
5
- function useStoreData(initialState = defaultInitialState) {
6
- const store = useRef(initialState), get = () => store.current, subscribers = useRef(/* @__PURE__ */ new Set());
7
- const set = (value) => {
8
- if (typeof value === "function") store.current = value(store.current);
9
- else store.current = value;
10
- subscribers.current.forEach((callback) => callback());
11
- };
12
- const subscribe = (callback) => {
13
- subscribers.current.add(callback);
14
- return () => subscribers.current.delete(callback);
15
- };
4
+ function createFastContext(initialState) {
5
+ function useStoreData() {
6
+ const store = useRef(initialState);
7
+ const get = useCallback(() => store.current, []);
8
+ const subscribers = useRef(/* @__PURE__ */ new Set());
16
9
  return {
17
10
  get,
18
- set,
19
- subscribe
11
+ set: useCallback((value) => {
12
+ store.current = {
13
+ ...store.current,
14
+ ...value
15
+ };
16
+ subscribers.current.forEach((callback) => callback());
17
+ }, []),
18
+ subscribe: useCallback((callback) => {
19
+ subscribers.current.add(callback);
20
+ return () => subscribers.current.delete(callback);
21
+ }, [])
20
22
  };
21
23
  }
22
24
  const StoreContext = createContext(null);
23
- function Provider({ initialValue = defaultInitialState, ...props }) {
25
+ function Provider({ children }) {
24
26
  return /* @__PURE__ */ jsx(StoreContext.Provider, {
25
- value: useStoreData(initialValue),
26
- ...props
27
+ value: useStoreData(),
28
+ children
27
29
  });
28
30
  }
29
- function useStore(selector, initialValue) {
31
+ function useStore(selector) {
30
32
  const store = useContext(StoreContext);
31
- if (!store) {
32
- const selectedValue = selector(initialValue !== void 0 ? initialValue : defaultInitialState);
33
- const noOpSet = () => console.warn("Attempting to set store value outside of Provider");
34
- return [selectedValue, noOpSet];
35
- }
36
- return [useSyncExternalStore(store.subscribe, () => selector(store.get()), () => selector(initialValue !== void 0 ? initialValue : defaultInitialState)), store.set];
33
+ if (!store) throw new Error("Store not found");
34
+ return [useSyncExternalStore(store.subscribe, () => selector(store.get()), () => selector(initialState)), store.set];
37
35
  }
38
36
  return {
39
37
  Provider,
@@ -43,15 +41,12 @@ function createFastContext(defaultInitialState) {
43
41
  //#endregion
44
42
  //#region src/hooks/use-form-status.tsx
45
43
  const DEFAULT_STATUS = "incomplete";
46
- const { Provider, useStore } = createFastContext(DEFAULT_STATUS);
47
- function FormStatusProvider({ children, initialStatus = DEFAULT_STATUS }) {
48
- return /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(Provider, {
49
- initialValue: initialStatus,
50
- children
51
- }) });
52
- }
53
- function useFormStatus() {
54
- return useStore((store) => store);
44
+ function useFormStatusContext(initialStatus = DEFAULT_STATUS) {
45
+ const { Provider: FormStatusProvider, useStore: useFormStatus } = createFastContext(initialStatus);
46
+ return {
47
+ FormStatusProvider,
48
+ useFormStatus
49
+ };
55
50
  }
56
51
  //#endregion
57
52
  //#region src/hooks/use-pointer-movement.ts
@@ -180,4 +175,4 @@ function useMobileDevice() {
180
175
  return isMobileDevice;
181
176
  }
182
177
  //#endregion
183
- export { FormStatusProvider, createFastContext, useFormStatus, useMobileDevice, usePointerMovement };
178
+ export { createFastContext, useFormStatusContext, useMobileDevice, usePointerMovement };
@@ -1,10 +1,8 @@
1
- import { type JSX, type ReactNode } from 'react';
2
- export type FormStatus = 'error' | 'incomplete' | 'loading' | 'ready' | 'success' | 'readonly';
3
- export declare function FormStatusProvider({ children, initialStatus, }: {
4
- children?: ReactNode;
5
- initialStatus?: FormStatus;
6
- }): JSX.Element;
7
- export declare function useFormStatus(): [
8
- FormStatus | undefined,
9
- (((value: FormStatus | ((prevState: FormStatus) => FormStatus)) => void) | undefined)
10
- ];
1
+ import type { SubmitButtonProps } from '../components';
2
+ type FormStatus = SubmitButtonProps['formStatus'];
3
+ import { type FastContextProvider, type FastContextUseStore } from './create-fast-context';
4
+ export declare function useFormStatusContext(initialStatus?: FormStatus): {
5
+ FormStatusProvider: FastContextProvider;
6
+ useFormStatus: FastContextUseStore<FormStatus>;
7
+ };
8
+ export {};