@faststore/ui 1.6.16 → 1.6.19
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/CHANGELOG.md +33 -0
- package/dist/index.d.ts +2 -0
- package/dist/molecules/Dropdown/Dropdown.d.ts +9 -0
- package/dist/molecules/Dropdown/DropdownButton.d.ts +10 -0
- package/dist/molecules/Dropdown/DropdownItem.d.ts +10 -0
- package/dist/molecules/Dropdown/DropdownMenu.d.ts +22 -0
- package/dist/molecules/Dropdown/contexts/DropdownContext.d.ts +41 -0
- package/dist/molecules/Dropdown/hooks/useDropdown.d.ts +6 -0
- package/dist/molecules/Dropdown/hooks/useDropdownPosition.d.ts +11 -0
- package/dist/molecules/Dropdown/index.d.ts +8 -0
- package/dist/molecules/Dropdown/stories/Dropdown.stories.d.ts +7 -0
- package/dist/molecules/Dropdown/stories/assets/Caret.d.ts +2 -0
- package/dist/ui.cjs.development.js +286 -3
- package/dist/ui.cjs.development.js.map +1 -1
- package/dist/ui.cjs.production.min.js +1 -1
- package/dist/ui.cjs.production.min.js.map +1 -1
- package/dist/ui.esm.js +283 -4
- package/dist/ui.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +13 -0
- package/src/molecules/Dropdown/Dropdown.test.tsx +159 -0
- package/src/molecules/Dropdown/Dropdown.tsx +65 -0
- package/src/molecules/Dropdown/DropdownButton.tsx +42 -0
- package/src/molecules/Dropdown/DropdownItem.tsx +72 -0
- package/src/molecules/Dropdown/DropdownMenu.tsx +156 -0
- package/src/molecules/Dropdown/contexts/DropdownContext.ts +53 -0
- package/src/molecules/Dropdown/hooks/useDropdown.ts +18 -0
- package/src/molecules/Dropdown/hooks/useDropdownPosition.ts +26 -0
- package/src/molecules/Dropdown/index.ts +11 -0
- package/src/molecules/Dropdown/stories/Dropdown.mdx +51 -0
- package/src/molecules/Dropdown/stories/Dropdown.stories.tsx +94 -0
- package/src/molecules/Dropdown/stories/assets/Caret.tsx +19 -0
- package/src/molecules/Modal/ModalContent.tsx +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 1.6.19 (2022-03-24)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Add exports to dropdown ([#1188](https://github.com/vtex/faststore/issues/1188)) ([f24359a](https://github.com/vtex/faststore/commit/f24359a34439e0ec8d3069483c31a6f62fa6535d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 1.6.18 (2022-03-24)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **api:** Add session mutation ([#1176](https://github.com/vtex/faststore/issues/1176)) ([0306167](https://github.com/vtex/faststore/commit/030616739cc62d9b5aa55cdf532ee6dea0bd793c))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## 1.6.17 (2022-03-23)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Features
|
|
32
|
+
|
|
33
|
+
* **UI:** Add dropdown component ([#1178](https://github.com/vtex/faststore/issues/1178)) ([e5153a6](https://github.com/vtex/faststore/commit/e5153a674c37bd2a8b4c65ae6f56eb5cabaf3fc8))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
6
39
|
## 1.6.16 (2022-03-23)
|
|
7
40
|
|
|
8
41
|
**Note:** Version bump only for package @faststore/ui
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ export { default as Alert } from './molecules/Alert';
|
|
|
66
66
|
export type { AlertProps } from './molecules/Alert';
|
|
67
67
|
export { default as QuantitySelector } from './molecules/QuantitySelector';
|
|
68
68
|
export type { QuantitySelectorProps } from './molecules/QuantitySelector';
|
|
69
|
+
export { default as Dropdown, DropdownButton, DropdownItem, DropdownMenu, } from './molecules/Dropdown';
|
|
70
|
+
export type { DropdownProps, DropdownButtonProps, DropdownItemProps, DropdownMenuProps, } from './molecules/Dropdown';
|
|
69
71
|
export { default as Card, CardImage, CardContent, CardActions, } from './organisms/Card';
|
|
70
72
|
export type { CardProps, CardImageProps, CardContentProps, CardActionsProps, } from './organisms/Card';
|
|
71
73
|
export { default as useSlider } from './hooks/useSlider';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export declare type DropdownProps = {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
onDismiss?(): void;
|
|
5
|
+
isOpen?: boolean;
|
|
6
|
+
id?: string;
|
|
7
|
+
};
|
|
8
|
+
declare const Dropdown: ({ children, isOpen: isOpenDefault, onDismiss, id, }: DropdownProps) => JSX.Element;
|
|
9
|
+
export default Dropdown;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface DropdownButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
4
|
+
/**
|
|
5
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
6
|
+
*/
|
|
7
|
+
testId?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const DropdownButton: React.ForwardRefExoticComponent<DropdownButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
10
|
+
export default DropdownButton;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ButtonHTMLAttributes } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export interface DropdownItemProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
4
|
+
/**
|
|
5
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
6
|
+
*/
|
|
7
|
+
testId?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const DropdownItem: React.ForwardRefExoticComponent<DropdownItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
10
|
+
export default DropdownItem;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AriaAttributes, KeyboardEvent, MouseEvent, PropsWithChildren, ReactElement } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { ModalContentProps } from '../Modal/ModalContent';
|
|
4
|
+
export interface DropdownMenuProps extends ModalContentProps {
|
|
5
|
+
/**
|
|
6
|
+
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
|
|
7
|
+
*/
|
|
8
|
+
testId?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Identifies the element (or elements) that labels the current element.
|
|
11
|
+
* @see aria-labelledby https://www.w3.org/TR/wai-aria-1.1/#aria-labelledby
|
|
12
|
+
*/
|
|
13
|
+
'aria-labelledby'?: AriaAttributes['aria-label'];
|
|
14
|
+
/**
|
|
15
|
+
* This function is called whenever the user hits "Escape" or clicks outside
|
|
16
|
+
* the dialog.
|
|
17
|
+
*/
|
|
18
|
+
onDismiss?: (event: MouseEvent | KeyboardEvent) => void;
|
|
19
|
+
children: ReactElement[];
|
|
20
|
+
}
|
|
21
|
+
declare const DropdownMenu: ({ children, testId, style, ...otherProps }: PropsWithChildren<DropdownMenuProps>) => React.ReactPortal | null;
|
|
22
|
+
export default DropdownMenu;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type DropdownContextState = {
|
|
3
|
+
/**
|
|
4
|
+
* Control de Dropdown state as Opened (true) or Closed (false).
|
|
5
|
+
*/
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Reference to DropdownButton, used to calculate a position for the DropdownMenu.
|
|
9
|
+
*/
|
|
10
|
+
dropdownButtonRef: React.RefObject<HTMLButtonElement> | null;
|
|
11
|
+
/**
|
|
12
|
+
* Reference to a selected DropdownItem, used to manipulate focus.
|
|
13
|
+
*/
|
|
14
|
+
selectedDropdownItemIndexRef: React.MutableRefObject<number> | null;
|
|
15
|
+
/**
|
|
16
|
+
* Array of References to dropdownItems in a DropdownMenu.
|
|
17
|
+
*/
|
|
18
|
+
dropdownItemsRef: React.MutableRefObject<HTMLButtonElement[]> | null;
|
|
19
|
+
/**
|
|
20
|
+
* Close DropdownMenu event inherited from Modal.
|
|
21
|
+
*/
|
|
22
|
+
onDismiss?(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Function responsible for close the DropdownMenu in this context.
|
|
25
|
+
*/
|
|
26
|
+
close?(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Function responsible for open the DropdownMenu in this context.
|
|
29
|
+
*/
|
|
30
|
+
open?(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Function responsible for switch the the DropdownMenu state in this context.
|
|
33
|
+
*/
|
|
34
|
+
toggle?(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Identifier to be used in aria-controls
|
|
37
|
+
*/
|
|
38
|
+
id: string;
|
|
39
|
+
};
|
|
40
|
+
declare const DropdownContext: import("react").Context<DropdownContextState>;
|
|
41
|
+
export default DropdownContext;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type DropdownPosition = {
|
|
2
|
+
position: 'absolute';
|
|
3
|
+
top: number;
|
|
4
|
+
left: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Hook used to find the DropdownMenu position in relation to DropdownButton
|
|
8
|
+
* @returns Style with positions.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useDropdownPosition: () => DropdownPosition;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default } from './Dropdown';
|
|
2
|
+
export type { DropdownProps } from './Dropdown';
|
|
3
|
+
export { default as DropdownButton } from './DropdownButton';
|
|
4
|
+
export type { DropdownButtonProps } from './DropdownButton';
|
|
5
|
+
export { default as DropdownItem } from './DropdownItem';
|
|
6
|
+
export type { DropdownItemProps } from './DropdownItem';
|
|
7
|
+
export { default as DropdownMenu } from './DropdownMenu';
|
|
8
|
+
export type { DropdownMenuProps } from './DropdownMenu';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { DropdownProps } from '..';
|
|
3
|
+
export declare const Uncontrolled: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, React.PropsWithChildren<DropdownProps>>;
|
|
4
|
+
export declare const Controlled: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, React.PropsWithChildren<DropdownProps>>;
|
|
5
|
+
export declare const Selectable: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, React.PropsWithChildren<DropdownProps>>;
|
|
6
|
+
declare const _default: import("@storybook/csf").ComponentAnnotations<import("@storybook/react").ReactFramework, import("@storybook/react").Args>;
|
|
7
|
+
export default _default;
|
|
@@ -956,14 +956,13 @@ const ModalContentPure = ({
|
|
|
956
956
|
tabIndex: 0,
|
|
957
957
|
"aria-hidden": "true"
|
|
958
958
|
}), React__default.createElement("div", Object.assign({
|
|
959
|
-
"data-store-modal-content": true
|
|
960
|
-
}, otherProps, {
|
|
959
|
+
"data-store-modal-content": true,
|
|
961
960
|
"data-testid": testId,
|
|
962
961
|
ref: trapFocusRef,
|
|
963
962
|
"aria-modal": "true",
|
|
964
963
|
role: "dialog",
|
|
965
964
|
tabIndex: -1
|
|
966
|
-
}), children), React__default.createElement("div", {
|
|
965
|
+
}, otherProps), children), React__default.createElement("div", {
|
|
967
966
|
ref: afterElementRef,
|
|
968
967
|
"data-testid": "afterElement",
|
|
969
968
|
tabIndex: 0,
|
|
@@ -1560,6 +1559,286 @@ const QuantitySelector = /*#__PURE__*/React.forwardRef(function QuantitySelector
|
|
|
1560
1559
|
}, rightButtonProps)));
|
|
1561
1560
|
});
|
|
1562
1561
|
|
|
1562
|
+
const defaultState = {
|
|
1563
|
+
isOpen: false,
|
|
1564
|
+
dropdownButtonRef: null,
|
|
1565
|
+
selectedDropdownItemIndexRef: null,
|
|
1566
|
+
dropdownItemsRef: null,
|
|
1567
|
+
id: 'store-dropdown'
|
|
1568
|
+
};
|
|
1569
|
+
const DropdownContext = /*#__PURE__*/React.createContext(defaultState);
|
|
1570
|
+
|
|
1571
|
+
const Dropdown = ({
|
|
1572
|
+
children,
|
|
1573
|
+
isOpen: isOpenDefault = false,
|
|
1574
|
+
onDismiss,
|
|
1575
|
+
id = 'store-dropdown'
|
|
1576
|
+
}) => {
|
|
1577
|
+
const [isOpen, setIsOpen] = React.useState(isOpenDefault);
|
|
1578
|
+
const dropdownItemsRef = React.useRef([]);
|
|
1579
|
+
const selectedDropdownItemIndexRef = React.useRef(0);
|
|
1580
|
+
const dropdownButtonRef = React.useRef(null);
|
|
1581
|
+
|
|
1582
|
+
const close = () => {
|
|
1583
|
+
setIsOpen(false);
|
|
1584
|
+
};
|
|
1585
|
+
|
|
1586
|
+
const open = () => {
|
|
1587
|
+
setIsOpen(true);
|
|
1588
|
+
};
|
|
1589
|
+
|
|
1590
|
+
const toggle = () => {
|
|
1591
|
+
setIsOpen(old => !old);
|
|
1592
|
+
};
|
|
1593
|
+
|
|
1594
|
+
React.useEffect(() => {
|
|
1595
|
+
setIsOpen(isOpenDefault);
|
|
1596
|
+
}, [isOpenDefault]);
|
|
1597
|
+
React.useEffect(() => {
|
|
1598
|
+
var _dropdownItemsRef$cur;
|
|
1599
|
+
|
|
1600
|
+
isOpen && (dropdownItemsRef == null ? void 0 : (_dropdownItemsRef$cur = dropdownItemsRef.current[0]) == null ? void 0 : _dropdownItemsRef$cur.focus());
|
|
1601
|
+
}, [isOpen]);
|
|
1602
|
+
const value = React.useMemo(() => {
|
|
1603
|
+
return {
|
|
1604
|
+
isOpen,
|
|
1605
|
+
close,
|
|
1606
|
+
open,
|
|
1607
|
+
toggle,
|
|
1608
|
+
dropdownButtonRef,
|
|
1609
|
+
onDismiss,
|
|
1610
|
+
selectedDropdownItemIndexRef,
|
|
1611
|
+
dropdownItemsRef,
|
|
1612
|
+
id
|
|
1613
|
+
};
|
|
1614
|
+
}, [id, isOpen, onDismiss]);
|
|
1615
|
+
return React__default.createElement(DropdownContext.Provider, {
|
|
1616
|
+
value: value
|
|
1617
|
+
}, children);
|
|
1618
|
+
};
|
|
1619
|
+
|
|
1620
|
+
/**
|
|
1621
|
+
* Hook to use the Dropdown context.
|
|
1622
|
+
* @returns Dropdown context.
|
|
1623
|
+
*/
|
|
1624
|
+
|
|
1625
|
+
const useDropdown = () => {
|
|
1626
|
+
const context = React.useContext(DropdownContext);
|
|
1627
|
+
|
|
1628
|
+
if (context === undefined) {
|
|
1629
|
+
throw new Error('Do not use useDropdown hook outside the Dropdown context.');
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
return context;
|
|
1633
|
+
};
|
|
1634
|
+
|
|
1635
|
+
const DropdownButton = /*#__PURE__*/React.forwardRef(function Button({
|
|
1636
|
+
children,
|
|
1637
|
+
testId = 'store-dropdown-button',
|
|
1638
|
+
...otherProps
|
|
1639
|
+
}, ref) {
|
|
1640
|
+
const {
|
|
1641
|
+
toggle,
|
|
1642
|
+
dropdownButtonRef,
|
|
1643
|
+
isOpen,
|
|
1644
|
+
id
|
|
1645
|
+
} = useDropdown();
|
|
1646
|
+
React.useImperativeHandle(ref, () => dropdownButtonRef.current, [dropdownButtonRef]);
|
|
1647
|
+
return React__default.createElement("button", Object.assign({
|
|
1648
|
+
"data-store-dropdown-button": true,
|
|
1649
|
+
onClick: toggle,
|
|
1650
|
+
"data-testid": testId,
|
|
1651
|
+
ref: dropdownButtonRef,
|
|
1652
|
+
"aria-expanded": isOpen,
|
|
1653
|
+
"aria-haspopup": "menu",
|
|
1654
|
+
"aria-controls": id
|
|
1655
|
+
}, otherProps), children);
|
|
1656
|
+
});
|
|
1657
|
+
|
|
1658
|
+
const DropdownItem = /*#__PURE__*/React.forwardRef(function Button({
|
|
1659
|
+
children,
|
|
1660
|
+
onClick,
|
|
1661
|
+
testId = 'store-dropdown-item',
|
|
1662
|
+
...otherProps
|
|
1663
|
+
}, ref) {
|
|
1664
|
+
const {
|
|
1665
|
+
dropdownItemsRef,
|
|
1666
|
+
selectedDropdownItemIndexRef,
|
|
1667
|
+
close
|
|
1668
|
+
} = useDropdown();
|
|
1669
|
+
const [dropdownItemIndex, setDropdownItemIndex] = React.useState(0);
|
|
1670
|
+
const dropdownItemRef = React.useRef();
|
|
1671
|
+
|
|
1672
|
+
const addToRefs = el => {
|
|
1673
|
+
if (el && !(dropdownItemsRef != null && dropdownItemsRef.current.includes(el))) {
|
|
1674
|
+
var _dropdownItemsRef$cur;
|
|
1675
|
+
|
|
1676
|
+
dropdownItemsRef == null ? void 0 : dropdownItemsRef.current.push(el);
|
|
1677
|
+
setDropdownItemIndex((_dropdownItemsRef$cur = dropdownItemsRef == null ? void 0 : dropdownItemsRef.current.findIndex(element => element === el)) != null ? _dropdownItemsRef$cur : 0);
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
dropdownItemRef.current = el;
|
|
1681
|
+
};
|
|
1682
|
+
|
|
1683
|
+
const onFocusItem = () => {
|
|
1684
|
+
var _dropdownItemsRef$cur2;
|
|
1685
|
+
|
|
1686
|
+
selectedDropdownItemIndexRef.current = dropdownItemIndex;
|
|
1687
|
+
dropdownItemsRef == null ? void 0 : (_dropdownItemsRef$cur2 = dropdownItemsRef.current[selectedDropdownItemIndexRef.current]) == null ? void 0 : _dropdownItemsRef$cur2.focus();
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
const handleOnClickItem = event => {
|
|
1691
|
+
onClick == null ? void 0 : onClick(event);
|
|
1692
|
+
close == null ? void 0 : close();
|
|
1693
|
+
};
|
|
1694
|
+
|
|
1695
|
+
React.useImperativeHandle(ref, () => dropdownItemRef.current, []);
|
|
1696
|
+
return React__default.createElement("button", Object.assign({
|
|
1697
|
+
"data-store-dropdown-item": true,
|
|
1698
|
+
"data-testid": testId,
|
|
1699
|
+
ref: addToRefs,
|
|
1700
|
+
onFocus: onFocusItem,
|
|
1701
|
+
onMouseEnter: onFocusItem,
|
|
1702
|
+
onClick: handleOnClickItem,
|
|
1703
|
+
role: "menuitem",
|
|
1704
|
+
tabIndex: -1,
|
|
1705
|
+
"data-index": dropdownItemIndex
|
|
1706
|
+
}, otherProps), children);
|
|
1707
|
+
});
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* Hook used to find the DropdownMenu position in relation to DropdownButton
|
|
1711
|
+
* @returns Style with positions.
|
|
1712
|
+
*/
|
|
1713
|
+
|
|
1714
|
+
const useDropdownPosition = () => {
|
|
1715
|
+
var _dropdownButtonRef$cu, _dropdownButtonRef$cu2, _dropdownButtonRef$cu3, _dropdownButtonRef$cu4, _dropdownButtonRef$cu5, _dropdownButtonRef$cu6;
|
|
1716
|
+
|
|
1717
|
+
const {
|
|
1718
|
+
dropdownButtonRef
|
|
1719
|
+
} = useDropdown();
|
|
1720
|
+
const topLevel = (_dropdownButtonRef$cu = dropdownButtonRef == null ? void 0 : (_dropdownButtonRef$cu2 = dropdownButtonRef.current) == null ? void 0 : _dropdownButtonRef$cu2.offsetTop) != null ? _dropdownButtonRef$cu : 0;
|
|
1721
|
+
const topOffset = (_dropdownButtonRef$cu3 = dropdownButtonRef == null ? void 0 : (_dropdownButtonRef$cu4 = dropdownButtonRef.current) == null ? void 0 : _dropdownButtonRef$cu4.offsetHeight) != null ? _dropdownButtonRef$cu3 : 0;
|
|
1722
|
+
const topPosition = topLevel + topOffset;
|
|
1723
|
+
const leftPosition = (_dropdownButtonRef$cu5 = dropdownButtonRef == null ? void 0 : (_dropdownButtonRef$cu6 = dropdownButtonRef.current) == null ? void 0 : _dropdownButtonRef$cu6.offsetLeft) != null ? _dropdownButtonRef$cu5 : 0;
|
|
1724
|
+
return {
|
|
1725
|
+
position: 'absolute',
|
|
1726
|
+
top: topPosition,
|
|
1727
|
+
left: leftPosition
|
|
1728
|
+
};
|
|
1729
|
+
};
|
|
1730
|
+
|
|
1731
|
+
/*
|
|
1732
|
+
* This component is based on @reach/dialog.
|
|
1733
|
+
* https://github.com/reach/reach-ui/blob/main/packages/dialog/src/index.tsx
|
|
1734
|
+
* https://reach.tech/dialog
|
|
1735
|
+
*/
|
|
1736
|
+
|
|
1737
|
+
const DropdownMenu = ({
|
|
1738
|
+
children,
|
|
1739
|
+
testId = 'store-dropdown-menu',
|
|
1740
|
+
style,
|
|
1741
|
+
...otherProps
|
|
1742
|
+
}) => {
|
|
1743
|
+
const {
|
|
1744
|
+
isOpen,
|
|
1745
|
+
close,
|
|
1746
|
+
onDismiss,
|
|
1747
|
+
dropdownItemsRef,
|
|
1748
|
+
selectedDropdownItemIndexRef,
|
|
1749
|
+
id
|
|
1750
|
+
} = useDropdown();
|
|
1751
|
+
const dropdownPosition = useDropdownPosition();
|
|
1752
|
+
const childrenLength = children.length;
|
|
1753
|
+
|
|
1754
|
+
const handleBackdropClick = event => {
|
|
1755
|
+
if (event.defaultPrevented) {
|
|
1756
|
+
return;
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
event.stopPropagation();
|
|
1760
|
+
onDismiss == null ? void 0 : onDismiss();
|
|
1761
|
+
close == null ? void 0 : close();
|
|
1762
|
+
};
|
|
1763
|
+
|
|
1764
|
+
const handleDownPress = () => {
|
|
1765
|
+
var _dropdownItemsRef$cur;
|
|
1766
|
+
|
|
1767
|
+
if (selectedDropdownItemIndexRef.current < childrenLength - 1) {
|
|
1768
|
+
selectedDropdownItemIndexRef.current++;
|
|
1769
|
+
} else {
|
|
1770
|
+
selectedDropdownItemIndexRef.current = 0;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
dropdownItemsRef == null ? void 0 : (_dropdownItemsRef$cur = dropdownItemsRef.current[selectedDropdownItemIndexRef.current]) == null ? void 0 : _dropdownItemsRef$cur.focus();
|
|
1774
|
+
};
|
|
1775
|
+
|
|
1776
|
+
const handleUpPress = () => {
|
|
1777
|
+
var _dropdownItemsRef$cur2;
|
|
1778
|
+
|
|
1779
|
+
if (selectedDropdownItemIndexRef.current > 0) {
|
|
1780
|
+
selectedDropdownItemIndexRef.current--;
|
|
1781
|
+
} else {
|
|
1782
|
+
selectedDropdownItemIndexRef.current = childrenLength - 1;
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
dropdownItemsRef == null ? void 0 : (_dropdownItemsRef$cur2 = dropdownItemsRef.current[selectedDropdownItemIndexRef.current]) == null ? void 0 : _dropdownItemsRef$cur2.focus();
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1788
|
+
const handleHomePress = () => {
|
|
1789
|
+
var _dropdownItemsRef$cur3;
|
|
1790
|
+
|
|
1791
|
+
selectedDropdownItemIndexRef.current = 0;
|
|
1792
|
+
dropdownItemsRef == null ? void 0 : (_dropdownItemsRef$cur3 = dropdownItemsRef.current[selectedDropdownItemIndexRef.current]) == null ? void 0 : _dropdownItemsRef$cur3.focus();
|
|
1793
|
+
};
|
|
1794
|
+
|
|
1795
|
+
const handleEndPress = () => {
|
|
1796
|
+
var _dropdownItemsRef$cur4;
|
|
1797
|
+
|
|
1798
|
+
selectedDropdownItemIndexRef.current = childrenLength - 1;
|
|
1799
|
+
dropdownItemsRef == null ? void 0 : (_dropdownItemsRef$cur4 = dropdownItemsRef.current[selectedDropdownItemIndexRef.current]) == null ? void 0 : _dropdownItemsRef$cur4.focus();
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1802
|
+
const handleEscapePress = () => {
|
|
1803
|
+
onDismiss == null ? void 0 : onDismiss();
|
|
1804
|
+
close == null ? void 0 : close();
|
|
1805
|
+
};
|
|
1806
|
+
|
|
1807
|
+
const handleBackdropKeyDown = event => {
|
|
1808
|
+
if (event.defaultPrevented) {
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
event.key === 'Escape' && handleEscapePress();
|
|
1813
|
+
event.key === 'ArrowDown' && handleDownPress();
|
|
1814
|
+
event.key === 'ArrowUp' && handleUpPress();
|
|
1815
|
+
event.key === 'Home' && handleHomePress();
|
|
1816
|
+
event.key === 'End' && handleEndPress();
|
|
1817
|
+
event.key === 'Tab' && event.preventDefault();
|
|
1818
|
+
event.stopPropagation();
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
const clearChildrenReferences = () => {
|
|
1822
|
+
dropdownItemsRef.current = [];
|
|
1823
|
+
return null;
|
|
1824
|
+
};
|
|
1825
|
+
|
|
1826
|
+
return isOpen ? reactDom.createPortal(React__default.createElement(Overlay, {
|
|
1827
|
+
"data-store-dropdown-overlay": true,
|
|
1828
|
+
onClick: handleBackdropClick,
|
|
1829
|
+
onKeyDown: handleBackdropKeyDown
|
|
1830
|
+
}, React__default.createElement("div", Object.assign({
|
|
1831
|
+
role: "menu",
|
|
1832
|
+
"aria-orientation": "vertical",
|
|
1833
|
+
"data-store-dropdown-menu": true,
|
|
1834
|
+
"data-testid": testId,
|
|
1835
|
+
style: { ...dropdownPosition,
|
|
1836
|
+
...style
|
|
1837
|
+
},
|
|
1838
|
+
id: id
|
|
1839
|
+
}, otherProps), children)), document.body) : clearChildrenReferences();
|
|
1840
|
+
};
|
|
1841
|
+
|
|
1563
1842
|
const Card = /*#__PURE__*/React.forwardRef(function Card({
|
|
1564
1843
|
testId = 'store-card',
|
|
1565
1844
|
children,
|
|
@@ -1627,6 +1906,10 @@ exports.CardContent = CardContent;
|
|
|
1627
1906
|
exports.CardImage = CardImage;
|
|
1628
1907
|
exports.Carousel = Carousel;
|
|
1629
1908
|
exports.Checkbox = Checkbox;
|
|
1909
|
+
exports.Dropdown = Dropdown;
|
|
1910
|
+
exports.DropdownButton = DropdownButton;
|
|
1911
|
+
exports.DropdownItem = DropdownItem;
|
|
1912
|
+
exports.DropdownMenu = DropdownMenu;
|
|
1630
1913
|
exports.Form = Form;
|
|
1631
1914
|
exports.Icon = Icon;
|
|
1632
1915
|
exports.IconButton = IconButton;
|