@lumx/react 3.10.0 → 3.10.1-alpha.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.
Files changed (101) hide show
  1. package/_internal/index.d.ts +1 -1
  2. package/index.d.ts +13 -5
  3. package/index.js +217 -202
  4. package/index.js.map +1 -1
  5. package/package.json +3 -3
  6. package/src/components/autocomplete/Autocomplete.test.tsx +9 -2
  7. package/src/components/autocomplete/Autocomplete.tsx +3 -1
  8. package/src/components/autocomplete/AutocompleteMultiple.test.tsx +9 -2
  9. package/src/components/autocomplete/AutocompleteMultiple.tsx +3 -1
  10. package/src/components/avatar/Avatar.test.tsx +14 -4
  11. package/src/components/avatar/Avatar.tsx +3 -2
  12. package/src/components/button/Button.test.tsx +9 -3
  13. package/src/components/button/Button.tsx +3 -2
  14. package/src/components/button/IconButton.test.tsx +9 -3
  15. package/src/components/button/IconButton.tsx +13 -2
  16. package/src/components/checkbox/Checkbox.test.tsx +9 -3
  17. package/src/components/checkbox/Checkbox.tsx +4 -4
  18. package/src/components/chip/Chip.test.tsx +14 -4
  19. package/src/components/chip/Chip.tsx +3 -2
  20. package/src/components/comment-block/CommentBlock.test.tsx +9 -3
  21. package/src/components/comment-block/CommentBlock.tsx +3 -2
  22. package/src/components/date-picker/DatePickerField.test.tsx +9 -3
  23. package/src/components/dialog/Dialog.test.tsx +17 -4
  24. package/src/components/dialog/Dialog.tsx +61 -58
  25. package/src/components/divider/Divider.test.tsx +9 -3
  26. package/src/components/divider/Divider.tsx +4 -4
  27. package/src/components/drag-handle/DragHandle.test.tsx +38 -0
  28. package/src/components/drag-handle/DragHandle.tsx +3 -1
  29. package/src/components/expansion-panel/ExpansionPanel.test.tsx +12 -3
  30. package/src/components/expansion-panel/ExpansionPanel.tsx +4 -4
  31. package/src/components/flag/Flag.test.tsx +14 -4
  32. package/src/components/flag/Flag.tsx +4 -4
  33. package/src/components/icon/Icon.test.tsx +13 -4
  34. package/src/components/icon/Icon.tsx +13 -1
  35. package/src/components/image-block/ImageBlock.test.tsx +12 -4
  36. package/src/components/image-block/ImageBlock.tsx +3 -2
  37. package/src/components/input-helper/InputHelper.test.tsx +14 -4
  38. package/src/components/input-helper/InputHelper.tsx +3 -2
  39. package/src/components/input-label/InputLabel.test.tsx +14 -4
  40. package/src/components/input-label/InputLabel.tsx +4 -4
  41. package/src/components/lightbox/Lightbox.test.tsx +17 -6
  42. package/src/components/lightbox/Lightbox.tsx +8 -5
  43. package/src/components/link-preview/LinkPreview.test.tsx +9 -3
  44. package/src/components/link-preview/LinkPreview.tsx +3 -2
  45. package/src/components/mosaic/Mosaic.test.tsx +9 -3
  46. package/src/components/mosaic/Mosaic.tsx +4 -4
  47. package/src/components/navigation/Navigation.test.tsx +18 -9
  48. package/src/components/navigation/Navigation.tsx +13 -5
  49. package/src/components/navigation/NavigationItem.tsx +3 -3
  50. package/src/components/navigation/NavigationSection.tsx +4 -4
  51. package/src/components/notification/Notification.tsx +3 -2
  52. package/src/components/popover/Popover.test.tsx +18 -4
  53. package/src/components/popover/Popover.tsx +2 -1
  54. package/src/components/post-block/PostBlock.test.tsx +9 -3
  55. package/src/components/post-block/PostBlock.tsx +3 -2
  56. package/src/components/progress/Progress.tsx +3 -2
  57. package/src/components/progress/ProgressCircular.test.tsx +9 -16
  58. package/src/components/progress/ProgressCircular.tsx +3 -2
  59. package/src/components/progress/ProgressLinear.test.tsx +13 -18
  60. package/src/components/progress/ProgressLinear.tsx +4 -4
  61. package/src/components/radio-button/RadioButton.test.tsx +9 -3
  62. package/src/components/radio-button/RadioButton.tsx +4 -4
  63. package/src/components/select/Select.test.tsx +9 -3
  64. package/src/components/select/Select.tsx +27 -23
  65. package/src/components/select/SelectMultiple.test.tsx +9 -3
  66. package/src/components/select/SelectMultiple.tsx +109 -103
  67. package/src/components/select/WithSelectContext.tsx +8 -6
  68. package/src/components/side-navigation/SideNavigation.tsx +3 -1
  69. package/src/components/skeleton/SkeletonCircle.test.tsx +9 -3
  70. package/src/components/skeleton/SkeletonCircle.tsx +4 -4
  71. package/src/components/skeleton/SkeletonRectangle.test.tsx +9 -3
  72. package/src/components/skeleton/SkeletonRectangle.tsx +3 -2
  73. package/src/components/skeleton/SkeletonTypography.test.tsx +9 -3
  74. package/src/components/skeleton/SkeletonTypography.tsx +4 -4
  75. package/src/components/slider/Slider.test.tsx +9 -3
  76. package/src/components/slider/Slider.tsx +3 -2
  77. package/src/components/slideshow/Slides.tsx +3 -1
  78. package/src/components/slideshow/Slideshow.test.tsx +9 -3
  79. package/src/components/slideshow/Slideshow.tsx +3 -2
  80. package/src/components/slideshow/SlideshowControls.tsx +3 -2
  81. package/src/components/switch/Switch.test.tsx +9 -3
  82. package/src/components/switch/Switch.tsx +3 -2
  83. package/src/components/table/Table.test.tsx +9 -3
  84. package/src/components/table/Table.tsx +4 -4
  85. package/src/components/tabs/TabList.test.tsx +9 -3
  86. package/src/components/tabs/TabList.tsx +11 -2
  87. package/src/components/text-field/TextField.test.tsx +9 -3
  88. package/src/components/text-field/TextField.tsx +3 -2
  89. package/src/components/thumbnail/Thumbnail.test.tsx +9 -3
  90. package/src/components/thumbnail/Thumbnail.tsx +3 -2
  91. package/src/components/uploader/Uploader.test.tsx +9 -3
  92. package/src/components/uploader/Uploader.tsx +13 -2
  93. package/src/components/user-block/UserBlock.test.tsx +9 -3
  94. package/src/components/user-block/UserBlock.tsx +3 -2
  95. package/src/index.ts +1 -0
  96. package/src/testing/utils/ThemeSentinel.tsx +11 -0
  97. package/src/testing/utils/commonTestsSuiteRTL.tsx +190 -0
  98. package/src/utils/theme/ThemeContext.ts +16 -0
  99. package/src/utils/theme/invertTheme.ts +4 -0
  100. package/src/testing/utils/commonTestsSuiteRTL.ts +0 -64
  101. package/src/utils/ThemeContext.ts +0 -4
