@faststore/components 3.0.135 → 3.0.144
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/dist/cjs/atoms/Button/index.d.ts +1 -1
- package/dist/cjs/molecules/Dropdown/Dropdown.d.ts +1 -1
- package/dist/cjs/molecules/Dropdown/Dropdown.js +20 -16
- package/dist/cjs/molecules/Dropdown/Dropdown.js.map +1 -1
- package/dist/cjs/molecules/Dropdown/DropdownButton.d.ts +23 -5
- package/dist/cjs/molecules/Dropdown/DropdownButton.js +7 -7
- package/dist/cjs/molecules/Dropdown/DropdownButton.js.map +1 -1
- package/dist/cjs/molecules/Dropdown/DropdownItem.d.ts +9 -0
- package/dist/cjs/molecules/Dropdown/DropdownItem.js +8 -23
- package/dist/cjs/molecules/Dropdown/DropdownItem.js.map +1 -1
- package/dist/cjs/molecules/Dropdown/DropdownMenu.d.ts +7 -3
- package/dist/cjs/molecules/Dropdown/DropdownMenu.js +39 -11
- package/dist/cjs/molecules/Dropdown/DropdownMenu.js.map +1 -1
- package/dist/cjs/molecules/Dropdown/contexts/DropdownContext.d.ts +8 -8
- package/dist/cjs/molecules/Dropdown/contexts/DropdownContext.js +1 -1
- package/dist/cjs/molecules/Dropdown/contexts/DropdownContext.js.map +1 -1
- package/dist/cjs/molecules/Dropdown/hooks/useDropdown.d.ts +1 -1
- package/dist/cjs/molecules/Dropdown/hooks/useDropdown.js.map +1 -1
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownItem.d.ts +15 -0
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownItem.js +37 -0
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownItem.js.map +1 -0
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownPosition.d.ts +4 -2
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownPosition.js +55 -18
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownPosition.js.map +1 -1
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownTrigger.d.ts +13 -0
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownTrigger.js +20 -0
- package/dist/cjs/molecules/Dropdown/hooks/useDropdownTrigger.js.map +1 -0
- package/dist/cjs/molecules/QuantitySelector/QuantitySelector.js +6 -2
- package/dist/cjs/molecules/QuantitySelector/QuantitySelector.js.map +1 -1
- package/dist/esm/atoms/Button/index.d.ts +1 -1
- package/dist/esm/molecules/Dropdown/Dropdown.d.ts +1 -1
- package/dist/esm/molecules/Dropdown/Dropdown.js +20 -16
- package/dist/esm/molecules/Dropdown/Dropdown.js.map +1 -1
- package/dist/esm/molecules/Dropdown/DropdownButton.d.ts +23 -5
- package/dist/esm/molecules/Dropdown/DropdownButton.js +8 -8
- package/dist/esm/molecules/Dropdown/DropdownButton.js.map +1 -1
- package/dist/esm/molecules/Dropdown/DropdownItem.d.ts +9 -0
- package/dist/esm/molecules/Dropdown/DropdownItem.js +9 -24
- package/dist/esm/molecules/Dropdown/DropdownItem.js.map +1 -1
- package/dist/esm/molecules/Dropdown/DropdownMenu.d.ts +7 -3
- package/dist/esm/molecules/Dropdown/DropdownMenu.js +39 -11
- package/dist/esm/molecules/Dropdown/DropdownMenu.js.map +1 -1
- package/dist/esm/molecules/Dropdown/contexts/DropdownContext.d.ts +8 -8
- package/dist/esm/molecules/Dropdown/contexts/DropdownContext.js +1 -1
- package/dist/esm/molecules/Dropdown/contexts/DropdownContext.js.map +1 -1
- package/dist/esm/molecules/Dropdown/hooks/useDropdown.d.ts +1 -1
- package/dist/esm/molecules/Dropdown/hooks/useDropdown.js.map +1 -1
- package/dist/esm/molecules/Dropdown/hooks/useDropdownItem.d.ts +15 -0
- package/dist/esm/molecules/Dropdown/hooks/useDropdownItem.js +33 -0
- package/dist/esm/molecules/Dropdown/hooks/useDropdownItem.js.map +1 -0
- package/dist/esm/molecules/Dropdown/hooks/useDropdownPosition.d.ts +4 -2
- package/dist/esm/molecules/Dropdown/hooks/useDropdownPosition.js +55 -18
- package/dist/esm/molecules/Dropdown/hooks/useDropdownPosition.js.map +1 -1
- package/dist/esm/molecules/Dropdown/hooks/useDropdownTrigger.d.ts +13 -0
- package/dist/esm/molecules/Dropdown/hooks/useDropdownTrigger.js +16 -0
- package/dist/esm/molecules/Dropdown/hooks/useDropdownTrigger.js.map +1 -0
- package/dist/esm/molecules/QuantitySelector/QuantitySelector.js +6 -2
- package/dist/esm/molecules/QuantitySelector/QuantitySelector.js.map +1 -1
- package/package.json +2 -2
- package/src/atoms/Button/index.ts +1 -1
- package/src/molecules/Dropdown/Dropdown.tsx +27 -18
- package/src/molecules/Dropdown/DropdownButton.tsx +45 -32
- package/src/molecules/Dropdown/DropdownItem.tsx +39 -47
- package/src/molecules/Dropdown/DropdownMenu.tsx +58 -18
- package/src/molecules/Dropdown/contexts/DropdownContext.ts +11 -9
- package/src/molecules/Dropdown/hooks/useDropdown.ts +3 -3
- package/src/molecules/Dropdown/hooks/useDropdownItem.ts +56 -0
- package/src/molecules/Dropdown/hooks/useDropdownPosition.ts +62 -19
- package/src/molecules/Dropdown/hooks/useDropdownTrigger.ts +26 -0
- package/src/molecules/QuantitySelector/QuantitySelector.tsx +6 -1
|
@@ -1,25 +1,62 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
1
2
|
import { useDropdown } from './useDropdown';
|
|
2
3
|
/**
|
|
3
4
|
* Hook used to find the DropdownMenu position in relation to DropdownButton
|
|
4
5
|
* @returns Style with positions.
|
|
5
6
|
*/
|
|
6
|
-
export const useDropdownPosition = () => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
7
|
+
export const useDropdownPosition = (align = 'left') => {
|
|
8
|
+
const { dropdownTriggerRef, isOpen } = useDropdown();
|
|
9
|
+
const [positionProps, setPositionProps] = useState({
|
|
10
|
+
top: 0,
|
|
11
|
+
left: 0,
|
|
12
|
+
right: 'auto',
|
|
13
|
+
transform: 'none',
|
|
14
|
+
loading: true
|
|
15
|
+
});
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const updateMenuPosition = () => {
|
|
18
|
+
// Necessary to use this component in SSR
|
|
19
|
+
const isBrowser = typeof window !== 'undefined';
|
|
20
|
+
if (!dropdownTriggerRef?.current)
|
|
21
|
+
return;
|
|
22
|
+
const buttonRect = dropdownTriggerRef.current.getBoundingClientRect();
|
|
23
|
+
const topLevel = buttonRect?.top ?? 0;
|
|
24
|
+
const topOffset = buttonRect?.height ?? 0;
|
|
25
|
+
const leftLevel = buttonRect?.left ?? 0;
|
|
26
|
+
const buttonWidth = buttonRect?.width ?? 0;
|
|
27
|
+
// The scroll properties fix the position of DropdownMenu when the scroll is activated.
|
|
28
|
+
const scrollTop = isBrowser ? document?.documentElement?.scrollTop : 0;
|
|
29
|
+
const scrollLeft = isBrowser ? document?.documentElement?.scrollLeft : 0;
|
|
30
|
+
const topPosition = topLevel + topOffset + scrollTop;
|
|
31
|
+
let leftPosition = leftLevel + scrollLeft;
|
|
32
|
+
let rightPosition = 'auto';
|
|
33
|
+
let transform = 'none';
|
|
34
|
+
if (align === 'right') {
|
|
35
|
+
rightPosition = `${document.documentElement.clientWidth - leftLevel - buttonWidth}px`;
|
|
36
|
+
leftPosition = 'auto';
|
|
37
|
+
}
|
|
38
|
+
else if (align === 'center') {
|
|
39
|
+
leftPosition = leftLevel + (buttonWidth / 2) + scrollLeft;
|
|
40
|
+
transform = 'translateX(-50%)';
|
|
41
|
+
}
|
|
42
|
+
setPositionProps({
|
|
43
|
+
top: topPosition,
|
|
44
|
+
left: leftPosition,
|
|
45
|
+
right: rightPosition,
|
|
46
|
+
transform,
|
|
47
|
+
loading: false
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
if (isOpen) {
|
|
51
|
+
// Update the position of the menu
|
|
52
|
+
updateMenuPosition();
|
|
53
|
+
window.addEventListener('resize', updateMenuPosition);
|
|
54
|
+
}
|
|
55
|
+
// Cleanup listener on unmount or close
|
|
56
|
+
return () => {
|
|
57
|
+
window.removeEventListener('resize', updateMenuPosition);
|
|
58
|
+
};
|
|
59
|
+
}, [dropdownTriggerRef, isOpen, align]);
|
|
60
|
+
return { ...positionProps, position: 'absolute' };
|
|
24
61
|
};
|
|
25
62
|
//# sourceMappingURL=useDropdownPosition.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDropdownPosition.js","sourceRoot":"","sources":["../../../../../src/molecules/Dropdown/hooks/useDropdownPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"useDropdownPosition.js","sourceRoot":"","sources":["../../../../../src/molecules/Dropdown/hooks/useDropdownPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAM3C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAqC,MAAM,EAAoB,EAAE;IACnG,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,CAAA;IAEpD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAC;QACjD,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,CAAgC;QACtC,KAAK,EAAE,MAAM;QACb,SAAS,EAAE,MAAM;QACjB,OAAO,EAAE,IAAI;KACd,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,kBAAkB,GAAG,GAAG,EAAE;YAC9B,yCAAyC;YACzC,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAA;YAE/C,IAAI,CAAC,kBAAkB,EAAE,OAAO;g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CAAA;QAED,IAAI,MAAM,EAAE;YACV,kCAAkC;YAClC,kBAAkB,EAAE,CAAA;YACpB,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAA;SACtD;QAED,uCAAuC;QACvC,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAA;QAC1D,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,kBAAkB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAA;IAEvC,OAAO,EAAE,GAAG,aAAa,EAAE,QAAQ,EAAE,UAAmB,EAAE,CAAA;AAC5D,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type UseDropdownTriggerProps<T extends HTMLElement = HTMLElement> = {
|
|
3
|
+
triggerRef: React.ForwardedRef<T>;
|
|
4
|
+
label?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const useDropdownTrigger: <T extends HTMLElement = HTMLElement>({ triggerRef, }: UseDropdownTriggerProps<T>) => {
|
|
7
|
+
onClick: (() => void) | undefined;
|
|
8
|
+
ref: ((ref: T | null) => void) | undefined;
|
|
9
|
+
'aria-expanded': boolean;
|
|
10
|
+
'aria-controls': string;
|
|
11
|
+
'aria-haspopup': "menu";
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useDropdown } from './useDropdown';
|
|
2
|
+
import { useImperativeHandle } from 'react';
|
|
3
|
+
export const useDropdownTrigger = ({ triggerRef, }) => {
|
|
4
|
+
const { toggle, dropdownTriggerRef, addDropdownTriggerRef, isOpen, id } = useDropdown();
|
|
5
|
+
useImperativeHandle(triggerRef, () => dropdownTriggerRef.current, [
|
|
6
|
+
dropdownTriggerRef,
|
|
7
|
+
]);
|
|
8
|
+
return {
|
|
9
|
+
onClick: toggle,
|
|
10
|
+
ref: addDropdownTriggerRef,
|
|
11
|
+
'aria-expanded': isOpen,
|
|
12
|
+
'aria-controls': id,
|
|
13
|
+
'aria-haspopup': 'menu',
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=useDropdownTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDropdownTrigger.js","sourceRoot":"","sources":["../../../../../src/molecules/Dropdown/hooks/useDropdownTrigger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAc,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAA;AAOlD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAsC,EACtE,UAAU,GACiB,EAAE,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,EAAE,EAAE,EAAE,GACrE,WAAW,EAAK,CAAA;IAElB,mBAAmB,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,kBAAmB,CAAC,OAAQ,EAAE;QAClE,kBAAkB;KACnB,CAAC,CAAA;IAEF,OAAO;QACL,OAAO,EAAE,MAAM;QACf,GAAG,EAAE,qBAAqB;QAC1B,eAAe,EAAE,MAAM;QACvB,eAAe,EAAE,EAAE;QACnB,eAAe,EAAE,MAAe;KACjC,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -43,11 +43,15 @@ const QuantitySelector = ({ max, min = 1, unitMultiplier = 1, useUnitMultiplier,
|
|
|
43
43
|
initial && setQuantity(initial);
|
|
44
44
|
}, [initial]);
|
|
45
45
|
const changeInputValue = (e) => {
|
|
46
|
-
|
|
46
|
+
const numericValue = e.target.value.replace(/\D/g, '');
|
|
47
|
+
setQuantity(Number(numericValue));
|
|
47
48
|
};
|
|
48
49
|
return (React.createElement("div", { "data-fs-quantity-selector": disabled ? 'disabled' : 'true', "data-testid": testId, ...otherProps },
|
|
49
50
|
React.createElement(IconButton, { "data-quantity-selector-button": "left", icon: React.createElement(Icon, { name: "Minus", width: 16, height: 16, weight: "bold" }), "aria-label": "Decrement Quantity", "aria-controls": "quantity-selector-input", disabled: isLeftDisabled || disabled, onClick: decrease, testId: `${testId}-left-button`, size: "small" }),
|
|
50
|
-
React.createElement(Input, { "data-quantity-selector-input": true, id: "quantity-selector-input", "aria-label": "Quantity", value: useUnitMultiplier ? multipliedUnit : quantity, onChange: changeInputValue, onBlur: validateBlur,
|
|
51
|
+
React.createElement(Input, { "data-quantity-selector-input": true, id: "quantity-selector-input", "aria-label": "Quantity", value: useUnitMultiplier ? multipliedUnit : quantity, onChange: changeInputValue, onBlur: validateBlur, onInput: (event) => {
|
|
52
|
+
const input = event.currentTarget;
|
|
53
|
+
input.value = input.value.replace(/\D/g, '');
|
|
54
|
+
}, disabled: disabled }),
|
|
51
55
|
React.createElement(IconButton, { "data-quantity-selector-button": "right", "aria-controls": "quantity-selector-input", "aria-label": "Increment Quantity", disabled: isRightDisabled || disabled, icon: React.createElement(Icon, { name: "Plus", width: 16, height: 16, weight: "bold" }), onClick: increase, testId: `${testId}-right-button`, size: "small" })));
|
|
52
56
|
};
|
|
53
57
|
export default QuantitySelector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuantitySelector.js","sourceRoot":"","sources":["../../../../src/molecules/QuantitySelector/QuantitySelector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAElD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AA2ChD,MAAM,gBAAgB,GAAG,CAAC,EACxB,GAAG,EACH,GAAG,GAAG,CAAC,EACP,cAAc,GAAG,CAAC,EAClB,iBAAiB,EACjB,OAAO,EACP,QAAQ,GAAG,KAAK,EAChB,QAAQ,EACR,cAAc,EACd,MAAM,GAAG,sBAAsB,EAC/B,GAAG,UAAU,EACS,EAAE,EAAE;IAC1B,MAAM,CAAC,QAA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name": "@faststore/components",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.144",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"typings": "dist/esm/index.d.ts",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"volta": {
|
|
53
53
|
"extends": "../../package.json"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "90c18b6ff88534e99b479e2ece4e156af16b011d"
|
|
56
56
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from './Button'
|
|
2
|
-
export type { ButtonProps } from './Button'
|
|
2
|
+
export type { ButtonProps, Variant as ButtonVariant, Size as ButtonSize, IconPosition as ButtonIconPosition } from './Button'
|
|
@@ -20,38 +20,47 @@ export interface DropdownProps {
|
|
|
20
20
|
|
|
21
21
|
const Dropdown = ({
|
|
22
22
|
children,
|
|
23
|
-
isOpen:
|
|
23
|
+
isOpen: isOpenControlled,
|
|
24
24
|
onDismiss,
|
|
25
25
|
id = 'fs-dropdown',
|
|
26
26
|
}: PropsWithChildren<DropdownProps>) => {
|
|
27
|
-
const [
|
|
28
|
-
const dropdownItemsRef = useRef<
|
|
27
|
+
const [isOpenInternal, setIsOpenInternal] = useState(false)
|
|
28
|
+
const dropdownItemsRef = useRef<HTMLElement[]>([])
|
|
29
29
|
const selectedDropdownItemIndexRef = useRef(0)
|
|
30
|
-
const
|
|
30
|
+
const dropdownTriggerRef = useRef<HTMLElement | null>(null)
|
|
31
|
+
|
|
32
|
+
const isOpen = isOpenControlled ?? isOpenInternal
|
|
31
33
|
|
|
32
34
|
const close = useCallback(() => {
|
|
33
|
-
|
|
35
|
+
setIsOpenInternal(false)
|
|
34
36
|
onDismiss?.()
|
|
35
37
|
}, [onDismiss])
|
|
36
38
|
|
|
37
39
|
const open = () => {
|
|
38
|
-
|
|
40
|
+
setIsOpenInternal(true)
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
const toggle = useCallback(() => {
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
+
setIsOpenInternal((currentIsOpen) => {
|
|
45
|
+
if (currentIsOpen) {
|
|
44
46
|
onDismiss?.()
|
|
45
|
-
|
|
47
|
+
dropdownTriggerRef.current?.focus()
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
return !
|
|
50
|
+
return !currentIsOpen
|
|
49
51
|
})
|
|
50
52
|
}, [onDismiss])
|
|
51
53
|
|
|
54
|
+
const addDropdownTriggerRef = useCallback(
|
|
55
|
+
<T extends HTMLElement = HTMLElement>(ref: T) => {
|
|
56
|
+
dropdownTriggerRef.current = ref
|
|
57
|
+
},
|
|
58
|
+
[]
|
|
59
|
+
)
|
|
60
|
+
|
|
52
61
|
useEffect(() => {
|
|
53
|
-
|
|
54
|
-
}, [
|
|
62
|
+
setIsOpenInternal(isOpenControlled ?? false)
|
|
63
|
+
}, [isOpenControlled])
|
|
55
64
|
|
|
56
65
|
useEffect(() => {
|
|
57
66
|
isOpen && dropdownItemsRef?.current[0]?.focus()
|
|
@@ -61,8 +70,8 @@ const Dropdown = ({
|
|
|
61
70
|
let firstClick = true
|
|
62
71
|
|
|
63
72
|
const event = (e: MouseEvent) => {
|
|
64
|
-
const
|
|
65
|
-
(item) => e.target === item
|
|
73
|
+
const wasSomeItemClicked = dropdownItemsRef?.current.some(
|
|
74
|
+
(item) => e.target === item || item.contains(e.target as Node)
|
|
66
75
|
)
|
|
67
76
|
|
|
68
77
|
if (firstClick) {
|
|
@@ -71,7 +80,7 @@ const Dropdown = ({
|
|
|
71
80
|
return
|
|
72
81
|
}
|
|
73
82
|
|
|
74
|
-
!
|
|
83
|
+
!wasSomeItemClicked && close()
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
if (isOpen) {
|
|
@@ -91,13 +100,13 @@ const Dropdown = ({
|
|
|
91
100
|
close,
|
|
92
101
|
open,
|
|
93
102
|
toggle,
|
|
94
|
-
|
|
95
|
-
|
|
103
|
+
dropdownTriggerRef,
|
|
104
|
+
addDropdownTriggerRef,
|
|
96
105
|
selectedDropdownItemIndexRef,
|
|
97
106
|
dropdownItemsRef,
|
|
98
107
|
id,
|
|
99
108
|
}
|
|
100
|
-
}, [
|
|
109
|
+
}, [isOpen, close, toggle, addDropdownTriggerRef, id])
|
|
101
110
|
|
|
102
111
|
return (
|
|
103
112
|
<DropdownContext.Provider value={value}>
|
|
@@ -1,51 +1,64 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import Button, { ButtonProps } from '../../atoms/Button'
|
|
3
|
-
|
|
4
|
-
import { useDropdown } from './hooks/useDropdown'
|
|
1
|
+
import React, { cloneElement, forwardRef, ReactNode } from 'react'
|
|
2
|
+
import Button, { ButtonProps, ButtonIconPosition } from '../../atoms/Button'
|
|
3
|
+
import { useDropdownTrigger } from './hooks/useDropdownTrigger'
|
|
5
4
|
|
|
6
5
|
export interface DropdownButtonProps
|
|
7
|
-
extends Omit<ButtonProps, 'variant' | 'inverse'> {
|
|
6
|
+
extends Omit<ButtonProps, 'variant' | 'inverse' | 'icon' | 'iconPosition'> {
|
|
8
7
|
/**
|
|
9
8
|
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
10
9
|
*/
|
|
11
10
|
testId?: string
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* Replace the default rendered element with the provided child element, merging their props and behavior.
|
|
13
|
+
*/
|
|
14
|
+
asChild?: boolean
|
|
15
|
+
/**
|
|
16
|
+
* Boolean that represents a loading state.
|
|
17
|
+
*/
|
|
18
|
+
loading?: boolean
|
|
19
|
+
/**
|
|
20
|
+
* Specifies a label for loading state.
|
|
21
|
+
*/
|
|
22
|
+
loadingLabel?: string
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated
|
|
25
|
+
* A React component that will be rendered as an icon.
|
|
26
|
+
*/
|
|
27
|
+
icon?: ReactNode
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated
|
|
30
|
+
* Specifies where the icon should be positioned
|
|
14
31
|
*/
|
|
15
|
-
|
|
32
|
+
iconPosition?: ButtonIconPosition
|
|
16
33
|
}
|
|
17
34
|
|
|
18
35
|
const DropdownButton = forwardRef<HTMLButtonElement, DropdownButtonProps>(
|
|
19
36
|
function DropdownButton(
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
'aria-label': ariaLabel,
|
|
23
|
-
children,
|
|
24
|
-
...otherProps
|
|
25
|
-
},
|
|
26
|
-
ref
|
|
37
|
+
{ testId = 'fs-dropdown-button', children, asChild = false, ...otherProps },
|
|
38
|
+
triggerRef
|
|
27
39
|
) {
|
|
28
|
-
const
|
|
40
|
+
const triggerProps = useDropdownTrigger({ triggerRef })
|
|
29
41
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
const asChildrenTrigger = React.isValidElement(children)
|
|
43
|
+
? cloneElement(children, { ...triggerProps, ...children.props })
|
|
44
|
+
: children
|
|
33
45
|
|
|
34
46
|
return (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
<>
|
|
48
|
+
{asChild ? (
|
|
49
|
+
asChildrenTrigger
|
|
50
|
+
) : (
|
|
51
|
+
<Button
|
|
52
|
+
data-fs-dropdown-button
|
|
53
|
+
data-testid={testId}
|
|
54
|
+
variant="tertiary"
|
|
55
|
+
{...triggerProps}
|
|
56
|
+
{...otherProps}
|
|
57
|
+
>
|
|
58
|
+
{children}
|
|
59
|
+
</Button>
|
|
60
|
+
)}
|
|
61
|
+
</>
|
|
49
62
|
)
|
|
50
63
|
}
|
|
51
64
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ButtonHTMLAttributes, ReactNode } from 'react'
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { cloneElement, forwardRef } from 'react'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { useDropdownItem } from './hooks/useDropdownItem'
|
|
5
5
|
|
|
6
6
|
export interface DropdownItemProps
|
|
7
7
|
extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
@@ -10,63 +10,55 @@ export interface DropdownItemProps
|
|
|
10
10
|
*/
|
|
11
11
|
testId?: string
|
|
12
12
|
/**
|
|
13
|
+
* @deprecated
|
|
13
14
|
* A React component that will be rendered as an icon.
|
|
14
15
|
*/
|
|
15
16
|
icon?: ReactNode
|
|
17
|
+
/**
|
|
18
|
+
* Replace the default rendered element with the one passed as a child, merging their props and behavior.
|
|
19
|
+
* */
|
|
20
|
+
asChild?: boolean
|
|
21
|
+
/**
|
|
22
|
+
* Emit onDismiss event when the component is clicked.
|
|
23
|
+
*/
|
|
24
|
+
dismissOnClick?: boolean
|
|
16
25
|
}
|
|
17
26
|
|
|
18
27
|
const DropdownItem = forwardRef<HTMLButtonElement, DropdownItemProps>(
|
|
19
28
|
function Button(
|
|
20
|
-
{
|
|
29
|
+
{
|
|
30
|
+
children,
|
|
31
|
+
asChild,
|
|
32
|
+
icon,
|
|
33
|
+
onClick,
|
|
34
|
+
dismissOnClick = true,
|
|
35
|
+
testId = 'fs-dropdown-item',
|
|
36
|
+
...otherProps
|
|
37
|
+
},
|
|
21
38
|
ref
|
|
22
39
|
) {
|
|
23
|
-
const {
|
|
24
|
-
useDropdown()
|
|
25
|
-
|
|
26
|
-
const [dropdownItemIndex, setDropdownItemIndex] = useState(0)
|
|
27
|
-
const dropdownItemRef = useRef<HTMLButtonElement>()
|
|
28
|
-
|
|
29
|
-
const addToRefs = (el: HTMLButtonElement) => {
|
|
30
|
-
if (el && !dropdownItemsRef?.current.includes(el)) {
|
|
31
|
-
dropdownItemsRef?.current.push(el)
|
|
32
|
-
setDropdownItemIndex(
|
|
33
|
-
dropdownItemsRef?.current.findIndex((element) => element === el) ?? 0
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
dropdownItemRef.current = el
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const onFocusItem = () => {
|
|
41
|
-
selectedDropdownItemIndexRef!.current = dropdownItemIndex
|
|
42
|
-
dropdownItemsRef?.current[selectedDropdownItemIndexRef!.current]?.focus()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const handleOnClickItem = (
|
|
46
|
-
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
|
|
47
|
-
) => {
|
|
48
|
-
onClick?.(event)
|
|
49
|
-
close?.()
|
|
50
|
-
}
|
|
40
|
+
const itemProps = useDropdownItem({ ref, onClick, dismissOnClick })
|
|
51
41
|
|
|
52
|
-
|
|
42
|
+
const asChildrenItem = React.isValidElement(children)
|
|
43
|
+
? cloneElement(children, { ...itemProps, ...children.props })
|
|
44
|
+
: children
|
|
53
45
|
|
|
54
46
|
return (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
47
|
+
<>
|
|
48
|
+
{asChild ? (
|
|
49
|
+
asChildrenItem
|
|
50
|
+
) : (
|
|
51
|
+
<button
|
|
52
|
+
data-fs-dropdown-item
|
|
53
|
+
data-testid={testId}
|
|
54
|
+
{...itemProps}
|
|
55
|
+
{...otherProps}
|
|
56
|
+
>
|
|
57
|
+
{!!icon && icon}
|
|
58
|
+
{children}
|
|
59
|
+
</button>
|
|
60
|
+
)}
|
|
61
|
+
</>
|
|
70
62
|
)
|
|
71
63
|
}
|
|
72
64
|
)
|
|
@@ -22,17 +22,19 @@ export interface DropdownMenuProps extends ModalContentProps {
|
|
|
22
22
|
* @see aria-labelledby https://www.w3.org/TR/wai-aria-1.1/#aria-labelledby
|
|
23
23
|
*/
|
|
24
24
|
'aria-labelledby'?: AriaAttributes['aria-label']
|
|
25
|
-
|
|
26
25
|
/**
|
|
27
26
|
* This function is called whenever the user hits "Escape" or clicks outside
|
|
28
27
|
* the dialog.
|
|
29
28
|
*/
|
|
30
29
|
onDismiss?: (event: MouseEvent | KeyboardEvent) => void
|
|
31
|
-
|
|
32
|
-
/**
|
|
30
|
+
/**
|
|
33
31
|
* Specifies the size variant.
|
|
34
32
|
*/
|
|
35
33
|
size?: 'small' | 'regular'
|
|
34
|
+
/**
|
|
35
|
+
* Alignment for the dropdown
|
|
36
|
+
*/
|
|
37
|
+
align?: 'left' | 'right' | 'center'
|
|
36
38
|
|
|
37
39
|
children: ReactNode[] | ReactNode
|
|
38
40
|
}
|
|
@@ -47,13 +49,20 @@ const DropdownMenu = ({
|
|
|
47
49
|
children,
|
|
48
50
|
testId = 'fs-dropdown-menu',
|
|
49
51
|
size = 'regular',
|
|
52
|
+
align = 'left',
|
|
50
53
|
style,
|
|
51
54
|
...otherProps
|
|
52
55
|
}: PropsWithChildren<DropdownMenuProps>) => {
|
|
53
|
-
const {
|
|
54
|
-
|
|
56
|
+
const {
|
|
57
|
+
isOpen,
|
|
58
|
+
close,
|
|
59
|
+
dropdownItemsRef,
|
|
60
|
+
selectedDropdownItemIndexRef,
|
|
61
|
+
dropdownTriggerRef,
|
|
62
|
+
id,
|
|
63
|
+
} = useDropdown()
|
|
55
64
|
|
|
56
|
-
const dropdownPosition = useDropdownPosition()
|
|
65
|
+
const { loading: loadingPosition, ...dropdownPosition } = useDropdownPosition(align)
|
|
57
66
|
|
|
58
67
|
const childrenLength = React.Children.toArray(children).length
|
|
59
68
|
|
|
@@ -89,25 +98,56 @@ const DropdownMenu = ({
|
|
|
89
98
|
|
|
90
99
|
const handleEscapePress = () => {
|
|
91
100
|
close?.()
|
|
92
|
-
|
|
101
|
+
dropdownTriggerRef?.current?.focus()
|
|
93
102
|
}
|
|
94
103
|
|
|
104
|
+
const handleKeyNavigatePress = (key: string) => {
|
|
105
|
+
const dropdownItems = dropdownItemsRef?.current ?? [];
|
|
106
|
+
const selectedIndex = selectedDropdownItemIndexRef!.current;
|
|
107
|
+
|
|
108
|
+
const rearrangedDropdownItems = [
|
|
109
|
+
...dropdownItems.slice(selectedIndex + 1),
|
|
110
|
+
...dropdownItems.slice(0, selectedIndex + 1),
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
const matchItem = rearrangedDropdownItems.find(
|
|
114
|
+
(item) => item.textContent?.[0]?.toLowerCase() === key.toLowerCase()
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if (matchItem) {
|
|
118
|
+
selectedDropdownItemIndexRef!.current = dropdownItems.indexOf(matchItem);
|
|
119
|
+
matchItem.focus();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
|
|
95
124
|
const handleBackdropKeyDown = (event: KeyboardEvent) => {
|
|
96
|
-
if (event.defaultPrevented || event.key === 'Enter') {
|
|
125
|
+
if (event.defaultPrevented || event.key === 'Enter' || event.key === ' ') {
|
|
97
126
|
return
|
|
98
127
|
}
|
|
99
128
|
|
|
100
129
|
event.preventDefault()
|
|
101
130
|
|
|
102
|
-
event.key
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
131
|
+
switch (event.key) {
|
|
132
|
+
case 'Escape':
|
|
133
|
+
handleEscapePress()
|
|
134
|
+
break
|
|
135
|
+
case 'ArrowDown':
|
|
136
|
+
handleDownPress()
|
|
137
|
+
break
|
|
138
|
+
case 'ArrowUp':
|
|
139
|
+
handleUpPress()
|
|
140
|
+
break
|
|
141
|
+
case 'Home':
|
|
142
|
+
handleHomePress()
|
|
143
|
+
break
|
|
144
|
+
case 'End':
|
|
145
|
+
handleEndPress()
|
|
146
|
+
break
|
|
147
|
+
default:
|
|
148
|
+
handleKeyNavigatePress(event.key)
|
|
149
|
+
break
|
|
150
|
+
}
|
|
111
151
|
|
|
112
152
|
event.stopPropagation()
|
|
113
153
|
}
|
|
@@ -118,7 +158,7 @@ const DropdownMenu = ({
|
|
|
118
158
|
return null
|
|
119
159
|
}
|
|
120
160
|
|
|
121
|
-
return isOpen
|
|
161
|
+
return (isOpen && !loadingPosition)
|
|
122
162
|
? createPortal(
|
|
123
163
|
<div
|
|
124
164
|
role="presentation"
|