@koine/react 1.0.13 → 1.0.16
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/Details/Details.d.ts +6 -12
- package/hooks/useScrollPosition.d.ts +1 -1
- package/node/Alert/Alert.js +14 -0
- package/node/Alert/index.js +4 -0
- package/node/Animations/Reveal.js +21 -0
- package/node/Animations/Underline.js +8 -0
- package/node/Animations/index.js +6 -0
- package/node/Animations/useReveal.js +75 -0
- package/node/Autocomplete/AutocompleteDownshift.js +161 -0
- package/node/Autocomplete/AutocompleteDownshiftMultiselect.js +356 -0
- package/node/Autocomplete/AutocompleteMui.js +180 -0
- package/node/Autocomplete/AutocompleteReach.js +115 -0
- package/node/Autocomplete/components.js +37 -0
- package/node/Autocomplete/helpers.js +32 -0
- package/node/Autocomplete/index.js +7 -0
- package/node/Bg/BgColor.js +25 -0
- package/node/Bg/BgPhoto.js +20 -0
- package/node/Bg/BgSvg.js +16 -0
- package/node/Bg/index.js +6 -0
- package/node/Breadcrumbs/Breadcrumbs.js +31 -0
- package/node/Breadcrumbs/index.js +4 -0
- package/node/Buttons/Button.js +17 -0
- package/node/Buttons/ButtonComposite.js +32 -0
- package/node/Buttons/ButtonFab.js +9 -0
- package/node/Buttons/ButtonLink.js +15 -0
- package/node/Buttons/IconButton.js +10 -0
- package/node/Buttons/index.js +8 -0
- package/node/Calendar/CalendarDaygridCell.js +61 -0
- package/node/Calendar/CalendarDaygridNav.js +28 -0
- package/node/Calendar/CalendarDaygridTable.js +61 -0
- package/node/Calendar/CalendarLegend.js +20 -0
- package/node/Calendar/calendar-api-google.js +131 -0
- package/node/Calendar/index.js +9 -0
- package/node/Calendar/types.js +2 -0
- package/node/Calendar/useCalendar.js +187 -0
- package/node/Calendar/utils.js +215 -0
- package/node/Carousel/Carousel.js +381 -0
- package/node/Carousel/CarouselCss.js +27 -0
- package/node/Carousel/index.js +4 -0
- package/node/Collapsable/Collapsable.js +4 -0
- package/node/Collapsable/CollapsableReach.js +253 -0
- package/node/Collapsable/index.js +5 -0
- package/node/Debug/Debug.js +13 -0
- package/node/Debug/index.js +4 -0
- package/node/Details/Details.js +67 -0
- package/node/Details/index.js +4 -0
- package/node/Dialog/DialogMui.js +83 -0
- package/node/Dialog/css/bare.js +24 -0
- package/node/Dialog/index.js +5 -0
- package/node/Dialog/m/bare.js +55 -0
- package/node/Dialog/m/basic.js +35 -0
- package/node/Dialog/m/index.js +8 -0
- package/node/Dialog/sc/bare.js +46 -0
- package/node/Dialog/sc/framer.js +19 -0
- package/node/Dialog/sc/framerMaterial.js +19 -0
- package/node/Dialog/sc/material.js +24 -0
- package/node/Dialog/tw/bare.js +45 -0
- package/node/Dialog/tw/elegant.js +23 -0
- package/node/Dialog/tw/framer.js +19 -0
- package/node/Dialog/tw/framerMaterial.js +19 -0
- package/node/Dialog/tw/material.js +23 -0
- package/node/Editor/Editor--tiptap.js +31 -0
- package/node/Editor/components.js +15 -0
- package/node/Editor/index.js +4 -0
- package/node/Favicon/FaviconTags.js +19 -0
- package/node/Favicon/index.js +4 -0
- package/node/Form/Form.js +65 -0
- package/node/Form/index.js +4 -0
- package/node/Form/sc/bare.js +23 -0
- package/node/Forms/Checkbox/Checkbox.js +21 -0
- package/node/Forms/Checkbox/index.js +4 -0
- package/node/Forms/Feedback/Feedback.js +13 -0
- package/node/Forms/Feedback/index.js +4 -0
- package/node/Forms/Field/Field.js +52 -0
- package/node/Forms/Field/FieldControl.js +51 -0
- package/node/Forms/Field/FieldHint.js +7 -0
- package/node/Forms/Field/index.js +5 -0
- package/node/Forms/Input/Input.js +20 -0
- package/node/Forms/Input/index.js +4 -0
- package/node/Forms/InputGroup/InputGroup.js +19 -0
- package/node/Forms/InputGroup/index.js +4 -0
- package/node/Forms/Label/Label.js +9 -0
- package/node/Forms/Label/index.js +4 -0
- package/node/Forms/Password/Password.js +20 -0
- package/node/Forms/Password/index.js +4 -0
- package/node/Forms/Radio/Radio.js +28 -0
- package/node/Forms/Radio/index.js +4 -0
- package/node/Forms/Switch/Switch.js +23 -0
- package/node/Forms/Switch/index.js +4 -0
- package/node/Forms/Textarea/Textarea.js +15 -0
- package/node/Forms/Textarea/TextareaRich.js +31 -0
- package/node/Forms/Textarea/index.js +5 -0
- package/node/Forms/Toggle/Toggle.js +37 -0
- package/node/Forms/Toggle/index.js +4 -0
- package/node/Forms/Toggle/useToggle.js +149 -0
- package/node/Forms/antispam.js +61 -0
- package/node/Forms/helpers.js +52 -0
- package/node/Forms/index.js +19 -0
- package/node/Forms/styles.js +32 -0
- package/node/Gauge/Gauge.js +106 -0
- package/node/Grid/Grid.js +56 -0
- package/node/Grid/index.js +4 -0
- package/node/Hamburger/Hamburger.js +56 -0
- package/node/Hamburger/index.js +4 -0
- package/node/Header/index.js +4 -0
- package/node/Header/useHeader.js +34 -0
- package/node/Hidden/Hidden.js +13 -0
- package/node/Hidden/index.js +4 -0
- package/node/Img/index.js +4 -0
- package/node/Img/sc/bare.js +42 -0
- package/node/Img/types.js +2 -0
- package/node/Link/Link.js +7 -0
- package/node/Link/LinkBlank.js +21 -0
- package/node/Link/index.js +5 -0
- package/node/Menu/Menu.js +7 -0
- package/node/Menu/index.js +4 -0
- package/node/MenuItem/MenuItem.js +7 -0
- package/node/MenuItem/index.js +4 -0
- package/node/Meta/Meta.js +9 -0
- package/node/Meta/index.js +4 -0
- package/node/NoJs/NoJs.js +10 -0
- package/node/NoJs/index.js +4 -0
- package/node/Pagination/PaginationNav.js +65 -0
- package/node/Pagination/PaginationResults.js +15 -0
- package/node/Pagination/index.js +5 -0
- package/node/Pill/Pill.js +10 -0
- package/node/Pill/index.js +4 -0
- package/node/Progress/ProgressCircular.js +19 -0
- package/node/Progress/ProgressLinear.js +28 -0
- package/node/Progress/ProgressOverlay.js +28 -0
- package/node/Progress/index.js +6 -0
- package/node/Rating/Rating.js +76 -0
- package/node/Rating/index.js +57 -0
- package/node/Select/SelectDownshift.js +41 -0
- package/node/Select/components.js +15 -0
- package/node/Select/index.js +7 -0
- package/node/Sidebar/Sidebar.js +27 -0
- package/node/Sidebar/index.js +4 -0
- package/node/Spacing/Spacing.js +49 -0
- package/node/Spacing/index.js +4 -0
- package/node/Sticky/Sticky.js +222 -0
- package/node/Sticky/StickyCss.js +10 -0
- package/node/Sticky/index.js +4 -0
- package/node/Tabs/TabsMui.js +49 -0
- package/node/Tabs/index.js +4 -0
- package/node/Tabs/sc/bare.js +87 -0
- package/node/Tabs/tw/bare.js +20 -0
- package/node/Tabs/tw/material.js +21 -0
- package/node/Tabs/useTabs.js +48 -0
- package/node/Typography/CopyPasteVisible.js +7 -0
- package/node/Typography/Native.js +17 -0
- package/node/Typography/ReadMore.js +47 -0
- package/node/Typography/TextLoop.js +51 -0
- package/node/Typography/TypeStairs.js +53 -0
- package/node/Typography/index.js +8 -0
- package/node/css/index.js +36 -0
- package/node/helpers/classed.js +72 -0
- package/node/helpers/extend-component.js +16 -0
- package/node/helpers/index.js +5 -0
- package/node/hooks/index.js +18 -0
- package/node/hooks/types.js +2 -0
- package/node/hooks/useAsyncFn.js +40 -0
- package/node/hooks/useDateLocale.js +42 -0
- package/node/hooks/useEffectOnce.js +12 -0
- package/node/hooks/useFirstMountState.js +16 -0
- package/node/hooks/useFocus.js +15 -0
- package/node/hooks/useId.js +12 -0
- package/node/hooks/useIsomorphicLayoutEffect.js +11 -0
- package/node/hooks/useMount.js +13 -0
- package/node/hooks/useMountedState.js +19 -0
- package/node/hooks/usePrevious.js +12 -0
- package/node/hooks/useScrollPosition.js +84 -0
- package/node/hooks/useScrollTo.js +25 -0
- package/node/hooks/useTraceUpdate.js +25 -0
- package/node/hooks/useUpdateEffect.js +18 -0
- package/node/hooks/useWindowSize.js +17 -0
- package/node/index.js +8 -0
- package/node/m/MotionProvider.js +43 -0
- package/node/m/index.js +9 -0
- package/node/m/lite.js +4 -0
- package/node/m/max.js +4 -0
- package/node/sc/index.js +37 -0
- package/node/scm/index.js +36 -0
- package/node/shared/index.js +11 -0
- package/node/styles/Body.js +16 -0
- package/node/styles/Global.js +21 -0
- package/node/styles/index.js +10 -0
- package/node/styles/media.js +160 -0
- package/node/styles/spacing.js +52 -0
- package/node/styles/styled.js +17 -0
- package/node/styles/theme--vanilla.js +61 -0
- package/node/styles/theme.js +45 -0
- package/node/tw/index.js +36 -0
- package/node/twm/index.js +36 -0
- package/node/types.js +2 -0
- package/package.json +2 -1
- package/styles/theme--vanilla.d.ts +1 -1
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Autocomplete = void 0;
|
|
4
|
+
// TODO: remove, just use mui version...
|
|
5
|
+
exports.Autocomplete = null;
|
|
6
|
+
// import {
|
|
7
|
+
// forwardRef,
|
|
8
|
+
// useCallback,
|
|
9
|
+
// useEffect,
|
|
10
|
+
// useRef,
|
|
11
|
+
// useState,
|
|
12
|
+
// ForwardedRef,
|
|
13
|
+
// ReactNode,
|
|
14
|
+
// ComponentPropsWithRef,
|
|
15
|
+
// CSSProperties,
|
|
16
|
+
// } from "react";
|
|
17
|
+
// import { SetRequired } from "@koine/utils";
|
|
18
|
+
// import {
|
|
19
|
+
// useCombobox,
|
|
20
|
+
// useMultipleSelection,
|
|
21
|
+
// UseMultipleSelectionProps,
|
|
22
|
+
// UseMultipleSelectionStateChange,
|
|
23
|
+
// UseMultipleSelectionReturnValue,
|
|
24
|
+
// } from "downshift";
|
|
25
|
+
// import { usePopper } from "react-popper"; // imports from downshift demo
|
|
26
|
+
// // import { useDeepCompareEffect } from "react-use"; // imports from downshift demo
|
|
27
|
+
// import type { Option } from "../types";
|
|
28
|
+
// import {
|
|
29
|
+
// normaliseOptions,
|
|
30
|
+
// defaultOptionsFilterFn,
|
|
31
|
+
// triggerOnChange,
|
|
32
|
+
// } from "../Forms/helpers";
|
|
33
|
+
// import {
|
|
34
|
+
// AutocompleteRoot,
|
|
35
|
+
// AutocompleteLabel,
|
|
36
|
+
// AutocompleteWrap,
|
|
37
|
+
// AutocompleteInner,
|
|
38
|
+
// AutocompleteItem,
|
|
39
|
+
// AutocompleteItemLabel,
|
|
40
|
+
// AutocompleteItemRemove,
|
|
41
|
+
// AutocompleteInputWrap,
|
|
42
|
+
// AutocompleteInput,
|
|
43
|
+
// AutocompleteInputArrow,
|
|
44
|
+
// AutocompleteMenu,
|
|
45
|
+
// AutocompleteMenuItem,
|
|
46
|
+
// } from "./components";
|
|
47
|
+
// const USE_POPPER = false;
|
|
48
|
+
// export type AutocompleteItem = Option;
|
|
49
|
+
// export type AutocompleteValue = AutocompleteItem[];
|
|
50
|
+
// export type AutocompleteProps = SetRequired<
|
|
51
|
+
// Omit<ComponentPropsWithRef<"input">, "defaultValue" | "onSelect">,
|
|
52
|
+
// "onChange" | "name"
|
|
53
|
+
// > & {
|
|
54
|
+
// selectedItems: UseMultipleSelectionReturnValue<AutocompleteItem>["selectedItems"];
|
|
55
|
+
// onSelectedItemsChange: UseMultipleSelectionProps<AutocompleteItem>["onSelectedItemsChange"];
|
|
56
|
+
// onCreateItem: (item?: AutocompleteItem) => any;
|
|
57
|
+
// creatable?: boolean;
|
|
58
|
+
// onSelect?: (value?: AutocompleteValue) => any;
|
|
59
|
+
// options?: AutocompleteItem[];
|
|
60
|
+
// loadOptions?: (query?: string) => Promise<AutocompleteItem[]>;
|
|
61
|
+
// label?: string | ReactNode;
|
|
62
|
+
// defaultValue?: AutocompleteValue | string[];
|
|
63
|
+
// className?: string;
|
|
64
|
+
// style?: CSSProperties;
|
|
65
|
+
// $ref?: ForwardedRef<HTMLInputElement>;
|
|
66
|
+
// };
|
|
67
|
+
// /**
|
|
68
|
+
// * @see https://www.downshift-js.com/use-multiple-selection
|
|
69
|
+
// * @see https://codesandbox.io/s/y34o5l3p61?file=/src/hooks/useMultipleSelection/combobox.js
|
|
70
|
+
// * @see https://codesandbox.io/s/y34o5l3p61?file=/src/downshift/ordered-examples/05-multi-create.js
|
|
71
|
+
// */
|
|
72
|
+
// export const _Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
|
73
|
+
// function _Autocomplete(
|
|
74
|
+
// {
|
|
75
|
+
// selectedItems,
|
|
76
|
+
// onSelectedItemsChange,
|
|
77
|
+
// onCreateItem,
|
|
78
|
+
// creatable,
|
|
79
|
+
// onSelect,
|
|
80
|
+
// options = [],
|
|
81
|
+
// label,
|
|
82
|
+
// loadOptions,
|
|
83
|
+
// $ref,
|
|
84
|
+
// className,
|
|
85
|
+
// style,
|
|
86
|
+
// ...props
|
|
87
|
+
// },
|
|
88
|
+
// ref
|
|
89
|
+
// ) {
|
|
90
|
+
// options = normaliseOptions(options);
|
|
91
|
+
// const [isCreating, setIsCreating] = useState(false);
|
|
92
|
+
// const [filteredOptions, setFilteredOptions] = useState(options);
|
|
93
|
+
// const disclosureRef = useRef(null);
|
|
94
|
+
// const popoverRef = useRef(null);
|
|
95
|
+
// const { styles, attributes } = USE_POPPER
|
|
96
|
+
// ? usePopper(disclosureRef.current, popoverRef.current, {
|
|
97
|
+
// placement: "bottom-start",
|
|
98
|
+
// })
|
|
99
|
+
// : { styles: {}, attributes: {} };
|
|
100
|
+
// const {
|
|
101
|
+
// getSelectedItemProps,
|
|
102
|
+
// getDropdownProps,
|
|
103
|
+
// addSelectedItem,
|
|
104
|
+
// removeSelectedItem,
|
|
105
|
+
// // selectedItems,
|
|
106
|
+
// activeIndex,
|
|
107
|
+
// } = useMultipleSelection<AutocompleteItem>({
|
|
108
|
+
// selectedItems,
|
|
109
|
+
// onSelectedItemsChange,
|
|
110
|
+
// // onSelectedItemsChange: ({ selectedItems = [] }) => {
|
|
111
|
+
// // triggerChange(selectedItems);
|
|
112
|
+
// // },
|
|
113
|
+
// // initialSelectedItems: normaliseOptions(defaultValue),
|
|
114
|
+
// stateReducer: (_, actionAndChanges) => {
|
|
115
|
+
// const { type, changes } = actionAndChanges;
|
|
116
|
+
// switch (type) {
|
|
117
|
+
// case useMultipleSelection.stateChangeTypes.FunctionRemoveSelectedItem:
|
|
118
|
+
// return {
|
|
119
|
+
// ...changes,
|
|
120
|
+
// activeIndex: undefined,
|
|
121
|
+
// };
|
|
122
|
+
// default:
|
|
123
|
+
// return changes;
|
|
124
|
+
// }
|
|
125
|
+
// },
|
|
126
|
+
// });
|
|
127
|
+
// const selectedItemsValues = selectedItems.map((item) => item.value);
|
|
128
|
+
// const {
|
|
129
|
+
// isOpen,
|
|
130
|
+
// getToggleButtonProps,
|
|
131
|
+
// getLabelProps,
|
|
132
|
+
// getMenuProps,
|
|
133
|
+
// getInputProps,
|
|
134
|
+
// getComboboxProps,
|
|
135
|
+
// highlightedIndex,
|
|
136
|
+
// getItemProps,
|
|
137
|
+
// openMenu,
|
|
138
|
+
// selectItem,
|
|
139
|
+
// setHighlightedIndex,
|
|
140
|
+
// inputValue,
|
|
141
|
+
// } = useCombobox<null | AutocompleteItem>({
|
|
142
|
+
// selectedItem: null,
|
|
143
|
+
// items: filteredOptions,
|
|
144
|
+
// onInputValueChange: ({ inputValue }) => {
|
|
145
|
+
// // perhaps allows the optionsFilterFn as prop
|
|
146
|
+
// const filteredItems = defaultOptionsFilterFn(options, inputValue);
|
|
147
|
+
// if (creatable && isCreating && filteredItems.length > 0) {
|
|
148
|
+
// setIsCreating(false);
|
|
149
|
+
// }
|
|
150
|
+
// setFilteredOptions(filteredItems);
|
|
151
|
+
// },
|
|
152
|
+
// stateReducer: (state, actionAndChanges) => {
|
|
153
|
+
// const { changes, type } = actionAndChanges;
|
|
154
|
+
// switch (type) {
|
|
155
|
+
// case useCombobox.stateChangeTypes.InputBlur:
|
|
156
|
+
// return {
|
|
157
|
+
// ...changes,
|
|
158
|
+
// highlightedIndex: state.highlightedIndex,
|
|
159
|
+
// // clear input on blur to avoid have "pending" uncompleted behaviours
|
|
160
|
+
// inputValue: "",
|
|
161
|
+
// };
|
|
162
|
+
// case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
163
|
+
// case useCombobox.stateChangeTypes.ItemClick:
|
|
164
|
+
// return {
|
|
165
|
+
// ...changes,
|
|
166
|
+
// highlightedIndex: state.highlightedIndex,
|
|
167
|
+
// isOpen: true,
|
|
168
|
+
// inputValue: "",
|
|
169
|
+
// };
|
|
170
|
+
// default:
|
|
171
|
+
// return changes;
|
|
172
|
+
// }
|
|
173
|
+
// },
|
|
174
|
+
// onStateChange: ({ type, selectedItem }) => {
|
|
175
|
+
// switch (type) {
|
|
176
|
+
// case useCombobox.stateChangeTypes.InputKeyDownEnter:
|
|
177
|
+
// case useCombobox.stateChangeTypes.ItemClick:
|
|
178
|
+
// if (selectedItem) {
|
|
179
|
+
// if (selectedItemsValues.includes(selectedItem.value)) {
|
|
180
|
+
// removeSelectedItem(selectedItem);
|
|
181
|
+
// } else {
|
|
182
|
+
// if (creatable && onCreateItem) {
|
|
183
|
+
// onCreateItem(selectedItem);
|
|
184
|
+
// }
|
|
185
|
+
// addSelectedItem(selectedItem);
|
|
186
|
+
// if (isCreating) {
|
|
187
|
+
// setIsCreating(false);
|
|
188
|
+
// setFilteredOptions(options);
|
|
189
|
+
// }
|
|
190
|
+
// }
|
|
191
|
+
// selectItem(null);
|
|
192
|
+
// }
|
|
193
|
+
// break;
|
|
194
|
+
// default:
|
|
195
|
+
// break;
|
|
196
|
+
// }
|
|
197
|
+
// },
|
|
198
|
+
// });
|
|
199
|
+
// useEffect(() => {
|
|
200
|
+
// if (
|
|
201
|
+
// creatable &&
|
|
202
|
+
// filteredOptions.length === 0 &&
|
|
203
|
+
// activeIndex === -1 &&
|
|
204
|
+
// inputValue.length > 0
|
|
205
|
+
// ) {
|
|
206
|
+
// setIsCreating(true);
|
|
207
|
+
// setFilteredOptions(normaliseOptions([inputValue]));
|
|
208
|
+
// setHighlightedIndex(0);
|
|
209
|
+
// }
|
|
210
|
+
// }, [
|
|
211
|
+
// creatable,
|
|
212
|
+
// filteredOptions,
|
|
213
|
+
// setIsCreating,
|
|
214
|
+
// setHighlightedIndex,
|
|
215
|
+
// inputValue,
|
|
216
|
+
// activeIndex,
|
|
217
|
+
// ]);
|
|
218
|
+
// // useEffect(() => {
|
|
219
|
+
// // setSelectedItems(normaliseOptions(defaultValue));
|
|
220
|
+
// // }, [defaultValue]);
|
|
221
|
+
// // useDeepCompareEffect(() => {
|
|
222
|
+
// // setFilteredOptions(options);
|
|
223
|
+
// // }, [options]);
|
|
224
|
+
// // useDeepCompareEffect(() => {
|
|
225
|
+
// // triggerChange(values);
|
|
226
|
+
// // }, [values]);
|
|
227
|
+
// return (
|
|
228
|
+
// <AutocompleteRoot>
|
|
229
|
+
// {label && (
|
|
230
|
+
// <AutocompleteLabel {...getLabelProps()}>{label}</AutocompleteLabel>
|
|
231
|
+
// )}
|
|
232
|
+
// <AutocompleteWrap
|
|
233
|
+
// {...getComboboxProps({
|
|
234
|
+
// ref: disclosureRef,
|
|
235
|
+
// })}
|
|
236
|
+
// >
|
|
237
|
+
// <AutocompleteInner>
|
|
238
|
+
// {selectedItems.map((selectedItem, index) => (
|
|
239
|
+
// <AutocompleteItem
|
|
240
|
+
// key={`selected-item-${index}`}
|
|
241
|
+
// {...getSelectedItemProps({ selectedItem, index })}
|
|
242
|
+
// >
|
|
243
|
+
// <AutocompleteItemLabel>
|
|
244
|
+
// {selectedItem?.label || selectedItem}
|
|
245
|
+
// </AutocompleteItemLabel>
|
|
246
|
+
// <AutocompleteItemRemove
|
|
247
|
+
// onClick={(e) => {
|
|
248
|
+
// e.stopPropagation();
|
|
249
|
+
// removeSelectedItem(selectedItem);
|
|
250
|
+
// }}
|
|
251
|
+
// >
|
|
252
|
+
// ✕
|
|
253
|
+
// </AutocompleteItemRemove>
|
|
254
|
+
// </AutocompleteItem>
|
|
255
|
+
// ))}
|
|
256
|
+
// <AutocompleteInputWrap>
|
|
257
|
+
// <AutocompleteInput
|
|
258
|
+
// {...getInputProps({
|
|
259
|
+
// ...getDropdownProps({
|
|
260
|
+
// // this option used in the official example prevents the
|
|
261
|
+
// // backspace key to behave correctly
|
|
262
|
+
// // preventKeyAction: isOpen,
|
|
263
|
+
// onClick: isOpen ? () => {} : openMenu,
|
|
264
|
+
// onFocus: isOpen ? () => {} : openMenu,
|
|
265
|
+
// ref: $ref || ref,
|
|
266
|
+
// // ref: disclosureRef,
|
|
267
|
+
// }),
|
|
268
|
+
// // ref: $ref || ref,
|
|
269
|
+
// })}
|
|
270
|
+
// {...props}
|
|
271
|
+
// />
|
|
272
|
+
// </AutocompleteInputWrap>
|
|
273
|
+
// </AutocompleteInner>
|
|
274
|
+
// {!!filteredOptions.length && (
|
|
275
|
+
// <AutocompleteInputArrow
|
|
276
|
+
// {...getToggleButtonProps()}
|
|
277
|
+
// aria-label={"toggle menu"}
|
|
278
|
+
// isOpen={isOpen}
|
|
279
|
+
// />
|
|
280
|
+
// )}
|
|
281
|
+
// </AutocompleteWrap>
|
|
282
|
+
// <AutocompleteMenu
|
|
283
|
+
// style={styles.popper}
|
|
284
|
+
// {...attributes.popper}
|
|
285
|
+
// {...getMenuProps({ ref: popoverRef })}
|
|
286
|
+
// >
|
|
287
|
+
// {isOpen &&
|
|
288
|
+
// filteredOptions.map((item, index) => (
|
|
289
|
+
// <AutocompleteMenuItem
|
|
290
|
+
// $active={highlightedIndex === index}
|
|
291
|
+
// key={`${item.value}${index}`}
|
|
292
|
+
// {...getItemProps({ item, index })}
|
|
293
|
+
// >
|
|
294
|
+
// {isCreating ? (
|
|
295
|
+
// <>
|
|
296
|
+
// <span>+</span> <strong>{item.label}</strong>
|
|
297
|
+
// </>
|
|
298
|
+
// ) : (
|
|
299
|
+
// <>
|
|
300
|
+
// {/* {selectedItemsValues.includes(item.value) && (
|
|
301
|
+
// <CheckboxToggle />
|
|
302
|
+
// )} */}
|
|
303
|
+
// {item.label}
|
|
304
|
+
// </>
|
|
305
|
+
// )}
|
|
306
|
+
// </AutocompleteMenuItem>
|
|
307
|
+
// ))}
|
|
308
|
+
// </AutocompleteMenu>
|
|
309
|
+
// </AutocompleteRoot>
|
|
310
|
+
// );
|
|
311
|
+
// }
|
|
312
|
+
// );
|
|
313
|
+
// /**
|
|
314
|
+
// * @see https://www.downshift-js.com/use-multiple-selection
|
|
315
|
+
// * @see https://codesandbox.io/s/y34o5l3p61?file=/src/hooks/useMultipleSelection/combobox.js
|
|
316
|
+
// * @see https://codesandbox.io/s/y34o5l3p61?file=/src/downshift/ordered-examples/05-multi-create.js
|
|
317
|
+
// */
|
|
318
|
+
// export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
|
319
|
+
// function Autocomplete(
|
|
320
|
+
// { defaultValue = [], onChange, onSelect, name, ...props },
|
|
321
|
+
// ref
|
|
322
|
+
// ) {
|
|
323
|
+
// const [selectedItems, setSelectedItems] = useState(
|
|
324
|
+
// normaliseOptions(defaultValue)
|
|
325
|
+
// );
|
|
326
|
+
// const triggerChange = useCallback(
|
|
327
|
+
// (values: AutocompleteValue) => {
|
|
328
|
+
// triggerOnChange(
|
|
329
|
+
// onChange,
|
|
330
|
+
// name,
|
|
331
|
+
// values.map((item) => item.value || item)
|
|
332
|
+
// );
|
|
333
|
+
// if (onSelect) onSelect(values);
|
|
334
|
+
// },
|
|
335
|
+
// [onChange, onSelect, name]
|
|
336
|
+
// );
|
|
337
|
+
// const handleCreateItem = (item?: AutocompleteItem) => {
|
|
338
|
+
// // setSelectedItems((curr) => [...curr, item]);
|
|
339
|
+
// };
|
|
340
|
+
// const handleSelectedItemsChange = ({
|
|
341
|
+
// selectedItems = [],
|
|
342
|
+
// }: UseMultipleSelectionStateChange<AutocompleteItem>) => {
|
|
343
|
+
// setSelectedItems(selectedItems);
|
|
344
|
+
// triggerChange(selectedItems);
|
|
345
|
+
// };
|
|
346
|
+
// return (
|
|
347
|
+
// <_Autocomplete
|
|
348
|
+
// {...props}
|
|
349
|
+
// selectedItems={selectedItems}
|
|
350
|
+
// onSelectedItemsChange={handleSelectedItemsChange}
|
|
351
|
+
// onCreateItem={handleCreateItem}
|
|
352
|
+
// $ref={ref}
|
|
353
|
+
// />
|
|
354
|
+
// );
|
|
355
|
+
// }
|
|
356
|
+
// );
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Autocomplete = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
var react_1 = require("react");
|
|
7
|
+
var AutocompleteUnstyled_1 = require("@mui/base/AutocompleteUnstyled");
|
|
8
|
+
var utils_1 = require("@koine/utils");
|
|
9
|
+
var helpers_1 = require("../Forms/helpers");
|
|
10
|
+
var helpers_2 = require("./helpers");
|
|
11
|
+
var components_1 = require("./components");
|
|
12
|
+
var styles_1 = require("../Forms/styles");
|
|
13
|
+
/**
|
|
14
|
+
* Autocomplete/autocomplete component based on [`@mui useAutocomplete hook`](https://mui.com/components/autocomplete/#useautocomplete).
|
|
15
|
+
*
|
|
16
|
+
* This component is design to work out of the box with [`react-hook-form`](https://react-hook-form.com/)
|
|
17
|
+
* and [`yup`](https://github.com/jquense/yup) alongside our custom `Field`
|
|
18
|
+
* component.
|
|
19
|
+
*
|
|
20
|
+
* After a lot of tests and attempts with `downshift` and `@reach` this proved
|
|
21
|
+
* the best headless hook, small in size and behaving correctly in all scenarios.
|
|
22
|
+
* `downshift` had in fact problems treating the initial `defaultValue` which
|
|
23
|
+
* here is elegantly managed by the `isOptionEqualToValue` option passed into
|
|
24
|
+
* the `useAutocomplete` hook.
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* Validation with `yup` and `react-hook-form` example:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* const schema = object({
|
|
31
|
+
* // the value must be an array with at least one non-empty string
|
|
32
|
+
* test1: array(string().required()).required().min(1),
|
|
33
|
+
* // the value must be an array of strings or an empty array
|
|
34
|
+
* test2: array(string().required()).required(),
|
|
35
|
+
* }).required();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
// export const Autocomplete = <TOption, TValue>forwardRef<
|
|
39
|
+
// HTMLInputElement,
|
|
40
|
+
// PropsWithChildren<AutocompleteProps<TOption, TValue>
|
|
41
|
+
// >(function Autocomplete(
|
|
42
|
+
// {
|
|
43
|
+
// creatable,
|
|
44
|
+
// multiple,
|
|
45
|
+
// autoComplete,
|
|
46
|
+
// loadOptions,
|
|
47
|
+
// options: defaultOptions = [],
|
|
48
|
+
// defaultValue = [],
|
|
49
|
+
// label,
|
|
50
|
+
// register,
|
|
51
|
+
// setValue,
|
|
52
|
+
// // trigger,
|
|
53
|
+
// name,
|
|
54
|
+
// onChange,
|
|
55
|
+
// $ref,
|
|
56
|
+
// children,
|
|
57
|
+
// ...props
|
|
58
|
+
// },
|
|
59
|
+
// ref
|
|
60
|
+
// ) {
|
|
61
|
+
var Autocomplete = function (_a) {
|
|
62
|
+
var creatable = _a.creatable, multiple = _a.multiple, autoComplete = _a.autoComplete, loadOptions = _a.loadOptions, _b = _a.options, defaultOptions = _b === void 0 ? [] : _b, defaultValue = _a.defaultValue, controlledValue = _a.value, defaultInputValue = _a.defaultInputValue, label = _a.label, placeholder = _a.placeholder, register = _a.register, setValue = _a.setValue,
|
|
63
|
+
// trigger,
|
|
64
|
+
name = _a.name, onChange = _a.onChange, $ref = _a.$ref, children = _a.children, props = tslib_1.__rest(_a, ["creatable", "multiple", "autoComplete", "loadOptions", "options", "defaultValue", "value", "defaultInputValue", "label", "placeholder", "register", "setValue", "name", "onChange", "$ref", "children"]);
|
|
65
|
+
var defaultOptionsMemo = (0, react_1.useMemo)(function () { return (0, helpers_1.normaliseOptions)(defaultOptions); }, [defaultOptions]);
|
|
66
|
+
var _c = (0, react_1.useState)(defaultOptionsMemo), options = _c[0], setOptions = _c[1];
|
|
67
|
+
var _d = (0, react_1.useState)(false), loading = _d[0], setLoading = _d[1];
|
|
68
|
+
var _e = (0, AutocompleteUnstyled_1.useAutocomplete)({
|
|
69
|
+
id: "Autocomplete",
|
|
70
|
+
multiple: multiple ? true : undefined,
|
|
71
|
+
freeSolo: creatable ? true : undefined,
|
|
72
|
+
// autoComplete: autoComplete ? true : undefined,
|
|
73
|
+
disableCloseOnSelect: true,
|
|
74
|
+
openOnFocus: true,
|
|
75
|
+
blurOnSelect: autoComplete && !multiple,
|
|
76
|
+
selectOnFocus: creatable,
|
|
77
|
+
// TODO: passing the defaultInputValue makes the input controlled, which is
|
|
78
|
+
// not what I want, so we probably need to handle the input default value
|
|
79
|
+
// ourselves
|
|
80
|
+
// inputValue: defaultInputValue,
|
|
81
|
+
// @ts-expect-error FIXME: how?
|
|
82
|
+
defaultValue: defaultValue,
|
|
83
|
+
// @ts-expect-error FIXME: how?
|
|
84
|
+
value: controlledValue,
|
|
85
|
+
// defaultValue: useMemo(
|
|
86
|
+
// () => normaliseAutocompleteValue(defaultValue, multiple),
|
|
87
|
+
// [defaultValue]
|
|
88
|
+
// ),
|
|
89
|
+
options: (0, react_1.useMemo)(function () { return (loadOptions ? options : defaultOptions); }, [loadOptions, options, defaultOptions]),
|
|
90
|
+
// update input change only if we are searching as you type, @see
|
|
91
|
+
// https://mui.com/components/autocomplete/#search-as-you-type
|
|
92
|
+
onInputChange: (0, react_1.useCallback)(function (_event, inputValue) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
93
|
+
var newOptions, e_1;
|
|
94
|
+
return tslib_1.__generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
if (!loadOptions) {
|
|
98
|
+
return [2 /*return*/];
|
|
99
|
+
}
|
|
100
|
+
if (!inputValue) return [3 /*break*/, 6];
|
|
101
|
+
setLoading(true);
|
|
102
|
+
_a.label = 1;
|
|
103
|
+
case 1:
|
|
104
|
+
_a.trys.push([1, 3, 4, 5]);
|
|
105
|
+
return [4 /*yield*/, loadOptions(inputValue)];
|
|
106
|
+
case 2:
|
|
107
|
+
newOptions = _a.sent();
|
|
108
|
+
setOptions(newOptions);
|
|
109
|
+
return [3 /*break*/, 5];
|
|
110
|
+
case 3:
|
|
111
|
+
e_1 = _a.sent();
|
|
112
|
+
console.warn(e_1);
|
|
113
|
+
return [3 /*break*/, 5];
|
|
114
|
+
case 4:
|
|
115
|
+
setLoading(false);
|
|
116
|
+
return [7 /*endfinally*/];
|
|
117
|
+
case 5: return [3 /*break*/, 7];
|
|
118
|
+
case 6:
|
|
119
|
+
setOptions(options);
|
|
120
|
+
_a.label = 7;
|
|
121
|
+
case 7: return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}); }, [loadOptions, options]),
|
|
125
|
+
// TODO: check if we need this, probably, and check how to structure the
|
|
126
|
+
// callback, here we get the actual input event
|
|
127
|
+
onChange: function (event, newValue) {
|
|
128
|
+
var value = (0, helpers_2.normaliseAutocompleteValue)(newValue, multiple);
|
|
129
|
+
// @ts-expect-error FIXME: how?
|
|
130
|
+
if (onChange)
|
|
131
|
+
onChange(newValue);
|
|
132
|
+
if (setValue)
|
|
133
|
+
setValue(name, value, { shouldValidate: true });
|
|
134
|
+
// triggerOnChange(onChange, name, value);
|
|
135
|
+
},
|
|
136
|
+
// support both freeSolo free text and full option structure
|
|
137
|
+
isOptionEqualToValue: function (option, value) {
|
|
138
|
+
var optValue = (0, utils_1.isString)(option) ? option : option.value;
|
|
139
|
+
var valValue = (0, utils_1.isString)(value) ? value : value.value;
|
|
140
|
+
return optValue === valValue;
|
|
141
|
+
},
|
|
142
|
+
getOptionLabel: function (option) {
|
|
143
|
+
// @ts-expect-error TODO: I don't get this error
|
|
144
|
+
return (0, utils_1.isString)(option) ? option : option.label || "";
|
|
145
|
+
},
|
|
146
|
+
}), getRootProps = _e.getRootProps, getInputLabelProps = _e.getInputLabelProps, getInputProps = _e.getInputProps, getTagProps = _e.getTagProps, getListboxProps = _e.getListboxProps, getOptionProps = _e.getOptionProps, getPopupIndicatorProps = _e.getPopupIndicatorProps, groupedOptions = _e.groupedOptions, stateValue = _e.value, setAnchorEl = _e.setAnchorEl, popupOpen = _e.popupOpen, focused = _e.focused;
|
|
147
|
+
var value = typeof controlledValue !== "undefined" ? controlledValue : stateValue;
|
|
148
|
+
var inputProps = function () {
|
|
149
|
+
var autocompleteProps = getInputProps();
|
|
150
|
+
// here we merge the mui's `useAutocomplete` props with the react-hook-form's
|
|
151
|
+
// `register` props
|
|
152
|
+
var registerProps = register
|
|
153
|
+
? register(name, {
|
|
154
|
+
// @ts-expect-error FIXME: can't remember
|
|
155
|
+
ref: autocompleteProps.ref.current,
|
|
156
|
+
// this makes the validation works when a valid `defaultValue`
|
|
157
|
+
// is provided
|
|
158
|
+
value: (0, helpers_2.normaliseAutocompleteValue)(value, multiple),
|
|
159
|
+
})
|
|
160
|
+
: {};
|
|
161
|
+
return tslib_1.__assign(tslib_1.__assign({}, registerProps), autocompleteProps);
|
|
162
|
+
};
|
|
163
|
+
// to focus the input on error this works too
|
|
164
|
+
// @see https://react-hook-form.com/faqs#question12 but probably it is
|
|
165
|
+
// better to do as now passing the input ref to the register options
|
|
166
|
+
// useEffect(() => {
|
|
167
|
+
// if (errors[name]) {
|
|
168
|
+
// inputProps.ref.current.focus();
|
|
169
|
+
// }
|
|
170
|
+
// }, [errors, name, inputProps.ref]);
|
|
171
|
+
return ((0, jsx_runtime_1.jsxs)(components_1.AutocompleteRoot, { children: [label && ((0, jsx_runtime_1.jsx)(components_1.AutocompleteLabel, tslib_1.__assign({}, getInputLabelProps(), { children: label }))), (0, jsx_runtime_1.jsxs)(components_1.AutocompleteWrap, tslib_1.__assign({}, getRootProps(), { "data-focus": focused }, { children: [(0, jsx_runtime_1.jsxs)(components_1.AutocompleteInner, tslib_1.__assign({ ref: setAnchorEl }, { children: [multiple &&
|
|
172
|
+
value.map(function (valueItem, index) {
|
|
173
|
+
var _a = getTagProps({ index: index }), onDelete = _a.onDelete, key = _a.key, tagProps = tslib_1.__rest(_a, ["onDelete", "key"]);
|
|
174
|
+
return ((0, jsx_runtime_1.jsxs)(components_1.AutocompleteItem, tslib_1.__assign({}, tagProps, { children: [(0, jsx_runtime_1.jsx)(components_1.AutocompleteItemLabel, { children: (0, utils_1.isString)(valueItem)
|
|
175
|
+
? valueItem
|
|
176
|
+
: valueItem.Label || valueItem.label }), (0, jsx_runtime_1.jsx)(components_1.AutocompleteItemRemove, tslib_1.__assign({ onClick: onDelete }, { children: "\u2715" }))] }), key));
|
|
177
|
+
}), (0, jsx_runtime_1.jsx)(components_1.AutocompleteInput, tslib_1.__assign({}, inputProps(), { placeholder: placeholder }))] })), !!options.length && ((0, jsx_runtime_1.jsx)(components_1.AutocompleteInputArrow, tslib_1.__assign({}, getPopupIndicatorProps(), { isOpen: popupOpen }))), loading && (0, jsx_runtime_1.jsx)(styles_1.InputProgress, {})] })), groupedOptions.length ? ((0, jsx_runtime_1.jsx)(components_1.AutocompleteMenu, tslib_1.__assign({}, getListboxProps(), { children: groupedOptions.map(function (option, index) { return ((0, jsx_runtime_1.jsx)(components_1.AutocompleteMenuItem, tslib_1.__assign({}, getOptionProps({ option: option, index: index }), { children: (0, utils_1.isString)(option) ? option : option.Label || option.label }), index)); }) }))) : null, children] }));
|
|
178
|
+
// });
|
|
179
|
+
};
|
|
180
|
+
exports.Autocomplete = Autocomplete;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Autocomplete = void 0;
|
|
4
|
+
// TODO: remove, just use mui version...
|
|
5
|
+
exports.Autocomplete = null;
|
|
6
|
+
// import {
|
|
7
|
+
// forwardRef,
|
|
8
|
+
// useCallback,
|
|
9
|
+
// useState,
|
|
10
|
+
// ForwardedRef,
|
|
11
|
+
// ReactNode,
|
|
12
|
+
// ComponentPropsWithRef,
|
|
13
|
+
// CSSProperties,
|
|
14
|
+
// ChangeEventHandler,
|
|
15
|
+
// } from "react";
|
|
16
|
+
// import {
|
|
17
|
+
// Combobox,
|
|
18
|
+
// ComboboxInput,
|
|
19
|
+
// ComboboxPopover,
|
|
20
|
+
// ComboboxList,
|
|
21
|
+
// ComboboxOption,
|
|
22
|
+
// ComboboxOptionText,
|
|
23
|
+
// } from "@reach/combobox";
|
|
24
|
+
// import {
|
|
25
|
+
// AutocompleteRoot,
|
|
26
|
+
// AutocompleteInput,
|
|
27
|
+
// AutocompleteLabel,
|
|
28
|
+
// } from "./components";
|
|
29
|
+
// import type { Option } from "../types";
|
|
30
|
+
// import { SetRequired } from "@koine/utils";
|
|
31
|
+
// export type AutocompleteOption =
|
|
32
|
+
// | null
|
|
33
|
+
// | (Option & {
|
|
34
|
+
// key: string;
|
|
35
|
+
// });
|
|
36
|
+
// export type AutocompleteProps = SetRequired<
|
|
37
|
+
// ComponentPropsWithRef<"input">,
|
|
38
|
+
// "onChange" | "name"
|
|
39
|
+
// > & {
|
|
40
|
+
// onSelect?: (option?: AutocompleteOption) => any;
|
|
41
|
+
// options: AutocompleteOption[];
|
|
42
|
+
// loadOptions: (query?: string) => Promise<AutocompleteOption[]>;
|
|
43
|
+
// label?: string | ReactNode;
|
|
44
|
+
// className?: string;
|
|
45
|
+
// style?: CSSProperties;
|
|
46
|
+
// $ref: ForwardedRef<HTMLInputElement>;
|
|
47
|
+
// };
|
|
48
|
+
// export const Autocomplete = forwardRef<HTMLInputElement, AutocompleteProps>(
|
|
49
|
+
// function Autocomplete(
|
|
50
|
+
// {
|
|
51
|
+
// options = [],
|
|
52
|
+
// label,
|
|
53
|
+
// name,
|
|
54
|
+
// value,
|
|
55
|
+
// onChange,
|
|
56
|
+
// loadOptions,
|
|
57
|
+
// $ref,
|
|
58
|
+
// className,
|
|
59
|
+
// style,
|
|
60
|
+
// ...props
|
|
61
|
+
// },
|
|
62
|
+
// ref
|
|
63
|
+
// ) {
|
|
64
|
+
// const [items, setItems] = useState(options);
|
|
65
|
+
// const [loading, setLoading] = useState(false);
|
|
66
|
+
// const handleInputValueChange: ChangeEventHandler<HTMLInputElement> =
|
|
67
|
+
// useCallback(
|
|
68
|
+
// async (event) => {
|
|
69
|
+
// const inputValue = event.target.value;
|
|
70
|
+
// if (loadOptions) {
|
|
71
|
+
// setLoading(true);
|
|
72
|
+
// try {
|
|
73
|
+
// const newOptions = await loadOptions(inputValue);
|
|
74
|
+
// setItems(newOptions);
|
|
75
|
+
// } catch (e) {}
|
|
76
|
+
// setLoading(false);
|
|
77
|
+
// }
|
|
78
|
+
// },
|
|
79
|
+
// [loadOptions]
|
|
80
|
+
// );
|
|
81
|
+
// return (
|
|
82
|
+
// <AutocompleteRoot>
|
|
83
|
+
// {label && <AutocompleteLabel>{label}</AutocompleteLabel>}
|
|
84
|
+
// <Combobox aria-label="choose a fruit" openOnFocus={true}>
|
|
85
|
+
// <AutocompleteInput
|
|
86
|
+
// forwardedAs={ComboboxInput}
|
|
87
|
+
// ref={$ref}
|
|
88
|
+
// onChange={handleInputValueChange}
|
|
89
|
+
// selectOnClick={true}
|
|
90
|
+
// autocomplete={false}
|
|
91
|
+
// />
|
|
92
|
+
// {(!!items.length || loading) && (
|
|
93
|
+
// <ComboboxPopover>
|
|
94
|
+
// <ComboboxList persistSelection>
|
|
95
|
+
// {items
|
|
96
|
+
// // .filter(item => !inputValue || item.includes(inputValue))
|
|
97
|
+
// .map(
|
|
98
|
+
// (item, index) =>
|
|
99
|
+
// item && (
|
|
100
|
+
// <ComboboxOption
|
|
101
|
+
// key={`${item.value}${index}`}
|
|
102
|
+
// value={item.label}
|
|
103
|
+
// >
|
|
104
|
+
// <ComboboxOptionText />
|
|
105
|
+
// </ComboboxOption>
|
|
106
|
+
// )
|
|
107
|
+
// )}
|
|
108
|
+
// </ComboboxList>
|
|
109
|
+
// </ComboboxPopover>
|
|
110
|
+
// )}
|
|
111
|
+
// </Combobox>
|
|
112
|
+
// </AutocompleteRoot>
|
|
113
|
+
// );
|
|
114
|
+
// }
|
|
115
|
+
// );
|