@vuu-ui/vuu-ui-controls 4.0.0-alpha.2 → 4.0.0-alpha.21

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.
Files changed (54) hide show
  1. package/package.json +15 -14
  2. package/src/drag-drop/Draggable.css.js +2 -2
  3. package/src/expando-input/ExpandoInput.css.js +1 -1
  4. package/src/icon-button/ToggleIconButton.css.js +1 -1
  5. package/src/index.js +1 -1
  6. package/src/item-picker/ItemPicker.css.js +1 -5
  7. package/src/item-picker/ItemPicker.js +69 -60
  8. package/src/item-picker/useItemPicker.js +2 -5
  9. package/src/price-ticker/PriceTicker.css.js +4 -4
  10. package/src/split-pane/SplitPane.css.js +82 -0
  11. package/src/split-pane/SplitPane.js +60 -0
  12. package/src/split-pane/Splitter.js +82 -0
  13. package/src/split-pane/index.js +1 -0
  14. package/src/split-pane/useSplitPane.js +101 -0
  15. package/src/tabstrip/Tab.css.js +3 -3
  16. package/src/tabstrip/Tabstrip.css.js +2 -2
  17. package/src/time-input/MaskedInput.js +176 -156
  18. package/src/time-input/TimeInput.css.js +41 -18
  19. package/src/time-input/TimeInput.js +25 -14
  20. package/src/time-input/useTimeInput.js +57 -47
  21. package/src/toolbar/Toolbar.css.js +1 -1
  22. package/src/vuu-date-picker/VuuDatePicker.js +46 -52
  23. package/src/vuu-time-picker/VuuTimePicker.js +6 -5
  24. package/types/context-panel-provider/ContextPanelProvider.d.ts +1 -1
  25. package/types/drag-drop/DragDropProvider.d.ts +1 -1
  26. package/types/hover-overlay/HoverOverlay.d.ts +1 -1
  27. package/types/icon-button/Icon.d.ts +1 -1
  28. package/types/icon-button/ToggleIconButton.d.ts +1 -1
  29. package/types/index.d.ts +4 -4
  30. package/types/instrument-picker/SearchCell.d.ts +1 -1
  31. package/types/instrument-picker/TablePicker.d.ts +1 -1
  32. package/types/item-picker/ItemPicker.d.ts +25 -7
  33. package/types/item-picker/useItemPicker.d.ts +3 -6
  34. package/types/modal-provider/ModalProvider.d.ts +1 -1
  35. package/types/price-ticker/PriceTicker.d.ts +1 -1
  36. package/types/prompt/Prompt.d.ts +1 -1
  37. package/types/sortable-list/SortableList.d.ts +2 -2
  38. package/types/split-button/useSplitButton.d.ts +12 -12
  39. package/types/split-pane/SplitPane.d.ts +44 -0
  40. package/types/split-pane/Splitter.d.ts +10 -0
  41. package/types/split-pane/index.d.ts +2 -0
  42. package/types/split-pane/useSplitPane.d.ts +18 -0
  43. package/types/table-search/SearchCell.d.ts +1 -1
  44. package/types/table-search/TableSearch.d.ts +1 -1
  45. package/types/tabstrip/TabMenu.d.ts +1 -1
  46. package/types/tabstrip/Tabstrip.d.ts +1 -2
  47. package/types/time-input/MaskedInput.d.ts +60 -10
  48. package/types/time-input/TimeInput.d.ts +4 -3
  49. package/types/time-input/useTimeInput.d.ts +24 -5
  50. package/types/toolbar/Toolbar.d.ts +1 -2
  51. package/types/vuu-date-picker/VuuDatePicker.d.ts +19 -3
  52. package/types/vuu-time-picker/VuuTimePicker.d.ts +8 -6
  53. package/types/vuu-typeahead-input/VuuTypeaheadInput.d.ts +1 -1
  54. package/src/modal-provider/ModalProvider.js +0 -147
