@coveord/plasma-mantine 49.1.0 → 49.1.2

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 (59) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test.log +9 -9
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/cjs/components/button/Button.js +16 -8
  5. package/dist/cjs/components/button/Button.js.map +1 -1
  6. package/dist/cjs/components/button/ButtonWithDisabledTooltip.js +17 -36
  7. package/dist/cjs/components/button/ButtonWithDisabledTooltip.js.map +1 -1
  8. package/dist/cjs/components/collection/Collection.js +5 -4
  9. package/dist/cjs/components/collection/Collection.js.map +1 -1
  10. package/dist/cjs/components/inline-confirm/InlineConfirm.js +2 -0
  11. package/dist/cjs/components/inline-confirm/InlineConfirm.js.map +1 -1
  12. package/dist/cjs/components/inline-confirm/InlineConfirmButton.js +16 -11
  13. package/dist/cjs/components/inline-confirm/InlineConfirmButton.js.map +1 -1
  14. package/dist/cjs/components/inline-confirm/InlineConfirmMenuItem.js +33 -0
  15. package/dist/cjs/components/inline-confirm/InlineConfirmMenuItem.js.map +1 -0
  16. package/dist/cjs/components/menu/Menu.js +17 -6
  17. package/dist/cjs/components/menu/Menu.js.map +1 -1
  18. package/dist/cjs/theme/Theme.js +9 -2
  19. package/dist/cjs/theme/Theme.js.map +1 -1
  20. package/dist/definitions/components/button/Button.d.ts +1 -2
  21. package/dist/definitions/components/button/Button.d.ts.map +1 -1
  22. package/dist/definitions/components/button/ButtonWithDisabledTooltip.d.ts +10 -9
  23. package/dist/definitions/components/button/ButtonWithDisabledTooltip.d.ts.map +1 -1
  24. package/dist/definitions/components/collection/Collection.d.ts.map +1 -1
  25. package/dist/definitions/components/inline-confirm/InlineConfirm.d.ts +2 -0
  26. package/dist/definitions/components/inline-confirm/InlineConfirm.d.ts.map +1 -1
  27. package/dist/definitions/components/inline-confirm/InlineConfirmButton.d.ts +4 -4
  28. package/dist/definitions/components/inline-confirm/InlineConfirmButton.d.ts.map +1 -1
  29. package/dist/definitions/components/inline-confirm/InlineConfirmMenuItem.d.ts +8 -0
  30. package/dist/definitions/components/inline-confirm/InlineConfirmMenuItem.d.ts.map +1 -0
  31. package/dist/definitions/components/menu/Menu.d.ts.map +1 -1
  32. package/dist/definitions/theme/Theme.d.ts.map +1 -1
  33. package/dist/esm/components/button/Button.js +17 -9
  34. package/dist/esm/components/button/Button.js.map +1 -1
  35. package/dist/esm/components/button/ButtonWithDisabledTooltip.js +18 -37
  36. package/dist/esm/components/button/ButtonWithDisabledTooltip.js.map +1 -1
  37. package/dist/esm/components/collection/Collection.js +6 -5
  38. package/dist/esm/components/collection/Collection.js.map +1 -1
  39. package/dist/esm/components/inline-confirm/InlineConfirm.js +2 -0
  40. package/dist/esm/components/inline-confirm/InlineConfirm.js.map +1 -1
  41. package/dist/esm/components/inline-confirm/InlineConfirmButton.js +16 -11
  42. package/dist/esm/components/inline-confirm/InlineConfirmButton.js.map +1 -1
  43. package/dist/esm/components/inline-confirm/InlineConfirmMenuItem.js +23 -0
  44. package/dist/esm/components/inline-confirm/InlineConfirmMenuItem.js.map +1 -0
  45. package/dist/esm/components/menu/Menu.js +17 -6
  46. package/dist/esm/components/menu/Menu.js.map +1 -1
  47. package/dist/esm/theme/Theme.js +9 -2
  48. package/dist/esm/theme/Theme.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/components/button/Button.tsx +12 -18
  51. package/src/components/button/ButtonWithDisabledTooltip.tsx +17 -38
  52. package/src/components/button/__tests__/ButtonWithDisabledTooltip.spec.tsx +22 -28
  53. package/src/components/collection/Collection.tsx +5 -3
  54. package/src/components/inline-confirm/InlineConfirm.tsx +3 -0
  55. package/src/components/inline-confirm/InlineConfirmButton.tsx +15 -11
  56. package/src/components/inline-confirm/InlineConfirmMenuItem.tsx +21 -0
  57. package/src/components/inline-confirm/__tests__/InlineConfirm.spec.tsx +25 -0
  58. package/src/components/menu/Menu.tsx +13 -4
  59. package/src/theme/Theme.tsx +7 -0
