@peculiar/react-components 0.0.2-alpha.267 → 0.0.2-alpha.271

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 (83) hide show
  1. package/dist/cjs/Autocomplete/autocomplete.js +258 -0
  2. package/dist/cjs/Autocomplete/autocomplete.js.map +1 -0
  3. package/dist/cjs/Autocomplete/index.js +6 -0
  4. package/dist/cjs/Autocomplete/index.js.map +1 -0
  5. package/dist/cjs/Chip/chip.js +60 -13
  6. package/dist/cjs/Chip/chip.js.map +1 -1
  7. package/dist/cjs/Modal/modal.js +3 -3
  8. package/dist/cjs/Modal/modal.js.map +1 -1
  9. package/dist/cjs/hooks/index.js +5 -1
  10. package/dist/cjs/hooks/index.js.map +1 -1
  11. package/dist/cjs/hooks/use_autocomplete.js +345 -0
  12. package/dist/cjs/hooks/use_autocomplete.js.map +1 -0
  13. package/dist/cjs/hooks/use_event_callback.js +44 -0
  14. package/dist/cjs/hooks/use_event_callback.js.map +1 -0
  15. package/dist/cjs/index.js +1 -1
  16. package/dist/esm/Autocomplete/autocomplete.js +251 -0
  17. package/dist/esm/Autocomplete/autocomplete.js.map +1 -0
  18. package/dist/esm/Autocomplete/index.js +2 -0
  19. package/dist/esm/Autocomplete/index.js.map +1 -0
  20. package/dist/esm/Chip/chip.js +60 -13
  21. package/dist/esm/Chip/chip.js.map +1 -1
  22. package/dist/esm/Modal/modal.js +3 -3
  23. package/dist/esm/Modal/modal.js.map +1 -1
  24. package/dist/esm/hooks/index.js +2 -0
  25. package/dist/esm/hooks/index.js.map +1 -1
  26. package/dist/esm/hooks/use_autocomplete.js +338 -0
  27. package/dist/esm/hooks/use_autocomplete.js.map +1 -0
  28. package/dist/esm/hooks/use_event_callback.js +21 -0
  29. package/dist/esm/hooks/use_event_callback.js.map +1 -0
  30. package/dist/esm/index.js +1 -1
  31. package/dist/esnext/Autocomplete/autocomplete.js +255 -0
  32. package/dist/esnext/Autocomplete/autocomplete.js.map +1 -0
  33. package/dist/esnext/Autocomplete/index.js +2 -0
  34. package/dist/esnext/Autocomplete/index.js.map +1 -0
  35. package/dist/esnext/Chip/chip.js +74 -7
  36. package/dist/esnext/Chip/chip.js.map +1 -1
  37. package/dist/esnext/Modal/modal.js +3 -3
  38. package/dist/esnext/Modal/modal.js.map +1 -1
  39. package/dist/esnext/hooks/index.js +2 -0
  40. package/dist/esnext/hooks/index.js.map +1 -1
  41. package/dist/esnext/hooks/use_autocomplete.js +333 -0
  42. package/dist/esnext/hooks/use_autocomplete.js.map +1 -0
  43. package/dist/esnext/hooks/use_event_callback.js +16 -0
  44. package/dist/esnext/hooks/use_event_callback.js.map +1 -0
  45. package/dist/esnext/index.js +1 -1
  46. package/dist/types/Autocomplete/autocomplete.d.ts +86 -0
  47. package/dist/types/Autocomplete/index.d.ts +1 -0
  48. package/dist/types/Chip/chip.d.ts +15 -1
  49. package/dist/types/Modal/modal.d.ts +1 -1
  50. package/dist/types/Popover/popover.d.ts +1 -1
  51. package/dist/types/hooks/index.d.ts +2 -0
  52. package/dist/types/hooks/use_autocomplete.d.ts +91 -0
  53. package/dist/types/hooks/use_event_callback.d.ts +4 -0
  54. package/dist/types/index.d.ts +1 -1
  55. package/package.json +3 -3
  56. package/dist/cjs/ComboBox/combo_box.js +0 -262
  57. package/dist/cjs/ComboBox/combo_box.js.map +0 -1
  58. package/dist/cjs/ComboBox/index.js +0 -6
  59. package/dist/cjs/ComboBox/index.js.map +0 -1
  60. package/dist/cjs/SelectPicker/index.js +0 -6
  61. package/dist/cjs/SelectPicker/index.js.map +0 -1
  62. package/dist/cjs/SelectPicker/select_picker.js +0 -429
  63. package/dist/cjs/SelectPicker/select_picker.js.map +0 -1
  64. package/dist/esm/ComboBox/combo_box.js +0 -240
  65. package/dist/esm/ComboBox/combo_box.js.map +0 -1
  66. package/dist/esm/ComboBox/index.js +0 -2
  67. package/dist/esm/ComboBox/index.js.map +0 -1
  68. package/dist/esm/SelectPicker/index.js +0 -2
  69. package/dist/esm/SelectPicker/index.js.map +0 -1
  70. package/dist/esm/SelectPicker/select_picker.js +0 -422
  71. package/dist/esm/SelectPicker/select_picker.js.map +0 -1
  72. package/dist/esnext/ComboBox/combo_box.js +0 -214
  73. package/dist/esnext/ComboBox/combo_box.js.map +0 -1
  74. package/dist/esnext/ComboBox/index.js +0 -2
  75. package/dist/esnext/ComboBox/index.js.map +0 -1
  76. package/dist/esnext/SelectPicker/index.js +0 -2
  77. package/dist/esnext/SelectPicker/index.js.map +0 -1
  78. package/dist/esnext/SelectPicker/select_picker.js +0 -418
  79. package/dist/esnext/SelectPicker/select_picker.js.map +0 -1
  80. package/dist/types/ComboBox/combo_box.d.ts +0 -19
  81. package/dist/types/ComboBox/index.d.ts +0 -1
  82. package/dist/types/SelectPicker/index.d.ts +0 -1
  83. package/dist/types/SelectPicker/select_picker.d.ts +0 -89
