@moda/om 21.1.1 → 21.2.1
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/dist/index.cjs.js +46 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +46 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/src/components/Select/Select.d.ts +6 -0
- package/dist/src/components/Select/Select.stories.d.ts +1 -0
- package/dist/src/components/Select/SelectOptions.d.ts +2 -1
- package/dist/styles.css +1 -1
- package/package.json +42 -44
- package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +3 -3
- package/src/components/Breakpoint/Breakpoint.stories.tsx +1 -1
- package/src/components/Button/Button.stories.tsx +1 -1
- package/src/components/Button/Button.test.tsx +1 -1
- package/src/components/Checkbox/Checkbox.test.tsx +2 -2
- package/src/components/Clickable/Clickable.stories.tsx +1 -1
- package/src/components/ColorSwatch/ColorSwatch.stories.tsx +1 -1
- package/src/components/ControlLink/ControlLink.stories.tsx +1 -1
- package/src/components/Field/Field.stories.tsx +1 -1
- package/src/components/Modal/Modal.test.tsx +4 -4
- package/src/components/Paginator/Paginator.stories.tsx +1 -1
- package/src/components/SearchInput/SearchInput.stories.tsx +1 -1
- package/src/components/Select/Select.stories.tsx +34 -26
- package/src/components/Select/Select.test.tsx +2 -2
- package/src/components/Select/Select.tsx +5 -0
- package/src/components/Select/SelectOptions.scss +7 -0
- package/src/components/Select/SelectOptions.tsx +14 -1
- package/src/components/SelectableButton/SelectableButton.stories.tsx +1 -1
- package/src/components/Tag/Tag.stories.tsx +1 -1
- package/src/components/Tag/Tag.test.tsx +1 -1
- package/src/components/Toast/Toast.stories.tsx +1 -1
- package/src/components/Toast/Toast.test.tsx +1 -1
- package/src/hooks/useKeyboardListNavigation.spec.ts +4 -4
|
@@ -11,6 +11,8 @@ import { useSelect } from './useSelect';
|
|
|
11
11
|
|
|
12
12
|
import './Select.scss';
|
|
13
13
|
|
|
14
|
+
export type SelectExtraOption = { callback: () => void; disabled?: boolean; label: string };
|
|
15
|
+
|
|
14
16
|
export type SelectableOption = {
|
|
15
17
|
value: string;
|
|
16
18
|
label: string;
|
|
@@ -39,6 +41,7 @@ export type SelectProps = Omit<
|
|
|
39
41
|
value?: string | undefined;
|
|
40
42
|
dataTestId?: string;
|
|
41
43
|
colorSwatch?: TextColor;
|
|
44
|
+
extraOption?: SelectExtraOption;
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
export const Select: React.FC<SelectProps> = ({
|
|
@@ -60,6 +63,7 @@ export const Select: React.FC<SelectProps> = ({
|
|
|
60
63
|
value,
|
|
61
64
|
dataTestId,
|
|
62
65
|
colorSwatch,
|
|
66
|
+
extraOption,
|
|
63
67
|
...rest
|
|
64
68
|
}) => {
|
|
65
69
|
const { state, dispatch, Mode, selectRef } = useSelect({ value, defaultValue });
|
|
@@ -165,6 +169,7 @@ export const Select: React.FC<SelectProps> = ({
|
|
|
165
169
|
onSelect={handleSelect}
|
|
166
170
|
onFocus={handleFocus}
|
|
167
171
|
selectedOption={selected}
|
|
172
|
+
extraOption={extraOption}
|
|
168
173
|
/>
|
|
169
174
|
)}
|
|
170
175
|
</div>
|
|
@@ -4,8 +4,9 @@ import { useKeyboardListNavigation } from '../../hooks/useKeyboardListNavigation
|
|
|
4
4
|
import { useUpdateEffect } from '../../hooks/useUpdateEffect';
|
|
5
5
|
import { Text } from '../Text';
|
|
6
6
|
import { SearchInput } from '../SearchInput';
|
|
7
|
+
import { ControlLink } from '../ControlLink';
|
|
7
8
|
import { SelectOption } from './SelectOption';
|
|
8
|
-
import { SelectableOption } from './Select';
|
|
9
|
+
import { SelectableOption, SelectExtraOption } from './Select';
|
|
9
10
|
|
|
10
11
|
import './SelectOptions.scss';
|
|
11
12
|
|
|
@@ -21,6 +22,7 @@ export type SelectOptionsProps = Omit<
|
|
|
21
22
|
onFocus?(option: SelectableOption): void;
|
|
22
23
|
onSelect(option: SelectableOption): void;
|
|
23
24
|
dataTestId?: string;
|
|
25
|
+
extraOption?: SelectExtraOption;
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
export const SelectOptions: React.FC<SelectOptionsProps> = ({
|
|
@@ -33,6 +35,7 @@ export const SelectOptions: React.FC<SelectOptionsProps> = ({
|
|
|
33
35
|
onFocus,
|
|
34
36
|
className,
|
|
35
37
|
dataTestId,
|
|
38
|
+
extraOption,
|
|
36
39
|
...rest
|
|
37
40
|
}) => {
|
|
38
41
|
const [searchPhrase, setSearchPhrase] = useState('');
|
|
@@ -92,6 +95,16 @@ export const SelectOptions: React.FC<SelectOptionsProps> = ({
|
|
|
92
95
|
onClick={onSelect}
|
|
93
96
|
/>
|
|
94
97
|
))}
|
|
98
|
+
|
|
99
|
+
{extraOption && (
|
|
100
|
+
<ControlLink
|
|
101
|
+
className='SelectOptions__extra-option'
|
|
102
|
+
disabled={extraOption.disabled}
|
|
103
|
+
onClick={extraOption.callback}
|
|
104
|
+
>
|
|
105
|
+
{extraOption.label}
|
|
106
|
+
</ControlLink>
|
|
107
|
+
)}
|
|
95
108
|
</ul>
|
|
96
109
|
|
|
97
110
|
{options.length === 0 && (
|
|
@@ -153,7 +153,7 @@ describe('useKeyboardListNavigation', () => {
|
|
|
153
153
|
|
|
154
154
|
fireEvent.keyDown(window, { key: 'Enter' });
|
|
155
155
|
|
|
156
|
-
expect(onEnter).
|
|
156
|
+
expect(onEnter).toHaveBeenCalledTimes(1);
|
|
157
157
|
expect(onEnter).toHaveBeenCalledWith({
|
|
158
158
|
element: 'first',
|
|
159
159
|
event: expect.anything(),
|
|
@@ -166,7 +166,7 @@ describe('useKeyboardListNavigation', () => {
|
|
|
166
166
|
|
|
167
167
|
fireEvent.keyDown(window, { key: 'Enter' });
|
|
168
168
|
|
|
169
|
-
expect(onEnter).
|
|
169
|
+
expect(onEnter).toHaveBeenCalledTimes(2);
|
|
170
170
|
expect(onEnter).toHaveBeenLastCalledWith({
|
|
171
171
|
element: 'third',
|
|
172
172
|
event: expect.anything(),
|
|
@@ -220,13 +220,13 @@ describe('useKeyboardListNavigation', () => {
|
|
|
220
220
|
|
|
221
221
|
fireEvent.keyDown(window, { key: 'Enter' });
|
|
222
222
|
|
|
223
|
-
expect(onEnter).
|
|
223
|
+
expect(onEnter).toHaveBeenCalledTimes(0);
|
|
224
224
|
|
|
225
225
|
fireEvent.keyDown(window, { key: 'ArrowDown' });
|
|
226
226
|
|
|
227
227
|
fireEvent.keyDown(window, { key: 'Enter' });
|
|
228
228
|
|
|
229
|
-
expect(onEnter).
|
|
229
|
+
expect(onEnter).toHaveBeenCalledTimes(1);
|
|
230
230
|
});
|
|
231
231
|
});
|
|
232
232
|
});
|