@moda/om 16.3.0 → 17.0.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.
@@ -2,6 +2,7 @@ import React, { ReactNode } from 'react';
2
2
  import './Expandable.scss';
3
3
  export declare type ExpandableProps = React.HTMLAttributes<HTMLDivElement> & {
4
4
  name: string | ReactNode;
5
+ defaultExpanded?: boolean;
5
6
  expanded?: boolean;
6
7
  children: ReactNode;
7
8
  icon?: 'chevron' | 'plus-minus';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moda/om",
3
- "version": "16.3.0",
3
+ "version": "17.0.0",
4
4
  "description": "Moda Operandi design system",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useState, ReactNode } from 'react';
1
+ import React, { useEffect, useCallback, useState, ReactNode } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import ChevronDownIcon from '@moda/icons/chevron-down-12';
4
4
  import ChevronUpIcon from '@moda/icons/chevron-up-12';
@@ -7,6 +7,7 @@ import './Expandable.scss';
7
7
 
8
8
  export type ExpandableProps = React.HTMLAttributes<HTMLDivElement> & {
9
9
  name: string | ReactNode;
10
+ defaultExpanded?: boolean;
10
11
  expanded?: boolean;
11
12
  children: ReactNode;
12
13
  icon?: 'chevron' | 'plus-minus';
@@ -21,11 +22,16 @@ export const Expandable: React.FC<ExpandableProps> = ({
21
22
  virtual = false,
22
23
  icon = 'plus-minus',
23
24
  'data-testid': dataTestId,
25
+ defaultExpanded = false,
24
26
  // eslint-disable-next-line @typescript-eslint/naming-convention
25
- expanded: __expanded__ = false,
27
+ expanded: __expanded__,
26
28
  ...rest
27
29
  }) => {
28
- const [expanded, setExpanded] = useState(__expanded__);
30
+ const [expanded, setExpanded] = useState(defaultExpanded);
31
+
32
+ useEffect(() => {
33
+ if (__expanded__ != null && __expanded__ !== expanded) setExpanded(__expanded__);
34
+ }, [expanded, __expanded__]);
29
35
 
30
36
  const handleClick = useCallback(() => setExpanded(expanded => !expanded), []);
31
37