@@ -0,0 +1,333 @@
1
+ import React from 'react';
2
+ import { useId } from './use_id';
3
+ import { useControllableState } from './use_controllable';
4
+ import { useEventCallback } from './use_event_callback';
5
+ /**
6
+ *
7
+ */
8
+ const defaultFilterOptions = (options, value, getOptionLabel) => {
9
+ if (!options || !options.length) {
10
+ return [];
11
+ }
12
+ return options.filter((option) => {
13
+ const labelValue = getOptionLabel(option).trim().toLowerCase();
14
+ const searchValue = value.trim().toLowerCase();
15
+ return labelValue.includes(searchValue);
16
+ });
17
+ };
18
+ export function useAutocomplete(props) {
19
+ const { id: idProp, options, defaultValue = props.multiple ? [] : null, value: valueProp, disableCloseOnSelect = false, multiple = false, groupBy,
20
+ // @ts-ignore
21
+ getOptionLabel = (option) => option.label ?? option, filterOptions = defaultFilterOptions, onOpen, onClose, onInputChange, onChange, } = props;
22
+ const id = useId(idProp);
23
+ const anchorEl = React.useRef(null);
24
+ const listboxRef = React.useRef(null);
25
+ const highlightedIndexRef = React.useRef(-1);
26
+ const [popupOpen, setPopupOpen] = React.useState(false);
27
+ const [searchValue, setSearchValue] = React.useState('');
28
+ const [value, setValue] = useControllableState({
29
+ value: valueProp,
30
+ defaultValue,
31
+ });
32
+ const filteredOptions = popupOpen
33
+ ? filterOptions(options, searchValue, getOptionLabel)
34
+ : [];
35
+ const validOptionIndex = (index, direction) => {
36
+ if (!listboxRef.current || index === -1) {
37
+ return -1;
38
+ }
39
+ let nextFocus = index;
40
+ while (true) {
41
+ // Out of range
42
+ if ((direction === 'next' && nextFocus === filteredOptions.length)
43
+ || (direction === 'previous' && nextFocus === -1)) {
44
+ return -1;
45
+ }
46
+ const option = listboxRef.current.querySelector(`[data-option-index="${nextFocus}"]`);
47
+ if ((option && !option.hasAttribute('tabindex'))) {
48
+ // Move to the next element.
49
+ nextFocus += direction === 'next' ? 1 : -1;
50
+ }
51
+ else {
52
+ return nextFocus;
53
+ }
54
+ }
55
+ };
56
+ const setHighlightedIndex = useEventCallback((index, reason = 'auto') => {
57
+ highlightedIndexRef.current = index;
58
+ const listboxNode = listboxRef.current;
59
+ if (!listboxNode) {
60
+ return;
61
+ }
62
+ const prevOptionNode = listboxNode.querySelector('[role="option"][data-focused="true"]');
63
+ if (prevOptionNode) {
64
+ prevOptionNode.setAttribute('data-focused', 'false');
65
+ }
66
+ if (index === -1) {
67
+ listboxNode.scrollTop = 0;
68
+ return;
69
+ }
70
+ const option = listboxNode.querySelector(`[data-option-index="${index}"]`);
71
+ if (!option) {
72
+ return;
73
+ }
74
+ option.setAttribute('data-focused', 'true');
75
+ // Scroll active descendant into view.
76
+ // Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
77
+ //
78
+ // Consider this API instead once it has a better browser support:
79
+ // .scrollIntoView({ scrollMode: 'if-needed', block: 'nearest' });
80
+ if (listboxNode.scrollHeight > listboxNode.clientHeight && reason !== 'mouse') {
81
+ const element = option;
82
+ const scrollBottom = listboxNode.clientHeight + listboxNode.scrollTop;
83
+ const elementBottom = element.offsetTop + element.offsetHeight;
84
+ if (elementBottom > scrollBottom) {
85
+ listboxNode.scrollTop = elementBottom - listboxNode.clientHeight;
86
+ }
87
+ else if (element.offsetTop - element.offsetHeight * (groupBy ? 1.3 : 0) < listboxNode.scrollTop) {
88
+ listboxNode.scrollTop = element.offsetTop - element.offsetHeight * (groupBy ? 1.3 : 0);
89
+ }
90
+ }
91
+ });
92
+ const changeHighlightedIndex = useEventCallback((diff, direction = 'next', reason = 'auto') => {
93
+ if (!popupOpen) {
94
+ return;
95
+ }
96
+ const getNextIndex = () => {
97
+ const maxIndex = filteredOptions.length - 1;
98
+ if (diff === 'reset') {
99
+ return -1;
100
+ }
101
+ if (diff === 'start') {
102
+ return 0;
103
+ }
104
+ if (diff === 'end') {
105
+ return maxIndex;
106
+ }
107
+ const newIndex = highlightedIndexRef.current + diff;
108
+ if (newIndex < 0) {
109
+ if (newIndex === -1) {
110
+ return -1;
111
+ }
112
+ if ((highlightedIndexRef.current !== -1) || Math.abs(diff) > 1) {
113
+ return 0;
114
+ }
115
+ return maxIndex;
116
+ }
117
+ if (newIndex > maxIndex) {
118
+ if (newIndex === maxIndex + 1) {
119
+ return -1;
120
+ }
121
+ if (Math.abs(diff) > 1) {
122
+ return maxIndex;
123
+ }
124
+ return 0;
125
+ }
126
+ return newIndex;
127
+ };
128
+ const nextIndex = validOptionIndex(getNextIndex(), direction);
129
+ setHighlightedIndex(nextIndex, reason);
130
+ });
131
+ const syncHighlightedIndex = React.useCallback(() => {
132
+ if (!popupOpen) {
133
+ return;
134
+ }
135
+ const valueItem = Array.isArray(value) ? value[0] : value;
136
+ if (filteredOptions.length === 0 || valueItem == null) {
137
+ changeHighlightedIndex('reset');
138
+ return;
139
+ }
140
+ if (!listboxRef.current) {
141
+ return;
142
+ }
143
+ if (valueItem != null) {
144
+ const itemIndex = filteredOptions.findIndex((o) => o === valueItem);
145
+ if (itemIndex === -1) {
146
+ changeHighlightedIndex('reset');
147
+ }
148
+ else {
149
+ setHighlightedIndex(itemIndex);
150
+ }
151
+ return;
152
+ }
153
+ // Prevent the highlighted index to leak outside the boundaries.
154
+ if (highlightedIndexRef.current >= filteredOptions.length - 1) {
155
+ setHighlightedIndex(filteredOptions.length - 1);
156
+ return;
157
+ }
158
+ setHighlightedIndex(highlightedIndexRef.current);
159
+ }, [
160
+ filteredOptions.length,
161
+ multiple ? false : value,
162
+ changeHighlightedIndex,
163
+ setHighlightedIndex,
164
+ popupOpen,
165
+ searchValue,
166
+ multiple,
167
+ ]);
168
+ const handleListboxRef = useEventCallback((node) => {
169
+ listboxRef.current = node;
170
+ if (!node) {
171
+ return;
172
+ }
173
+ syncHighlightedIndex();
174
+ });
175
+ React.useEffect(() => {
176
+ syncHighlightedIndex();
177
+ }, [syncHighlightedIndex]);
178
+ const handleOpen = (event) => {
179
+ if (popupOpen) {
180
+ return;
181
+ }
182
+ setPopupOpen(true);
183
+ if (onOpen) {
184
+ onOpen(event);
185
+ }
186
+ };
187
+ const handleClick = (event) => {
188
+ handleOpen(event);
189
+ };
190
+ const handleClose = (event) => {
191
+ if (!popupOpen) {
192
+ return;
193
+ }
194
+ setPopupOpen(false);
195
+ setSearchValue('');
196
+ if (onClose) {
197
+ onClose(event);
198
+ }
199
+ };
200
+ const selectNewValue = (event, option) => {
201
+ let newValue = option;
202
+ if (multiple) {
203
+ newValue = Array.isArray(value) ? value.slice() : [];
204
+ const itemIndex = newValue.findIndex((v) => option === v);
205
+ if (itemIndex === -1) {
206
+ newValue.push(option);
207
+ }
208
+ else {
209
+ newValue.splice(itemIndex, 1);
210
+ }
211
+ }
212
+ setValue(newValue);
213
+ if (!disableCloseOnSelect) {
214
+ handleClose(event);
215
+ }
216
+ if (onChange) {
217
+ onChange(event, newValue);
218
+ }
219
+ };
220
+ const handleInputChange = (event) => {
221
+ const { value: valueInput } = event.target;
222
+ setSearchValue(valueInput);
223
+ if (onInputChange) {
224
+ onInputChange(event, valueInput);
225
+ }
226
+ };
227
+ const handleKeyDown = (event) => {
228
+ // Wait until IME is settled.
229
+ if (event.which !== 229) {
230
+ switch (event.key) {
231
+ case 'ArrowDown':
232
+ // Prevent cursor move
233
+ event.preventDefault();
234
+ changeHighlightedIndex(1, 'next', 'keyboard');
235
+ break;
236
+ case 'ArrowUp':
237
+ // Prevent cursor move
238
+ event.preventDefault();
239
+ changeHighlightedIndex(-1, 'previous', 'keyboard');
240
+ break;
241
+ case 'Enter':
242
+ // Avoid early form validation, let the end-users continue filling the form.
243
+ event.preventDefault();
244
+ if (highlightedIndexRef.current !== -1 && popupOpen) {
245
+ const option = filteredOptions[highlightedIndexRef.current];
246
+ selectNewValue(event, option);
247
+ }
248
+ break;
249
+ default:
250
+ }
251
+ }
252
+ };
253
+ const handleOptionClick = (event) => {
254
+ const index = Number(event.currentTarget.getAttribute('data-option-index'));
255
+ const option = filteredOptions[index];
256
+ selectNewValue(event, option);
257
+ };
258
+ const handleTagDelete = (option) => (event) => {
259
+ selectNewValue(event, option);
260
+ };
261
+ let groupedOptions = filteredOptions;
262
+ if (groupBy) {
263
+ groupedOptions = filteredOptions.reduce((acc, option, index) => {
264
+ const group = groupBy(option);
265
+ if (acc.length > 0 && acc[acc.length - 1].group === group) {
266
+ acc[acc.length - 1].options.push(option);
267
+ }
268
+ else {
269
+ acc.push({
270
+ key: index,
271
+ index,
272
+ group,
273
+ options: [option],
274
+ });
275
+ }
276
+ return acc;
277
+ }, []);
278
+ }
279
+ return {
280
+ getRootProps: () => ({
281
+ ref: anchorEl,
282
+ 'aria-expanded': popupOpen,
283
+ 'aria-haspopup': 'listbox',
284
+ onClick: handleClick,
285
+ }),
286
+ getListboxProps: () => ({
287
+ ref: handleListboxRef,
288
+ role: 'listbox',
289
+ tabIndex: -1,
290
+ id: `${id}-listbox`,
291
+ }),
292
+ getInputProps: () => ({
293
+ type: 'search',
294
+ value: searchValue,
295
+ autoComplete: 'off',
296
+ autoCapitalize: 'none',
297
+ autoCorrect: 'false',
298
+ spellCheck: 'false',
299
+ onChange: handleInputChange,
300
+ }),
301
+ getOptionProps: (option, index) => {
302
+ const selected = (Array.isArray(value) ? value : [value]).some((v) => v != null && option === v);
303
+ return {
304
+ key: getOptionLabel(option),
305
+ tabIndex: -1,
306
+ role: 'option',
307
+ id: `${id}-option-${index}`,
308
+ 'data-option-index': index,
309
+ 'aria-selected': selected,
310
+ onClick: handleOptionClick,
311
+ };
312
+ },
313
+ getPopoverProps: () => ({
314
+ open: popupOpen,
315
+ anchorEl: anchorEl.current,
316
+ onClose: handleClose,
317
+ onKeyDown: handleKeyDown,
318
+ }),
319
+ getTagProps: (option, index) => ({
320
+ key: index,
321
+ 'data-tag-index': index,
322
+ tabIndex: -1,
323
+ onDelete: handleTagDelete(option),
324
+ }),
325
+ getOptionLabel,
326
+ groupedOptions,
327
+ popupOpen,
328
+ value,
329
+ searchValue,
330
+ id,
331
+ };
332
+ }
333
+ //# sourceMappingURL=use_autocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_autocomplete.js","sourceRoot":"","sources":["../../../src/hooks/use_autocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AA8GxD;;GAEG;AAEH,MAAM,oBAAoB,GAAsB,CAAC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;IACjF,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QAC/B,OAAO,EAAE,CAAC;KACX;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;QAC/B,MAAM,UAAU,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC/D,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAE/C,OAAO,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IA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ACT,KAAK;QACL,WAAW;QACX,EAAE;KACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * https://github.com/facebook/react/issues/14099#issuecomment-440013892
4
+ */
5
+ export function useEventCallback(fn) {
6
+ const ref = React.useRef(fn);
7
+ React.useLayoutEffect(() => {
8
+ ref.current = fn;
9
+ });
10
+ return React.useCallback((...args) =>
11
+ // @ts-expect-error hide `this`
12
+ // tslint:disable-next-line:ban-comma-operator
13
+ // eslint-disable-next-line implicit-arrow-linebreak
14
+ (0, ref.current)(...args), []);
15
+ }
16
+ //# sourceMappingURL=use_event_callback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use_event_callback.js","sourceRoot":"","sources":["../../../src/hooks/use_event_callback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,EAA6B;IAE7B,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAE7B,KAAK,CAAC,eAAe,CAAC,GAAG,EAAE;QACzB,GAAG,CAAC,OAAO,GAAG,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC,WAAW,CACtB,CAAC,GAAG,IAAU,EAAE,EAAE;IAChB,+BAA+B;IAC/B,8CAA8C;IAC9C,oDAAoD;IACpD,CAAC,CAAC,EAAE,GAAG,CAAC,OAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,EAC5B,EAAE,CACH,CAAC;AACJ,CAAC"}
@@ -19,7 +19,7 @@ export * from './Popover';
19
19
  export * from './Portal';
