@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
@@ -18,6 +18,7 @@ import { mergeRefs } from '@lumx/react/utils/mergeRefs';
18
18
 
19
19
  import { useDisableBodyScroll } from '@lumx/react/hooks/useDisableBodyScroll';
20
20
  import { useTransitionVisibility } from '@lumx/react/hooks/useTransitionVisibility';
21
+ import { ThemeProvider } from '@lumx/react/utils/theme/ThemeContext';
21
22
 
22
23
  /**
23
24
  * Defines the props of the component.
@@ -208,65 +209,67 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
208
209
  >
209
210
  <div className={`${CLASSNAME}__overlay`} />
210
211
 
211
- <section className={`${CLASSNAME}__container`} role="dialog" aria-modal="true" {...dialogProps}>
212
- <ClickAwayProvider
213
- callback={!shouldPreventCloseOnClickAway && onClose}
214
- childrenRefs={clickAwayRefs}
215
- parentRef={rootRef}
216
- >
217
- <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>
218
- {(header || headerChildContent) && (
219
- <header
220
- {...headerChildProps}
221
- className={classNames(
222
- `${CLASSNAME}__header`,
223
- (forceHeaderDivider || hasTopIntersection) &&
224
- `${CLASSNAME}__header--has-divider`,
225
- headerChildProps?.className,
226
- )}
227
- >
228
- {header}
229
- {headerChildContent}
230
- </header>
231
- )}
232
-
233
- <div ref={mergeRefs(contentRef, localContentRef)} className={`${CLASSNAME}__content`}>
234
- <div
235
- className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--top`}
236
- ref={setSentinelTop}
237
- />
238
-
239
- {content}
240
-
241
- <div
242
- className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--bottom`}
243
- ref={setSentinelBottom}
244
- />
245
- </div>
246
-
247
- {(footer || footerChildContent) && (
248
- <footer
249
- {...footerChildProps}
250
- className={classNames(
251
- `${CLASSNAME}__footer`,
252
- (forceFooterDivider || hasBottomIntersection) &&
253
- `${CLASSNAME}__footer--has-divider`,
254
- footerChildProps?.className,
255
- )}
256
- >
257
- {footer}
258
- {footerChildContent}
259
- </footer>
260
- )}
261
-
262
- {isLoading && (
263
- <div className={`${CLASSNAME}__progress-overlay`}>
264
- <Progress variant={ProgressVariant.circular} />
212
+ <ThemeProvider value={undefined}>
213
+ <section className={`${CLASSNAME}__container`} role="dialog" aria-modal="true" {...dialogProps}>
214
+ <ClickAwayProvider
215
+ callback={!shouldPreventCloseOnClickAway && onClose}
216
+ childrenRefs={clickAwayRefs}
217
+ parentRef={rootRef}
218
+ >
219
+ <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>
220
+ {(header || headerChildContent) && (
221
+ <header
222
+ {...headerChildProps}
223
+ className={classNames(
224
+ `${CLASSNAME}__header`,
225
+ (forceHeaderDivider || hasTopIntersection) &&
226
+ `${CLASSNAME}__header--has-divider`,
227
+ headerChildProps?.className,
228
+ )}
229
+ >
230
+ {header}
231
+ {headerChildContent}
232
+ </header>
233
+ )}
234
+
235
+ <div ref={mergeRefs(contentRef, localContentRef)} className={`${CLASSNAME}__content`}>
236
+ <div
237
+ className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--top`}
238
+ ref={setSentinelTop}
239
+ />
240
+
241
+ {content}
242
+
243
+ <div
244
+ className={`${CLASSNAME}__sentinel ${CLASSNAME}__sentinel--bottom`}
245
+ ref={setSentinelBottom}
246
+ />
265
247
  </div>
266
- )}
267
- </div>
268
- </ClickAwayProvider>
269
- </section>
248
+
249
+ {(footer || footerChildContent) && (
250
+ <footer
251
+ {...footerChildProps}
252
+ className={classNames(
253
+ `${CLASSNAME}__footer`,
254
+ (forceFooterDivider || hasBottomIntersection) &&
255
+ `${CLASSNAME}__footer--has-divider`,
256
+ footerChildProps?.className,
257
+ )}
258
+ >
259
+ {footer}
260
+ {footerChildContent}
261
+ </footer>
262
+ )}
263
+
264
+ {isLoading && (
265
+ <div className={`${CLASSNAME}__progress-overlay`}>
266
+ <Progress variant={ProgressVariant.circular} />
267
+ </div>
268
+ )}
269
+ </div>
270
+ </ClickAwayProvider>
271
+ </section>
272
+ </ThemeProvider>
270
273
  </div>,
271
274
  document.body,
272
275
  )
@@ -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 { Theme } from '@lumx/react';
6
6
  import { render, screen } from '@testing-library/react';
@@ -13,10 +13,10 @@ type SetupProps = Partial<DividerProps>;
13
13
  /**
14
14
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
15
15
  */
