@lumx/react 3.1.2 → 3.1.3-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.
- package/_internal/types.d.ts +1 -1
- package/index.d.ts +5 -5
- package/index.js +4 -4
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/expansion-panel/ExpansionPanel.stories.tsx +65 -0
- package/src/components/expansion-panel/ExpansionPanel.test.tsx +2 -2
- package/src/components/expansion-panel/ExpansionPanel.tsx +8 -8
package/package.json
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@juggle/resize-observer": "^3.2.0",
|
|
10
|
-
"@lumx/core": "^3.1.
|
|
11
|
-
"@lumx/icons": "^3.1.
|
|
10
|
+
"@lumx/core": "^3.1.3-alpha.0",
|
|
11
|
+
"@lumx/icons": "^3.1.3-alpha.0",
|
|
12
12
|
"@popperjs/core": "^2.5.4",
|
|
13
13
|
"body-scroll-lock": "^3.1.5",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
"build:storybook": "cd storybook && ./build"
|
|
114
114
|
},
|
|
115
115
|
"sideEffects": false,
|
|
116
|
-
"version": "3.1.
|
|
116
|
+
"version": "3.1.3-alpha.0"
|
|
117
117
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Button, Dropdown, ExpansionPanel, List, ListItem, Placement, Size } from '@lumx/react';
|
|
4
|
+
|
|
5
|
+
export default { title: 'LumX components/expansion-panel/ExpansionPanel' };
|
|
6
|
+
|
|
7
|
+
export const ExpansionPanelInADropdown = () => {
|
|
8
|
+
const anchorDropdownButton = React.useRef(null);
|
|
9
|
+
|
|
10
|
+
const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);
|
|
11
|
+
const toggleDropdown = () => setIsDropdownOpen(!isDropdownOpen);
|
|
12
|
+
const closeDropdown = () => setIsDropdownOpen(false);
|
|
13
|
+
|
|
14
|
+
const [isExpansionPanelOpen, setIsExpansionPanelOpen] = React.useState(false);
|
|
15
|
+
|
|
16
|
+
const toggleExpansionPanel = (shouldOpen: boolean, evt: React.MouseEvent) => {
|
|
17
|
+
evt.preventDefault();
|
|
18
|
+
evt.stopPropagation();
|
|
19
|
+
setIsExpansionPanelOpen(shouldOpen);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const onItemSelected = (item: string) => () => {
|
|
23
|
+
console.log('selected item', item);
|
|
24
|
+
closeDropdown();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
<Button ref={anchorDropdownButton} onClick={toggleDropdown}>
|
|
30
|
+
Open dropdown
|
|
31
|
+
</Button>
|
|
32
|
+
<Dropdown
|
|
33
|
+
closeOnClickAway
|
|
34
|
+
closeOnEscape
|
|
35
|
+
isOpen={isDropdownOpen}
|
|
36
|
+
onClose={closeDropdown}
|
|
37
|
+
placement={Placement.BOTTOM_START}
|
|
38
|
+
anchorRef={anchorDropdownButton}
|
|
39
|
+
>
|
|
40
|
+
<List>
|
|
41
|
+
<ListItem onItemSelected={onItemSelected('paris')} size={Size.tiny}>
|
|
42
|
+
Paris
|
|
43
|
+
</ListItem>
|
|
44
|
+
<ExpansionPanel
|
|
45
|
+
label="Lorem ipsum"
|
|
46
|
+
isOpen={isExpansionPanelOpen}
|
|
47
|
+
onToggleOpen={(shouldOpen, event) => toggleExpansionPanel(shouldOpen, event)}
|
|
48
|
+
toggleButtonProps={{ label: 'Toggle' }}
|
|
49
|
+
>
|
|
50
|
+
<header>
|
|
51
|
+
<ListItem size={Size.tiny}>United States</ListItem>
|
|
52
|
+
</header>
|
|
53
|
+
<ListItem onItemSelected={onItemSelected('georgetown')} size={Size.tiny}>
|
|
54
|
+
Georgetown
|
|
55
|
+
</ListItem>
|
|
56
|
+
|
|
57
|
+
<ListItem onItemSelected={onItemSelected('newyork')} size={Size.tiny}>
|
|
58
|
+
New York
|
|
59
|
+
</ListItem>
|
|
60
|
+
</ExpansionPanel>
|
|
61
|
+
</List>
|
|
62
|
+
</Dropdown>
|
|
63
|
+
</>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -94,7 +94,7 @@ describe(`<${ExpansionPanel.displayName}>`, () => {
|
|
|
94
94
|
await userEvent.click(query.toggleButton() as any);
|
|
95
95
|
expect(onOpen).toHaveBeenCalled();
|
|
96
96
|
expect(onClose).not.toHaveBeenCalled();
|
|
97
|
-
expect(onToggleOpen).toHaveBeenCalledWith(true);
|
|
97
|
+
expect(onToggleOpen).toHaveBeenCalledWith(true, expect.anything());
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it('should close on click', async () => {
|
|
@@ -107,7 +107,7 @@ describe(`<${ExpansionPanel.displayName}>`, () => {
|
|
|
107
107
|
await userEvent.click(query.header() as any);
|
|
108
108
|
expect(onOpen).not.toHaveBeenCalled();
|
|
109
109
|
expect(onClose).toHaveBeenCalled();
|
|
110
|
-
expect(onToggleOpen).toHaveBeenCalledWith(false);
|
|
110
|
+
expect(onToggleOpen).toHaveBeenCalledWith(false, expect.anything());
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
|
|
@@ -9,7 +9,7 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
9
9
|
import isFunction from 'lodash/isFunction';
|
|
10
10
|
|
|
11
11
|
import { ColorPalette, DragHandle, Emphasis, IconButton, IconButtonProps, Theme } from '@lumx/react';
|
|
12
|
-
import {
|
|
12
|
+
import { Comp, GenericProps, HasTheme, isComponent } from '@lumx/react/utils/type';
|
|
13
13
|
import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
|
|
14
14
|
import { partitionMulti } from '@lumx/react/utils/partitionMulti';
|
|
15
15
|
|
|
@@ -26,14 +26,14 @@ export interface ExpansionPanelProps extends GenericProps, HasTheme {
|
|
|
26
26
|
/** Label text (overwritten if a `<header>` is provided in the children). */
|
|
27
27
|
label?: string;
|
|
28
28
|
/** On open callback. */
|
|
29
|
-
onOpen?:
|
|
29
|
+
onOpen?: (event: React.MouseEvent) => void;
|
|
30
30
|
/** On close callback. */
|
|
31
|
-
onClose?:
|
|
31
|
+
onClose?: (event: React.MouseEvent) => void;
|
|
32
32
|
/** Props to pass to the toggle button (minus those already set by the ExpansionPanel props). */
|
|
33
33
|
toggleButtonProps: Pick<IconButtonProps, 'label'> &
|
|
34
34
|
Omit<IconButtonProps, 'label' | 'onClick' | 'icon' | 'emphasis' | 'color'>;
|
|
35
35
|
/** On toggle open or close callback. */
|
|
36
|
-
onToggleOpen?(shouldOpen: boolean): void;
|
|
36
|
+
onToggleOpen?(shouldOpen: boolean, event: React.MouseEvent): void;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
@@ -93,16 +93,16 @@ export const ExpansionPanel: Comp<ExpansionPanelProps, HTMLDivElement> = forward
|
|
|
93
93
|
<span className={`${CLASSNAME}__label`}>{label}</span>
|
|
94
94
|
);
|
|
95
95
|
|
|
96
|
-
const toggleOpen = () => {
|
|
96
|
+
const toggleOpen = (event: React.MouseEvent) => {
|
|
97
97
|
const shouldOpen = !isOpen;
|
|
98
98
|
if (isFunction(onOpen) && shouldOpen) {
|
|
99
|
-
onOpen();
|
|
99
|
+
onOpen(event);
|
|
100
100
|
}
|
|
101
101
|
if (isFunction(onClose) && !shouldOpen) {
|
|
102
|
-
onClose();
|
|
102
|
+
onClose(event);
|
|
103
103
|
}
|
|
104
104
|
if (isFunction(onToggleOpen)) {
|
|
105
|
-
onToggleOpen(shouldOpen);
|
|
105
|
+
onToggleOpen(shouldOpen, event);
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
|