20
20
  export * from './Radio';
21
21
  export * from './Select';
22
- export * from './SelectPicker';
22
+ export * from './Autocomplete';
23
23
  export * from './Slide';
24
24
  export * from './Slider';
25
25
  export * from './Tabs';
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ import { UseAutocompleteProps, AutocompleteValue } from '../hooks';
3
+ /**
4
+ * Types.
5
+ */
6
+ export declare type AutocompleteRenderGroupParams = {
7
+ key: string | number;
8
+ group: string;
9
+ children?: React.ReactNode;
10
+ };
11
+ export declare type AutocompleteProps<T, Multiple extends boolean | undefined = undefined> = UseAutocompleteProps<T, Multiple> & {
12
+ /**
13
+ * The short hint displayed in the `input` before the user enters a value.
14
+ */
15
+ placeholder?: string;
16
+ /**
17
+ * Text to display when there are no options.
18
+ */
19
+ noOptionsText?: React.ReactNode;
20
+ /**
21
+ * If `true`, the component is in a loading state.
22
+ * This shows the `loadingText` in place of suggestions (only if there are no
23
+ * suggestions to show, e.g. `options` are empty).
24
+ */
25
+ loading?: boolean;
26
+ /**
27
+ * Text to display when in a loading state.
28
+ */
29
+ loadingText?: React.ReactNode;
30
+ /**
31
+ * The maximum number of tags that will be visible when not focused.
32
+ */
33
+ limitTags?: number;
34
+ /**
35
+ * If `true`, the popup search input will be hidden.
36
+ */
37
+ disableSearch?: boolean;
38
+ /**
39
+ * Name attribute of the `input` element.
40
+ */
41
+ name?: string;
42
+ /**
43
+ * If `true`, the `input` element is required.
44
+ */
45
+ required?: boolean;
46
+ /**
47
+ * Text to display when in the create button element.
48
+ */
49
+ createOptionText?: string;
50
+ /**
51
+ * If `true`, the create button element will be shown.
52
+ */
53
+ allowCreateOption?: boolean;
54
+ /**
55
+ * Render the root element.
56
+ */
57
+ renderRoot?: (props: object, value: AutocompleteValue<T, Multiple>) => React.ReactNode;
58
+ /**
59
+ * Render the option, use `getOptionLabel` by default.
60
+ */
61
+ renderOption?: (props: object, option: T) => React.ReactNode;
62
+ /**
63
+ * The label to display when the tags are truncated (`limitTags`).
64
+ */
65
+ getLimitTagsText?: (more: number) => string;
66
+ /**
67
+ * Callback fired when the create button clicked.
68
+ */
69
+ onCreate?: (event: React.SyntheticEvent, value: string) => void;
70
+ };
71
+ /**
72
+ *
73
+ */
74
+ export declare function Autocomplete<T, Multiple extends boolean | undefined = undefined>(props: AutocompleteProps<T, Multiple>): JSX.Element;
75
+ export declare namespace Autocomplete {
76
+ var defaultProps: {
77
+ disableSearch: boolean;
78
+ noOptionsText: string;
79
+ loading: boolean;
80
+ loadingText: string;
81
+ limitTags: number;
82
+ required: boolean;
83
+ allowCreateOption: boolean;
84
+ createOptionText: string;
85
+ };
86
+ }
@@ -0,0 +1 @@
1
+ export { Autocomplete } from './autocomplete';
@@ -1,4 +1,7 @@
1
1
  import * as React from 'react';
