@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.
Files changed (32) hide show
  1. package/dist/index.cjs.js +46 -13
  2. package/dist/index.cjs.js.map +1 -1
  3. package/dist/index.esm.js +46 -13
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/src/components/Select/Select.d.ts +6 -0
  6. package/dist/src/components/Select/Select.stories.d.ts +1 -0
  7. package/dist/src/components/Select/SelectOptions.d.ts +2 -1
  8. package/dist/styles.css +1 -1
  9. package/package.json +42 -44
  10. package/src/components/Breadcrumbs/Breadcrumbs.test.tsx +3 -3
  11. package/src/components/Breakpoint/Breakpoint.stories.tsx +1 -1
  12. package/src/components/Button/Button.stories.tsx +1 -1
  13. package/src/components/Button/Button.test.tsx +1 -1
  14. package/src/components/Checkbox/Checkbox.test.tsx +2 -2
  15. package/src/components/Clickable/Clickable.stories.tsx +1 -1
  16. package/src/components/ColorSwatch/ColorSwatch.stories.tsx +1 -1
  17. package/src/components/ControlLink/ControlLink.stories.tsx +1 -1
  18. package/src/components/Field/Field.stories.tsx +1 -1
  19. package/src/components/Modal/Modal.test.tsx +4 -4
  20. package/src/components/Paginator/Paginator.stories.tsx +1 -1
  21. package/src/components/SearchInput/SearchInput.stories.tsx +1 -1
  22. package/src/components/Select/Select.stories.tsx +34 -26
  23. package/src/components/Select/Select.test.tsx +2 -2
  24. package/src/components/Select/Select.tsx +5 -0
  25. package/src/components/Select/SelectOptions.scss +7 -0
  26. package/src/components/Select/SelectOptions.tsx +14 -1
  27. package/src/components/SelectableButton/SelectableButton.stories.tsx +1 -1
  28. package/src/components/Tag/Tag.stories.tsx +1 -1
  29. package/src/components/Tag/Tag.test.tsx +1 -1
  30. package/src/components/Toast/Toast.stories.tsx +1 -1
  31. package/src/components/Toast/Toast.test.tsx +1 -1
  32. 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>
@@ -21,4 +21,11 @@
21
21
  @include om.overflow-scroll();
22
22
  max-height: om.space(12);
23
23
  }
24
+
25
+ &__extra-option {
26
+ left: 50%;
27
+ margin-bottom: om.space(1);
28
+ margin-top: om.space(2);
29
+ transform: translate(-50%);
30
+ }
24
31
  }
@@ -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 && (
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { action } from '@storybook/addon-actions';
2
+ import { action } from 'storybook/actions';
3
3
 
4
4
  import { States } from '../../utilities';
5
5
  import { Stack } from '../Stack';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { action } from '@storybook/addon-actions';
2
+ import { action } from 'storybook/actions';
3
3
  import { States } from '../../utilities';
4
4
  import { Tag, TagProps } from './Tag';
5
5
 
@@ -11,6 +11,6 @@ describe('Tag', () => {
11
11
  expect(screen.getByText('Hello')).toBeInTheDocument();
12
12
 
13
13
  await userEvent.click(screen.getByRole('button'));
14
- expect(onRemove).toBeCalled();
14
+ expect(onRemove).toHaveBeenCalled();
15
15
  });
16
16
  });
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { action } from '@storybook/addon-actions';
2
+ import { action } from 'storybook/actions';
3
3
  import { States } from '../../utilities';
4
4
  import { Toast, ToastProps } from './Toast';
5
5
 
@@ -15,6 +15,6 @@ describe('Toast', () => {
15
15
  expect(screen.getByText('Hello')).toBeInTheDocument();
16
16
 
17
17
  await userEvent.click(screen.getByRole('button', { name: 'Remove' }));
18
- expect(onRemove).toBeCalled();
18
+ expect(onRemove).toHaveBeenCalled();
19
19
  });
20
20
  });
@@ -153,7 +153,7 @@ describe('useKeyboardListNavigation', () => {
153
153
 
154
154
  fireEvent.keyDown(window, { key: 'Enter' });
155
155
 
156
- expect(onEnter).toBeCalledTimes(1);
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).toBeCalledTimes(2);
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).toBeCalledTimes(0);
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).toBeCalledTimes(1);
229
+ expect(onEnter).toHaveBeenCalledTimes(1);
230
230
  });
231
231
  });
232
232
  });