@conveyorhq/arrow-ds 1.125.0 → 1.126.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.
- package/package.json +1 -1
- package/public/components/Accordion/Accordion.d.ts +5 -4
- package/public/components/Accordion/Accordion.js +20 -7
- package/public/components/Accordion/context.d.ts +1 -0
- package/public/components/Accordion/context.js +2 -0
- package/public/components/Accordion/types.d.ts +1 -0
- package/src/components/Accordion/Accordion.tsx +25 -3
- package/src/components/Accordion/context.ts +3 -0
- package/src/components/Accordion/types.ts +4 -0
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ declare type AccordionGroupChildrenUnionType = AccordionGroupChildFunction | {
|
|
|
13
13
|
children: React.ReactNode;
|
|
14
14
|
};
|
|
15
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;
|
|
16
|
+
export declare const AccordionGroup: ({ children, spacing, defaultValue, disableAnimation, allowMultiple, allowToggle, className, ...rest }: AccordionGroupProps) => JSX.Element;
|
|
17
17
|
export declare type AccordionItemProps = AccordionItemOwnProps & BoxProps;
|
|
18
18
|
export declare const AccordionItem: ({ value, defaultIsOpen: defaultIsOpenProp, children, className, ...rest }: AccordionItemProps) => JSX.Element;
|
|
19
19
|
declare type AccordionButtonChildProps = Omit<AccordionDisclosureProps, "onToggle">;
|
|
@@ -28,8 +28,9 @@ export declare const AccordionButton: React.ForwardRefExoticComponent<AccordionB
|
|
|
28
28
|
export declare type AccordionIconProps = {
|
|
29
29
|
className?: string;
|
|
30
30
|
direction?: "up" | "down" | "left" | "right";
|
|
31
|
+
disabled?: boolean;
|
|
31
32
|
} & Pick<IconProps, "color">;
|
|
32
|
-
export declare const AccordionIcon: ({ className, direction, color, }: AccordionIconProps) => JSX.Element;
|
|
33
|
+
export declare const AccordionIcon: ({ className, direction, color, disabled, }: AccordionIconProps) => JSX.Element;
|
|
33
34
|
export declare type AccordionContentProps = {
|
|
34
35
|
children: React.ReactNode;
|
|
35
36
|
maxHeight?: string;
|
|
@@ -41,10 +42,10 @@ export declare const AccordionContent: ({ children, maxHeight, style, className,
|
|
|
41
42
|
export declare type AccordionProps = AccordionOwnProps & BoxProps;
|
|
42
43
|
export declare const Accordion: {
|
|
43
44
|
(props: AccordionProps): JSX.Element;
|
|
44
|
-
Group: ({ children, spacing, defaultValue, disableAnimation, allowMultiple, className, ...rest }: AccordionGroupProps) => JSX.Element;
|
|
45
|
+
Group: ({ children, spacing, defaultValue, disableAnimation, allowMultiple, allowToggle, className, ...rest }: AccordionGroupProps) => JSX.Element;
|
|
45
46
|
Item: ({ value, defaultIsOpen: defaultIsOpenProp, children, className, ...rest }: AccordionItemProps) => JSX.Element;
|
|
46
47
|
Button: React.ForwardRefExoticComponent<AccordionButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
47
|
-
Icon: ({ className, direction, color, }: AccordionIconProps) => JSX.Element;
|
|
48
|
+
Icon: ({ className, direction, color, disabled, }: AccordionIconProps) => JSX.Element;
|
|
48
49
|
Content: ({ children, maxHeight, style, className, scrollClassName, ...rest }: AccordionContentProps) => JSX.Element;
|
|
49
50
|
};
|
|
50
51
|
export {};
|
|
@@ -20,7 +20,7 @@ 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, allowMultiple = true, className, ...rest }) => {
|
|
23
|
+
const AccordionGroup = ({ children, spacing = 0, defaultValue, disableAnimation, allowMultiple = true, allowToggle = true, className, ...rest }) => {
|
|
24
24
|
const totalItems = react_1.default.Children.count(children);
|
|
25
25
|
const [currentValue, setCurrentValue] = react_1.default.useState(defaultValue || "");
|
|
26
26
|
const context = react_1.default.useMemo(() => ({
|
|
@@ -30,13 +30,21 @@ const AccordionGroup = ({ children, spacing = 0, defaultValue, disableAnimation,
|
|
|
30
30
|
currentValue,
|
|
31
31
|
setCurrentValue,
|
|
32
32
|
allowMultiple,
|
|
33
|
-
|
|
33
|
+
allowToggle,
|
|
34
|
+
}), [
|
|
35
|
+
defaultValue,
|
|
36
|
+
disableAnimation,
|
|
37
|
+
totalItems,
|
|
38
|
+
currentValue,
|
|
39
|
+
allowMultiple,
|
|
40
|
+
allowToggle,
|
|
41
|
+
]);
|
|
34
42
|
return (react_1.default.createElement(context_1.AccordionGroupContext.Provider, { value: context },
|
|
35
43
|
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)));
|
|
36
44
|
};
|
|
37
45
|
exports.AccordionGroup = AccordionGroup;
|
|
38
46
|
const AccordionItem = ({ value, defaultIsOpen: defaultIsOpenProp, children, className, ...rest }) => {
|
|
39
|
-
const { defaultValue, currentValue, setCurrentValue, allowMultiple, } = context_1.useAccordionGroupContext();
|
|
47
|
+
const { defaultValue, currentValue, setCurrentValue, allowMultiple, allowToggle, } = context_1.useAccordionGroupContext();
|
|
40
48
|
const hasDefaultValue = typeof defaultValue === "undefined" ? false : defaultValue === value;
|
|
41
49
|
const defaultIsOpen = typeof defaultIsOpenProp === "undefined"
|
|
42
50
|
? hasDefaultValue
|
|
@@ -57,6 +65,7 @@ const AccordionItem = ({ value, defaultIsOpen: defaultIsOpenProp, children, clas
|
|
|
57
65
|
currentValue,
|
|
58
66
|
setCurrentValue,
|
|
59
67
|
allowMultiple,
|
|
68
|
+
allowToggle,
|
|
60
69
|
}), [
|
|
61
70
|
defaultIsOpen,
|
|
62
71
|
isOpen,
|
|
@@ -69,6 +78,7 @@ const AccordionItem = ({ value, defaultIsOpen: defaultIsOpenProp, children, clas
|
|
|
69
78
|
currentValue,
|
|
70
79
|
setCurrentValue,
|
|
71
80
|
allowMultiple,
|
|
81
|
+
allowToggle,
|
|
72
82
|
]);
|
|
73
83
|
react_1.default.useEffect(() => {
|
|
74
84
|
if (!allowMultiple && currentValue !== value) {
|
|
@@ -83,7 +93,7 @@ const AccordionItem = ({ value, defaultIsOpen: defaultIsOpenProp, children, clas
|
|
|
83
93
|
exports.AccordionItem = AccordionItem;
|
|
84
94
|
exports.AccordionButton = react_1.default.forwardRef((props, forwardedRef) => {
|
|
85
95
|
const { children, className, onClick, disabled = false, ...rest } = props;
|
|
86
|
-
const { buttonId, contentId, isOpen, onToggle, onClose, onOpen, value, setCurrentValue, } = context_1.useAccordionItemContext();
|
|
96
|
+
const { buttonId, contentId, isOpen, onToggle, onClose, onOpen, value, setCurrentValue, allowToggle, } = context_1.useAccordionItemContext();
|
|
87
97
|
const buttonRef = react_1.default.useRef(null);
|
|
88
98
|
const ref = react_merge_refs_1.default([forwardedRef, buttonRef]);
|
|
89
99
|
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) => {
|
|
@@ -94,21 +104,24 @@ exports.AccordionButton = react_1.default.forwardRef((props, forwardedRef) => {
|
|
|
94
104
|
if (setCurrentValue && value) {
|
|
95
105
|
setCurrentValue(value);
|
|
96
106
|
}
|
|
97
|
-
if (onToggle) {
|
|
107
|
+
if (onToggle && allowToggle) {
|
|
98
108
|
onToggle();
|
|
99
109
|
}
|
|
110
|
+
if (onOpen && !allowToggle) {
|
|
111
|
+
onOpen();
|
|
112
|
+
}
|
|
100
113
|
} }, rest), typeof children === "function"
|
|
101
114
|
? children({ isOpen, onClose, onOpen })
|
|
102
115
|
: children));
|
|
103
116
|
});
|
|
104
|
-
const AccordionIcon = ({ className, direction = "down", color, }) => {
|
|
117
|
+
const AccordionIcon = ({ className, direction = "down", color, disabled = false, }) => {
|
|
105
118
|
const icon = {
|
|
106
119
|
up: Icon_1.ICON_TYPE.CHEVRON_UP,
|
|
107
120
|
down: Icon_1.ICON_TYPE.CHEVRON_DOWN,
|
|
108
121
|
left: Icon_1.ICON_TYPE.CHEVRON_LEFT,
|
|
109
122
|
right: Icon_1.ICON_TYPE.CHEVRON_RIGHT,
|
|
110
123
|
};
|
|
111
|
-
return (react_1.default.createElement(Icon_1.Icon, { className: classnames_1.default([cn({ e: "icon" }), className]), "data-direction": direction, icon: icon[direction], color: color }));
|
|
124
|
+
return (react_1.default.createElement(Icon_1.Icon, { className: classnames_1.default([cn({ e: "icon" }), className]), "data-direction": disabled ? undefined : direction, icon: icon[direction], color: color }));
|
|
112
125
|
};
|
|
113
126
|
exports.AccordionIcon = AccordionIcon;
|
|
114
127
|
const AccordionContent = ({ children, maxHeight, style, className, scrollClassName, ...rest }) => {
|
|
@@ -13,6 +13,7 @@ declare type AccordionItemContextType = AccordionItemOwnProps & AccordionDisclos
|
|
|
13
13
|
currentValue?: string;
|
|
14
14
|
setCurrentValue?(value: string): void;
|
|
15
15
|
allowMultiple?: boolean;
|
|
16
|
+
allowToggle?: boolean;
|
|
16
17
|
};
|
|
17
18
|
export declare const AccordionItemContext: Context<AccordionItemContextType>;
|
|
18
19
|
export declare function useAccordionItemContext(): AccordionItemContextType;
|
|
@@ -9,6 +9,7 @@ const defaultGroupContext = {
|
|
|
9
9
|
currentValue: undefined,
|
|
10
10
|
setCurrentValue: () => { },
|
|
11
11
|
allowMultiple: true,
|
|
12
|
+
allowToggle: true,
|
|
12
13
|
};
|
|
13
14
|
exports.AccordionGroupContext = react_1.createContext(defaultGroupContext);
|
|
14
15
|
function useAccordionGroupContext() {
|
|
@@ -29,6 +30,7 @@ const defaultContext = {
|
|
|
29
30
|
currentValue: undefined,
|
|
30
31
|
setCurrentValue: () => { },
|
|
31
32
|
allowMultiple: true,
|
|
33
|
+
allowToggle: true,
|
|
32
34
|
};
|
|
33
35
|
exports.AccordionItemContext = react_1.createContext(defaultContext);
|
|
34
36
|
function useAccordionItemContext() {
|
|
@@ -51,6 +51,7 @@ export const AccordionGroup = ({
|
|
|
51
51
|
defaultValue,
|
|
52
52
|
disableAnimation,
|
|
53
53
|
allowMultiple = true,
|
|
54
|
+
allowToggle = true,
|
|
54
55
|
className,
|
|
55
56
|
...rest
|
|
56
57
|
}: AccordionGroupProps) => {
|
|
@@ -64,8 +65,16 @@ export const AccordionGroup = ({
|
|
|
64
65
|
currentValue,
|
|
65
66
|
setCurrentValue,
|
|
66
67
|
allowMultiple,
|
|
68
|
+
allowToggle,
|
|
67
69
|
}),
|
|
68
|
-
[
|
|
70
|
+
[
|
|
71
|
+
defaultValue,
|
|
72
|
+
disableAnimation,
|
|
73
|
+
totalItems,
|
|
74
|
+
currentValue,
|
|
75
|
+
allowMultiple,
|
|
76
|
+
allowToggle,
|
|
77
|
+
],
|
|
69
78
|
);
|
|
70
79
|
return (
|
|
71
80
|
<AccordionGroupContext.Provider value={context}>
|
|
@@ -99,6 +108,7 @@ export const AccordionItem = ({
|
|
|
99
108
|
currentValue,
|
|
100
109
|
setCurrentValue,
|
|
101
110
|
allowMultiple,
|
|
111
|
+
allowToggle,
|
|
102
112
|
} = useAccordionGroupContext();
|
|
103
113
|
|
|
104
114
|
/**
|
|
@@ -131,6 +141,7 @@ export const AccordionItem = ({
|
|
|
131
141
|
currentValue,
|
|
132
142
|
setCurrentValue,
|
|
133
143
|
allowMultiple,
|
|
144
|
+
allowToggle,
|
|
134
145
|
}),
|
|
135
146
|
[
|
|
136
147
|
defaultIsOpen,
|
|
@@ -144,6 +155,7 @@ export const AccordionItem = ({
|
|
|
144
155
|
currentValue,
|
|
145
156
|
setCurrentValue,
|
|
146
157
|
allowMultiple,
|
|
158
|
+
allowToggle,
|
|
147
159
|
],
|
|
148
160
|
);
|
|
149
161
|
|
|
@@ -197,6 +209,7 @@ export const AccordionButton = React.forwardRef<
|
|
|
197
209
|
onOpen,
|
|
198
210
|
value,
|
|
199
211
|
setCurrentValue,
|
|
212
|
+
allowToggle,
|
|
200
213
|
} = useAccordionItemContext();
|
|
201
214
|
const buttonRef = React.useRef<HTMLButtonElement>(null);
|
|
202
215
|
const ref = mergeRefs<HTMLButtonElement>([forwardedRef, buttonRef]);
|
|
@@ -219,9 +232,12 @@ export const AccordionButton = React.forwardRef<
|
|
|
219
232
|
if (setCurrentValue && value) {
|
|
220
233
|
setCurrentValue(value);
|
|
221
234
|
}
|
|
222
|
-
if (onToggle) {
|
|
235
|
+
if (onToggle && allowToggle) {
|
|
223
236
|
onToggle();
|
|
224
237
|
}
|
|
238
|
+
if (onOpen && !allowToggle) {
|
|
239
|
+
onOpen();
|
|
240
|
+
}
|
|
225
241
|
}}
|
|
226
242
|
{...rest}
|
|
227
243
|
>
|
|
@@ -243,12 +259,18 @@ export type AccordionIconProps = {
|
|
|
243
259
|
* point down, unless direction=down, then it will point up
|
|
244
260
|
*/
|
|
245
261
|
direction?: "up" | "down" | "left" | "right";
|
|
262
|
+
/**
|
|
263
|
+
* Prevent the icon from rotating when the accordion is opened or closed; the
|
|
264
|
+
* direction will always be what is specified in the `direction` prop
|
|
265
|
+
*/
|
|
266
|
+
disabled?: boolean;
|
|
246
267
|
} & Pick<IconProps, "color">;
|
|
247
268
|
|
|
248
269
|
export const AccordionIcon = ({
|
|
249
270
|
className,
|
|
250
271
|
direction = "down",
|
|
251
272
|
color,
|
|
273
|
+
disabled = false,
|
|
252
274
|
}: AccordionIconProps) => {
|
|
253
275
|
const icon = {
|
|
254
276
|
up: ICON_TYPE.CHEVRON_UP,
|
|
@@ -260,7 +282,7 @@ export const AccordionIcon = ({
|
|
|
260
282
|
return (
|
|
261
283
|
<Icon
|
|
262
284
|
className={classNames([cn({ e: "icon" }), className])}
|
|
263
|
-
data-direction={direction}
|
|
285
|
+
data-direction={disabled ? undefined : direction}
|
|
264
286
|
icon={icon[direction]}
|
|
265
287
|
color={color}
|
|
266
288
|
/>
|
|
@@ -22,6 +22,7 @@ const defaultGroupContext: AccordionGroupContextType = {
|
|
|
22
22
|
currentValue: undefined,
|
|
23
23
|
setCurrentValue: () => {},
|
|
24
24
|
allowMultiple: true,
|
|
25
|
+
allowToggle: true,
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
export const AccordionGroupContext: Context<AccordionGroupContextType> = createContext<AccordionGroupContextType>(
|
|
@@ -49,6 +50,7 @@ type AccordionItemContextType = AccordionItemOwnProps &
|
|
|
49
50
|
currentValue?: string;
|
|
50
51
|
setCurrentValue?(value: string): void;
|
|
51
52
|
allowMultiple?: boolean;
|
|
53
|
+
allowToggle?: boolean;
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
const defaultContext: AccordionItemContextType = {
|
|
@@ -62,6 +64,7 @@ const defaultContext: AccordionItemContextType = {
|
|
|
62
64
|
currentValue: undefined,
|
|
63
65
|
setCurrentValue: () => {},
|
|
64
66
|
allowMultiple: true,
|
|
67
|
+
allowToggle: true,
|
|
65
68
|
};
|
|
66
69
|
|
|
67
70
|
export const AccordionItemContext: Context<AccordionItemContextType> = createContext<AccordionItemContextType>(
|
|
@@ -14,6 +14,10 @@ export type AccordionGroupOwnProps = {
|
|
|
14
14
|
* Whether or not multiple items can be expanded at once
|
|
15
15
|
*/
|
|
16
16
|
allowMultiple?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Allow any expanded accordion item to be collapsed
|
|
19
|
+
*/
|
|
20
|
+
allowToggle?: boolean;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
export type AccordionItemOwnProps = {
|