package/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/core": "^3.10.0",
10
- "@lumx/icons": "^3.10.0",
9
+ "@lumx/core": "^3.10.1-alpha.0",
10
+ "@lumx/icons": "^3.10.1-alpha.0",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -110,5 +110,5 @@
110
110
  "build:storybook": "storybook build"
111
111
  },
112
112
  "sideEffects": false,
113
- "version": "3.10.0"
113
+ "version": "3.10.1-alpha.0"
114
114
  }
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { Dropdown, List, ListItem, Size, TextField } from '@lumx/react';
4
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
5
5
  import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import { render } from '@testing-library/react';
7
7
  import userEvent from '@testing-library/user-event';
@@ -14,7 +14,7 @@ const CLASSNAME = Autocomplete.className as string;
14
14
  /**
15
15
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
16
16
  */
17
- const setup = (props: Partial<AutocompleteProps> = {}) => {
17
+ const setup = (props: Partial<AutocompleteProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
18
18
  render(
19
19
  <Autocomplete {...(props as any)}>
20
20
  <List>
@@ -25,6 +25,7 @@ const setup = (props: Partial<AutocompleteProps> = {}) => {
25
25
  ))}
26
26
  </List>
27
27
  </Autocomplete>,
28
+ { wrapper },
28
29
  );
