@pushwoosh/dumb-components 2.9.9 → 2.9.11
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/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/shared/dropdownField/__tests__/useDropdownPosition.test.d.ts +1 -0
- package/shared/dropdownField/__tests__/useDropdownPosition.test.js +60 -0
- package/shared/dropdownField/constants.d.ts +1 -1
- package/shared/dropdownField/constants.js +1 -1
- package/shared/dropdownField/useDropdownPosition.js +2 -2
package/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { DatePicker, DatePickerField, DateTimePicker, DateTimePickerField, } fro
|
|
|
12
12
|
export { DropdownMenu, DropdownMenuButton, DropdownMenuSection, DropdownMenuItem, DropdownMenuSubmenu, } from './DropdownMenu';
|
|
13
13
|
export { GetStartedPage } from './GetStartedPage';
|
|
14
14
|
export { EditableField } from './EditableField';
|
|
15
|
+
export { EmojiPicker } from './EmojiPicker';
|
|
15
16
|
export { InputFile } from './InputFile';
|
|
16
17
|
export { Modal, ModalTitle, ModalConfirm, ModalConfirmProvider, useModalConfirm, ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter, } from './Modal';
|
|
17
18
|
export { Pagination } from './Pagination';
|
package/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export { DatePicker, DatePickerField, DateTimePicker, DateTimePickerField } from
|
|
|
12
12
|
export { DropdownMenu, DropdownMenuButton, DropdownMenuSection, DropdownMenuItem, DropdownMenuSubmenu } from './DropdownMenu';
|
|
13
13
|
export { GetStartedPage } from './GetStartedPage';
|
|
14
14
|
export { EditableField } from './EditableField';
|
|
15
|
+
export { EmojiPicker } from './EmojiPicker';
|
|
15
16
|
export { InputFile } from './InputFile';
|
|
16
17
|
export { Modal, ModalTitle, ModalConfirm, ModalConfirmProvider, useModalConfirm, ModalHeader, ModalBodyGroup, ModalBodyItem, ModalBody, ModalFooter } from './Modal';
|
|
17
18
|
export { Pagination } from './Pagination';
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react';
|
|
2
|
+
import { useDropdownPosition } from '../useDropdownPosition';
|
|
3
|
+
const floating = {
|
|
4
|
+
middleware: []
|
|
5
|
+
};
|
|
6
|
+
jest.mock('@floating-ui/react-dom', () => ({
|
|
7
|
+
...jest.requireActual('@floating-ui/react-dom'),
|
|
8
|
+
size: options => ({
|
|
9
|
+
name: 'size',
|
|
10
|
+
options
|
|
11
|
+
}),
|
|
12
|
+
useFloating: config => {
|
|
13
|
+
floating.middleware = config.middleware;
|
|
14
|
+
return {
|
|
15
|
+
refs: {
|
|
16
|
+
reference: {
|
|
17
|
+
current: null
|
|
18
|
+
},
|
|
19
|
+
floating: {
|
|
20
|
+
current: null
|
|
21
|
+
},
|
|
22
|
+
setReference: jest.fn(),
|
|
23
|
+
setFloating: jest.fn()
|
|
24
|
+
},
|
|
25
|
+
floatingStyles: {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
const maxHeightFor = availableHeight => {
|
|
30
|
+
renderHook(() => useDropdownPosition({
|
|
31
|
+
isOpen: true
|
|
32
|
+
}));
|
|
33
|
+
const style = {};
|
|
34
|
+
floating.middleware.find(m => m.name === 'size').options.apply({
|
|
35
|
+
rects: {
|
|
36
|
+
reference: {
|
|
37
|
+
width: 200
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
elements: {
|
|
41
|
+
floating: {
|
|
42
|
+
style
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
availableWidth: 1000,
|
|
46
|
+
availableHeight
|
|
47
|
+
});
|
|
48
|
+
return style.maxHeight;
|
|
49
|
+
};
|
|
50
|
+
describe('useDropdownPosition max height', () => {
|
|
51
|
+
it('caps the dropdown at 300px when there is more room', () => {
|
|
52
|
+
expect(maxHeightFor(1200)).toBe('300px');
|
|
53
|
+
});
|
|
54
|
+
it('shrinks to the room below the field when it is less than the cap', () => {
|
|
55
|
+
expect(maxHeightFor(200)).toBe('192px');
|
|
56
|
+
});
|
|
57
|
+
it('never goes negative', () => {
|
|
58
|
+
expect(maxHeightFor(4)).toBe('0px');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Color } from '@pushwoosh/kit-constants';
|
|
2
2
|
export declare const LOADING_BORDER_COLORS: readonly [Color.PRIMARY, Color.BRIGHT, Color.BRAND_GREEN, Color.EXCEPTIONAL];
|
|
3
3
|
export declare const LOADING_BORDER_ANIMATION_MS = 3000;
|
|
4
|
-
export declare const DROPDOWN_MAX_HEIGHT =
|
|
4
|
+
export declare const DROPDOWN_MAX_HEIGHT = 300;
|
|
5
5
|
/** Default dropdown width cap. A field wider than this stretches the dropdown to its own width only when the field opts in via `fullWidth`; otherwise the dropdown stays capped here. */
|
|
6
6
|
export declare const DROPDOWN_DEFAULT_WIDTH = 320;
|
|
7
7
|
/** Default debounce (ms) before an async `loadItems` call fires after the query changes. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Color } from '@pushwoosh/kit-constants';
|
|
2
2
|
export const LOADING_BORDER_COLORS = [Color.PRIMARY, Color.BRIGHT, Color.BRAND_GREEN, Color.EXCEPTIONAL];
|
|
3
3
|
export const LOADING_BORDER_ANIMATION_MS = 3000;
|
|
4
|
-
export const DROPDOWN_MAX_HEIGHT =
|
|
4
|
+
export const DROPDOWN_MAX_HEIGHT = 300;
|
|
5
5
|
/** Default dropdown width cap. A field wider than this stretches the dropdown to its own width only when the field opts in via `fullWidth`; otherwise the dropdown stays capped here. */
|
|
6
6
|
export const DROPDOWN_DEFAULT_WIDTH = 320;
|
|
7
7
|
/** Default debounce (ms) before an async `loadItems` call fires after the query changes. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { autoUpdate, flip, offset, size, useFloating } from '@floating-ui/react-dom';
|
|
2
|
-
import { DROPDOWN_DEFAULT_WIDTH } from './constants';
|
|
2
|
+
import { DROPDOWN_DEFAULT_WIDTH, DROPDOWN_MAX_HEIGHT } from './constants';
|
|
3
3
|
import { useOnClickOutside } from '../../hooks';
|
|
4
4
|
/**
|
|
5
5
|
* Positions the dropdown relative to the field via floating-ui (flip, offset,
|
|
@@ -32,7 +32,7 @@ export function useDropdownPosition({
|
|
|
32
32
|
Object.assign(elements.floating.style, {
|
|
33
33
|
minWidth: `${minWidth}px`,
|
|
34
34
|
maxWidth: `${maxWidth}px`,
|
|
35
|
-
maxHeight: `${Math.max(0, availableHeight - 8)}px`
|
|
35
|
+
maxHeight: `${Math.max(0, Math.min(DROPDOWN_MAX_HEIGHT, availableHeight - 8))}px`
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
})],
|