@faststore/ui 2.0.37-alpha.0 → 2.0.41-alpha.0

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 (62) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/index.d.ts +0 -4
  3. package/dist/index.js +0 -2
  4. package/dist/index.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/base/tokens.scss +1 -1
  7. package/src/components/molecules/Accordion/styles.scss +70 -0
  8. package/src/components/molecules/Dropdown/styles.scss +93 -0
  9. package/src/index.ts +0 -26
  10. package/src/styles/components.scss +2 -0
  11. package/dist/components/molecules/Accordion/Accordion.d.ts +0 -26
  12. package/dist/components/molecules/Accordion/Accordion.js +0 -21
  13. package/dist/components/molecules/Accordion/Accordion.js.map +0 -1
  14. package/dist/components/molecules/Accordion/AccordionButton.d.ts +0 -10
  15. package/dist/components/molecules/Accordion/AccordionButton.js +0 -37
  16. package/dist/components/molecules/Accordion/AccordionButton.js.map +0 -1
  17. package/dist/components/molecules/Accordion/AccordionItem.d.ts +0 -31
  18. package/dist/components/molecules/Accordion/AccordionItem.js +0 -22
  19. package/dist/components/molecules/Accordion/AccordionItem.js.map +0 -1
  20. package/dist/components/molecules/Accordion/AccordionPanel.d.ts +0 -10
  21. package/dist/components/molecules/Accordion/AccordionPanel.js +0 -10
  22. package/dist/components/molecules/Accordion/AccordionPanel.js.map +0 -1
  23. package/dist/components/molecules/Accordion/index.d.ts +0 -8
  24. package/dist/components/molecules/Accordion/index.js +0 -5
  25. package/dist/components/molecules/Accordion/index.js.map +0 -1
  26. package/dist/components/molecules/Dropdown/Dropdown.d.ts +0 -9
  27. package/dist/components/molecules/Dropdown/Dropdown.js +0 -67
  28. package/dist/components/molecules/Dropdown/Dropdown.js.map +0 -1
  29. package/dist/components/molecules/Dropdown/DropdownButton.d.ts +0 -10
  30. package/dist/components/molecules/Dropdown/DropdownButton.js +0 -11
  31. package/dist/components/molecules/Dropdown/DropdownButton.js.map +0 -1
  32. package/dist/components/molecules/Dropdown/DropdownItem.d.ts +0 -10
  33. package/dist/components/molecules/Dropdown/DropdownItem.js +0 -26
  34. package/dist/components/molecules/Dropdown/DropdownItem.js.map +0 -1
  35. package/dist/components/molecules/Dropdown/DropdownMenu.d.ts +0 -22
  36. package/dist/components/molecules/Dropdown/DropdownMenu.js +0 -65
  37. package/dist/components/molecules/Dropdown/DropdownMenu.js.map +0 -1
  38. package/dist/components/molecules/Dropdown/contexts/DropdownContext.d.ts +0 -41
  39. package/dist/components/molecules/Dropdown/contexts/DropdownContext.js +0 -11
  40. package/dist/components/molecules/Dropdown/contexts/DropdownContext.js.map +0 -1
  41. package/dist/components/molecules/Dropdown/hooks/useDropdown.d.ts +0 -6
  42. package/dist/components/molecules/Dropdown/hooks/useDropdown.js +0 -14
  43. package/dist/components/molecules/Dropdown/hooks/useDropdown.js.map +0 -1
  44. package/dist/components/molecules/Dropdown/hooks/useDropdownPosition.d.ts +0 -8
  45. package/dist/components/molecules/Dropdown/hooks/useDropdownPosition.js +0 -25
  46. package/dist/components/molecules/Dropdown/hooks/useDropdownPosition.js.map +0 -1
  47. package/dist/components/molecules/Dropdown/index.d.ts +0 -8
  48. package/dist/components/molecules/Dropdown/index.js +0 -5
  49. package/dist/components/molecules/Dropdown/index.js.map +0 -1
  50. package/src/components/molecules/Accordion/Accordion.tsx +0 -76
  51. package/src/components/molecules/Accordion/AccordionButton.tsx +0 -81
  52. package/src/components/molecules/Accordion/AccordionItem.tsx +0 -92
  53. package/src/components/molecules/Accordion/AccordionPanel.tsx +0 -40
  54. package/src/components/molecules/Accordion/index.ts +0 -11
  55. package/src/components/molecules/Dropdown/Dropdown.tsx +0 -102
  56. package/src/components/molecules/Dropdown/DropdownButton.tsx +0 -42
  57. package/src/components/molecules/Dropdown/DropdownItem.tsx +0 -69
  58. package/src/components/molecules/Dropdown/DropdownMenu.tsx +0 -139
  59. package/src/components/molecules/Dropdown/contexts/DropdownContext.ts +0 -53
  60. package/src/components/molecules/Dropdown/hooks/useDropdown.ts +0 -18
  61. package/src/components/molecules/Dropdown/hooks/useDropdownPosition.ts +0 -33
  62. package/src/components/molecules/Dropdown/index.ts +0 -11
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropdownButton.js","sourceRoot":"","sources":["../../../../src/components/molecules/Dropdown/DropdownButton.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAA;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAUjD,MAAM,cAAc,GAAG,UAAU,CAC/B,SAAS,MAAM,CACb,EAAE,QAAQ,EAAE,MAAM,GAAG,uBAAuB,EAAE,GAAG,UAAU,EAAE,EAC7D,GAAG;IAEH,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,WAAW,EAAE,CAAA;IAE/D,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAkB,CAAC,OAAQ,EAAE;QAC1D,iBAAiB;KAClB,CAAC,CAAA;IAEF,OAAO,CACL,iEAEE,OAAO,EAAE,MAAM,iBACF,MAAM,EACnB,GAAG,EAAE,iBAAiB,mBACP,MAAM,mBACP,MAAM,mBACL,EAAE,KACb,UAAU,IAEb,QAAQ,CACF,CACV,CAAA;AACH,CAAC,CACF,CAAA;AAED,eAAe,cAAc,CAAA"}
@@ -1,10 +0,0 @@
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;
@@ -1,26 +0,0 @@
1
- import React, { useImperativeHandle, forwardRef, useRef, useState } from 'react';
2
- import { useDropdown } from './hooks/useDropdown';
3
- const DropdownItem = forwardRef(function Button({ children, onClick, testId = 'store-dropdown-item', ...otherProps }, ref) {
4
- const { dropdownItemsRef, selectedDropdownItemIndexRef, close } = useDropdown();
5
- const [dropdownItemIndex, setDropdownItemIndex] = useState(0);
6
- const dropdownItemRef = useRef();
7
- const addToRefs = (el) => {
8
- if (el && !dropdownItemsRef?.current.includes(el)) {
9
- dropdownItemsRef?.current.push(el);
10
- setDropdownItemIndex(dropdownItemsRef?.current.findIndex((element) => element === el) ?? 0);
11
- }
12
- dropdownItemRef.current = el;
13
- };
14
- const onFocusItem = () => {
15
- selectedDropdownItemIndexRef.current = dropdownItemIndex;
16
- dropdownItemsRef?.current[selectedDropdownItemIndexRef.current]?.focus();
17
- };
18
- const handleOnClickItem = (event) => {
19
- onClick?.(event);
20
- close?.();
21
- };
22
- useImperativeHandle(ref, () => dropdownItemRef.current, []);
23
- return (React.createElement("button", { "data-fs-dropdown-item": true, "data-testid": testId, ref: addToRefs, onFocus: onFocusItem, onMouseEnter: onFocusItem, onClick: handleOnClickItem, role: "menuitem", tabIndex: -1, "data-index": dropdownItemIndex, ...otherProps }, children));
24
- });
25
- export default DropdownItem;
26
- //# sourceMappingURL=DropdownItem.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropdownItem.js","sourceRoot":"","sources":["../../../../src/components/molecules/Dropdown/DropdownItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAUjD,MAAM,YAAY,GAAG,UAAU,CAC7B,SAAS,MAAM,CACb,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,qBAAqB,EAAE,GAAG,UAAU,EAAE,EACpE,GAAG;IAEH,MAAM,EAAE,gBAAgB,EAAE,4BAA4B,EAAE,KAAK,E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,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -1,22 +0,0 @@
1
- import type { AriaAttributes, KeyboardEvent, PropsWithChildren, MouseEvent, ReactNode } 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: ReactNode[] | ReactNode;
20
- }
21
- declare const DropdownMenu: ({ children, testId, style, ...otherProps }: PropsWithChildren<DropdownMenuProps>) => React.ReactPortal | null;
22
- export default DropdownMenu;
@@ -1,65 +0,0 @@
1
- import React from 'react';
2
- import { createPortal } from 'react-dom';
3
- import { useDropdown } from './hooks/useDropdown';
4
- import { useDropdownPosition } from './hooks/useDropdownPosition';
5
- /*
6
- * This component is based on @reach/dialog.
7
- * https://github.com/reach/reach-ui/blob/main/packages/dialog/src/index.tsx
8
- * https://reach.tech/dialog
9
- */
10
- const DropdownMenu = ({ children, testId = 'store-dropdown-menu', style, ...otherProps }) => {
11
- const { isOpen, close, dropdownItemsRef, selectedDropdownItemIndexRef, id } = useDropdown();
12
- const dropdownPosition = useDropdownPosition();
13
- const childrenLength = React.Children.toArray(children).length;
14
- const handleDownPress = () => {
15
- if (selectedDropdownItemIndexRef.current < childrenLength - 1) {
16
- selectedDropdownItemIndexRef.current++;
17
- }
18
- else {
19
- selectedDropdownItemIndexRef.current = 0;
20
- }
21
- dropdownItemsRef?.current[selectedDropdownItemIndexRef.current]?.focus();
22
- };
23
- const handleUpPress = () => {
24
- if (selectedDropdownItemIndexRef.current > 0) {
25
- selectedDropdownItemIndexRef.current--;
26
- }
27
- else {
28
- selectedDropdownItemIndexRef.current = childrenLength - 1;
29
- }
30
- dropdownItemsRef?.current[selectedDropdownItemIndexRef.current]?.focus();
31
- };
32
- const handleHomePress = () => {
33
- selectedDropdownItemIndexRef.current = 0;
34
- dropdownItemsRef?.current[selectedDropdownItemIndexRef.current]?.focus();
35
- };
36
- const handleEndPress = () => {
37
- selectedDropdownItemIndexRef.current = childrenLength - 1;
38
- dropdownItemsRef?.current[selectedDropdownItemIndexRef.current]?.focus();
39
- };
40
- const handleEscapePress = () => {
41
- close?.();
42
- };
43
- const handleBackdropKeyDown = (event) => {
44
- if (event.defaultPrevented || event.key === 'Enter') {
45
- return;
46
- }
47
- event.preventDefault();
48
- event.key === 'Escape' && handleEscapePress();
49
- event.key === 'ArrowDown' && handleDownPress();
50
- event.key === 'ArrowUp' && handleUpPress();
51
- event.key === 'Home' && handleHomePress();
52
- event.key === 'End' && handleEndPress();
53
- event.stopPropagation();
54
- };
55
- const clearChildrenReferences = () => {
56
- dropdownItemsRef.current = [];
57
- return null;
58
- };
59
- return isOpen
60
- ? createPortal(React.createElement("div", { role: "presentation", "data-fs-dropdown-overlay": true, onKeyDown: handleBackdropKeyDown, "data-testid": `${testId}-overlay` },
61
- React.createElement("div", { role: "menu", "aria-orientation": "vertical", "data-fs-dropdown-menu": true, "data-testid": testId, style: { ...dropdownPosition, ...style }, id: id, ...otherProps }, children)), document.body)
62
- : clearChildrenReferences();
63
- };
64
- export default DropdownMenu;
65
- //# sourceMappingURL=DropdownMenu.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropdownMenu.js","sourceRoot":"","sources":["../../../../src/components/molecules/Dropdown/DropdownMenu.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAGxC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,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QAAQ,CAAC,IAAI,CACd;QACH,CAAC,CAAC,uBAAuB,EAAE,CAAA;AAC/B,CAAC,CAAA;AAED,eAAe,YAAY,CAAA"}
@@ -1,41 +0,0 @@
1
- /// <reference types="react" />
2
- export 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;
@@ -1,11 +0,0 @@
1
- import { createContext } from 'react';
2
- const defaultState = {
3
- isOpen: false,
4
- dropdownButtonRef: null,
5
- selectedDropdownItemIndexRef: null,
6
- dropdownItemsRef: null,
7
- id: 'store-dropdown',
8
- };
9
- const DropdownContext = createContext(defaultState);
10
- export default DropdownContext;
11
- //# sourceMappingURL=DropdownContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DropdownContext.js","sourceRoot":"","sources":["../../../../../src/components/molecules/Dropdown/contexts/DropdownContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AA0CrC,MAAM,YAAY,GAAyB;IACzC,MAAM,EAAE,KAAK;IACb,iBAAiB,EAAE,IAAI;IACvB,4BAA4B,EAAE,IAAI;IAClC,gBAAgB,EAAE,IAAI;IACtB,EAAE,EAAE,gBAAgB;CACrB,CAAA;AAED,MAAM,eAAe,GAAG,aAAa,CAAuB,YAAY,CAAC,CAAA;AAEzE,eAAe,eAAe,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { DropdownContextState } from '../contexts/DropdownContext';
2
- /**
3
- * Hook to use the Dropdown context.
4
- * @returns Dropdown context.
5
- */
6
- export declare const useDropdown: () => DropdownContextState;
@@ -1,14 +0,0 @@
1
- import { useContext } from 'react';
2
- import DropdownContext from '../contexts/DropdownContext';
3
- /**
4
- * Hook to use the Dropdown context.
5
- * @returns Dropdown context.
6
- */
7
- export const useDropdown = () => {
8
- const context = useContext(DropdownContext);
9
- if (context === undefined) {
10
- throw new Error('Do not use useDropdown hook outside the Dropdown context.');
11
- }
12
- return context;
13
- };
14
- //# sourceMappingURL=useDropdown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDropdown.js","sourceRoot":"","sources":["../../../../../src/components/molecules/Dropdown/hooks/useDropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGlC,OAAO,eAAe,MAAM,6BAA6B,CAAA;AAEzD;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,MAAM,OAAO,GAAG,UAAU,CAAuB,eAAe,CAAC,CAAA;IAEjE,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;KAC7E;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- type DropdownPosition = Pick<React.CSSProperties, 'position' | 'top' | 'left'>;
3
- /**
4
- * Hook used to find the DropdownMenu position in relation to DropdownButton
5
- * @returns Style with positions.
6
- */
7
- export declare const useDropdownPosition: () => DropdownPosition;
8
- export {};
@@ -1,25 +0,0 @@
1
- import { useDropdown } from './useDropdown';
2
- /**
3
- * Hook used to find the DropdownMenu position in relation to DropdownButton
4
- * @returns Style with positions.
5
- */
6
- export const useDropdownPosition = () => {
7
- const { dropdownButtonRef } = useDropdown();
8
- // Necessary to use this component in SSR
9
- const isBrowser = typeof window !== 'undefined';
10
- const buttonRect = dropdownButtonRef?.current?.getBoundingClientRect();
11
- const topLevel = buttonRect?.top ?? 0;
12
- const topOffset = buttonRect?.height ?? 0;
13
- const leftLevel = buttonRect?.left ?? 0;
14
- // The scroll properties fix the position of DropdownMenu when the scroll is activated.
15
- const scrollTop = isBrowser ? document?.documentElement?.scrollTop : 0;
16
- const scrollLeft = isBrowser ? document?.documentElement?.scrollLeft : 0;
17
- const topPosition = topLevel + topOffset + scrollTop;
18
- const leftPosition = leftLevel + scrollLeft;
19
- return {
20
- position: 'absolute',
21
- top: topPosition,
22
- left: leftPosition,
23
- };
24
- };
25
- //# sourceMappingURL=useDropdownPosition.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useDropdownPosition.js","sourceRoot":"","sources":["../../../../../src/components/molecules/Dropdown/hooks/useDropdownPosition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAI3C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAqB,EAAE;IACxD,MAAM,EAAE,iBAAiB,EAAE,GAAG,WAAW,EAAE,CAAA;IAE3C,yCAAyC;IACzC,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAA;IAE/C,MAAM,UAAU,GAAG,iBAAiB,EAAE,OAAO,EAAE,qBAAqB,EAAE,CAAA;IACtE,MAAM,QAAQ,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,CAAA;IACrC,MAAM,SAAS,GAAG,UAAU,EAAE,MAAM,IAAI,CAAC,CAAA;IACzC,MAAM,SAAS,GAAG,UAAU,EAAE,IAAI,IAAI,CAAC,CAAA;IAEvC,uFAAuF;IACvF,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IACtE,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;IAExE,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;IAEpD,MAAM,YAAY,GAAG,SAAS,GAAG,UAAU,CAAA;IAE3C,OAAO;QACL,QAAQ,EAAE,UAAU;QACpB,GAAG,EAAE,WAAW;QAChB,IAAI,EAAE,YAAY;KACnB,CAAA;AACH,CAAC,CAAA"}
@@ -1,8 +0,0 @@
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';
@@ -1,5 +0,0 @@
1
- export { default } from './Dropdown';
2
- export { default as DropdownButton } from './DropdownButton';
3
- export { default as DropdownItem } from './DropdownItem';
4
- export { default as DropdownMenu } from './DropdownMenu';
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/molecules/Dropdown/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGpC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAG5D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAGxD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
@@ -1,76 +0,0 @@
1
- import type { HTMLAttributes, ReactElement } from 'react'
2
- import React, {
3
- useContext,
4
- cloneElement,
5
- forwardRef,
6
- createContext,
7
- } from 'react'
8
-
9
- interface AccordionContext {
10
- indices: Set<number>
11
- onChange: (index: number) => void
12
- numberOfItems: number
13
- }
14
-
15
- const AccordionContext = createContext<AccordionContext | undefined>(undefined)
16
-
17
- export interface AccordionProps
18
- extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'> {
19
- /**
20
- * ID to find this component in testing tools (e.g.: cypress,
21
- * testing-library, and jest).
22
- */
23
- testId?: string
24
- /**
25
- * Indices that indicate which accordion items are opened.
26
- */
27
- indices: Iterable<number>
28
- /**
29
- * Function that is triggered when an accordion item is opened/closed.
30
- */
31
- onChange: (index: number) => void
32
- }
33
-
34
- const Accordion = forwardRef<HTMLDivElement, AccordionProps>(function Accordion(
35
- { testId = 'store-accordion', indices, onChange, children, ...otherProps },
36
- ref
37
- ) {
38
- const childrenWithIndex = React.Children.map(
39
- children as ReactElement,
40
- (child, index) => cloneElement(child, { index: child.props.index ?? index })
41
- )
42
-
43
- const context = {
44
- indices: new Set(indices),
45
- onChange,
46
- numberOfItems: childrenWithIndex.length,
47
- }
48
-
49
- return (
50
- <AccordionContext.Provider value={context}>
51
- <div
52
- ref={ref}
53
- data-fs-accordion
54
- data-testid={testId}
55
- role="region"
56
- {...otherProps}
57
- >
58
- {childrenWithIndex}
59
- </div>
60
- </AccordionContext.Provider>
61
- )
62
- })
63
-
64
- export function useAccordion() {
65
- const context = useContext(AccordionContext)
66
-
67
- if (context === undefined) {
68
- throw new Error(
69
- 'Do not use Accordion components outside the Accordion context.'
70
- )
71
- }
72
-
73
- return context
74
- }
75
-
76
- export default Accordion
@@ -1,81 +0,0 @@
1
- import React, { forwardRef } from 'react'
2
-
3
- import { useAccordion } from './Accordion'
4
- import { useAccordionItem } from './AccordionItem'
5
-
6
- import { Button } from '@faststore/components'
7
- import type { ButtonProps } from '@faststore/components'
8
-
9
- export interface AccordionButtonProps extends ButtonProps {
10
- /**
11
- * ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
12
- */
13
- testId?: string
14
- }
15
-
16
- const AccordionButton = forwardRef<HTMLButtonElement, AccordionButtonProps>(
17
- function AccordionButton(
18
- { testId = 'store-accordion-button', children, ...otherProps },
19
- ref
20
- ) {
21
- const { indices, onChange, numberOfItems } = useAccordion()
22
- const { index, panel, button, prefixId } = useAccordionItem()
23
-
24
- const onKeyDown = (event: React.KeyboardEvent) => {
25
- if (!['ArrowDown', 'ArrowUp'].includes(event.key)) {
26
- return
27
- }
28
-
29
- const getNext = () => {
30
- const next = Number(index) + 1 === numberOfItems ? 0 : Number(index) + 1
31
-
32
- return document.getElementById(
33
- `${prefixId && `${prefixId}-`}button--${next}`
34
- )
35
- }
36
-
37
- const getPrevious = () => {
38
- const previous =
39
- Number(index) - 1 < 0 ? numberOfItems - 1 : Number(index) - 1
40
-
41
- return document.getElementById(
42
- `${prefixId && `${prefixId}-`}button--${previous}`
43
- )
44
- }
45
-
46
- switch (event.key) {
47
- case 'ArrowDown':
48
- event.preventDefault()
49
- getNext()?.focus()
50
- break
51
-
52
- case 'ArrowUp':
53
- event.preventDefault()
54
- getPrevious()?.focus()
55
- break
56
-
57
- default:
58
- }
59
- }
60
-
61
- return (
62
- <Button
63
- ref={ref}
64
- id={button}
65
- aria-expanded={indices.has(index)}
66
- aria-controls={panel}
67
- data-accordion-button
68
- data-testid={testId}
69
- onKeyDown={onKeyDown}
70
- onClick={() => {
71
- onChange(index)
72
- }}
73
- {...otherProps}
74
- >
75
- {children}
76
- </Button>
77
- )
78
- }
79
- )
80
-
81
- export default AccordionButton
@@ -1,92 +0,0 @@
1
- import type { ElementType, HTMLAttributes, ReactElement } from 'react'
2
- import React, { createContext, forwardRef, useContext } from 'react'
3
- import type {
4
- PolymorphicComponentPropsWithRef,
5
- PolymorphicRef,
6
- } from '../../../typings'
7
-
8
- interface AccordionItemContext {
9
- index: number
10
- panel: string
11
- button: string
12
- prefixId: string
13
- }
14
-
15
- const AccordionItemContext = createContext<AccordionItemContext | undefined>(
16
- undefined
17
- )
18
-
19
- interface Props extends HTMLAttributes<HTMLDivElement> {
20
- /**
21
- * ID to find this component in testing tools (e.g.: cypress,
22
- * testing-library, and jest).
23
- */
24
- testId?: string
25
- /**
26
- * Index of the current accordion item within the accordion.
27
- */
28
- index?: number
29
- /**
30
- * Namespace ID prefix for the current Accordion item's panel and button
31
- * to avoid ID duplication when multiple instances are on the same page.
32
- */
33
- prefixId?: string
34
- }
35
-
36
- export type AccordionItemProps<
37
- C extends ElementType
38
- > = PolymorphicComponentPropsWithRef<C, Props>
39
-
40
- type AccordionItemComponent = <C extends ElementType = 'div'>(
41
- props: AccordionItemProps<C>
42
- ) => ReactElement | null
43
-
44
- const AccordionItem: AccordionItemComponent = forwardRef(function AccordionItem<
45
- C extends ElementType = 'div'
46
- >(
47
- {
48
- testId = 'store-accordion-item',
49
- children,
50
- prefixId = '',
51
- index = 0,
52
- as: MaybeComponent,
53
- ...otherProps
54
- }: AccordionItemProps<C>,
55
- ref: PolymorphicRef<C>
56
- ) {
57
- const Component = MaybeComponent ?? 'div'
58
-
59
- const context = {
60
- index,
61
- prefixId,
62
- panel: `${prefixId && `${prefixId}-`}panel--${index}`,
63
- button: `${prefixId && `${prefixId}-`}button--${index}`,
64
- }
65
-
66
- return (
67
- <AccordionItemContext.Provider value={context}>
68
- <Component
69
- ref={ref}
70
- data-accordion-item
71
- data-testid={testId}
72
- {...otherProps}
73
- >
74
- {children}
75
- </Component>
76
- </AccordionItemContext.Provider>
77
- )
78
- })
79
-
80
- export function useAccordionItem() {
81
- const context = useContext(AccordionItemContext)
82
-
83
- if (context === undefined) {
84
- throw new Error(
85
- 'Do not use AccordionItem components outside the AccordionItem context.'
86
- )
87
- }
88
-
89
- return context
90
- }
91
-
92
- export default AccordionItem
@@ -1,40 +0,0 @@
1
- import type { HTMLAttributes } from 'react'
2
- import React, { forwardRef } from 'react'
3
-
4
- import { useAccordion } from './Accordion'
5
- import { useAccordionItem } from './AccordionItem'
6
-
7
- export interface AccordionPanelProps
8
- extends Omit<HTMLAttributes<HTMLDivElement>, 'role'> {
9
- /**
10
- * ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
11
- */
12
- testId?: string
13
- }
14
-
15
- const AccordionPanel = forwardRef<HTMLDivElement, AccordionPanelProps>(
16
- function AccordionPanel(
17
- { testId = 'store-accordion-panel', children, ...otherProps },
18
- ref
19
- ) {
20
- const { indices } = useAccordion()
21
- const { index, button, panel } = useAccordionItem()
22
-
23
- return (
24
- <div
25
- ref={ref}
26
- id={panel}
27
- aria-labelledby={button}
28
- role="region"
29
- data-accordion-panel
30
- data-testid={testId}
31
- hidden={!indices.has(index)}
32
- {...otherProps}
33
- >
34
- {children}
35
- </div>
36
- )
37
- }
38
- )
39
-
40
- export default AccordionPanel
@@ -1,11 +0,0 @@
1
- export { default } from './Accordion'
2
- export type { AccordionProps } from './Accordion'
3
-
4
- export { default as AccordionItem } from './AccordionItem'
5
- export type { AccordionItemProps } from './AccordionItem'
6
-
7
- export { default as AccordionButton } from './AccordionButton'
8
- export type { AccordionButtonProps } from './AccordionButton'
9
-
10
- export { default as AccordionPanel } from './AccordionPanel'
11
- export type { AccordionPanelProps } from './AccordionPanel'