@moda/om 16.2.1 → 17.1.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/CHANGELOG.md +26 -0
- package/dist/index.cjs.js +46 -26
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +46 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/src/components/Expandable/Expandable.d.ts +2 -0
- package/dist/src/components/Select/Select.d.ts +1 -0
- package/dist/src/components/Select/SelectOption.d.ts +1 -0
- package/dist/src/components/Select/SelectOptions.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/Expandable/Expandable.tsx +15 -4
- package/src/components/Select/Select.tsx +4 -0
- package/src/components/Select/SelectOption.tsx +4 -1
- package/src/components/Select/SelectOptions.tsx +3 -0
|
@@ -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>;
|
|
@@ -6,5 +6,6 @@ export declare type SelectOptionProps = Omit<React.HTMLAttributes<HTMLLIElement>
|
|
|
6
6
|
selected: boolean;
|
|
7
7
|
option: SelectableOption;
|
|
8
8
|
onClick: (option: SelectableOption) => void;
|
|
9
|
+
dataTestId?: string;
|
|
9
10
|
};
|
|
10
11
|
export declare const SelectOption: React.FC<SelectOptionProps>;
|
|
@@ -9,5 +9,6 @@ export declare type SelectOptionsProps = Omit<React.HTMLAttributes<HTMLUListElem
|
|
|
9
9
|
selectedOption?: SelectableOption | undefined;
|
|
10
10
|
onFocus?(option: SelectableOption): void;
|
|
11
11
|
onSelect(option: SelectableOption): void;
|
|
12
|
+
dataTestId?: string;
|
|
12
13
|
};
|
|
13
14
|
export declare const SelectOptions: React.FC<SelectOptionsProps>;
|
package/package.json
CHANGED
|
@@ -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__
|
|
28
|
+
expanded: __expanded__,
|
|
29
|
+
onToggle,
|
|
26
30
|
...rest
|
|
27
31
|
}) => {
|
|
28
|
-
const [expanded, setExpanded] = useState(
|
|
32
|
+
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
29
33
|
|
|
30
|
-
|
|
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
|
|
@@ -29,6 +29,7 @@ export type SelectProps = Omit<
|
|
|
29
29
|
searchable?: boolean;
|
|
30
30
|
shiftIconLeftwards?: boolean;
|
|
31
31
|
value?: string | undefined;
|
|
32
|
+
dataTestId?: string;
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
export const Select: React.FC<SelectProps> = ({
|
|
@@ -48,6 +49,7 @@ export const Select: React.FC<SelectProps> = ({
|
|
|
48
49
|
searchable,
|
|
49
50
|
shiftIconLeftwards = false,
|
|
50
51
|
value,
|
|
52
|
+
dataTestId,
|
|
51
53
|
...rest
|
|
52
54
|
}) => {
|
|
53
55
|
const { state, dispatch, Mode, selectRef } = useSelect({ value, defaultValue });
|
|
@@ -111,6 +113,7 @@ export const Select: React.FC<SelectProps> = ({
|
|
|
111
113
|
className="Select__value"
|
|
112
114
|
disabled={disabled}
|
|
113
115
|
onClick={handleToggle}
|
|
116
|
+
data-test-id={dataTestId}
|
|
114
117
|
aria-haspopup="listbox"
|
|
115
118
|
aria-expanded={state.mode === Mode.Open}
|
|
116
119
|
aria-labelledby={`Select__label--${idRef} Select__value--${idRef}`}
|
|
@@ -139,6 +142,7 @@ export const Select: React.FC<SelectProps> = ({
|
|
|
139
142
|
'Select__options--up': dropDirection === 'up',
|
|
140
143
|
'Select__options--down': dropDirection === 'down'
|
|
141
144
|
})}
|
|
145
|
+
dataTestId={dataTestId}
|
|
142
146
|
searchable={searchable}
|
|
143
147
|
options={options}
|
|
144
148
|
onSelect={handleSelect}
|
|
@@ -9,6 +9,7 @@ export type SelectOptionProps = Omit<React.HTMLAttributes<HTMLLIElement>, 'onCli
|
|
|
9
9
|
selected: boolean;
|
|
10
10
|
option: SelectableOption;
|
|
11
11
|
onClick: (option: SelectableOption) => void;
|
|
12
|
+
dataTestId?: string;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export const SelectOption: React.FC<SelectOptionProps> = ({
|
|
@@ -16,7 +17,8 @@ export const SelectOption: React.FC<SelectOptionProps> = ({
|
|
|
16
17
|
selected,
|
|
17
18
|
option,
|
|
18
19
|
onClick,
|
|
19
|
-
className
|
|
20
|
+
className,
|
|
21
|
+
dataTestId
|
|
20
22
|
}) => {
|
|
21
23
|
const ref = useRef<HTMLLIElement>(null);
|
|
22
24
|
|
|
@@ -43,6 +45,7 @@ export const SelectOption: React.FC<SelectOptionProps> = ({
|
|
|
43
45
|
'SelectOption--disabled': option.disabled
|
|
44
46
|
})}
|
|
45
47
|
onClick={handleClick}
|
|
48
|
+
data-test-id={dataTestId ? `${dataTestId}--${option.label.replace(' ', '-')}` : undefined}
|
|
46
49
|
aria-label={option.label}
|
|
47
50
|
aria-selected={selected}
|
|
48
51
|
role="option"
|
|
@@ -19,6 +19,7 @@ export type SelectOptionsProps = Omit<
|
|
|
19
19
|
selectedOption?: SelectableOption | undefined;
|
|
20
20
|
onFocus?(option: SelectableOption): void;
|
|
21
21
|
onSelect(option: SelectableOption): void;
|
|
22
|
+
dataTestId?: string;
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
export const SelectOptions: React.FC<SelectOptionsProps> = ({
|
|
@@ -30,6 +31,7 @@ export const SelectOptions: React.FC<SelectOptionsProps> = ({
|
|
|
30
31
|
onSelect,
|
|
31
32
|
onFocus,
|
|
32
33
|
className,
|
|
34
|
+
dataTestId,
|
|
33
35
|
...rest
|
|
34
36
|
}) => {
|
|
35
37
|
const [searchPhrase, setSearchPhrase] = useState('');
|
|
@@ -82,6 +84,7 @@ export const SelectOptions: React.FC<SelectOptionsProps> = ({
|
|
|
82
84
|
id={`SelectOption--${option.value}-${idRef}`}
|
|
83
85
|
key={option.value}
|
|
84
86
|
option={option}
|
|
87
|
+
dataTestId={dataTestId}
|
|
85
88
|
active={activeOption?.value === option.value}
|
|
86
89
|
selected={selectedOption?.value === option.value}
|
|
87
90
|
onClick={onSelect}
|