2
+ /**
3
+ * Types.
4
+ */
2
5
  declare type BaseProps = {
3
6
  /**
4
7
  * The content of the component.
@@ -19,11 +22,19 @@ declare type BaseProps = {
19
22
  /**
20
23
  * The color of the component.
21
24
  */
22
- color?: ('secondary' | 'wrong');
25
+ color?: ('secondary' | 'wrong' | 'default');
23
26
  /**
24
27
  * The className of the component.
25
28
  */
26
29
  className?: string;
30
+ /**
31
+ * Element placed before the children.
32
+ */
33
+ startContent?: React.ReactElement;
34
+ /**
35
+ * The component used for the root node.
36
+ */
37
+ component?: React.ElementType;
27
38
  /**
28
39
  * Callback function fired when the delete icon is clicked. If set, the delete icon will be shown.
29
40
  */
@@ -34,5 +45,8 @@ declare type BaseProps = {
34
45
  onClick?: React.MouseEventHandler<HTMLElement>;
35
46
  'data-testid'?: string;
36
47
  };
48
+ /**
49
+ *
50
+ */
37
51
  export declare const Chip: React.ForwardRefExoticComponent<BaseProps & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
38
52
  export {};
@@ -28,7 +28,7 @@ declare type BaseProps = {
28
28
  /**
29
29
  * Callback fired when the component requests to be closed.
30
30
  */
31
- onClose?: () => void;
31
+ onClose?: (event: React.SyntheticEvent) => void;
32
32
  /**
33
33
  * Always keep the children in the DOM.
34
34
  */
@@ -21,7 +21,7 @@ declare type BaseProps = {
21
21
  /**
22
22
  * Callback fired when the component requests to be closed.
23
23
  */
24
- onClose?: () => void;
24
+ onClose?: (event: React.SyntheticEvent) => void;
25
25
  /**
26
26
  * Props applied to the `Modal` element.
27
27
  */
@@ -5,3 +5,5 @@ export { useControllableState, UseControllableStateProps } from './use_controlla
5
5
  export { useId } from './use_id';
6
6
  export { useImage } from './use_image';
7
7
  export { useWindowEventListener } from './use_window_event_listener';
8
+ export { useAutocomplete, UseAutocompleteProps, UseAutocompleteReturnType, AutocompleteValue, AutocompleteGroupedOption, } from './use_autocomplete';
9
+ export { useEventCallback } from './use_event_callback';
@@ -0,0 +1,91 @@
1
+ import React from 'react';
2
+ import type { PopoverProps } from '../Popover';
3
+ /**
4
+ * Types.
5
+ */
6
+ export declare type AutocompleteHighlightChangeReason = ('auto' | 'mouse' | 'keyboard');
7
+ export declare type AutocompleteHighlightChangeDirectionType = ('next' | 'previous');
8
+ export declare type AutocompleteHighlightChangeDiffType = (number | 'reset' | 'start' | 'end');
9
+ export declare type FilterOptionsType = <T>(options: ReadonlyArray<T>, value: string, getOptionLabel: (option: T) => string) => T[];
10
+ export declare type AutocompleteValue<T, Multiple> = Multiple extends undefined | false ? T : T[];
11
+ export declare type AutocompleteGroupedOption<T> = {
12
+ key: number;
13
+ index: number;
14
+ group: string;
15
+ options: T[];
16
+ };
17
+ export declare type UseAutocompleteProps<T, Multiple extends boolean | undefined = undefined> = {
18
+ /**
19
+ * This prop is used to help implement the accessibility logic.
20
+ * If you don't provide an id it will fall back to a randomly generated one.
21
+ */
22
+ id?: string;
23
+ /**
24
+ * Array of options.
25
+ */
26
+ options: ReadonlyArray<T>;
27
+ /**
28
+ * The default value. Use when the component is not controlled.
29
+ */
30
+ defaultValue?: AutocompleteValue<T, Multiple>;
31
+ /**
32
+ * The value of the select.
33
+ */
34
+ value?: AutocompleteValue<T, Multiple>;
35
+ /**
36
+ * If `true`, the popup won't close when a value is selected.
37
+ */
38
+ disableCloseOnSelect?: boolean;
39
+ /**
40
+ * If `true`, `value` must be an array and the menu will support multiple selections.
41
+ */
42
+ multiple?: Multiple;
43
+ /**
44
+ * If provided, the options will be grouped under the returned string.
45
+ */
46
+ groupBy?: (option: T) => string;
47
+ /**
48
+ * Used to determine the string value for a given option. It's used to fill the input.
49
+ */
50
+ getOptionLabel?: (option: T) => string;
51
+ /**
52
+ * A filter function that determines the options that are eligible.
53
+ */
54
+ filterOptions?: FilterOptionsType;
55
+ /**
56
+ * Callback fired when the popup requests to be closed.
57
+ */
58
+ onClose?: (event: React.SyntheticEvent) => void;
59
+ /**
60
+ * Callback fired when the popup requests to be opened.
61
+ */
62
+ onOpen?: (event: React.SyntheticEvent) => void;
63
+ /**
64
+ * Callback fired when the value changes.
65
+ */
66
+ onChange?: (event: React.SyntheticEvent, value: AutocompleteValue<T, Multiple>) => void;
67
+ /**
68
+ * Callback fired when the input value changes.
69
+ */
70
+ onInputChange?: (event: React.SyntheticEvent, value: string) => void;
71
+ };
72
+ export declare type UseAutocompleteReturnType<T, Multiple extends boolean | undefined = undefined> = {
73
+ groupedOptions: T[] | AutocompleteGroupedOption<T>[];
74
+ value: AutocompleteValue<T, Multiple>;
75
+ searchValue: string;
76
+ popupOpen: boolean;
77
+ id: string;
78
+ getOptionProps: (option: T, index: number) => React.HTMLAttributes<HTMLLIElement>;
79
+ getListboxProps: () => React.HTMLAttributes<HTMLUListElement>;
80
+ getRootProps: () => React.HTMLAttributes<HTMLDivElement>;
81
+ getInputProps: () => React.HTMLAttributes<HTMLInputElement>;
82
+ getPopoverProps: () => Pick<Required<PopoverProps>, 'open' | 'anchorEl' | 'onClose' | 'onKeyDown'>;
83
+ getTagProps: (option: T, index: number) => {
84
+ key: number;
85
+ 'data-tag-index': number;
86
+ tabIndex: -1;
87
+ onDelete: (event: React.SyntheticEvent) => void;
88
+ };
89
+ getOptionLabel?: (option: T) => string;
90
+ };
91
+ export declare function useAutocomplete<T, Multiple extends boolean | undefined = undefined>(props: UseAutocompleteProps<T, Multiple>): UseAutocompleteReturnType<T, Multiple>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * https://github.com/facebook/react/issues/14099#issuecomment-440013892
3
+ */
4
+ export declare function useEventCallback<Args extends unknown[], Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
@@ -19,7 +19,7 @@ export * from './Popover';
19
19
  export * from './Portal';
20
20
  export * from './Radio';
21
21
  export * from './Select';
22
- export * from './SelectPicker';
22
+ export * from './Autocomplete';
23
23
  export * from './Slide';
24
24
  export * from './Slider';
25
25
  export * from './Tabs';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peculiar/react-components",
3
3
  "private": false,
4
- "version": "0.0.2-alpha.267+a394a2e",
4
+ "version": "0.0.2-alpha.271+985ca90",
5
5
  "author": "PeculiarVentures Team",
6
6
  "description": "A simple and customizable component library to build faster, beautiful, and more accessible React applications.",
7
7
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@emotion/core": "^10.1.1",
43
43
  "@emotion/css": "^11.7.1",
44
- "@peculiar/color": "^0.0.2-alpha.267+a394a2e",
44
+ "@peculiar/color": "^0.0.2-alpha.271+985ca90",
45
45
  "@popperjs/core": "^2.11.2",
46
46
  "@types/flat": "^5.0.2",
47
47
  "@types/react-transition-group": "^4.4.4",
@@ -84,5 +84,5 @@
84
84
  "node": ">=12.x"
85
85
  },
86
86
  "license": "MIT",
87
- "gitHead": "a394a2eb4cdcb9de5b1658adde136a74506281be"
87
+ "gitHead": "985ca90af329ba2461a50b77892541ca02ef065c"
88
88
  }