@@ -0,0 +1,44 @@
1
+ import { type FlexAlignment, type FlexContentAlignment, type ResponsiveProp } from "@salt-ds/core";
2
+ import { type HTMLAttributes, type ReactElement, type ReactNode } from "react";
3
+ import { type SplitPaneDirection, type SplitterMovedHandler } from "./useSplitPane";
4
+ export interface SplitPaneProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
5
+ /**
6
+ * Defines the default behavior for how flex items are laid out along the cross axis, default is "stretch".
7
+ */
8
+ align?: FlexAlignment | "stretch" | "baseline";
9
+ /**
10
+ * Exactly two children, typically Salt `FlexItem` components. A Splitter
11
+ * will be rendered between them. A single child is also accepted (e.g. when
12
+ * one pane is conditionally rendered), in which case no Splitter is rendered.
13
+ */
14
+ children: ReactElement | [ReactNode, ReactNode];
15
+ /**
16
+ * Establishes the main-axis, defining the direction children are placed. Default is "row".
17
+ */
18
+ direction?: ResponsiveProp<SplitPaneDirection>;
19
+ /**
20
+ * Controls the space between each item and the Splitter, default is 0.
21
+ */
22
+ gap?: ResponsiveProp<number | string>;
23
+ /**
24
+ * Defines the alignment along the main axis, default is "start".
25
+ */
26
+ justify?: FlexContentAlignment;
27
+ /**
28
+ * Defines the margin around the component. It can be specified as a number (which acts as a multiplier) or a string representing the margin value. Default is `0`.
29
+ */
30
+ margin?: ResponsiveProp<number | string>;
31
+ /**
32
+ * Invoked when user has finished moving the Splitter, receives the new sizes (px) of both panes.
33
+ */
34
+ onSplitterMoved?: SplitterMovedHandler;
35
+ /**
36
+ * Defines the padding within the component. It can be specified as a number (which acts as a multiplier) or a string representing the padding value. Default is `0`.
37
+ */
38
+ padding?: ResponsiveProp<number | string>;
39
+ /**
40
+ * Size (thickness) of the Splitter, in px. Default is 3.
41
+ */
42
+ splitterSize?: number;
43
+ }
44
+ export declare const SplitPane: import("react").ForwardRefExoticComponent<SplitPaneProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,10 @@
1
+ import { type HTMLAttributes } from "react";
2
+ import type { SplitPaneDirection } from "./useSplitPane";
3
+ export interface SplitterProps extends Omit<HTMLAttributes<HTMLDivElement>, "onResize"> {
4
+ direction: SplitPaneDirection;
5
+ onResizeStart: () => boolean;
6
+ onResize: (distance: number) => void;
7
+ onResizeEnd: () => void;
8
+ position?: number;
9
+ }
10
+ export declare const Splitter: ({ className, direction, onResize, onResizeEnd, onResizeStart, position, ...htmlAttributes }: SplitterProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export * from "./SplitPane";
2
+ export type { SplitPaneDirection, SplitPaneSizes, SplitterMovedHandler, } from "./useSplitPane";
@@ -0,0 +1,18 @@
1
+ export type SplitPaneDirection = "row" | "column";
2
+ /**
3
+ * Sizes (in px) of the two panes, measured along the main axis.
4
+ */
5
+ export type SplitPaneSizes = [number, number];
6
+ export type SplitterMovedHandler = (sizes: SplitPaneSizes) => void;
7
+ export interface SplitPaneHookProps {
8
+ direction: SplitPaneDirection;
9
+ onSplitterMoved?: SplitterMovedHandler;
10
+ paneCount: number;
11
+ }
12
+ export declare const useSplitPane: ({ direction, onSplitterMoved, paneCount, }: SplitPaneHookProps) => {
13
+ beginResize: () => boolean;
14
+ endResize: () => void;
15
+ resize: (distance: number) => void;
16
+ rootRef: import("react").RefObject<HTMLDivElement | null>;
17
+ splitterPosition: number | undefined;
18
+ };
@@ -1,2 +1,2 @@
1
1
  import { TableCellRendererProps } from "@vuu-ui/vuu-table-types";
2
- export declare const SearchCell: ({ column, dataRow, searchPattern, }: TableCellRendererProps) => import("react").JSX.Element;
2
+ export declare const SearchCell: ({ column, dataRow, searchPattern, }: TableCellRendererProps) => import("react/jsx-runtime").JSX.Element;
@@ -6,4 +6,4 @@ export interface TableSearchProps extends HTMLAttributes<HTMLDivElement> {
6
6
  placeHolder?: string;
7
7
  searchColumns: string[];
8
8
  }
9
- export declare const TableSearch: ({ TableProps: { dataSource: dataSourceProp, ...TableProps }, autoFocus, className, placeHolder, searchColumns, ...htmlAttributes }: TableSearchProps) => import("react").JSX.Element;
9
+ export declare const TableSearch: ({ TableProps: { dataSource: dataSourceProp, ...TableProps }, autoFocus, className, placeHolder, searchColumns, ...htmlAttributes }: TableSearchProps) => import("react/jsx-runtime").JSX.Element;
@@ -20,4 +20,4 @@ export interface TabMenuProps {
20
20
  */
21
21
  controlledComponentTitle?: string;
22
22
  }
23
- export declare const TabMenu: ({ allowClose, allowRename, controlledComponentId, controlledComponentTitle, location, onMenuAction, onMenuClose, index, }: TabMenuProps) => import("react").JSX.Element;
23
+ export declare const TabMenu: ({ allowClose, allowRename, controlledComponentId, controlledComponentTitle, location, onMenuAction, onMenuClose, index, }: TabMenuProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,3 +1,2 @@
1
- import React from "react";
2
1
  import type { TabstripProps } from "./TabsTypes";
3
- export declare const Tabstrip: ({ activeTabIndex: activeTabIndexProp, allowAddTab, allowCloseTab, allowDragDrop, allowRenameTab, animateSelectionThumb, children, className: classNameProp, id: idProp, keyBoardActivation, location, onActiveChange, onAddTab, onCloseTab, onExitEditMode, onMoveTab, orientation, showTabMenuButton, style: styleProp, tabClassName, variant, ...htmlAttributes }: TabstripProps) => React.JSX.Element;
2
+ export declare const Tabstrip: ({ activeTabIndex: activeTabIndexProp, allowAddTab, allowCloseTab, allowDragDrop, allowRenameTab, animateSelectionThumb, children, className: classNameProp, id: idProp, keyBoardActivation, location, onActiveChange, onAddTab, onCloseTab, onExitEditMode, onMoveTab, orientation, showTabMenuButton, style: styleProp, tabClassName, variant, ...htmlAttributes }: TabstripProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,13 +1,32 @@
1
- import { EventEmitter, TimeString, TimeUnit } from "@vuu-ui/vuu-utils";
1
+ import { EventEmitter, TimeString, TimeStringMillis, TimeUnit } from "@vuu-ui/vuu-utils";
2
2
  import { ChangeEventHandler } from "react";
3
3
  export type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
4
+ export type TimeValue = TimeString | TimeStringMillis;
5
+ export declare const invalidClassName = "vuuTimeInput-invalid";
6
+ export interface MaskedInputOptions {
7
+ /**
8
+ * When true, value includes milliseconds, hh:mm:ss.SSS
9
+ */
10
+ milliseconds?: boolean;
11
+ }
4
12
  export type MaskedInputEvents = {
5
13
  change: ChangeEventHandler<HTMLInputElement>;
6
14
  };
7
15
  export declare class MaskedInput extends EventEmitter<MaskedInputEvents> {
8
16
  #private;
9
- constructor(defaultValue: TimeString | undefined, inputEl?: HTMLInputElement | null);
10
- set input(el: HTMLInputElement);
17
+ constructor(defaultValue: TimeValue | undefined, inputEl?: HTMLInputElement | null, { milliseconds }?: MaskedInputOptions);
18
+ get milliseconds(): boolean;
19
+ private get zeroValue();
20
+ /**
21
+ * Length of the formatted value, hh:mm:ss or hh:mm:ss.SSS
22
+ */
23
+ get length(): 8 | 12;
24
+ private normalise;
25
+ /**
26
+ * Attach (or re-attach) the input element. Re-attaching the same element
27
+ * is a no-op, attaching a different element detaches the previous one.
28
+ */
29
+ set input(el: HTMLInputElement | null);
11
30
  /**
12
31
  * The change event is fired programatically. This will only be handled
13
32
  * by a native event handler ( not a React handler). We handle this event
@@ -21,25 +40,56 @@ export declare class MaskedInput extends EventEmitter<MaskedInputEvents> {
21
40
  set selectionStart(value: number);
22
41
  get selectionEnd(): number;
23
42
  set selectionEnd(value: number);
43
+ private nextUnit;
44
+ private previousUnit;
45
+ private get firstUnit();
46
+ private get lastUnit();
24
47
  private setValue;
25
- private setUnitValue;
26
48
  private getUnitValue;
27
- get value(): TimeString;
49
+ private setUnitValue;
50
+ private setInvalid;
51
+ get value(): TimeValue;
28
52
  /**
29
- * Setting the value this way invokes 'controlled' mode
53
+ * Setting the value this way invokes 'controlled' mode. Value
54
+ * will be normalised to the configured precision.
30
55
  */
31
- set value(value: TimeString);
56
+ set value(value: TimeValue);
32
57
  clear(unit: TimeUnit): void;
33
- select(unit: TimeUnit, halfUnit?: boolean): void;
58
+ /**
59
+ * Select a unit. If digitIndex > 0, only the digits of the unit
60
+ * not yet entered are selected.
61
+ */
62
+ select(unit: TimeUnit, digitIndex?: number): void;
34
63
  removeSelection(): void;
35
64
  restoreSelection(): void;
36
- advanceSelection(): void;
65
+ selectFirst(): void;
66
+ selectLast(): void;
37
67
  moveFocus(direction: "left" | "right"): void;
38
- pasteValue(value: TimeString): void;
68
+ /**
69
+ * Replace the entire value, e.g. from a paste. Values with or without
70
+ * milliseconds are accepted and converted to the configured precision.
71
+ * Invalid values are ignored. Returns true if value was accepted.
72
+ */
73
+ pasteValue(value: string): boolean;
39
74
  private getUnitAtCursorPos;
75
+ private get activeUnit();
40
76
  incrementValue(): void;
41
77
  decrementValue(): void;
78
+ /**
79
+ * If a full unit is selected, it is cleared and selection moves to the
80
+ * previous unit. If we are midway through entering a unit, the unit is
81
+ * cleared and remains selected.
82
+ */
42
83
  backspace(): void;
84
+ /**
85
+ * Typing the first digit of a unit sets the unit to that digit followed
86
+ * by zeros, e.g '1' => '10' and selection moves to the next digit. If
87
+ * the digit cannot be the first digit of a valid unit, e.g '3' for hours,
88
+ * the unit is zero padded, e.g '03', and selection advances to the next unit.
89
+ * Typing the last digit completes the unit and selection advances to the
90
+ * next unit. A digit which would produce an invalid value is rejected and
91
+ * the input is marked as invalid.
92
+ */
43
93
  update(key: Digit): void;
44
94
  private getSelection;
45
95
  click(): void;
@@ -1,5 +1,6 @@
1
1
  import { HTMLAttributes } from "react";
2
- import { TimeInputHookProps } from "./useTimeInput";
3
- export interface TimeInputProps extends TimeInputHookProps, Omit<HTMLAttributes<HTMLInputElement>, "defaultValue" | "onChange" | "value">, Partial<Pick<HTMLInputElement, "placeholder">> {
4
- }
2
+ import { TimeInputHookProps, TimeInputMillisecondsProps, TimeInputSecondsProps } from "./useTimeInput";
3
+ type TimeInputHtmlAttributes = Omit<HTMLAttributes<HTMLInputElement>, "defaultValue" | "onChange" | "value"> & Partial<Pick<HTMLInputElement, "placeholder">>;
4
+ export type { TimeInputMillisecondsProps, TimeInputSecondsProps };
5
+ export type TimeInputProps = TimeInputHookProps & TimeInputHtmlAttributes;
5
6
  export declare const TimeInput: import("react").ForwardRefExoticComponent<TimeInputProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -1,16 +1,34 @@
1
- import { type CommitHandler, DateStringISO, type TimeString } from "@vuu-ui/vuu-utils";
1
+ import { type CommitHandler, DateStringISO, type TimeString, type TimeStringMillis } from "@vuu-ui/vuu-utils";
2
2
  import { ChangeEventHandler, ClipboardEventHandler, FocusEventHandler, KeyboardEventHandler, MouseEventHandler, RefCallback } from "react";
3
- export interface TimeInputHookProps {
3
+ interface TimeInputCommonProps {
4
4
  date?: Date | DateStringISO;
5
- defaultValue?: TimeString;
6
5
  onChange?: ChangeEventHandler<HTMLInputElement>;
6
+ }
7
+ export interface TimeInputSecondsProps extends TimeInputCommonProps {
8
+ defaultValue?: TimeString;
9
+ /**
10
+ * When true, time is entered and displayed with millisecond
11
+ * precision, hh:mm:ss.SSS
12
+ */
13
+ milliseconds?: false;
7
14
  onCommit: CommitHandler<HTMLInputElement, TimeString>;
8
15
  value?: TimeString;
9
16
  }
10
- export declare const useTimeInput: ({ defaultValue, onChange, onCommit, value, }: TimeInputHookProps) => {
17
+ export interface TimeInputMillisecondsProps extends TimeInputCommonProps {
18
+ defaultValue?: TimeStringMillis;
19
+ /**
20
+ * When true, time is entered and displayed with millisecond
21
+ * precision, hh:mm:ss.SSS
22
+ */
23
+ milliseconds: true;
24
+ onCommit: CommitHandler<HTMLInputElement, TimeStringMillis>;
25
+ value?: TimeStringMillis;
26
+ }
27
+ export type TimeInputHookProps = TimeInputSecondsProps | TimeInputMillisecondsProps;
28
+ export declare const useTimeInput: ({ defaultValue, milliseconds, onChange, onCommit: onCommitProp, value, }: TimeInputHookProps) => {
11
29
  inputRef: RefCallback<HTMLInputElement>;
12
30
  eventHandlers: {
13
- onBlur: (() => void) | undefined;
31
+ onBlur: () => void;
14
32
  onDoubleClick: () => void;
15
33
  onFocus: FocusEventHandler<HTMLInputElement>;
16
34
  onKeyDown: KeyboardEventHandler<HTMLInputElement>;
@@ -19,3 +37,4 @@ export declare const useTimeInput: ({ defaultValue, onChange, onCommit, value, }
19
37
  onPaste: ClipboardEventHandler<HTMLInputElement>;
20
38
  };
21
39
  };
40
+ export {};
@@ -1,4 +1,3 @@
1
- import React from "react";
2
1
  import { OverflowContainerProps } from "../overflow-container";
3
2
  import { SelectionStrategy, SpecialKeyMultipleSelection } from "../common-hooks";
4
3
  export type ActiveItemChangeHandler = (itemIndex: number[]) => void;
@@ -17,4 +16,4 @@ export interface ToolbarProps extends OverflowContainerProps {
17
16
  selectionStrategy?: SelectionStrategy | SpecialKeyMultipleSelection;
18
17
  showSeparators?: boolean;
19
18
  }
20
- export declare const Toolbar: ({ activeItemIndex: activeItemIndexProp, alignItems, defaultActiveItemIndex, children, className, id: idProp, onActiveChange, onNavigateOutOfBounds, orientation, selectionStrategy, showSeparators, ...props }: ToolbarProps) => React.JSX.Element;
19
+ export declare const Toolbar: ({ activeItemIndex: activeItemIndexProp, alignItems, defaultActiveItemIndex, children, className, id: idProp, onActiveChange, onNavigateOutOfBounds, orientation, selectionStrategy, showSeparators, ...props }: ToolbarProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,23 @@
1
- import { CommitHandler } from "@vuu-ui/vuu-utils";
1
+ import { type CommitHandler, EpochTimestamp, type TimeZoneSpec } from "@vuu-ui/vuu-utils";
2
2
  import { SingleSelectionValueType } from "../calendar";
3
3
  import { DatePickerProps } from "../date-picker";
4
- export declare const VuuDatePicker: ({ className, onSelectionChange, selectedDate: selectedDateProp, onCommit, preserveFocusOnSelect, ...props }: Omit<DatePickerProps<SingleSelectionValueType>, "defaultSelectedDate"> & {
4
+ export interface VuuDatePickerProps extends Omit<DatePickerProps<SingleSelectionValueType>, "defaultSelectedDate" | "onChange"> {
5
+ /**
6
+ * Invoked when user selects a date from the calendar, or enters a valid date and
7
+ * presses Enter. Value is epoch millis at the start of the selected day, in timeZone.
8
+ */
5
9
  onCommit?: CommitHandler<HTMLElement, number>;
6
10
  preserveFocusOnSelect?: boolean;
7
- }) => import("react").JSX.Element;
11
+ /**
12
+ * The time zone used to convert between epoch values and calendar dates.
13
+ * Defaults to the application default time zone (see setDefaultTimeZone).
14
+ */
15
+ timeZone?: TimeZoneSpec;
16
+ /**
17
+ * An epoch value (millis as number, or millis/nanos as EpochTimestamp). An
18
+ * alternative to selectedDate, when the date is derived from a timestamp. The
19
+ * calendar date is determined in timeZone.
20
+ */
21
+ value?: EpochTimestamp | number;
22
+ }
23
+ export declare const VuuDatePicker: ({ className, onSelectionChange, onCommit, preserveFocusOnSelect, selectedDate: selectedDateProp, timeZone, value, ...props }: VuuDatePickerProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,9 @@
1
- import { CommitHandler, TimeString } from "@vuu-ui/vuu-utils";
2
1
  import { HTMLAttributes } from "react";
3
- import { TimeInputProps } from "../time-input/TimeInput";
4
- export interface VuuTimePickerProps extends Pick<TimeInputProps, "defaultValue" | "onChange" | "value">, Omit<HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange" | "value"> {
5
- onCommit: CommitHandler<HTMLInputElement, TimeString>;
6
- }
7
- export declare const VuuTimePicker: ({ className, defaultValue, onChange, onCommit, value, ...htmlAttributes }: VuuTimePickerProps) => import("react").JSX.Element;
2
+ import { TimeInputMillisecondsProps, TimeInputSecondsProps } from "../time-input/TimeInput";
3
+ type VuuTimePickerHtmlAttributes = Omit<HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange" | "value">;
4
+ type TimePickerInputProps = "defaultValue" | "milliseconds" | "onChange" | "onCommit" | "value";
5
+ export type VuuTimePickerSecondsProps = Pick<TimeInputSecondsProps, TimePickerInputProps> & VuuTimePickerHtmlAttributes;
6
+ export type VuuTimePickerMillisecondsProps = Pick<TimeInputMillisecondsProps, TimePickerInputProps> & VuuTimePickerHtmlAttributes;
7
+ export type VuuTimePickerProps = VuuTimePickerSecondsProps | VuuTimePickerMillisecondsProps;
8
+ export declare const VuuTimePicker: ({ className, defaultValue, milliseconds, onChange, onCommit, value, ...htmlAttributes }: VuuTimePickerProps) => import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -3,4 +3,4 @@ import { VuuTypeaheadInputHookProps } from "./useVuuTypeaheadInput";
3
3
  export interface VuuTypeaheadInputProps extends VuuTypeaheadInputHookProps, Pick<ComboBoxProps, "selectOnTab"> {
4
4
  className?: string;
5
5
  }
6
- export declare const VuuTypeaheadInput: ({ allowFreeInput, className, column, freeTextWarning, highlightFirstSuggestion, inputProps: inputPropsProp, minCharacterCountToTriggerSuggestions, onCommit, selectOnTab, table, }: VuuTypeaheadInputProps) => import("react").JSX.Element;
6
+ export declare const VuuTypeaheadInput: ({ allowFreeInput, className, column, freeTextWarning, highlightFirstSuggestion, inputProps: inputPropsProp, minCharacterCountToTriggerSuggestions, onCommit, selectOnTab, table, }: VuuTypeaheadInputProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,147 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Dialog, DialogActions, DialogCloseButton, DialogContent, DialogHeader } from "@salt-ds/core";
3
- import { createContext, useCallback, useContext, useMemo, useState } from "react";
4
- import { Prompt } from "../prompt/Prompt.js";
5
- const useDialogHost = ()=>{
6
- const [dialogState, setDialogState] = useState();
7
- const [promptState, setPromptState] = useState();
8
- const closePrompt = useCallback(()=>{
9
- setPromptState(void 0);
10
- }, []);
11
- const closeDialog = useCallback(()=>{
12
- setDialogState(void 0);
13
- }, []);
14
- const handleOpenChange = useCallback((open)=>{
15
- if (true !== open) closeDialog();
16
- }, [
17
- closeDialog
18
- ]);
19
- const dialog = dialogState ? /*#__PURE__*/ jsxs(Dialog, {
20
- open: true,
21
- onOpenChange: handleOpenChange,
22
- children: [
23
- /*#__PURE__*/ jsx(DialogHeader, {
24
- header: dialogState.title
25
- }),
26
- /*#__PURE__*/ jsx(DialogContent, {
27
- children: dialogState.content
28
- }),
29
- true !== dialogState.hideCloseButton ? /*#__PURE__*/ jsx(DialogCloseButton, {
30
- "data-embedded": true,
31
- "data-icon": "close",
32
- onClick: closeDialog
33
- }) : null,
34
- dialogState.actions ? /*#__PURE__*/ jsx(DialogActions, {
35
- children: dialogState.actions
36
- }) : null
37
- ]
38
- }) : null;
39
- const handleOpenChangePrompt = useCallback((open)=>{
40
- if (true !== open) closePrompt();
41
- promptState?.promptProps.onOpenChange?.(open);
42
- }, [
43
- closePrompt,
44
- promptState
45
- ]);
46
- const prompt = promptState ? /*#__PURE__*/ jsx(Prompt, {
47
- ...promptState.promptProps,
48
- onClose: closePrompt,
49
- onOpenChange: handleOpenChangePrompt,
50
- open: true,
51
- children: promptState.content
52
- }) : null;
53
- return {
54
- dialog,
55
- prompt,
56
- setDialogState,
57
- setPromptState
58
- };
59
- };
60
- const defaultShowDialog = ()=>{
61
- console.warn("No DialogProvider in place");
62
- };
63
- const defaultCloseDialog = ()=>{
64
- console.warn("No DialogProvider in place");
65
- };
66
- const defaultShowPrompt = ()=>{
67
- console.warn("No DialogProvider in place");
68
- };
69
- const defaultClosePrompt = ()=>{
70
- console.warn("No DialogProvider in place");
71
- };
72
- class DialogContextObject {
73
- showDialog = defaultShowDialog;
74
- closeDialog = defaultCloseDialog;
75
- showPrompt = defaultShowPrompt;
76
- closePrompt = defaultClosePrompt;
77
- setDispatchers = (showDialog, closeDialog, showPrompt, closePrompt)=>{
78
- this.showDialog = showDialog;
79
- this.closeDialog = closeDialog;
80
- this.showPrompt = showPrompt;
81
- this.closePrompt = closePrompt;
82
- };
83
- }
84
- const DialogContext = /*#__PURE__*/ createContext(new DialogContextObject());
85
- const DialogHost = ({ context })=>{
86
- const { dialog, setDialogState, prompt, setPromptState } = useDialogHost();
87
- const showDialog = useCallback((dialogContent, title, actionButtons, hideCloseButton)=>{
88
- setDialogState({
89
- actions: actionButtons,
90
- content: dialogContent,
91
- title,
92
- hideCloseButton
93
- });
94
- }, [
95
- setDialogState
96
- ]);
97
- const closeDialog = useCallback(()=>{
98
- setDialogState(void 0);
99
- }, [
100
- setDialogState
101
- ]);
102
- const showPrompt = useCallback((content, promptProps)=>{
103
- setPromptState({
104
- content,
105
- promptProps
106
- });
107
- }, [
108
- setPromptState
109
- ]);
110
- const closePrompt = useCallback(()=>{
111
- setPromptState(void 0);
112
- }, [
113
- setPromptState
114
- ]);
115
- useMemo(()=>{
116
- context.setDispatchers(showDialog, closeDialog, showPrompt, closePrompt);
117
- }, [
118
- closeDialog,
119
- closePrompt,
120
- context,
121
- showDialog,
122
- showPrompt
123
- ]);
124
- return dialog ?? prompt;
125
- };
126
- const ModalProvider = ({ children })=>{
127
- const context = useContext(DialogContext);
128
- return /*#__PURE__*/ jsxs(DialogContext.Provider, {
129
- value: context,
130
- children: [
131
- /*#__PURE__*/ jsx(DialogHost, {
132
- context: context
133
- }),
134
- children
135
- ]
136
- });
137
- };
138
- const useModal = ()=>{
139
- const { closeDialog, closePrompt, showDialog, showPrompt } = useContext(DialogContext);
140
- return {
141
- showDialog,
142
- closeDialog,
143
- showPrompt,
144
- closePrompt
145
- };
146
- };
147
- export { ModalProvider, useModal };