@vuu-ui/vuu-ui-controls 2.1.19-beta.1 → 2.1.19-beta.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.
- package/package.json +12 -13
- package/src/calendar/Calendar.css.js +10 -0
- package/src/calendar/Calendar.js +70 -0
- package/src/calendar/index.js +4 -0
- package/src/calendar/internal/CalendarCarousel.css.js +19 -0
- package/src/calendar/internal/CalendarCarousel.js +73 -0
- package/src/calendar/internal/CalendarContext.js +9 -0
- package/src/calendar/internal/CalendarDay.css.js +116 -0
- package/src/calendar/internal/CalendarDay.js +64 -0
- package/src/calendar/internal/CalendarMonth.css.js +13 -0
- package/src/calendar/internal/CalendarMonth.js +43 -0
- package/src/calendar/internal/CalendarNavigation.css.js +24 -0
- package/src/calendar/internal/CalendarNavigation.js +185 -0
- package/src/calendar/internal/CalendarWeekHeader.css.js +23 -0
- package/src/calendar/internal/CalendarWeekHeader.js +31 -0
- package/src/calendar/internal/useFocusManagement.js +66 -0
- package/src/calendar/internal/utils.js +57 -0
- package/src/calendar/useCalendar.js +116 -0
- package/src/calendar/useCalendarDay.js +74 -0
- package/src/calendar/useSelection.js +202 -0
- package/src/column-picker/ColumnPicker.css.js +8 -0
- package/src/column-picker/ColumnPicker.js +108 -0
- package/src/column-picker/ColumnSearch.css.js +61 -0
- package/src/column-picker/ColumnSearch.js +66 -0
- package/src/column-picker/index.js +2 -0
- package/src/column-picker/moving-window.js +49 -0
- package/src/common-hooks/index.js +3 -0
- package/src/common-hooks/selectionTypes.js +8 -0
- package/src/common-hooks/use-resize-observer.js +122 -0
- package/src/common-hooks/useControlled.js +45 -0
- package/src/context-panel-provider/ContextPanelProvider.js +80 -0
- package/src/cycle-state-button/CycleStateButton.js +30 -0
- package/src/cycle-state-button/index.js +1 -0
- package/src/date-input/DateInput.css.js +195 -0
- package/src/date-input/DateInput.js +210 -0
- package/src/date-input/index.js +1 -0
- package/src/date-picker/DatePicker.js +137 -0
- package/src/date-picker/DatePickerContext.js +20 -0
- package/src/date-picker/DatePickerPanel.css.js +25 -0
- package/src/date-picker/DatePickerPanel.js +124 -0
- package/src/date-picker/index.js +1 -0
- package/src/drag-drop/DragDropProvider.js +123 -0
- package/src/drag-drop/DragDropState.js +25 -0
- package/src/drag-drop/Draggable.css.js +57 -0
- package/src/drag-drop/Draggable.js +77 -0
- package/src/drag-drop/DropIndicator.css.js +11 -0
- package/src/drag-drop/DropIndicator.js +28 -0
- package/src/drag-drop/dragDropTypes.js +3 -0
- package/src/drag-drop/drop-target-utils.js +199 -0
- package/src/drag-drop/index.js +6 -0
- package/src/drag-drop/useAutoScroll.js +53 -0
- package/src/drag-drop/useDragDisplacers.js +126 -0
- package/src/drag-drop/useDragDrop.js +435 -0
- package/src/drag-drop/useDragDropCopy.js +22 -0
- package/src/drag-drop/useDragDropIndicator.js +182 -0
- package/src/drag-drop/useDragDropNaturalMovement.js +205 -0
- package/src/drag-drop/useDropIndicator.js +21 -0
- package/src/drag-drop/useGlobalDragDrop.js +67 -0
- package/src/drag-drop/useTransition.js +11 -0
- package/src/editable/index.js +1 -0
- package/src/editable/useEditableText.js +199 -0
- package/src/editable-label/EditableLabel.css.js +81 -0
- package/src/editable-label/EditableLabel.js +125 -0
- package/src/editable-label/index.js +1 -0
- package/src/expando-input/ExpandoInput.css.js +67 -0
- package/src/expando-input/ExpandoInput.js +40 -0
- package/src/expando-input/index.js +1 -0
- package/src/highlighter/Highlighter.css.js +8 -0
- package/src/highlighter/Highlighter.js +27 -0
- package/src/highlighter/index.js +1 -0
- package/src/hover-overlay/HoverOverlay.js +92 -0
- package/src/icon-button/Icon.css.js +8 -0
- package/src/icon-button/Icon.js +26 -0
- package/src/icon-button/IconButton.css.js +10 -0
- package/src/icon-button/IconButton.js +28 -0
- package/src/icon-button/ToggleIconButton.css.js +47 -0
- package/src/icon-button/ToggleIconButton.js +26 -0
- package/src/icon-button/index.js +3 -0
- package/src/index.js +31 -0
- package/src/instrument-picker/SearchCell.css.js +17 -0
- package/src/instrument-picker/SearchCell.js +29 -0
- package/src/instrument-picker/TablePicker.css.js +23 -0
- package/src/instrument-picker/TablePicker.js +89 -0
- package/src/instrument-picker/index.js +1 -0
- package/src/instrument-picker/moving-window.js +49 -0
- package/src/instrument-picker/useDataSource.js +38 -0
- package/src/instrument-picker/useTablePicker.js +136 -0
- package/src/measured-container/MeasuredContainer.css.js +11 -0
- package/src/measured-container/MeasuredContainer.js +50 -0
- package/src/measured-container/index.js +2 -0
- package/src/measured-container/useMeasuredContainer.js +156 -0
- package/src/modal-provider/ModalProvider.js +147 -0
- package/src/overflow-container/OverflowContainer.css.js +135 -0
- package/src/overflow-container/OverflowContainer.js +87 -0
- package/src/overflow-container/index.js +2 -0
- package/src/overflow-container/overflow-utils.js +211 -0
- package/src/overflow-container/useOverflowContainer.js +108 -0
- package/src/price-ticker/PriceTicker.css.js +32 -0
- package/src/price-ticker/PriceTicker.js +51 -0
- package/src/price-ticker/index.js +1 -0
- package/src/prompt/Prompt.css.js +48 -0
- package/src/prompt/Prompt.js +112 -0
- package/src/sortable-list/SortableList.js +39 -0
- package/src/split-button/SplitButton.css.js +117 -0
- package/src/split-button/SplitButton.js +60 -0
- package/src/split-button/SplitStateButton.css.js +66 -0
- package/src/split-button/SplitStateButton.js +23 -0
- package/src/split-button/index.js +2 -0
- package/src/split-button/useSplitButton.js +61 -0
- package/src/table-search/SearchCell.css.js +20 -0
- package/src/table-search/SearchCell.js +26 -0
- package/src/table-search/TableSearch.css.js +27 -0
- package/src/table-search/TableSearch.js +81 -0
- package/src/table-search/index.js +1 -0
- package/src/table-search/moving-window.js +49 -0
- package/src/table-search/useTableSearch.js +30 -0
- package/src/tabs-next/TabBar.css.js +26 -0
- package/src/tabs-next/TabBar.js +27 -0
- package/src/tabs-next/TabListNext.css.js +36 -0
- package/src/tabs-next/TabListNext.js +94 -0
- package/src/tabs-next/TabNext.css.js +76 -0
- package/src/tabs-next/TabNext.js +91 -0
- package/src/tabs-next/TabNextAction.js +26 -0
- package/src/tabs-next/TabNextContext.js +14 -0
- package/src/tabs-next/TabNextPanel.css.js +17 -0
- package/src/tabs-next/TabNextPanel.js +69 -0
- package/src/tabs-next/TabNextTrigger.css.js +22 -0
- package/src/tabs-next/TabNextTrigger.js +66 -0
- package/src/tabs-next/TabOverflowList.css.js +77 -0
- package/src/tabs-next/TabOverflowList.js +115 -0
- package/src/tabs-next/TabsNext.js +149 -0
- package/src/tabs-next/TabsNextContext.js +28 -0
- package/src/tabs-next/hooks/useCollection.js +80 -0
- package/src/tabs-next/hooks/useFocusOutside.js +23 -0
- package/src/tabs-next/hooks/useOverflow.js +118 -0
- package/src/tabs-next/index.js +7 -0
- package/src/tabstrip/Tab.css.js +148 -0
- package/src/tabstrip/Tab.js +107 -0
- package/src/tabstrip/TabMenu.css.js +8 -0
- package/src/tabstrip/TabMenu.js +48 -0
- package/src/tabstrip/TabMenuOptions.js +14 -0
- package/src/tabstrip/TabsTypes.js +0 -0
- package/src/tabstrip/Tabstrip.css.js +121 -0
- package/src/tabstrip/Tabstrip.js +106 -0
- package/src/tabstrip/ThemeTabstrip.css.js +20 -0
- package/src/tabstrip/index.js +4 -0
- package/src/tabstrip/tabstrip-dom-utils.js +11 -0
- package/src/tabstrip/useAnimatedSelectionThumb.js +68 -0
- package/src/tabstrip/useKeyboardNavigation.js +191 -0
- package/src/tabstrip/useSelection.js +50 -0
- package/src/tabstrip/useTabstrip.js +181 -0
- package/src/time-input/MaskedInput.js +285 -0
- package/src/time-input/TimeInput.css.js +39 -0
- package/src/time-input/TimeInput.js +37 -0
- package/src/time-input/useTimeInput.js +82 -0
- package/src/toolbar/Toolbar.css.js +46 -0
- package/src/toolbar/Toolbar.js +62 -0
- package/src/toolbar/index.js +1 -0
- package/src/toolbar/toolbar-dom-utils.js +11 -0
- package/src/toolbar/useKeyboardNavigation.js +240 -0
- package/src/toolbar/useSelection.js +82 -0
- package/src/toolbar/useToolbar.js +73 -0
- package/src/utils/deprecated-types.js +0 -0
- package/src/utils/escapeRegExp.js +5 -0
- package/src/utils/forwardCallbackProps.js +15 -0
- package/src/utils/index.js +5 -0
- package/src/utils/isOverflowElement.js +2 -0
- package/src/utils/isPlainObject.js +2 -0
- package/src/vuu-date-picker/VuuDatePicker.js +92 -0
- package/src/vuu-date-picker/index.js +1 -0
- package/src/vuu-input/VuuInput.css.js +13 -0
- package/src/vuu-input/VuuInput.js +85 -0
- package/src/vuu-input/index.js +1 -0
- package/src/vuu-time-picker/TimeRangePicker.js +0 -0
- package/src/vuu-time-picker/VuuTimePicker.css.js +14 -0
- package/src/vuu-time-picker/VuuTimePicker.js +26 -0
- package/src/vuu-typeahead-input/VuuTypeaheadInput.css.js +49 -0
- package/src/vuu-typeahead-input/VuuTypeaheadInput.js +46 -0
- package/src/vuu-typeahead-input/index.js +1 -0
- package/src/vuu-typeahead-input/useVuuTypeaheadInput.js +140 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { isValidNumber, useId } from "@vuu-ui/vuu-utils";
|
|
3
|
+
import { Input, Tooltip } from "@salt-ds/core";
|
|
4
|
+
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
5
|
+
import { useWindow } from "@salt-ds/window";
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
import { forwardRef, useCallback } from "react";
|
|
8
|
+
import VuuInput_0 from "./VuuInput.css";
|
|
9
|
+
const classBase = "vuuInput";
|
|
10
|
+
const VuuInput_VuuInput = /*#__PURE__*/ forwardRef(function({ className, commitOnBlur = true, commitWhenCleared = false, errorMessage, id: idProp, onCommit, onKeyDown, type, ...props }, forwardedRef) {
|
|
11
|
+
const targetWindow = useWindow();
|
|
12
|
+
useComponentCssInjection({
|
|
13
|
+
testId: "vuu-input",
|
|
14
|
+
css: VuuInput_0,
|
|
15
|
+
window: targetWindow
|
|
16
|
+
});
|
|
17
|
+
const id = useId(idProp);
|
|
18
|
+
const commitValue = useCallback((evt, value)=>{
|
|
19
|
+
if ("number" === type) {
|
|
20
|
+
const numericValue = parseFloat(value);
|
|
21
|
+
if (isValidNumber(numericValue)) onCommit(evt, numericValue, "text-input");
|
|
22
|
+
else throw Error("Invalid value");
|
|
23
|
+
} else "boolean" === type ? onCommit(evt, Boolean(value), "text-input") : onCommit(evt, value, "text-input");
|
|
24
|
+
}, [
|
|
25
|
+
onCommit,
|
|
26
|
+
type
|
|
27
|
+
]);
|
|
28
|
+
const handleChange = useCallback((evt)=>{
|
|
29
|
+
const value = evt.target.value;
|
|
30
|
+
if ("" === value.trim() && commitWhenCleared) onCommit?.(evt, value);
|
|
31
|
+
props.inputProps?.onChange?.(evt);
|
|
32
|
+
}, [
|
|
33
|
+
commitWhenCleared,
|
|
34
|
+
onCommit,
|
|
35
|
+
props.inputProps
|
|
36
|
+
]);
|
|
37
|
+
const handleKeyDown = useCallback((evt)=>{
|
|
38
|
+
if ("Enter" === evt.key) {
|
|
39
|
+
evt.preventDefault();
|
|
40
|
+
evt.stopPropagation();
|
|
41
|
+
const { value } = evt.target;
|
|
42
|
+
commitValue(evt, value);
|
|
43
|
+
}
|
|
44
|
+
onKeyDown?.(evt);
|
|
45
|
+
}, [
|
|
46
|
+
commitValue,
|
|
47
|
+
onKeyDown
|
|
48
|
+
]);
|
|
49
|
+
const handleBlur = useCallback((evt)=>{
|
|
50
|
+
if (commitOnBlur) {
|
|
51
|
+
const { value } = evt.target;
|
|
52
|
+
commitValue(evt, value);
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
commitOnBlur,
|
|
56
|
+
commitValue
|
|
57
|
+
]);
|
|
58
|
+
const endAdornment = errorMessage ? /*#__PURE__*/ jsx(Tooltip, {
|
|
59
|
+
content: errorMessage,
|
|
60
|
+
status: "error",
|
|
61
|
+
children: /*#__PURE__*/ jsx("span", {
|
|
62
|
+
className: `${classBase}-errorIcon`,
|
|
63
|
+
"data-icon": "error"
|
|
64
|
+
})
|
|
65
|
+
}) : void 0;
|
|
66
|
+
return /*#__PURE__*/ jsx(Fragment, {
|
|
67
|
+
children: /*#__PURE__*/ jsx(Input, {
|
|
68
|
+
...props,
|
|
69
|
+
endAdornment: endAdornment,
|
|
70
|
+
id: id,
|
|
71
|
+
inputProps: {
|
|
72
|
+
autoComplete: "off",
|
|
73
|
+
...props.inputProps,
|
|
74
|
+
onChange: handleChange
|
|
75
|
+
},
|
|
76
|
+
className: clsx(classBase, className, {
|
|
77
|
+
[`${classBase}-error`]: errorMessage
|
|
78
|
+
}),
|
|
79
|
+
onBlur: handleBlur,
|
|
80
|
+
ref: forwardedRef,
|
|
81
|
+
onKeyDown: handleKeyDown
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
export { VuuInput_VuuInput as VuuInput };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./VuuInput.js";
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
3
|
+
import { useWindow } from "@salt-ds/window";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import { TimeInput } from "../time-input/TimeInput.js";
|
|
6
|
+
import VuuTimePicker from "./VuuTimePicker.css";
|
|
7
|
+
const classBase = "vuuTimePicker";
|
|
8
|
+
const VuuTimePicker_VuuTimePicker = ({ className, defaultValue, onChange, onCommit, value, ...htmlAttributes })=>{
|
|
9
|
+
const targetWindow = useWindow();
|
|
10
|
+
useComponentCssInjection({
|
|
11
|
+
testId: "vuu-time-picker",
|
|
12
|
+
css: VuuTimePicker,
|
|
13
|
+
window: targetWindow
|
|
14
|
+
});
|
|
15
|
+
return /*#__PURE__*/ jsx("div", {
|
|
16
|
+
...htmlAttributes,
|
|
17
|
+
className: clsx(classBase, className),
|
|
18
|
+
children: /*#__PURE__*/ jsx(TimeInput, {
|
|
19
|
+
defaultValue: defaultValue,
|
|
20
|
+
onChange: onChange,
|
|
21
|
+
onCommit: onCommit,
|
|
22
|
+
value: value
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export { VuuTimePicker_VuuTimePicker as VuuTimePicker };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const css = `
|
|
2
|
+
.vuuTypeaheadInput {
|
|
3
|
+
& .saltPillInput-activationIndicator {
|
|
4
|
+
display: none;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
& .saltPillInput-endAdornmentContainer {
|
|
8
|
+
padding: 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
& .saltButton {
|
|
12
|
+
--vuuButton-borderColor: transparent;
|
|
13
|
+
width: 24px;
|
|
14
|
+
height: 24px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
& .saltButton:before {
|
|
18
|
+
content: "";
|
|
19
|
+
background-color: var(--salt-separable-secondary-borderColor);
|
|
20
|
+
height: 100%;
|
|
21
|
+
left: calc(-1 * var(--salt-spacing-100));
|
|
22
|
+
width: 1px;
|
|
23
|
+
position: absolute;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
& .saltButton:after {
|
|
27
|
+
--vuu-icon-color: var(--salt-content-primary-foreground);
|
|
28
|
+
--vuu-icon-size: 10px;
|
|
29
|
+
--vuu-icon-transform: rotate(45deg);
|
|
30
|
+
content: "";
|
|
31
|
+
background-color: var(--vuu-icon-color);
|
|
32
|
+
height: var(--vuu-icon-size);
|
|
33
|
+
mask: var(--vuu-svg-triangle-right) center center/var(--vuu-icon-size)
|
|
34
|
+
var(--vuu-icon-size);
|
|
35
|
+
transform: var(--vuu-icon-transform, none);
|
|
36
|
+
width: var(--vuu-icon-size);
|
|
37
|
+
position: absolute;
|
|
38
|
+
top: 3px;
|
|
39
|
+
mask-repeat: no-repeat;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.vuuTypeaheadOption[aria-disabled="true"] {
|
|
44
|
+
color: var(--salt-content-secondary-foreground);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
`;
|
|
49
|
+
export default css;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ComboBox, Option } from "@salt-ds/core";
|
|
3
|
+
import { useComponentCssInjection } from "@salt-ds/styles";
|
|
4
|
+
import { useWindow } from "@salt-ds/window";
|
|
5
|
+
import { NO_DATA_MATCH } from "@vuu-ui/vuu-utils";
|
|
6
|
+
import clsx from "clsx";
|
|
7
|
+
import { useVuuTypeaheadInput } from "./useVuuTypeaheadInput.js";
|
|
8
|
+
import VuuTypeaheadInput from "./VuuTypeaheadInput.css";
|
|
9
|
+
const classBase = "vuuTypeaheadInput";
|
|
10
|
+
const [noMatchingData] = NO_DATA_MATCH;
|
|
11
|
+
const VuuTypeaheadInput_VuuTypeaheadInput = ({ allowFreeInput, className, column, freeTextWarning, highlightFirstSuggestion, inputProps: inputPropsProp, minCharacterCountToTriggerSuggestions, onCommit, selectOnTab, table })=>{
|
|
12
|
+
const targetWindow = useWindow();
|
|
13
|
+
useComponentCssInjection({
|
|
14
|
+
testId: "vuu-typeahead-input",
|
|
15
|
+
css: VuuTypeaheadInput,
|
|
16
|
+
window: targetWindow
|
|
17
|
+
});
|
|
18
|
+
const { inputProps, noFreeText, onChange, onKeyDown, onOpenChange, onSelectionChange, open, ref, typeaheadValues, value } = useVuuTypeaheadInput({
|
|
19
|
+
allowFreeInput,
|
|
20
|
+
column,
|
|
21
|
+
freeTextWarning,
|
|
22
|
+
highlightFirstSuggestion,
|
|
23
|
+
inputProps: inputPropsProp,
|
|
24
|
+
minCharacterCountToTriggerSuggestions,
|
|
25
|
+
onCommit,
|
|
26
|
+
table
|
|
27
|
+
});
|
|
28
|
+
return /*#__PURE__*/ jsx(ComboBox, {
|
|
29
|
+
className: clsx(classBase, className),
|
|
30
|
+
inputProps: inputProps,
|
|
31
|
+
onChange: onChange,
|
|
32
|
+
onKeyDown: onKeyDown,
|
|
33
|
+
onOpenChange: onOpenChange,
|
|
34
|
+
onSelectionChange: onSelectionChange,
|
|
35
|
+
open: open,
|
|
36
|
+
ref: ref,
|
|
37
|
+
selectOnTab: selectOnTab,
|
|
38
|
+
value: value,
|
|
39
|
+
children: typeaheadValues.map((state)=>/*#__PURE__*/ jsx(Option, {
|
|
40
|
+
className: "vuuTypeaheadOption",
|
|
41
|
+
value: state,
|
|
42
|
+
disabled: state === noMatchingData || state === noFreeText
|
|
43
|
+
}, state))
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
export { VuuTypeaheadInput_VuuTypeaheadInput as VuuTypeaheadInput };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./VuuTypeaheadInput.js";
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { useTypeaheadSuggestions } from "@vuu-ui/vuu-data-react";
|
|
2
|
+
import { NO_DATA_MATCH, dispatchKeyboardEvent, getVuuTable, useStateRef } from "@vuu-ui/vuu-utils";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
const meetsMinTextLengthThreshold = (value, minLength)=>value.length >= minLength;
|
|
5
|
+
const defaultFreeTextWarning = "Please select a value from the list of suggestions. If no suggestions match your text, then the value is not valid. If you believe this should be a valid value, please reach out to the support team";
|
|
6
|
+
const useVuuTypeaheadInput = ({ allowFreeInput = true, column, freeTextWarning, highlightFirstSuggestion = true, inputProps: inputPropsProp, minCharacterCountToTriggerSuggestions = 1, onCommit, table })=>{
|
|
7
|
+
const NO_FREE_TEXT = useMemo(()=>[
|
|
8
|
+
freeTextWarning ?? defaultFreeTextWarning
|
|
9
|
+
], [
|
|
10
|
+
freeTextWarning
|
|
11
|
+
]);
|
|
12
|
+
const [valueRef, setValue] = useStateRef("");
|
|
13
|
+
const [open, setOpen] = useState(false);
|
|
14
|
+
const inputRef = useRef(null);
|
|
15
|
+
const rootRef = useRef(null);
|
|
16
|
+
const [typeaheadValues, setTypeaheadValues] = useState([]);
|
|
17
|
+
const getSuggestions = useTypeaheadSuggestions();
|
|
18
|
+
const pendingListFocusRef = useRef(false);
|
|
19
|
+
const { current: value } = valueRef;
|
|
20
|
+
useMemo(()=>{
|
|
21
|
+
if (inputPropsProp?.value !== void 0 && inputPropsProp?.value !== valueRef.current) setValue(`${inputPropsProp.value}`);
|
|
22
|
+
}, [
|
|
23
|
+
inputPropsProp?.value,
|
|
24
|
+
setValue,
|
|
25
|
+
valueRef
|
|
26
|
+
]);
|
|
27
|
+
const commitTimeout = useRef(null);
|
|
28
|
+
const handleKeyDown = useCallback((evt)=>{
|
|
29
|
+
const { current: value } = valueRef;
|
|
30
|
+
if ("Enter" === evt.key && "" !== value) if (allowFreeInput) commitTimeout.current = setTimeout(()=>{
|
|
31
|
+
onCommit?.(evt, value, "text-input");
|
|
32
|
+
setOpen(false);
|
|
33
|
+
commitTimeout.current = null;
|
|
34
|
+
}, 200);
|
|
35
|
+
else setTypeaheadValues(NO_FREE_TEXT);
|
|
36
|
+
else if ("Enter" === evt.key && "" === value) console.log("ENTER no value");
|
|
37
|
+
}, [
|
|
38
|
+
NO_FREE_TEXT,
|
|
39
|
+
allowFreeInput,
|
|
40
|
+
onCommit,
|
|
41
|
+
valueRef
|
|
42
|
+
]);
|
|
43
|
+
const callbackRef = useCallback((el)=>{
|
|
44
|
+
rootRef.current = el;
|
|
45
|
+
const input = el?.querySelector("input") ?? null;
|
|
46
|
+
inputRef.current = input;
|
|
47
|
+
}, []);
|
|
48
|
+
const refreshSuggestions = useCallback(()=>{
|
|
49
|
+
if (table) {
|
|
50
|
+
const vuuTable = getVuuTable(table);
|
|
51
|
+
if (meetsMinTextLengthThreshold(value, minCharacterCountToTriggerSuggestions)) {
|
|
52
|
+
const params = value ? [
|
|
53
|
+
vuuTable,
|
|
54
|
+
column,
|
|
55
|
+
value
|
|
56
|
+
] : [
|
|
57
|
+
vuuTable,
|
|
58
|
+
column
|
|
59
|
+
];
|
|
60
|
+
getSuggestions(params).then((suggestions)=>{
|
|
61
|
+
if (false === suggestions) setTypeaheadValues([]);
|
|
62
|
+
else if (0 === suggestions.length && value) setTypeaheadValues((values)=>values === NO_FREE_TEXT ? NO_FREE_TEXT : NO_DATA_MATCH);
|
|
63
|
+
else {
|
|
64
|
+
setTypeaheadValues(suggestions);
|
|
65
|
+
if (pendingListFocusRef.current && inputRef.current) setTimeout(()=>{
|
|
66
|
+
if (inputRef.current) dispatchKeyboardEvent(inputRef.current, "keydown", "ArrowDown");
|
|
67
|
+
}, 60);
|
|
68
|
+
}
|
|
69
|
+
pendingListFocusRef.current = false;
|
|
70
|
+
}).catch((err)=>{
|
|
71
|
+
console.error("Error getting suggestions", err);
|
|
72
|
+
});
|
|
73
|
+
} else setTypeaheadValues([]);
|
|
74
|
+
}
|
|
75
|
+
}, [
|
|
76
|
+
NO_FREE_TEXT,
|
|
77
|
+
column,
|
|
78
|
+
getSuggestions,
|
|
79
|
+
minCharacterCountToTriggerSuggestions,
|
|
80
|
+
table,
|
|
81
|
+
value
|
|
82
|
+
]);
|
|
83
|
+
useEffect(()=>{
|
|
84
|
+
refreshSuggestions();
|
|
85
|
+
}, [
|
|
86
|
+
refreshSuggestions
|
|
87
|
+
]);
|
|
88
|
+
const handleChange = useCallback((evt)=>{
|
|
89
|
+
const { value: newValue } = evt.target;
|
|
90
|
+
const { current: value } = valueRef;
|
|
91
|
+
if ("" === value && newValue) {
|
|
92
|
+
setOpen(true);
|
|
93
|
+
const input = rootRef.current?.querySelector("input");
|
|
94
|
+
if (input && highlightFirstSuggestion) pendingListFocusRef.current = true;
|
|
95
|
+
} else if ("" === newValue && value) onCommit(evt, "");
|
|
96
|
+
setValue(newValue);
|
|
97
|
+
}, [
|
|
98
|
+
highlightFirstSuggestion,
|
|
99
|
+
onCommit,
|
|
100
|
+
setValue,
|
|
101
|
+
valueRef
|
|
102
|
+
]);
|
|
103
|
+
const handleSelectionChange = (evt, [newSelected])=>{
|
|
104
|
+
if (commitTimeout.current) {
|
|
105
|
+
clearTimeout(commitTimeout.current);
|
|
106
|
+
commitTimeout.current = null;
|
|
107
|
+
}
|
|
108
|
+
setValue(newSelected);
|
|
109
|
+
onCommit(evt, newSelected, "typeahead-suggestion");
|
|
110
|
+
};
|
|
111
|
+
const handleOpenChange = (newOpen)=>{
|
|
112
|
+
newOpen && valueRef.current, setOpen(newOpen);
|
|
113
|
+
};
|
|
114
|
+
const handleInputFocus = useCallback((e)=>{
|
|
115
|
+
inputPropsProp?.onFocus?.(e);
|
|
116
|
+
refreshSuggestions();
|
|
117
|
+
}, [
|
|
118
|
+
inputPropsProp,
|
|
119
|
+
refreshSuggestions
|
|
120
|
+
]);
|
|
121
|
+
const inputProps = {
|
|
122
|
+
...inputPropsProp,
|
|
123
|
+
autoComplete: "off",
|
|
124
|
+
onFocus: handleInputFocus
|
|
125
|
+
};
|
|
126
|
+
const [noFreeText] = NO_FREE_TEXT;
|
|
127
|
+
return {
|
|
128
|
+
inputProps,
|
|
129
|
+
noFreeText,
|
|
130
|
+
onChange: handleChange,
|
|
131
|
+
onKeyDown: handleKeyDown,
|
|
132
|
+
onOpenChange: handleOpenChange,
|
|
133
|
+
onSelectionChange: handleSelectionChange,
|
|
134
|
+
open,
|
|
135
|
+
ref: callbackRef,
|
|
136
|
+
typeaheadValues,
|
|
137
|
+
value: valueRef.current
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
export { useVuuTypeaheadInput };
|