@conveyorhq/arrow-ds 1.120.0 → 1.121.1
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/package.json +1 -1
- package/public/components/Accordion/Accordion.d.ts +12 -3
- package/public/components/Accordion/Accordion.js +50 -16
- package/public/components/Accordion/context.d.ts +5 -0
- package/public/components/Accordion/context.js +7 -0
- package/public/components/Accordion/types.d.ts +2 -1
- package/public/css/styles.css +5 -5
- package/public/css/styles.min.css +1 -1
- package/public/css/styles.min.css.map +1 -1
- package/src/components/Accordion/Accordion.story.mdx +36 -0
- package/src/components/Accordion/Accordion.tsx +74 -19
- package/src/components/Accordion/context.ts +12 -0
- package/src/components/Accordion/types.ts +5 -4
package/package.json
CHANGED
|
@@ -3,8 +3,17 @@ import { BoxProps } from "../Box";
|
|
|
3
3
|
import { StackProps } from "../Stack";
|
|
4
4
|
import { IconProps } from "../Icon";
|
|
5
5
|
import type { AccordionOwnProps, AccordionItemOwnProps, AccordionDisclosureProps, AccordionGroupOwnProps } from "./types";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
declare type AccordionGroupChildProps = {
|
|
7
|
+
currentValue: string;
|
|
8
|
+
};
|
|
9
|
+
declare type AccordionGroupChildFunction = {
|
|
10
|
+
children(props: AccordionGroupChildProps): React.ReactElement;
|
|
11
|
+
};
|
|
12
|
+
declare type AccordionGroupChildrenUnionType = AccordionGroupChildFunction | {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export declare type AccordionGroupProps = AccordionGroupOwnProps & AccordionGroupChildrenUnionType & Pick<StackProps, "spacing" | "className">;
|
|
16
|
+
export declare const AccordionGroup: ({ children, spacing, defaultValue, disableAnimation, allowMultiple, className, ...rest }: AccordionGroupProps) => JSX.Element;
|
|
8
17
|
export declare type AccordionItemProps = AccordionItemOwnProps & BoxProps;
|
|
9
18
|
export declare const AccordionItem: ({ value, defaultIsOpen: defaultIsOpenProp, children, className, ...rest }: AccordionItemProps) => JSX.Element;
|
|
10
19
|
declare type AccordionButtonChildProps = Omit<AccordionDisclosureProps, "onToggle">;
|
|
@@ -31,7 +40,7 @@ export declare const AccordionContent: ({ children, maxHeight, style, className,
|
|
|
31
40
|
export declare type AccordionProps = AccordionOwnProps & BoxProps;
|
|
32
41
|
export declare const Accordion: {
|
|
33
42
|
(props: AccordionProps): JSX.Element;
|
|
34
|
-
Group: ({ children, spacing, defaultValue, disableAnimation, className, ...rest }: AccordionGroupProps) => JSX.Element;
|
|
43
|
+
Group: ({ children, spacing, defaultValue, disableAnimation, allowMultiple, className, ...rest }: AccordionGroupProps) => JSX.Element;
|
|
35
44
|
Item: ({ value, defaultIsOpen: defaultIsOpenProp, children, className, ...rest }: AccordionItemProps) => JSX.Element;
|
|
36
45
|
Button: React.ForwardRefExoticComponent<AccordionButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
37
46
|
Icon: ({ className, direction, color, }: AccordionIconProps) => JSX.Element;
|
|
@@ -20,31 +20,62 @@ const Heading_1 = require("../Heading");
|
|
|
20
20
|
const Icon_1 = require("../Icon");
|
|
21
21
|
const context_1 = require("./context");
|
|
22
22
|
const cn = utilities_1.bemHOF("Accordion");
|
|
23
|
-
const AccordionGroup = ({ children, spacing = 0, defaultValue, disableAnimation, className, ...rest }) => {
|
|
23
|
+
const AccordionGroup = ({ children, spacing = 0, defaultValue, disableAnimation, allowMultiple = true, className, ...rest }) => {
|
|
24
24
|
const totalItems = react_1.default.Children.count(children);
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const [currentValue, setCurrentValue] = react_1.default.useState(defaultValue || "");
|
|
26
|
+
const context = react_1.default.useMemo(() => ({
|
|
27
|
+
defaultValue,
|
|
28
|
+
disableAnimation,
|
|
29
|
+
totalItems,
|
|
30
|
+
currentValue,
|
|
31
|
+
setCurrentValue,
|
|
32
|
+
allowMultiple,
|
|
33
|
+
}), [defaultValue, disableAnimation, totalItems, currentValue, allowMultiple]);
|
|
34
|
+
return (react_1.default.createElement(context_1.AccordionGroupContext.Provider, { value: context },
|
|
35
|
+
react_1.default.createElement(Stack_1.Stack, Object.assign({ orientation: types_1.ORIENTATION.VERTICAL, spacing: spacing, className: className }, rest), typeof children === "function" ? children({ currentValue }) : children)));
|
|
27
36
|
};
|
|
28
37
|
exports.AccordionGroup = AccordionGroup;
|
|
29
38
|
const AccordionItem = ({ value, defaultIsOpen: defaultIsOpenProp, children, className, ...rest }) => {
|
|
30
|
-
const { defaultValue } = context_1.useAccordionGroupContext();
|
|
39
|
+
const { defaultValue, currentValue, setCurrentValue, allowMultiple, } = context_1.useAccordionGroupContext();
|
|
31
40
|
const hasDefaultValue = typeof defaultValue === "undefined" ? false : defaultValue === value;
|
|
32
41
|
const defaultIsOpen = typeof defaultIsOpenProp === "undefined"
|
|
33
42
|
? hasDefaultValue
|
|
34
43
|
: defaultIsOpenProp;
|
|
35
|
-
const { isOpen, onToggle, onClose } = hooks_1.useDisclosure(defaultIsOpen);
|
|
44
|
+
const { isOpen, onToggle, onClose, onOpen } = hooks_1.useDisclosure(defaultIsOpen);
|
|
36
45
|
const id = `accordion-${auto_id_1.useId()}`;
|
|
37
46
|
const buttonId = `${id}-button`;
|
|
38
47
|
const contentId = `${id}-content`;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
const context = react_1.default.useMemo(() => ({
|
|
49
|
+
defaultIsOpen,
|
|
50
|
+
isOpen,
|
|
51
|
+
onToggle,
|
|
52
|
+
onClose,
|
|
53
|
+
onOpen,
|
|
54
|
+
buttonId,
|
|
55
|
+
contentId,
|
|
56
|
+
value,
|
|
57
|
+
currentValue,
|
|
58
|
+
setCurrentValue,
|
|
59
|
+
allowMultiple,
|
|
60
|
+
}), [
|
|
61
|
+
defaultIsOpen,
|
|
62
|
+
isOpen,
|
|
63
|
+
onToggle,
|
|
64
|
+
onClose,
|
|
65
|
+
onOpen,
|
|
66
|
+
buttonId,
|
|
67
|
+
contentId,
|
|
68
|
+
value,
|
|
69
|
+
currentValue,
|
|
70
|
+
setCurrentValue,
|
|
71
|
+
allowMultiple,
|
|
72
|
+
]);
|
|
73
|
+
react_1.default.useEffect(() => {
|
|
74
|
+
if (!allowMultiple && currentValue !== value) {
|
|
75
|
+
onClose();
|
|
76
|
+
}
|
|
77
|
+
}, [allowMultiple, currentValue, value, onClose]);
|
|
78
|
+
return (react_1.default.createElement(context_1.AccordionItemContext.Provider, { value: context },
|
|
48
79
|
react_1.default.createElement(Box_1.Box, Object.assign({ "data-component": "accordion", className: classnames_1.default(cn(), className, {
|
|
49
80
|
[cn({ m: "isOpen" })]: isOpen,
|
|
50
81
|
}) }, rest), children)));
|
|
@@ -52,7 +83,7 @@ const AccordionItem = ({ value, defaultIsOpen: defaultIsOpenProp, children, clas
|
|
|
52
83
|
exports.AccordionItem = AccordionItem;
|
|
53
84
|
exports.AccordionButton = react_1.default.forwardRef((props, forwardedRef) => {
|
|
54
85
|
const { children, className, onClick, disabled = false, ...rest } = props;
|
|
55
|
-
const { buttonId, contentId, isOpen, onToggle, onClose, } = context_1.useAccordionItemContext();
|
|
86
|
+
const { buttonId, contentId, isOpen, onToggle, onClose, onOpen, value, setCurrentValue, } = context_1.useAccordionItemContext();
|
|
56
87
|
const buttonRef = react_1.default.useRef(null);
|
|
57
88
|
const ref = react_merge_refs_1.default([forwardedRef, buttonRef]);
|
|
58
89
|
return (react_1.default.createElement("button", Object.assign({ ref: ref, type: "button", className: className, id: buttonId, "aria-controls": contentId, "aria-expanded": isOpen, "aria-disabled": disabled, disabled: disabled, onClick: (event) => {
|
|
@@ -60,11 +91,14 @@ exports.AccordionButton = react_1.default.forwardRef((props, forwardedRef) => {
|
|
|
60
91
|
if (onClick) {
|
|
61
92
|
onClick(event);
|
|
62
93
|
}
|
|
94
|
+
if (setCurrentValue && value) {
|
|
95
|
+
setCurrentValue(value);
|
|
96
|
+
}
|
|
63
97
|
if (onToggle) {
|
|
64
98
|
onToggle();
|
|
65
99
|
}
|
|
66
100
|
} }, rest), typeof children === "function"
|
|
67
|
-
? children({ isOpen, onClose })
|
|
101
|
+
? children({ isOpen, onClose, onOpen })
|
|
68
102
|
: children));
|
|
69
103
|
});
|
|
70
104
|
const AccordionIcon = ({ className, direction = "down", color, }) => {
|
|
@@ -2,12 +2,17 @@ import { Context } from "react";
|
|
|
2
2
|
import type { AccordionGroupOwnProps, AccordionItemOwnProps, AccordionDisclosureProps } from "./types";
|
|
3
3
|
declare type AccordionGroupContextType = {
|
|
4
4
|
totalItems?: number;
|
|
5
|
+
currentValue?: string;
|
|
6
|
+
setCurrentValue?(value: string): void;
|
|
5
7
|
} & AccordionGroupOwnProps;
|
|
6
8
|
export declare const AccordionGroupContext: Context<AccordionGroupContextType>;
|
|
7
9
|
export declare function useAccordionGroupContext(): AccordionGroupContextType;
|
|
8
10
|
declare type AccordionItemContextType = AccordionItemOwnProps & AccordionDisclosureProps & {
|
|
9
11
|
buttonId: string;
|
|
10
12
|
contentId: string;
|
|
13
|
+
currentValue?: string;
|
|
14
|
+
setCurrentValue?(value: string): void;
|
|
15
|
+
allowMultiple?: boolean;
|
|
11
16
|
};
|
|
12
17
|
export declare const AccordionItemContext: Context<AccordionItemContextType>;
|
|
13
18
|
export declare function useAccordionItemContext(): AccordionItemContextType;
|
|
@@ -6,6 +6,9 @@ const defaultGroupContext = {
|
|
|
6
6
|
defaultValue: undefined,
|
|
7
7
|
disableAnimation: false,
|
|
8
8
|
totalItems: 0,
|
|
9
|
+
currentValue: undefined,
|
|
10
|
+
setCurrentValue: () => { },
|
|
11
|
+
allowMultiple: true,
|
|
9
12
|
};
|
|
10
13
|
exports.AccordionGroupContext = react_1.createContext(defaultGroupContext);
|
|
11
14
|
function useAccordionGroupContext() {
|
|
@@ -20,8 +23,12 @@ const defaultContext = {
|
|
|
20
23
|
isOpen: false,
|
|
21
24
|
onToggle: () => { },
|
|
22
25
|
onClose: () => { },
|
|
26
|
+
onOpen: () => { },
|
|
23
27
|
buttonId: "accordion-0-button",
|
|
24
28
|
contentId: "accordion-0-content",
|
|
29
|
+
currentValue: undefined,
|
|
30
|
+
setCurrentValue: () => { },
|
|
31
|
+
allowMultiple: true,
|
|
25
32
|
};
|
|
26
33
|
exports.AccordionItemContext = react_1.createContext(defaultContext);
|
|
27
34
|
function useAccordionItemContext() {
|
|
@@ -3,6 +3,7 @@ import type { DisclosureProps } from "../../types";
|
|
|
3
3
|
export declare type AccordionGroupOwnProps = {
|
|
4
4
|
defaultValue?: string;
|
|
5
5
|
disableAnimation?: boolean;
|
|
6
|
+
allowMultiple?: boolean;
|
|
6
7
|
};
|
|
7
8
|
export declare type AccordionItemOwnProps = {
|
|
8
9
|
defaultIsOpen?: boolean;
|
|
@@ -15,4 +16,4 @@ export declare type AccordionOwnProps = Pick<AccordionItemOwnProps, "defaultIsOp
|
|
|
15
16
|
iconSlot?: ReactNode;
|
|
16
17
|
removePadding?: ReactNode;
|
|
17
18
|
};
|
|
18
|
-
export declare type AccordionDisclosureProps =
|
|
19
|
+
export declare type AccordionDisclosureProps = DisclosureProps;
|
package/public/css/styles.css
CHANGED
|
@@ -8664,6 +8664,11 @@ override built-in Image component classes */
|
|
|
8664
8664
|
border-color: rgb(51 198 159 / var(--tw-border-opacity));
|
|
8665
8665
|
}
|
|
8666
8666
|
|
|
8667
|
+
.bg-gray-100 {
|
|
8668
|
+
--tw-bg-opacity: 1;
|
|
8669
|
+
background-color: rgb(249 251 252 / var(--tw-bg-opacity));
|
|
8670
|
+
}
|
|
8671
|
+
|
|
8667
8672
|
.bg-gray-400 {
|
|
8668
8673
|
--tw-bg-opacity: 1;
|
|
8669
8674
|
background-color: rgb(222 231 238 / var(--tw-bg-opacity));
|
|
@@ -8679,11 +8684,6 @@ override built-in Image component classes */
|
|
|
8679
8684
|
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
|
|
8680
8685
|
}
|
|
8681
8686
|
|
|
8682
|
-
.bg-gray-100 {
|
|
8683
|
-
--tw-bg-opacity: 1;
|
|
8684
|
-
background-color: rgb(249 251 252 / var(--tw-bg-opacity));
|
|
8685
|
-
}
|
|
8686
|
-
|
|
8687
8687
|
.bg-gray-200 {
|
|
8688
8688
|
--tw-bg-opacity: 1;
|
|
8689
8689
|
background-color: rgb(244 247 249 / var(--tw-bg-opacity));
|