@@ -1,58 +1,37 @@
1
- import {Box, Tooltip} from '@mantine/core';
2
- import {Property} from 'csstype';
3
- import {forwardRef, MouseEventHandler} from 'react';
1
+ import {Box, Tooltip, TooltipProps} from '@mantine/core';
2
+ import {forwardRef, ReactNode} from 'react';
4
3
 
5
4
  import {createPolymorphicComponent} from '../../utils';
6
5
 
7
6
  export interface ButtonWithDisabledTooltipProps {
8
- disabled?: boolean;
9
- onClick?: MouseEventHandler<HTMLButtonElement>;
10
7
  /**
11
8
  * The tooltip message to display when disabled
12
9
  */
13
10
  disabledTooltip?: string;
14
11
  /**
15
- * The background color when disabled
16
- *
17
- * @default 'unset'
12
+ * Whether the button underneath the tooltip is disabled
13
+ */
14
+ disabled?: boolean;
15
+ children?: ReactNode;
16
+ /**
17
+ * Additional tooltip props to set on the disabled button tooltip
18
18
  */
19
- disabledHoverColor?: Property.BackgroundColor;
19
+ disabledTooltipProps?: Omit<TooltipProps, 'disabled' | 'label' | 'children'>;
20
20
  }
21
21
 