16
- const setup = (propsOverride: SetupProps = {}) => {
16
+ const setup = (propsOverride: SetupProps = {}, { wrapper }: SetupRenderOptions = {}) => {
17
17
  const props: DividerProps = { ...propsOverride };
18
18
 
19
- render(<Divider {...props} />);
19
+ render(<Divider {...props} />, { wrapper });
20
20
  const divider = screen.queryByRole('separator');
21
21
 
22
22
  return { props, divider };
@@ -43,5 +43,11 @@ describe(`<${Divider.displayName}>`, () => {
43
43
  forwardClassName: 'divider',
44
44
  forwardAttributes: 'divider',
45
45
  forwardRef: 'divider',
46
+ applyTheme: {
47
+ affects: [{ element: 'divider' }],
48
+ viaProp: true,
49
+ viaContext: true,
50
+ defaultTheme: 'light',
51
+ },
46
52
  });
47
53
  });
@@ -5,6 +5,7 @@ import classNames from 'classnames';
5
5
  import { Theme } from '@lumx/react';
6
6
  import { Comp, GenericProps, HasTheme } from '@lumx/react/utils/type';
7
7
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
8
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
8
9
 
9
10
  /**
10
11
  * Defines the props of the component.
@@ -24,9 +25,7 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
24
25
  /**
25
26
  * Component default props.
26
27
  */
27
- const DEFAULT_PROPS: Partial<DividerProps> = {
28
- theme: Theme.light,
29
- };
28
+ const DEFAULT_PROPS: Partial<DividerProps> = {};
30
29
 
31
30
  /**
32
31
  * Divider component.
@@ -36,7 +35,8 @@ const DEFAULT_PROPS: Partial<DividerProps> = {
36
35
  * @return React element.
37
36
  */
