@pushwoosh/dumb-components 1.1.140 → 1.1.141

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 (45) hide show
  1. package/Combobox/Combobox.d.ts +4 -0
  2. package/Combobox/Combobox.js +254 -0
  3. package/Combobox/index.d.ts +2 -0
  4. package/Combobox/index.js +1 -0
  5. package/Combobox/types.d.ts +38 -0
  6. package/Combobox/types.js +1 -0
  7. package/ComboboxMulti/ComboboxMulti.d.ts +3 -0
  8. package/ComboboxMulti/ComboboxMulti.js +194 -0
  9. package/ComboboxMulti/index.d.ts +2 -0
  10. package/ComboboxMulti/index.js +1 -0
  11. package/ComboboxMulti/types.d.ts +32 -0
  12. package/ComboboxMulti/types.js +1 -0
  13. package/hooks/useLayer.js +41 -14
  14. package/hooks/useOnClickOutside.js +6 -5
  15. package/index.d.ts +2 -0
  16. package/index.js +2 -0
  17. package/package.json +2 -2
  18. package/shared/dropdownField/FieldInput.d.ts +5 -0
  19. package/shared/dropdownField/FieldInput.js +43 -0
  20. package/shared/dropdownField/FieldShell.d.ts +30 -0
  21. package/shared/dropdownField/FieldShell.js +99 -0
  22. package/shared/dropdownField/SuggestionsDropdown.d.ts +16 -0
  23. package/shared/dropdownField/SuggestionsDropdown.js +68 -0
  24. package/shared/dropdownField/constants.d.ts +6 -0
  25. package/shared/dropdownField/constants.js +6 -0
  26. package/shared/dropdownField/index.d.ts +12 -0
  27. package/shared/dropdownField/index.js +11 -0
  28. package/shared/dropdownField/shared.d.ts +4 -0
  29. package/shared/dropdownField/shared.js +18 -0
  30. package/shared/dropdownField/styles.d.ts +24 -0
  31. package/shared/dropdownField/styles.js +81 -0
  32. package/shared/dropdownField/types.d.ts +27 -0
  33. package/shared/dropdownField/types.js +1 -0
  34. package/shared/dropdownField/useActiveIndex.d.ts +2 -0
  35. package/shared/dropdownField/useActiveIndex.js +12 -0
  36. package/shared/dropdownField/useAsyncItems.d.ts +11 -0
  37. package/shared/dropdownField/useAsyncItems.js +46 -0
  38. package/shared/dropdownField/useDebouncedValue.d.ts +1 -0
  39. package/shared/dropdownField/useDebouncedValue.js +13 -0
  40. package/shared/dropdownField/useDropdownItems.d.ts +16 -0
  41. package/shared/dropdownField/useDropdownItems.js +36 -0
  42. package/shared/dropdownField/useDropdownPosition.d.ts +10 -0
  43. package/shared/dropdownField/useDropdownPosition.js +40 -0
  44. package/shared/dropdownField/useListNavigation.d.ts +16 -0
  45. package/shared/dropdownField/useListNavigation.js +45 -0
