@moda/om 16.3.0 → 17.2.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.
@@ -11,7 +11,7 @@ export declare type ColorSwatchProps = Omit<Omit<React.ButtonHTMLAttributes<HTML
11
11
  selected?: boolean;
12
12
  soldOut?: boolean;
13
13
  onSale?: boolean;
14
- onClick?(color: string): void;
15
- onMouseEnter?(color: string): void;
14
+ onClick?(color: string, title?: string): void;
15
+ onMouseEnter?(color: string, title?: string): void;
16
16
  };
17
17
  export declare const ColorSwatch: React.FC<ColorSwatchProps>;
@@ -2,10 +2,12 @@ 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';
8
9
  virtual?: boolean;
9
10
  'data-testid'?: string;
11
+ onToggle?: () => void;
10
12
  };
11
13
  export declare const Expandable: React.FC<ExpandableProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moda/om",
3
- "version": "16.3.0",
3
+ "version": "17.2.0",
4
4
  "description": "Moda Operandi design system",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -18,8 +18,8 @@ export type ColorSwatchProps = Omit<
18
18
  selected?: boolean;
19
19
  soldOut?: boolean;
20
20
  onSale?: boolean;
21
- onClick?(color: string): void;
22
- onMouseEnter?(color: string): void;
21
+ onClick?(color: string, title?: string): void;
22
+ onMouseEnter?(color: string, title?: string): void;
23
23
  };
24
24
 
25
25
  export const ColorSwatch: React.FC<ColorSwatchProps> = ({
@@ -35,20 +35,21 @@ export const ColorSwatch: React.FC<ColorSwatchProps> = ({
35
35
  onClick,
36
36
  onMouseEnter,
37
37
  disabled,
38
+ title,
38
39
  ...rest
39
40
  }) => {
40
41
  const handleClick = useCallback(
41
42
  (_event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
42
- onClick && onClick(color);
43
+ onClick && onClick(color, title);
43
44
  },
44
- [color, onClick]
45
+ [color, title, onClick]
45
46
  );
46
47
 
47
48
  const handleMouseEnter = useCallback(
48
49
  (_event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
49
- onMouseEnter && onMouseEnter(color);
50
+ onMouseEnter && onMouseEnter(color, title);
50
51
  },
51
- [color, onMouseEnter]
52
+ [color, title, onMouseEnter]
52
53
  );
53
54
 
54
55
  const backgroundColor = SKU_COLORS[color as SkuColor];
@@ -81,6 +82,7 @@ export const ColorSwatch: React.FC<ColorSwatchProps> = ({
81
82
  onClick={handleClick}
82
83
  onMouseEnter={handleMouseEnter}
83
84
  disabled={disabled}
85
+ title={title}
84
86
  {...rest}
85
87
  >
86
88
  <div className="ColorSwatch__chip" style={styles} />
@@ -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,11 +7,13 @@ 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';
13
14
  virtual?: boolean;
14
15
  'data-testid'?: string;
16
+ onToggle?: () => void;
15
17
  };
16
18
 
17
19
  export const Expandable: React.FC<ExpandableProps> = ({
@@ -21,13 +23,22 @@ export const Expandable: React.FC<ExpandableProps> = ({
21
23
  virtual = false,
22
24
  icon = 'plus-minus',
23
25
  'data-testid': dataTestId,
26
+ defaultExpanded = false,
24
27
  // eslint-disable-next-line @typescript-eslint/naming-convention
25
- expanded: __expanded__ = false,
28
+ expanded: __expanded__,
29
+ onToggle,
26
30
  ...rest
27
31
  }) => {
28
- const [expanded, setExpanded] = useState(__expanded__);
32
+ const [expanded, setExpanded] = useState(defaultExpanded);
29
33
 
30
- const handleClick = useCallback(() => setExpanded(expanded => !expanded), []);
34
+ useEffect(() => {
35
+ if (__expanded__ != null && __expanded__ !== expanded) setExpanded(__expanded__);
36
+ }, [expanded, __expanded__]);
37
+
38
+ const handleClick = useCallback(() => {
39
+ setExpanded(expanded => !expanded);
40
+ onToggle?.();
41
+ }, [onToggle]);
31
42
 
32
43
  return (
33
44
  <div