38
37
  export const Divider: Comp<DividerProps, HTMLHRElement> = forwardRef((props, ref) => {
39
- const { className, theme, ...forwardedProps } = props;
38
+ const defaultTheme = useTheme() || Theme.light;
39
+ const { className, theme = defaultTheme, ...forwardedProps } = props;
40
40
 
41
41
  return (
42
42
  <hr
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+
3
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
4
+
5
+ import { render } from '@testing-library/react';
6
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
7
+ import { DragHandle, DragHandleProps } from './DragHandle';
8
+
9
+ const CLASSNAME = DragHandle.className as string;
10
+
11
+ type SetupProps = Partial<DragHandleProps>;
12
+
13
+ /**
14
+ * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
15
+ */
16
+ const setup = (propsOverride: SetupProps = {}, { wrapper }: SetupRenderOptions = {}) => {
17
+ const props: DragHandleProps = { ...propsOverride };
18
+
19
+ const { container } = render(<DragHandle {...props} />, { wrapper });
20
+ const handle = queryByClassName(container, CLASSNAME);
21
+
22
+ return { props, handle };
23
+ };
24
+
25
+ describe(`<${DragHandle.displayName}>`, () => {
26
+ // Common tests suite.
27
+ commonTestsSuiteRTL(setup, {
28
+ baseClassName: CLASSNAME,
29
+ forwardClassName: 'handle',
30
+ forwardAttributes: 'handle',
31
+ forwardRef: 'handle',
32
+ applyTheme: {
33
+ affects: [{element:'handle'}],
34
+ viaProp: true,
35
+ viaContext: true,
36
+ },
37
+ });
38
+ });
@@ -6,6 +6,7 @@ import { mdiDragVertical } from '@lumx/icons';
6
6
  import { ColorPalette, Icon, Size, Theme } from '@lumx/react';
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
  * Defines the props of the component.
@@ -30,7 +31,8 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
30
31
  * @return React element.
31
32
  */
32
33
  export const DragHandle: Comp<DragHandleProps, HTMLDivElement> = forwardRef((props, ref) => {
33
- const { className, theme, ...forwardedProps } = props;
34
+ const defaultTheme = useTheme();
35
+ const { className, theme = defaultTheme, ...forwardedProps } = props;
34
36
 
35
37
  return (
36
38
  <div
@@ -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 { queryByRole, render, screen } from '@testing-library/react';
5
5
  import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import userEvent from '@testing-library/user-event';
@@ -29,7 +29,10 @@ const ControlledComponent = (props: ExpansionPanelProps) => {
29
29
  /**
30
30
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
31
31
  */
32
- const setup = (propsOverride: Partial<ExpansionPanelProps> = {}, options: { controlled?: boolean } = {}) => {
32
+ const setup = (
33
+ propsOverride: Partial<ExpansionPanelProps> = {},
34
+ options: { controlled?: boolean; wrapper?: SetupRenderOptions['wrapper'] } = {},
35
+ ) => {
33
36
  const props = {
34
37
  toggleButtonProps: { label: 'Toggle' },
35
38
  children: mockChildrenContent,
@@ -37,7 +40,7 @@ const setup = (propsOverride: Partial<ExpansionPanelProps> = {}, options: { cont
37
40
  };
38
41
 
39
42
  const Component = options.controlled ? ControlledComponent : ExpansionPanel;
40
- const { container } = render(<Component {...props} />);
43
+ const { container } = render(<Component {...props} />, { wrapper: options.wrapper });
41
44
 
42
45
  return {
43
46
  container,
@@ -154,5 +157,11 @@ describe(`<${ExpansionPanel.displayName}>`, () => {
154
157
  forwardClassName: 'element',
155
158
  forwardAttributes: 'element',
156
159
  forwardRef: 'element',
160
+ applyTheme: {
161
+ affects: [{ element: 'element' }],
162
+ viaProp: true,
163
+ viaContext: true,
164
+ defaultTheme: 'light',
165
+ },
157
166
  });
158
167
  });
@@ -14,6 +14,7 @@ import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/classNam
14
14
  import { partitionMulti } from '@lumx/react/utils/partitionMulti';
15
15
  import { useTransitionVisibility } from '@lumx/react/hooks/useTransitionVisibility';
16
16
  import { EXPANSION_PANEL_TRANSITION_DURATION } from '@lumx/core/js/constants';
17
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
17
18
 
18
19
  /**
19
20
  * Defines the props of the component.
@@ -51,9 +52,7 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
51
52
  /**
52
53
  * Component default props.
53
54
  */
54
- const DEFAULT_PROPS: Partial<ExpansionPanelProps> = {
55
- theme: Theme.light,
56
- };
55
+ const DEFAULT_PROPS: Partial<ExpansionPanelProps> = {};
57
56
 
58
57
  const isDragHandle = isComponent(DragHandle);
59
58
  const isHeader = isComponent('header');
@@ -67,6 +66,7 @@ const isFooter = isComponent('footer');
67
66
  * @return React element.
68
67
  */
69
68
  export const ExpansionPanel: Comp<ExpansionPanelProps, HTMLDivElement> = forwardRef((props, ref) => {
69
+ const defaultTheme = useTheme() || Theme.light;
70
70
  const {
71
71
  className,
72
72
  children: anyChildren,
@@ -77,7 +77,7 @@ export const ExpansionPanel: Comp<ExpansionPanelProps, HTMLDivElement> = forward
77
77
  onClose,
78
78
  onOpen,
79
79
  onToggleOpen,
80
- theme,
80
+ theme = defaultTheme,
81
81
  toggleButtonProps,
82
82
  ...forwardedProps
83
83
  } = props;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
 
3
3
  import { ColorPalette, Theme } from '@lumx/react';
4
4
  import { mdiAbTesting } from '@lumx/icons';
5
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
5
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
6
6
  import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
7
7
  import { render } from '@testing-library/react';
8
8
 
@@ -13,10 +13,10 @@ const CLASSNAME = Flag.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 = (propOverrides: Partial<FlagProps> = {}) => {
16
+ const setup = (propOverrides: Partial<FlagProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
17
17
  const props = { label: 'default', ...propOverrides };
18
18
 
19
- render(<Flag {...props} />);
19
+ render(<Flag {...props} />, { wrapper });
20
20
  const flag = getByClassName(document.body, CLASSNAME);
21
21
  const icon = queryByClassName(flag, `${CLASSNAME}__icon`);
22
22
 
@@ -50,5 +50,15 @@ describe(`<${Flag.displayName} />`, () => {
50
50
  });
51
51
 
52
52
  // Common tests suite.
53
- commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'flag', forwardAttributes: 'flag' });
53
+ commonTestsSuiteRTL(setup, {
54
+ baseClassName: CLASSNAME,
55
+ forwardClassName: 'flag',
56
+ forwardAttributes: 'flag',
57
+ applyTheme: {
58
+ affects: [{ element: 'flag', classModifier: 'color', inverted: true }],
59
+ viaProp: true,
60
+ viaContext: true,
61
+ defaultTheme: 'light',
62
+ },
63
+ });
54
64
  });
@@ -4,6 +4,7 @@ import classNames from 'classnames';
4
4
  import { ColorPalette, Icon, Size, Theme, Text } from '@lumx/react';
5
5
  import { Comp, GenericProps, HasTheme } from '@lumx/react/utils/type';
6
6
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
7
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
7
8
 
8
9
  export interface FlagProps extends GenericProps, HasTheme {
9
10
  /** Color of the component. */
@@ -18,9 +19,7 @@ export interface FlagProps extends GenericProps, HasTheme {
18
19
 
19
20
  const COMPONENT_NAME = 'Flag';
20
21
  const CLASSNAME = getRootClassName(COMPONENT_NAME);
21
- const DEFAULT_PROPS: Partial<FlagProps> = {
22
- theme: Theme.light,
23
- };
22
+ const DEFAULT_PROPS: Partial<FlagProps> = {};
24
23
 
25
24
  /**
26
25
  * Flag component.
@@ -30,7 +29,8 @@ const DEFAULT_PROPS: Partial<FlagProps> = {
30
29
  * @return React element.
31
30
  */
32
31
  export const Flag: Comp<FlagProps, HTMLDivElement> = forwardRef((props, ref) => {
33
- const { label, icon, color, className, theme, truncate, ...forwardedProps } = props;
32
+ const defaultTheme = useTheme() || Theme.light;
33
+ const { label, icon, color, className, theme = defaultTheme, truncate, ...forwardedProps } = props;
34
34
  const flagColor = color || (theme === Theme.light ? ColorPalette.dark : ColorPalette.light);
35
35
  const isTruncated = !!truncate;
36
36
 
@@ -2,7 +2,7 @@ import React from 'react';
2
2
 
3
3
  import { mdiAlertCircle } from '@lumx/icons';
4
4
  import { ColorPalette, ColorVariant, Size, Theme } from '@lumx/react';
5
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
5
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
6
6
 
7
7
  import { getByClassName, getByTagName } from '@lumx/react/testing/utils/queries';
8
8
  import { render } from '@testing-library/react';
@@ -15,12 +15,12 @@ type SetupProps = Partial<IconProps>;
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: IconProps = {
20
20
  icon: 'mdiPlus',
21
21
  ...propsOverride,
22
22
  };
23
- render(<Icon {...props} />);
23
+ render(<Icon {...props} />, { wrapper });
24
24
  const i = getByClassName(document.body, CLASSNAME);
25
25
  const svg = getByTagName(i, 'svg');
26
26
  const path = getByTagName(svg, 'path');
@@ -114,5 +114,14 @@ describe(`<${Icon.displayName}>`, () => {
114
114
  });
115
115
 
116
116
  // Common tests suite.
117
- commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'i', forwardAttributes: 'i' });
117
+ commonTestsSuiteRTL(setup, {
118
+ baseClassName: CLASSNAME,
119
+ forwardClassName: 'i',
120
+ forwardAttributes: 'i',
121
+ applyTheme: {
122
+ affects: [{ element: 'i', classModifier: 'color', inverted: true }],
123
+ viaProp: true,
124
+ viaContext: true,
125
+ },
126
+ });
118
127
  });
@@ -6,6 +6,7 @@ import { ColorPalette, ColorVariant, Size, Theme } from '@lumx/react';
6
6
  import { Comp, GenericProps, HasTheme } from '@lumx/react/utils/type';
7
7
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
8
8
  import { mdiAlertCircle } from '@lumx/icons';
9
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
9
10
 
10
11
  export type IconSizes = Extract<Size, 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'>;
11
12
 
@@ -53,7 +54,18 @@ const DEFAULT_PROPS: Partial<IconProps> = {};
53
54
  * @return React element.
54
55
  */
55
56
  export const Icon: Comp<IconProps, HTMLElement> = forwardRef((props, ref) => {
56
- const { className, color, colorVariant, hasShape, icon, size, theme, alt, ...forwardedProps } = props;
57
+ const defaultTheme = useTheme();
58
+ const {
59
+ className,
60
+ color,
61
+ colorVariant,
62
+ hasShape,
63
+ icon,
64
+ size,
65
+ theme = defaultTheme,
66
+ alt,
67
+ ...forwardedProps
68
+ } = props;
57
69
 
58
70
  // Color
59
71
  let iconColor = color;
@@ -1,19 +1,21 @@
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';
6
6
  import { toNestedProps } from '@lumx/react/stories/decorators/withNestedProps';
7
7
 
8
+ import { Thumbnail } from '@lumx/react';
8
9
  import { ImageBlock, ImageBlockProps } from './ImageBlock';
9
10
  import { FullFeatured } from './ImageBlock.stories';
10
11
 
11
12
  const CLASSNAME = ImageBlock.className as string;
12
13
 
13
- const setup = (props: Partial<ImageBlockProps> = {}) => {
14
- render(<ImageBlock {...(props as any)} />);
14
+ const setup = (props: Partial<ImageBlockProps> = {}, { wrapper }: SetupRenderOptions = {}) => {
15
+ render(<ImageBlock {...(props as any)} />, { wrapper });
15
16
  const imageBlock = queryByClassName(document.body, CLASSNAME);
16
- return { props, imageBlock };
17
+ const thumbnail = queryByClassName(imageBlock as any, Thumbnail.className as string);
18
+ return { props, imageBlock, thumbnail };
17
19
  };
18
20
 
19
21
  describe(`<${ImageBlock.displayName}>`, () => {
@@ -47,5 +49,11 @@ describe(`<${ImageBlock.displayName}>`, () => {
47
49
  baseClassName: CLASSNAME,
48
50
  forwardClassName: 'imageBlock',
49
51
  forwardAttributes: 'imageBlock',
52
+ applyTheme: {
53
+ affects: [{ element: 'imageBlock' }, { element: 'thumbnail' }],
54
+ viaProp: true,
55
+ viaContext: true,
56
+ defaultTheme: 'light',
57
+ },
50
58
  });
51
59
  });
@@ -7,6 +7,7 @@ import { Alignment, HorizontalAlignment, Size, Theme, Thumbnail } from '@lumx/re
7
7
  import { Comp, GenericProps, HasTheme, ValueOf } from '@lumx/react/utils/type';
8
8
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
9
9
 
10
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
10
11
  import { ThumbnailProps } from '../thumbnail/Thumbnail';
11
12
  import { ImageCaption, ImageCaptionMetadata } from './ImageCaption';
12
13
 
@@ -61,7 +62,6 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
61
62
  */
62
63
  const DEFAULT_PROPS: Partial<ImageBlockProps> = {
63
64
  captionPosition: ImageBlockCaptionPosition.below,
64
- theme: Theme.light,
65
65
  align: Alignment.left,
66
66
  };
67
67
 
@@ -73,6 +73,7 @@ const DEFAULT_PROPS: Partial<ImageBlockProps> = {
73
73
  * @return React element.
74
74
  */
75
75
  export const ImageBlock: Comp<ImageBlockProps, HTMLDivElement> = forwardRef((props, ref) => {
76
+ const defaultTheme = useTheme() || Theme.light;
76
77
  const {
77
78
  actions,
78
79
  align,
@@ -86,7 +87,7 @@ export const ImageBlock: Comp<ImageBlockProps, HTMLDivElement> = forwardRef((pro
86
87
  image,
87
88
  size,
88
89
  tags,
89
- theme,
90
+ theme = defaultTheme,
90
91
  thumbnailProps,
91
92
  title,
92
93
  titleProps,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { Kind, Theme } from '@lumx/react';
4
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
5
5
  import { getByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import { render } from '@testing-library/react';
7
7
  import { INPUT_HELPER_CONFIGURATION } from '@lumx/react/components/input-helper/constants';
@@ -14,9 +14,9 @@ type SetupProps = Partial<InputHelperProps>;
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(<InputHelper {...props} />);
19
+ render(<InputHelper {...props} />, { wrapper });
20
20
  const helper = getByClassName(document.body, CLASSNAME);
21
21
 
22
22
  return { helper, props };
@@ -43,5 +43,15 @@ describe(`<${InputHelper.displayName}>`, () => {
43
43
  });
44
44
  });
45
45
 
46
- commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'helper', forwardAttributes: 'helper' });
46
+ commonTestsSuiteRTL(setup, {
47
+ baseClassName: CLASSNAME,
48
+ forwardClassName: 'helper',
49
+ forwardAttributes: 'helper',
50
+ applyTheme: {
51
+ affects: [{ element: 'helper' }],
52
+ viaProp: true,
53
+ viaContext: true,
54
+ defaultTheme: 'light',
55
+ },
56
+ });
47
57
  });
@@ -4,6 +4,7 @@ import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/classNam
4
4
  import classNames from 'classnames';
5
5
  import React, { forwardRef, ReactNode } from 'react';
6
6
 
7
+ import { useTheme } from '@lumx/react/utils/theme/ThemeContext';
7
8
  import { INPUT_HELPER_CONFIGURATION } from './constants';
8
9
 
9
10
  /**
@@ -31,7 +32,6 @@ const CLASSNAME = getRootClassName(COMPONENT_NAME);
31
32
  */
32
33
  const DEFAULT_PROPS: Partial<InputHelperProps> = {
33
34
  kind: Kind.info,
34
- theme: Theme.light,
35
35
  };
36
36
 
37
37
  /**
@@ -42,7 +42,8 @@ const DEFAULT_PROPS: Partial<InputHelperProps> = {
42
42
  * @return React element.
43
43
  */
44
44
  export const InputHelper: Comp<InputHelperProps, HTMLParagraphElement> = forwardRef((props, ref) => {
45
- const { children, className, kind, theme, ...forwardedProps } = props;
45
+ const defaultTheme = useTheme() || Theme.light;
46
+ const { children, className, kind, theme = defaultTheme, ...forwardedProps } = props;
46
47
  const { color } = INPUT_HELPER_CONFIGURATION[kind as any] || {};
47
48
 
48
49
  return (
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  import { Theme } from '@lumx/react';
4
4
  import { getByClassName } from '@lumx/react/testing/utils/queries';
5
5
  import { render } from '@testing-library/react';
6
- import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
6
+ import { commonTestsSuiteRTL, SetupRenderOptions } from '@lumx/react/testing/utils';
7
7
  import { InputLabel, InputLabelProps } from './InputLabel';
8
8
 
9
9
  const CLASSNAME = InputLabel.className as string;
@@ -13,9 +13,9 @@ type SetupProps = Partial<InputLabelProps>;
13
13
  /**
14
14
  * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
15
15
  */
16
- const setup = (propsOverride: SetupProps = {}) => {
16
+ const setup = (propsOverride: SetupProps = {}, { wrapper }: SetupRenderOptions = {}) => {
17
17
  const props: any = { htmlFor: 'id', ...propsOverride };
18
- render(<InputLabel {...props} />);
18
+ render(<InputLabel {...props} />, { wrapper });
19
19
  const label = getByClassName(document.body, CLASSNAME);
20
20
 
21
21
  return { label, props };
@@ -40,5 +40,15 @@ describe(`<${InputLabel.displayName}>`, () => {
40
40
  });
41
41
  });
42
42
 
43
- commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'label', forwardAttributes: 'label' });
43
+ commonTestsSuiteRTL(setup, {
44
+ baseClassName: CLASSNAME,
45
+ forwardClassName: 'label',
46
+ forwardAttributes: 'label',
47
+ applyTheme: {
48
+ affects: [{ element: 'label' }],
49
+ viaProp: true,
50
+ viaContext: true,
51
+ defaultTheme: 'light',
52
+ },
53
+ });
44
54
  });