@@ -0,0 +1,40 @@
1
+ import { autoUpdate, flip, offset, size, useFloating } from '@floating-ui/react-dom';
2
+ import { DROPDOWN_MAX_WIDTH } from './constants';
3
+ import { useOnClickOutside } from '../../hooks';
4
+ export function useDropdownPosition({
5
+ isOpen,
6
+ onClickOutside
7
+ }) {
8
+ const {
9
+ refs,
10
+ floatingStyles
11
+ } = useFloating({
12
+ open: isOpen,
13
+ strategy: 'fixed',
14
+ placement: 'bottom-start',
15
+ middleware: [offset(4), flip(), size({
16
+ apply({
17
+ rects,
18
+ elements,
19
+ availableWidth,
20
+ availableHeight
21
+ }) {
22
+ const maxWidth = Math.min(DROPDOWN_MAX_WIDTH, availableWidth);
23
+ Object.assign(elements.floating.style, {
24
+ minWidth: `${Math.min(rects.reference.width, maxWidth)}px`,
25
+ maxWidth: `${maxWidth}px`,
26
+ maxHeight: `${Math.max(0, availableHeight - 8)}px`
27
+ });
28
+ }
29
+ })],
30
+ whileElementsMounted: autoUpdate
31
+ });
32
+ useOnClickOutside([refs.reference, refs.floating], () => {
33
+ if (isOpen) onClickOutside === null || onClickOutside === void 0 || onClickOutside();
34
+ });
35
+ return {
36
+ setReference: refs.setReference,
37
+ setFloating: refs.setFloating,
38
+ floatingStyles
39
+ };
40
+ }
@@ -0,0 +1,16 @@
1
+ import { type Dispatch, type KeyboardEvent, type SetStateAction } from 'react';
2
+ type Args = {
3
+ isOpen: boolean;
4
+ open: () => void;
5
+ itemCount: number;
6
+ activeIndex: number;
7
+ setActiveIndex: Dispatch<SetStateAction<number>>;
8
+ onSelectIndex: (index: number) => void;
9
+ onEscape: () => void;
10
+ hasExtraRow?: boolean;
11
+ onSelectExtra?: () => void;
12
+ isQueryEmpty?: boolean;
13
+ onBackspaceEmpty?: () => void;
14
+ };
15
+ export declare function useListNavigation({ isOpen, open, itemCount, activeIndex, setActiveIndex, onSelectIndex, onEscape, hasExtraRow, onSelectExtra, isQueryEmpty, onBackspaceEmpty, }: Args): (event: KeyboardEvent<HTMLInputElement>) => void;
16
+ export {};
@@ -0,0 +1,45 @@
1
+ import { useCallback } from 'react';
2
+ export function useListNavigation({
3
+ isOpen,
4
+ open,
5
+ itemCount,
6
+ activeIndex,
7
+ setActiveIndex,
8
+ onSelectIndex,
9
+ onEscape,
10
+ hasExtraRow,
11
+ onSelectExtra,
12
+ isQueryEmpty,
13
+ onBackspaceEmpty
14
+ }) {
15
+ const total = itemCount + (hasExtraRow ? 1 : 0);
16
+ return useCallback(event => {
17
+ if (event.key === 'ArrowDown') {
18
+ event.preventDefault();
19
+ if (!isOpen) open();else if (total > 0) setActiveIndex(prev => prev >= total - 1 ? 0 : prev + 1);
20
+ return;
21
+ }
22
+ if (event.key === 'ArrowUp') {
23
+ event.preventDefault();
24
+ if (!isOpen) open();else if (total > 0) setActiveIndex(prev => prev <= 0 ? total - 1 : prev - 1);
25
+ return;
26
+ }
27
+ if (event.key === 'Enter') {
28
+ if (!isOpen || activeIndex < 0 || activeIndex >= total) return;
29
+ event.preventDefault();
30
+ if (hasExtraRow && activeIndex === 0) onSelectExtra === null || onSelectExtra === void 0 || onSelectExtra();else onSelectIndex(hasExtraRow ? activeIndex - 1 : activeIndex);
31
+ return;
32
+ }
33
+ if (event.key === 'Escape') {
34
+ if (isOpen) {
35
+ event.preventDefault();
36
+ event.stopPropagation();
37
+ onEscape();
38
+ }
39
+ return;
40
+ }
41
+ if (event.key === 'Backspace' && isQueryEmpty && onBackspaceEmpty) {
42
+ onBackspaceEmpty();
43
+ }
44
+ }, [isOpen, open, total, activeIndex, setActiveIndex, onSelectIndex, onSelectExtra, onEscape, hasExtraRow, isQueryEmpty, onBackspaceEmpty]);
45
+ }