22
- const _ButtonWithDisabledTooltip = forwardRef<HTMLButtonElement, ButtonWithDisabledTooltipProps>(
23
- ({disabledTooltip, disabled, onClick, disabledHoverColor: hoverColor = 'unset', ...others}, ref) =>
22
+ const _ButtonWithDisabledTooltip = forwardRef<HTMLDivElement, ButtonWithDisabledTooltipProps>(
23
+ ({disabledTooltip, disabled, children, disabledTooltipProps, ...others}, ref) =>
24
24
  disabledTooltip ? (
25
- <Tooltip label={disabledTooltip} disabled={!disabled}>
26
- <Box
27
- component="button"
28
- ref={ref}
29
- {...(disabled ? {'data-disabled': true} : {})}
30
- sx={(theme) => ({
31
- '&[data-disabled]': {
32
- pointerEvents: 'all',
33
- color: theme.colors.gray[5],
34
- },
35
- '&[data-disabled]:hover': {
36
- backgroundColor: hoverColor,
37
- cursor: 'not-allowed',
38
- },
39
- })}
40
- onClick={(event) => {
41
- if (disabled) {
42
- event.preventDefault();
43
- event.stopPropagation();
44
- } else {
45
- onClick?.(event);
46
- }
47
- }}
48
- {...others}
49
- />
25
+ <Tooltip label={disabledTooltip} disabled={!disabled} {...disabledTooltipProps}>
26
+ <Box ref={ref} sx={{'&:hover': {cursor: 'not-allowed'}}} {...others}>
27
+ {children}
28
+ </Box>
50
29
  </Tooltip>
51
30
  ) : (
52
- <Box component="button" ref={ref} disabled={disabled} onClick={onClick} {...others} />
31
+ <>{children}</>
53
32
  )
54
33
  );
55
34
 
56
- export const ButtonWithDisabledTooltip = createPolymorphicComponent<'button', ButtonWithDisabledTooltipProps>(
35
+ export const ButtonWithDisabledTooltip = createPolymorphicComponent<'div', ButtonWithDisabledTooltipProps>(
57
36
  _ButtonWithDisabledTooltip
58
37
  );
@@ -2,40 +2,15 @@ import {render, screen, userEvent} from '@test-utils';
2
2
  import {ButtonWithDisabledTooltip} from '../ButtonWithDisabledTooltip';
3
3
 
4
4
  describe('ButtonWithDisabledTooltip', () => {
5
- it('disables the button when disabled prop is true', async () => {
6
- const user = userEvent.setup();
7
- const onClickSpy = jest.fn();
8
- render(
9
- <ButtonWithDisabledTooltip disabled onClick={onClickSpy}>
10
- save
11
- </ButtonWithDisabledTooltip>
12
- );
13
-
14
- const button = screen.getByRole('button', {name: /save/i});
15
- await user.click(button);
16
- expect(button).toBeDisabled();
17
- expect(onClickSpy).not.toHaveBeenCalled();
18
- });
19
-
20
- it('does not disable the button when disabled prop is false', async () => {
21
- const user = userEvent.setup();
22
- const onClickSpy = jest.fn();
23
- render(<ButtonWithDisabledTooltip onClick={onClickSpy}>save</ButtonWithDisabledTooltip>);
24
-
25
- const button = screen.getByRole('button', {name: /save/i});
26
- await user.click(button);
27
- expect(button).toBeEnabled();
28
- expect(onClickSpy).toHaveBeenCalledTimes(1);
29
- });
30
-
31
5
  it('shows a tooltip when hovering over the disabled button', async () => {
32
6
  const user = userEvent.setup();
33
7
  render(
34
8
  <ButtonWithDisabledTooltip disabled disabledTooltip="tooltip message">
35
- save
9
+ <button disabled>save</button>
36
10
  </ButtonWithDisabledTooltip>
37
11
  );
38
12
  const button = screen.getByRole('button', {name: /save/i});
13
+ expect(button).toBeDisabled();
39
14
  expect(screen.queryByRole('tooltip', {name: /tooltip message/i})).not.toBeInTheDocument();
40
15
  await user.hover(button);
41
16
  expect(screen.getByRole('tooltip', {name: /tooltip message/i})).toBeInTheDocument();
@@ -43,10 +18,29 @@ describe('ButtonWithDisabledTooltip', () => {
43
18
 
44
19
  it('does not show the tooltip when hovering over the button if it is not disabled', async () => {
45
20
  const user = userEvent.setup();
46
- render(<ButtonWithDisabledTooltip disabledTooltip="tooltip message">save</ButtonWithDisabledTooltip>);
21
+ render(
22
+ <ButtonWithDisabledTooltip disabledTooltip="tooltip message">
23
+ <button>save</button>
24
+ </ButtonWithDisabledTooltip>
25
+ );
47
26
  const button = screen.getByRole('button', {name: /save/i});
48
27
  expect(screen.queryByRole('tooltip', {name: /tooltip message/i})).not.toBeInTheDocument();
49
28
  await user.hover(button);
50
29
  expect(screen.queryByRole('tooltip', {name: /tooltip message/i})).not.toBeInTheDocument();
51
30
  });
31
+
32
+ it('does not render the tooltip if there is no disabled tooltip message', () => {
33
+ const {container} = render(
34
+ <ButtonWithDisabledTooltip>
35
+ <button>save</button>
36
+ </ButtonWithDisabledTooltip>
37
+ );
38
+ expect(container).toMatchInlineSnapshot(`
39
+ <div>
40
+ <button>
41
+ save
42
+ </button>
43
+ </div>
44
+ `);
45
+ });
52
46
  });
@@ -141,6 +141,7 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
141
141
  allowAdd,
142
142
  label,
143
143
  labelProps,
144
+ withAsterisk,
144
145
  description,
145
146
  descriptionProps,
146
147
  error,
@@ -166,8 +167,9 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
166
167
  onChange?.(value);
167
168
  }, [JSON.stringify(value)]);
168
169
 
170
+ const isRequired = typeof withAsterisk === 'boolean' ? withAsterisk : required;
169
171
  const _label = label ? (
170
- <Input.Label required={required} {...labelProps}>
172
+ <Input.Label required={isRequired} {...labelProps}>
171
173
  {label}
172
174
  </Input.Label>
173
175
  ) : null;
@@ -178,10 +180,10 @@ export const Collection = <T,>(props: CollectionProps<T>) => {
178
180
  const _error = error ? <Input.Error {...errorProps}>{error}</Input.Error> : null;
179
181
  const _header =
180
182
  _label || _description ? (
181
- <Box mb="sm">
183
+ <>
182
184
  {_label}
183
185
  {_description}
184
- </Box>
186
+ </>
185
187
  ) : null;
186
188
 
187
189
  const items = value.map((item, index) => (
@@ -2,11 +2,13 @@ import {Children, FunctionComponent, PropsWithChildren, ReactElement, useState}
2
2
 
3
3
  import {InlineConfirmButton} from './InlineConfirmButton';
4
4
  import {InlineConfirmContext} from './InlineConfirmContext';
5
+ import {InlineConfirmMenuItem} from './InlineConfirmMenuItem';
5
6
  import {InlineConfirmPrompt} from './InlineConfirmPrompt';
6
7
 
7
8
  type InlineConfirmType = FunctionComponent<PropsWithChildren> & {
8
9
  Prompt: typeof InlineConfirmPrompt;
9
10
  Button: typeof InlineConfirmButton;
11
+ MenuItem: typeof InlineConfirmMenuItem;
10
12
  };
11
13
 
12
14
  export const InlineConfirm: InlineConfirmType = ({children}) => {
@@ -27,3 +29,4 @@ export const InlineConfirm: InlineConfirmType = ({children}) => {
27
29
 
28
30
  InlineConfirm.Prompt = InlineConfirmPrompt;
29
31
  InlineConfirm.Button = InlineConfirmButton;
32
+ InlineConfirm.MenuItem = InlineConfirmMenuItem;
@@ -1,18 +1,22 @@
1
- import {HTMLAttributes, MouseEventHandler} from 'react';
1
+ import {Button} from '@mantine/core';
2
+ import {forwardRef, MouseEventHandler} from 'react';
2
3
 
3
- import {Button, ButtonProps} from '../button';
4
+ import {ButtonProps} from '../button';
4
5
  import {useInlineConfirm} from './useInlineConfirm';
5
6
 
6
- interface InlineConfirmButtonProps extends ButtonProps, Omit<HTMLAttributes<HTMLButtonElement>, 'color'> {
7
+ export interface InlineConfirmButtonProps extends ButtonProps {
7
8
  id: string;
9
+ onClick?: MouseEventHandler<HTMLButtonElement>;
8
10
  }
9
11
 
10
- export const InlineConfirmButton = (props: InlineConfirmButtonProps) => {
11
- const {setConfirmingId} = useInlineConfirm();
12
- const onClick: MouseEventHandler<HTMLButtonElement> = (e) => {
13
- setConfirmingId(props.id);
14
- props.onClick?.(e);
15
- };
12
+ export const InlineConfirmButton = forwardRef<HTMLButtonElement, InlineConfirmButtonProps>(
13
+ ({onClick, id, ...others}, ref) => {
14
+ const {setConfirmingId} = useInlineConfirm();
15
+ const handleOnClick: MouseEventHandler<HTMLButtonElement> = (e) => {
16
+ setConfirmingId(id);
17
+ onClick?.(e);
18
+ };
16
19
 
17
- return <Button {...props} onClick={onClick} />;
18
- };
20
+ return <Button ref={ref} onClick={handleOnClick} {...others} />;
21
+ }
22
+ );
@@ -0,0 +1,21 @@
1
+ import {forwardRef, MouseEventHandler} from 'react';
2
+
3
+ import {Menu, MenuItemProps} from '../menu';
4
+ import {useInlineConfirm} from './useInlineConfirm';
5
+
6
+ export interface InlineConfirmMenuItemProps extends MenuItemProps {
7
+ id: string;
8
+ onClick?: MouseEventHandler<HTMLButtonElement>;
9
+ }
10
+
11
+ export const InlineConfirmMenuItem = forwardRef<HTMLButtonElement, InlineConfirmMenuItemProps>(
12
+ ({onClick, id, ...others}, ref) => {
13
+ const {setConfirmingId} = useInlineConfirm();
14
+ const handleOnClick: MouseEventHandler<HTMLButtonElement> = (e) => {
15
+ setConfirmingId(id);
16
+ onClick?.(e);
17
+ };
18
+
19
+ return <Menu.Item ref={ref} onClick={handleOnClick} {...others} />;
20
+ }
21
+ );
@@ -1,3 +1,4 @@
1
+ import {Menu} from '@mantine/core';
1
2
  import {render, screen, userEvent} from '@test-utils';
2
3
 
3
4
  import {InlineConfirm} from '../InlineConfirm';
@@ -25,6 +26,30 @@ describe('InlineConfirm', () => {
25
26
  expect(onClickSpy).toHaveBeenCalledTimes(1);
26
27
  });
27
28
 
29
+ it('calls the onClick prop when clicking on the menu item', async () => {
30
+ const user = userEvent.setup({delay: null});
31
+ const onClickSpy = jest.fn();
32
+ render(
33
+ <InlineConfirm>
34
+ <Menu>
35
+ <Menu.Target>
36
+ <button>open menu</button>
37
+ </Menu.Target>
38
+ <Menu.Dropdown>
39
+ <InlineConfirm.MenuItem id="delete" onClick={onClickSpy}>
40
+ Delete
41
+ </InlineConfirm.MenuItem>
42
+ </Menu.Dropdown>
43
+ </Menu>
44
+ </InlineConfirm>
45
+ );
46
+
47
+ await user.click(screen.getByRole('button', {name: /open menu/i}));
48
+ await user.click(screen.getByRole('menuitem', {name: /delete/i}));
49
+
50
+ expect(onClickSpy).toHaveBeenCalledTimes(1);
51
+ });
52
+
28
53
  it('replace the children with a prompt when clicking on a button which requires confirmation', async () => {
29
54
  const user = userEvent.setup({delay: null});
30
55
  render(
@@ -2,13 +2,22 @@ import {Menu as MantineMenu, MenuItemProps as MantineMenuItemProps} from '@manti
2
2
  import {forwardRef} from 'react';
3
3
 
4
4
  import {createPolymorphicComponent, overrideComponent} from '../../utils';
5
- import {Button, ButtonWithDisabledTooltipProps} from '../button';
5
+ import {ButtonWithDisabledTooltipProps} from '../button';
6
+ import {ButtonWithDisabledTooltip} from '../button/ButtonWithDisabledTooltip';
6
7
 
7
8
  export interface MenuItemProps extends MantineMenuItemProps, ButtonWithDisabledTooltipProps {}
8
9
 
9
- const _MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>((props, ref) => (
10
- <Button.DisabledTooltip component={MantineMenu.Item} ref={ref} {...props} />
11
- ));
10
+ const _MenuItem = forwardRef<HTMLButtonElement, MenuItemProps>(
11
+ ({disabledTooltip, disabled, disabledTooltipProps, ...others}, ref) => (
12
+ <ButtonWithDisabledTooltip
13
+ disabled={disabled}
14
+ disabledTooltip={disabledTooltip}
15
+ disabledTooltipProps={disabledTooltipProps}
16
+ >
17
+ <MantineMenu.Item ref={ref} disabled={disabled} {...others} />
18
+ </ButtonWithDisabledTooltip>
19
+ )
20
+ );
12
21
 
13
22
  const MenuItem = createPolymorphicComponent<'button', MenuItemProps>(_MenuItem);
14
23
 
@@ -112,6 +112,7 @@ export const plasmaTheme: MantineThemeOverride = {
112
112
  color: 'navy',
113
113
  withArrow: true,
114
114
  withinPortal: true,
115
+ multiline: true,
115
116
  },
116
117
  },
117
118
  Breadcrumbs: {
@@ -183,6 +184,12 @@ export const plasmaTheme: MantineThemeOverride = {
183
184
  ColorSwatch: {
184
185
  defaultProps: {
185
186
  size: 8,
187
+ withShadow: false,
188
+ },
189
+ },
190
+ MenuItem: {
191
+ defaultProps: {
192
+ fw: 300,
186
193
  },
187
194
  },
188
195
  },