@lumx/react 3.13.3-alpha.2 → 3.14.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 CHANGED
@@ -6,8 +6,8 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/core": "^3.13.3-alpha.2",
10
- "@lumx/icons": "^3.13.3-alpha.2",
9
+ "@lumx/core": "^3.14.0",
10
+ "@lumx/icons": "^3.14.0",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -110,5 +110,5 @@
110
110
  "build:storybook": "storybook build"
111
111
  },
112
112
  "sideEffects": false,
113
- "version": "3.13.3-alpha.2"
113
+ "version": "3.14.0"
114
114
  }
@@ -1,9 +1,18 @@
1
1
  /* eslint-disable react-hooks/rules-of-hooks */
2
2
  import React from 'react';
3
3
 
4
- import { ExpansionPanel, FlexBox } from '@lumx/react';
4
+ import { ExpansionPanel, ExpansionPanelProps, Text } from '@lumx/react';
5
5
  import { withNestedProps } from '@lumx/react/stories/decorators/withNestedProps';
6
6
 
7
+ function useBaseProps({
8
+ toggleButtonProps = { label: 'Toggle' },
9
+ isOpen: initiallyOpen,
10
+ ...args
11
+ }: Partial<ExpansionPanelProps>) {
12
+ const [isOpen, setOpen] = React.useState(initiallyOpen);
13
+ return { isOpen, toggleButtonProps, onToggleOpen: setOpen, ...args };
14
+ }
15
+
7
16
  export default {
8
17
  title: 'LumX components/expansion-panel/ExpansionPanel',
9
18
  component: ExpansionPanel,
@@ -13,11 +22,8 @@ export default {
13
22
  label: 'Label',
14
23
  },
15
24
  decorators: [withNestedProps()],
16
- render({ toggleButtonProps, ...args }: any) {
17
- const [isOpen, setOpen] = React.useState(args.isOpen);
18
- return (
19
- <ExpansionPanel isOpen={isOpen} toggleButtonProps={toggleButtonProps} onToggleOpen={setOpen} {...args} />
20
- );
25
+ render(args: ExpansionPanelProps) {
26
+ return <ExpansionPanel {...useBaseProps(args)} />;
21
27
  },
22
28
  };
23
29
 
@@ -40,19 +46,34 @@ export const HasHeaderDivider = {
40
46
  },
41
47
  };
42
48
 
43
- /** Test resizable content work */
44
- export const ResizingContent = {
45
- args: {
46
- hasBackground: true,
47
- children: (
48
- <FlexBox
49
- style={{ resize: 'both', overflow: 'hidden' }}
50
- hAlign="center"
51
- vAlign="center"
52
- className="lumx-spacing-padding-huge"
53
- >
54
- Content
55
- </FlexBox>
56
- ),
49
+ /** Nested expansion panels */
50
+ export const Nested = {
51
+ args: {},
52
+ render(args: ExpansionPanelProps) {
53
+ return (
54
+ <ExpansionPanel {...useBaseProps(args)}>
55
+ <ExpansionPanel
56
+ label="Child 1"
57
+ hasBackground
58
+ className="lumx-spacing-margin-left-huge lumx-spacing-margin-bottom-big"
59
+ {...useBaseProps(args)}
60
+ >
61
+ <Text as="p" typography="body1" color="dark-L2" className="lumx-spacing-padding-big">
62
+ content child 1
63
+ </Text>
64
+ </ExpansionPanel>
65
+
66
+ <ExpansionPanel
67
+ label="Child 2"
68
+ hasBackground
69
+ className="lumx-spacing-margin-left-huge lumx-spacing-margin-bottom-big"
70
+ {...useBaseProps(args)}
71
+ >
72
+ <Text as="p" typography="body1" color="dark-L2" className="lumx-spacing-padding-big">
73
+ content child 2
74
+ </Text>
75
+ </ExpansionPanel>
76
+ </ExpansionPanel>
77
+ );
57
78
  },
58
79
  };
@@ -10,10 +10,9 @@ import { ColorPalette, DragHandle, Emphasis, IconButton, IconButtonProps, Theme
10
10
  import { GenericProps, HasTheme, isComponent } from '@lumx/react/utils/type';
11
11
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
12
12
  import { partitionMulti } from '@lumx/react/utils/partitionMulti';
13
- import { useTransitionVisibility } from '@lumx/react/hooks/useTransitionVisibility';
14
- import { EXPANSION_PANEL_TRANSITION_DURATION } from '@lumx/core/js/constants';
15
13
  import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
16
14
  import { forwardRef } from '@lumx/react/utils/react/forwardRef';
15
+ import { IS_BROWSER } from '@lumx/react/constants';
17
16
 
18
17
  /**
19
18
  * Defines the props of the component.
@@ -128,8 +127,32 @@ export const ExpansionPanel = forwardRef<ExpansionPanelProps, HTMLDivElement>((p
128
127
 
129
128
  const wrapperRef = useRef<HTMLDivElement>(null);
130
129
 
131
- /** Hide the children at the end of the transition */
132
- const isChildrenVisible = useTransitionVisibility(wrapperRef, !!isOpen, EXPANSION_PANEL_TRANSITION_DURATION);
130
+ // Children visible while the open/close transition is running
131
+ const [isChildrenVisible, setChildrenVisible] = React.useState(isOpen);
132
+
133
+ const isOpenRef = React.useRef(isOpen);
134
+ React.useEffect(() => {
135
+ if (isOpen) {
136
+ setChildrenVisible(true);
137
+ } else if (!IS_BROWSER) {
138
+ // Outside a browser we can't wait for the transition
139
+ setChildrenVisible(false);
140
+ }
141
+ isOpenRef.current = isOpen;
142
+ }, [isOpen]);
143
+
144
+ // Change children visibility on transition end
145
+ React.useEffect(() => {
146
+ const { current: wrapper } = wrapperRef;
147
+ if (!IS_BROWSER || !wrapper) {
148
+ return undefined;
149
+ }
150
+ const onTransitionEnd = () => {
151
+ setChildrenVisible(isOpenRef.current);
152
+ };
153
+ wrapper.addEventListener('transitionend', onTransitionEnd);
154
+ return () => wrapper.removeEventListener('transitionend', onTransitionEnd);
155
+ }, []);
133
156
 
134
157
  return (
135
158
  <section ref={ref} {...forwardedProps} className={rootClassName}>
@@ -152,9 +175,9 @@ export const ExpansionPanel = forwardRef<ExpansionPanelProps, HTMLDivElement>((p
152
175
  </div>
153
176
  </header>
154
177
 
155
- <div className={`${CLASSNAME}__wrapper`}>
178
+ <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>
156
179
  {(isOpen || isChildrenVisible) && (
157
- <div className={`${CLASSNAME}__container`} ref={wrapperRef}>
180
+ <div className={`${CLASSNAME}__container`}>
158
181
  <div className={`${CLASSNAME}__content`}>{content}</div>
159
182
 
160
183
  {footer && <div className={`${CLASSNAME}__footer`}>{footer}</div>}