29
30
  const autocomplete = getByClassName(document.body, CLASSNAME);
30
31
  const textField = getByClassName(autocomplete, TextField.className as string);
@@ -90,5 +91,11 @@ describe(`<${Autocomplete.displayName}>`, () => {
90
91
  forwardClassName: 'autocomplete',
91
92
  forwardAttributes: 'autocomplete',
92
93
  forwardRef: 'autocomplete',
94
+ applyTheme: {
95
+ affects: [{ element: 'textField' }],
96
+ viaProp: true,
97
+ viaContext: true,
98
+ defaultTheme: 'light',
99
+ },
93
100
  });
94
101
  });
@@ -8,6 +8,7 @@ import { Comp, GenericProps, HasTheme } from '@lumx/react/utils/type';
8
8
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
9
9
  import { useFocus } from '@lumx/react/hooks/useFocus';
10
10
  import { mergeRefs } from '@lumx/react/utils/mergeRefs';
11
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
11
12
 
12
13
  /**
13
14
  * Defines the props of the component.
@@ -200,6 +201,7 @@ const DEFAULT_PROPS: Partial<AutocompleteProps> = {
200
201
  * @return React element.
201
202
  */
202
203
  export const Autocomplete: Comp<AutocompleteProps, HTMLDivElement> = forwardRef((props, ref) => {
204
+ const defaultTheme = useTheme();
203
205
  const {
204
206
  anchorToInput,
205
207
  children,
@@ -231,7 +233,7 @@ export const Autocomplete: Comp<AutocompleteProps, HTMLDivElement> = forwardRef(
231
233
  placeholder,
232
234
  placement,
233
235
  shouldFocusOnClose,
234
- theme,
236
+ theme = defaultTheme,
235
237
  value,
236
238
  textFieldProps = {},
237
239
  focusAnchorOnClose,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { Dropdown, List, ListItem, Size, TextField } from '@lumx/react';
4
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
5
5
  import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import { render } from '@testing-library/react';
7
7
 
@@ -13,7 +13,7 @@ const CLASSNAME = AutocompleteMultiple.className as string;
13
13
  /**
14
14
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
15
15
  */
16
- const setup = (props: Partial<AutocompleteMultipleProps> = {}) => {
16
+ const setup = (props: Partial<AutocompleteMultipleProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
17
17
  render(
18
18
  <AutocompleteMultiple {...(props as any)}>
19
19
  <List>
@@ -24,6 +24,7 @@ const setup = (props: Partial<AutocompleteMultipleProps> = {}) => {
24
24
  ))}
25
25
  </List>
26
26
  </AutocompleteMultiple>,
27
+ { wrapper },
27
28
  );
28
29
  const autocompleteMultiple = getByClassName(document.body, CLASSNAME);
29
30
  const textField = getByClassName(autocompleteMultiple, TextField.className as string);
@@ -52,5 +53,11 @@ describe(`<${AutocompleteMultiple.displayName}>`, () => {
52
53
  forwardClassName: 'autocompleteMultiple',
53
54
  forwardRef: 'autocompleteMultiple',
54
55
  forwardAttributes: 'autocompleteMultiple',
56
+ applyTheme: {
57
+ affects: [{ element: 'textField' }],
58
+ viaProp: true,
59
+ viaContext: true,
60
+ defaultTheme: 'light',
61
+ },
55
62
  });
56
63
  });
@@ -6,6 +6,7 @@ import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/classNam
6
6
 
7
7
  import classNames from 'classnames';
8
8
  import React, { forwardRef, ReactNode } from 'react';
9
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
9
10
 
10
11
  /**
11
12
  * Defines the props of the component.
@@ -66,6 +67,7 @@ const DEFAULT_PROPS: Partial<AutocompleteMultipleProps> = {
66
67
  * @return React element.
67
68
  */
68
69
  export const AutocompleteMultiple: Comp<AutocompleteMultipleProps, HTMLDivElement> = forwardRef((props, ref) => {
70
+ const defaultTheme = useTheme();
69
71
  const {
70
72
  anchorToInput,
71
73
  children,
@@ -99,7 +101,7 @@ export const AutocompleteMultiple: Comp<AutocompleteMultipleProps, HTMLDivElemen
99
101
  placement,
100
102
  selectedChipRender,
101
103
  shouldFocusOnClose,
102
- theme,
104
+ theme = defaultTheme,
103
105
  type,
104
106
  value,
105
107
  values,
@@ -1,24 +1,34 @@
1
1
  import React from 'react';
2
2
 
3
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
3
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
4
4
  import { render } from '@testing-library/react';
5
5
  import { queryByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import { Avatar, AvatarProps } from './Avatar';
7
7
 
8
8
  const CLASSNAME = Avatar.className as string;
9
9
 
10
- const setup = (propsOverride: Partial<AvatarProps> = {}) => {
10
+ const setup = (propsOverride: Partial<AvatarProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
11
11
  const props: AvatarProps = {
12
12
  image: 'path/to/avatar/image.png',
13
13
  alt: 'Image',
14
14
  ...propsOverride,
15
15
  };
16
- render(<Avatar {...props} />);
16
+ render(<Avatar {...props} />, { wrapper });
17
17
  const avatar = queryByClassName(document.body, CLASSNAME);
18
18
  return { avatar, props };
19
19
  };
20
20
 
21
21
  describe(`<${Avatar.displayName}>`, () => {
22
22
  // Common tests suite.
23
- commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'avatar', forwardAttributes: 'avatar' });
23
+ commonTestsSuiteRTL(setup, {
24
+ baseClassName: CLASSNAME,
25
+ forwardClassName: 'avatar',
26
+ forwardAttributes: 'avatar',
27
+ applyTheme: {
28
+ affects: [{ element: 'avatar' }],
29
+ viaProp: true,
30
+ viaContext: true,
31
+ defaultTheme: 'light',
32
+ },
33
+ });
24
34
  });
@@ -6,6 +6,7 @@ import { AspectRatio, Size, Theme, Thumbnail, ThumbnailProps } from '@lumx/react
6
6
 
7
7
  import { Comp, GenericProps, HasTheme } from '@lumx/react/utils/type';
8
8
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
9
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
9
10
 
10
11
  /**
11
12
  * Avatar sizes.
@@ -56,7 +57,6 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
56
57
  */
57
58
  const DEFAULT_PROPS: Partial<AvatarProps> = {
58
59
  size: Size.m,
59
- theme: Theme.light,
60
60
  };
61
61
 
62
62
  /**
@@ -67,6 +67,7 @@ const DEFAULT_PROPS: Partial<AvatarProps> = {
67
67
  * @return React element.
68
68
  */
69
69
  export const Avatar: Comp<AvatarProps, HTMLDivElement> = forwardRef((props, ref) => {
70
+ const defaultTheme = useTheme() || Theme.light;
70
71
  const {
71
72
  actions,
72
73
  alt,
@@ -78,7 +79,7 @@ export const Avatar: Comp<AvatarProps, HTMLDivElement> = forwardRef((props, ref)
78
79
  onClick,
79
80
  onKeyPress,
80
81
  size,
81
- theme,
82
+ theme = defaultTheme,
82
83
  thumbnailProps,
83
84
  ...forwardedProps
84
85
  } = props;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { mdiCheck, mdiPlus } from '@lumx/icons';
4
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
5
5
  import { render, screen, within } from '@testing-library/react';
6
6
  import { getByClassName, queryAllByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
7
7
  import { Emphasis, Icon } from '@lumx/react';
@@ -15,9 +15,9 @@ type SetupProps = Partial<ButtonProps>;
15
15
  /**
16
16
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
17
17
  */
18
- const setup = (propsOverride: SetupProps = {}) => {
18
+ const setup = (propsOverride: SetupProps = {}, { wrapper }: SetupRenderOptions = {}) => {
19
19
  const props: any = { ...propsOverride };
20
- render(<Button {...props} />);
20
+ render(<Button {...props} />, { wrapper });
21
21
  const button = getByClassName(document.body, CLASSNAME);
22
22
  const buttonWrapper = queryByClassName(document.body, 'lumx-button-wrapper');
23
23
  const icons = queryAllByClassName(button, Icon.className as string);
@@ -71,5 +71,11 @@ describe(`<${Button.displayName}>`, () => {
71
71
  forwardClassName: 'button',
72
72
  forwardAttributes: 'button',
73
73
  forwardRef: 'button',
74
+ applyTheme: {
75
+ affects: [{ element: 'button' }],
76
+ viaProp: true,
77
+ viaContext: true,
78
+ defaultTheme: 'light',
79
+ },
74
80
  });
75
81
  });
@@ -6,6 +6,7 @@ import isEmpty from 'lodash/isEmpty';
6
6
  import { Emphasis, Icon, Size, Theme, Text } from '@lumx/react';
7
7
  import { Comp, isComponent } from '@lumx/react/utils/type';
8
8
  import { getBasicClass, getRootClassName } from '@lumx/react/utils/className';
9
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
9
10
  import { BaseButtonProps, ButtonRoot } from './ButtonRoot';
10
11
 
11
12
  /**
@@ -44,7 +45,6 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
44
45
  const DEFAULT_PROPS: Partial<ButtonProps> = {
45
46
  emphasis: Emphasis.high,
46
47
  size: Size.m,
47
- theme: Theme.light,
48
48
  };
49
49
 
50
50
  /**
@@ -55,7 +55,8 @@ const DEFAULT_PROPS: Partial<ButtonProps> = {
55
55
  * @return React element.
56
56
  */
57
57
  export const Button: Comp<ButtonProps, HTMLButtonElement | HTMLAnchorElement> = forwardRef((props, ref) => {
58
- const { children, className, emphasis, leftIcon, rightIcon, size, theme, ...forwardedProps } = props;
58
+ const defaultTheme = useTheme() || Theme.light;
59
+ const { children, className, emphasis, leftIcon, rightIcon, size, theme = defaultTheme, ...forwardedProps } = props;
59
60
 
60
61
  const buttonClassName = classNames(
61
62
  className,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
3
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
4
4
  import { Button } from '@lumx/react';
5
5
  import { render, screen } from '@testing-library/react';
6
6
  import { getByClassName, queryByClassName, queryByTagName } from '@lumx/react/testing/utils/queries';
@@ -14,9 +14,9 @@ type SetupProps = Partial<IconButtonProps>;
14
14
  /**
15
15
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
16
16
  */
17
- const setup = (propsOverride: SetupProps = {}) => {
17
+ const setup = (propsOverride: SetupProps = {}, { wrapper }: SetupRenderOptions = {}) => {
18
18
  const props: any = { ...propsOverride };
19
- render(<IconButton {...props} />);
19
+ render(<IconButton {...props} />, { wrapper });
20
20
  const iconButton = getByClassName(document.body, CLASSNAME);
21
21
  const icon = queryByClassName(iconButton, 'lumx-icon');
22
22
  const img = queryByTagName(iconButton, 'IMG');
@@ -58,5 +58,11 @@ describe(`<${IconButton.displayName}>`, () => {
58
58
  forwardClassName: 'iconButton',
59
59
  forwardAttributes: 'iconButton',
60
60
  forwardRef: 'iconButton',
61
+ applyTheme: {
62
+ affects: [{ element: 'iconButton' }],
63
+ viaProp: true,
64
+ viaContext: true,
65
+ defaultTheme: 'light',
66
+ },
61
67
  });
62
68
  });
@@ -4,6 +4,7 @@ import { Emphasis, Icon, Size, Theme, Tooltip, TooltipProps } from '@lumx/react'
4
4
  import { BaseButtonProps, ButtonRoot } from '@lumx/react/components/button/ButtonRoot';
5
5
  import { Comp } from '@lumx/react/utils/type';
6
6
  import { getRootClassName } from '@lumx/react/utils/className';
7
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
7
8
 
8
9
  export interface IconButtonProps extends BaseButtonProps {
9
10
  /**
@@ -46,7 +47,6 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
46
47
  const DEFAULT_PROPS: Partial<IconButtonProps> = {
47
48
  emphasis: Emphasis.high,
48
49
  size: Size.m,
49
- theme: Theme.light,
50
50
  };
51
51
 
52
52
  /**
@@ -57,7 +57,18 @@ const DEFAULT_PROPS: Partial<IconButtonProps> = {
57
57
  * @return React element.
58
58
  */
59
59
  export const IconButton: Comp<IconButtonProps, HTMLButtonElement> = forwardRef((props, ref) => {
60
- const { emphasis, image, icon, label, size, theme, tooltipProps, hideTooltip, ...forwardedProps } = props;
60
+ const defaultTheme = useTheme() || Theme.light;
61
+ const {
62
+ emphasis,
63
+ image,
64
+ icon,
65
+ label,
66
+ size,
67
+ theme = defaultTheme,
68
+ tooltipProps,
69
+ hideTooltip,
70
+ ...forwardedProps
71
+ } = props;
61
72
 
62
73
  return (
63
74
  <Tooltip label={hideTooltip ? '' : label} {...tooltipProps}>
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
3
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
4
4
 
5
5
  import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import { render } from '@testing-library/react';
@@ -14,9 +14,9 @@ type SetupProps = Partial<CheckboxProps>;
14
14
  /**
15
15
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
16
16
  */
17
- const setup = (propsOverride: SetupProps = {}) => {
17
+ const setup = (propsOverride: SetupProps = {}, { wrapper }: SetupRenderOptions = {}) => {
18
18
  const props: any = { id: 'fixedId', ...propsOverride };
19
- render(<Checkbox {...props} />);
19
+ render(<Checkbox {...props} />, { wrapper });
20
20
 
21
21
  const checkbox = getByClassName(document.body, CLASSNAME);
22
22
  const helper = queryByClassName(checkbox, `${CLASSNAME}__helper`);
@@ -117,5 +117,11 @@ describe(`<${Checkbox.displayName}>`, () => {
117
117
  baseClassName: CLASSNAME,
118
118
  forwardClassName: 'checkbox',
119
119
  forwardAttributes: 'checkbox',
120
+ applyTheme: {
121
+ affects: [{ element: 'checkbox' }],
122
+ viaProp: true,
123
+ viaContext: true,
124
+ defaultTheme: 'light',
125
+ },
120
126
  });
121
127
  });
@@ -9,6 +9,7 @@ import { Comp, GenericProps, HasTheme } from '@lumx/react/utils/type';
9
9
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
10
10
  import { useId } from '@lumx/react/hooks/useId';
11
11
  import { useMergeRefs } from '@lumx/react/utils/mergeRefs';
12
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
12
13
 
13
14
  /**
14
15
  * Intermediate state of checkbox.
@@ -54,9 +55,7 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
54
55
  /**
55
56
  * Component default props.
56
57
  */
57
- const DEFAULT_PROPS: Partial<CheckboxProps> = {
58
- theme: Theme.light,
59
- };
58
+ const DEFAULT_PROPS: Partial<CheckboxProps> = {};
60
59
 
61
60
  /**
62
61
  * Checkbox component.
@@ -66,6 +65,7 @@ const DEFAULT_PROPS: Partial<CheckboxProps> = {
66
65
  * @return React element.
67
66
  */
68
67
  export const Checkbox: Comp<CheckboxProps, HTMLDivElement> = forwardRef((props, ref) => {
68
+ const defaultTheme = useTheme() || Theme.light;
69
69
  const {
70
70
  checked,
71
71
  className,
@@ -78,7 +78,7 @@ export const Checkbox: Comp<CheckboxProps, HTMLDivElement> = forwardRef((props,
78
78
  label,
79
79
  name,
80
80
  onChange,
81
- theme,
81
+ theme = defaultTheme,
82
82
  value,
83
83
  inputProps = {},
84
84
  ...forwardedProps
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { Theme } from '@lumx/react';
4
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
5
5
  import { fireEvent, render, screen } from '@testing-library/react';
6
6
  import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
7
7
  import userEvent from '@testing-library/user-event';
@@ -12,12 +12,12 @@ const CLASSNAME = Chip.className as string;
12
12
  /**
13
13
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
14
14
  */
15
- const setup = (propOverrides: Partial<ChipProps> = {}) => {
15
+ const setup = (propOverrides: Partial<ChipProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
16
16
  const props = {
17
17
  ...propOverrides,
18
18
  };
19
19
 
20
- render(<Chip {...props} />);
20
+ render(<Chip {...props} />, { wrapper });
21
21
  const chip = getByClassName(document.body, CLASSNAME);
22
22
  const before = queryByClassName(chip, `${CLASSNAME}__before`);
23
23
  const after = queryByClassName(chip, `${CLASSNAME}__after`);
@@ -185,5 +185,15 @@ describe('<Chip />', () => {
185
185
  });
186
186
  });
187
187
 
188
- commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'chip', forwardAttributes: 'chip' });
188
+ commonTestsSuiteRTL(setup, {
189
+ baseClassName: CLASSNAME,
190
+ forwardClassName: 'chip',
191
+ forwardAttributes: 'chip',
192
+ applyTheme: {
193
+ affects: [{ element: 'chip', classModifier: 'color', inverted: true }],
194
+ viaProp: true,
195
+ viaContext: true,
196
+ defaultTheme: 'light',
197
+ },
198
+ });
189
199
  });
@@ -9,6 +9,7 @@ import classNames from 'classnames';
9
9
 
10
10
  import isFunction from 'lodash/isFunction';
11
11
  import React, { forwardRef, MouseEventHandler, ReactNode } from 'react';
12
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
12
13
 
13
14
  /**
14
15
  * Chip sizes.
@@ -56,7 +57,6 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
56
57
  */
57
58
  const DEFAULT_PROPS: Partial<ChipProps> = {
58
59
  size: Size.m,
59
- theme: Theme.light,
60
60
  };
61
61
 
62
62
  /**
@@ -67,6 +67,7 @@ const DEFAULT_PROPS: Partial<ChipProps> = {
67
67
  * @return React element.
68
68
  */
69
69
  export const Chip: Comp<ChipProps, HTMLAnchorElement> = forwardRef((props, ref) => {
70
+ const defaultTheme = useTheme() || Theme.light;
70
71
  const {
71
72
  after,
72
73
  before,
@@ -82,7 +83,7 @@ export const Chip: Comp<ChipProps, HTMLAnchorElement> = forwardRef((props, ref)
82
83
  onBeforeClick,
83
84
  onClick,
84
85
  size,
85
- theme,
86
+ theme = defaultTheme,
86
87
  href,
87
88
  onKeyDown,
88
89
  ...forwardedProps
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
2
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
3
3
 
4
4
  import { render } from '@testing-library/react';
5
5
  import { queryByClassName } from '@lumx/react/testing/utils/queries';
@@ -7,8 +7,8 @@ import { CommentBlock, CommentBlockProps } from './CommentBlock';
7
7
 
8
8
  const CLASSNAME = CommentBlock.className as string;
9
9
 
10
- const setup = (props: Partial<CommentBlockProps> = {}) => {
11
- render(<CommentBlock {...(props as any)} />);
10
+ const setup = (props: Partial<CommentBlockProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
11
+ render(<CommentBlock {...(props as any)} />, { wrapper });
12
12
  const commentBlock = queryByClassName(document.body, CLASSNAME);
13
13
  return { props, commentBlock };
14
14
  };
@@ -19,5 +19,11 @@ describe(`<${CommentBlock.displayName}>`, () => {
19
19
  baseClassName: CLASSNAME,
20
20
  forwardClassName: 'commentBlock',
21
21
  forwardAttributes: 'commentBlock',
22
+ applyTheme: {
23
+ affects: [{ element: 'commentBlock' }],
24
+ viaProp: true,
25
+ viaContext: true,
26
+ defaultTheme: 'light',
27
+ },
22
28
  });
23
29
  });
@@ -6,6 +6,7 @@ import { Avatar, Size, Theme, Tooltip } from '@lumx/react';
6
6
  import { Comp, GenericProps, HasTheme, ValueOf } from '@lumx/react/utils/type';
7
7
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
8
8
 
9
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
9
10
  import { AvatarProps } from '../avatar/Avatar';
10
11
 
11
12
  /**
@@ -76,7 +77,6 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
76
77
  * Component default props.
77
78
  */
78
79
  const DEFAULT_PROPS: Partial<CommentBlockProps> = {
79
- theme: Theme.light,
80
80
  variant: CommentBlockVariant.indented,
81
81
  };
82
82
 
@@ -88,6 +88,7 @@ const DEFAULT_PROPS: Partial<CommentBlockProps> = {
88
88
  * @return React element.
89
89
  */
90
90
  export const CommentBlock: Comp<CommentBlockProps, HTMLDivElement> = forwardRef((props, ref) => {
91
+ const defaultTheme = useTheme() || Theme.light;
91
92
  const {
92
93
  actions,
93
94
  avatarProps,
@@ -104,7 +105,7 @@ export const CommentBlock: Comp<CommentBlockProps, HTMLDivElement> = forwardRef(
104
105
  onMouseEnter,
105
106
  onMouseLeave,
106
107
  text,
107
- theme,
108
+ theme = defaultTheme,
108
109
  variant,
109
110
  ...forwardedProps
110
111
  } = props;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
3
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
4
4
  import { render, screen } from '@testing-library/react';
5
5
  import { getByClassName, getByTagName, queryByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import { TextField } from '@lumx/react';
@@ -15,7 +15,7 @@ jest.mock('@lumx/react/utils/date/getYearDisplayName', () => ({
15
15
  getYearDisplayName: () => 'année',
16
16
  }));
17
17
 
18
- const setup = (propsOverride: Partial<DatePickerFieldProps> = {}) => {
18
+ const setup = (propsOverride: Partial<DatePickerFieldProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
19
19
  const props: DatePickerFieldProps = {
20
20
  label: 'DatePickerField',
21
21
  locale: 'fr',
@@ -25,7 +25,7 @@ const setup = (propsOverride: Partial<DatePickerFieldProps> = {}) => {
25
25
  previousButtonProps: { label: 'Previous month' },
26
26
  ...propsOverride,
27
27
  };
28
- render(<DatePickerField {...props} />);
28
+ render(<DatePickerField {...props} />, { wrapper });
29
29
  const textField = getByClassName(document.body, TextField.className as string);
30
30
  const inputNative = getByTagName(textField, 'input');
31
31
  const getDatePicker = () => queryByClassName(document.body, CLASSNAME);
@@ -62,5 +62,11 @@ describe(`<${DatePickerField.displayName}>`, () => {
62
62
  forwardRef: 'textField',
63
63
  forwardAttributes: 'inputNative',
64
64
  forwardClassName: 'textField',
65
+ applyTheme: {
66
+ affects: [{ element: 'textField' }],
67
+ viaProp: true,
68
+ viaContext: true,
69
+ defaultTheme: 'light',
70
+ },
65
71
  });
66
72
  });
@@ -3,19 +3,26 @@ import React from 'react';
3
3
  import { Dialog, DialogProps } from '@lumx/react/components/dialog/Dialog';
4
4
  import { queryByClassName } from '@lumx/react/testing/utils/queries';
5
5
  import { render, screen } from '@testing-library/react';
6
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
6
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
7
7
  import userEvent from '@testing-library/user-event';
8
+ import { ThemeSentinel } from '@lumx/react/testing/utils/ThemeSentinel';
8
9
 
9
10
  const CLASSNAME = Dialog.className as string;
10
11
 
11
12
  /**
12
13
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
13
14
  */
14
- const setup = (props: Partial<DialogProps> = {}) => {
15
- render(<Dialog isOpen {...props} />);
15
+ const setup = (props: Partial<DialogProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
16
+ render(
17
+ <Dialog isOpen {...props}>
18
+ {props.children || <ThemeSentinel />}
19
+ </Dialog>,
20
+ { wrapper },
21
+ );
16
22
  const dialog = queryByClassName(document.body, CLASSNAME);
17
23
  const container = dialog && queryByClassName(dialog, `${CLASSNAME}__container`);
18
- return { props, dialog, container };
24
+ const themeSentinel = screen.queryByTestId(ThemeSentinel.testId);
25
+ return { props, dialog, container, themeSentinel };
19
26
  };
20
27
 
21
28
  describe(`<${Dialog.displayName}>`, () => {
@@ -66,5 +73,11 @@ describe(`<${Dialog.displayName}>`, () => {
66
73
  forwardAttributes: 'dialog',
67
74
  forwardRef: 'dialog',
68
75
  forwardClassName: 'dialog',
76
+ applyTheme: {
77
+ // Theme should not affect the children components
78
+ affects: [{ not: { element: 'themeSentinel' } }],
79
+ viaProp: true,
80
+ viaContext: true,
81
+ },
69
82
  });
70
83
  });