@lumx/react 3.1.4 → 3.2.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 (144) hide show
  1. package/_internal/types.d.ts +16 -5
  2. package/index.d.ts +51 -4
  3. package/index.js +621 -417
  4. package/index.js.map +1 -1
  5. package/package.json +3 -3
  6. package/src/components/alert-dialog/AlertDialog.stories.tsx +96 -165
  7. package/src/components/alert-dialog/AlertDialog.test.tsx +15 -23
  8. package/src/components/avatar/Avatar.stories.tsx +91 -62
  9. package/src/components/avatar/Avatar.test.tsx +9 -24
  10. package/src/components/badge/Badge.stories.tsx +63 -38
  11. package/src/components/button/Button.stories.tsx +147 -139
  12. package/src/components/button/IconButton.stories.tsx +45 -0
  13. package/src/components/checkbox/Checkbox.stories.tsx +37 -30
  14. package/src/components/chip/Chip.stories.tsx +77 -15
  15. package/src/components/comment-block/CommentBlock.stories.tsx +90 -25
  16. package/src/components/comment-block/CommentBlock.test.tsx +12 -17
  17. package/src/components/date-picker/DatePickerField.stories.tsx +52 -83
  18. package/src/components/dialog/Dialog.stories.tsx +132 -240
  19. package/src/components/dialog/Dialog.test.tsx +6 -30
  20. package/src/components/dialog/Dialog.tsx +17 -3
  21. package/src/components/dropdown/Dropdown.stories.tsx +1 -186
  22. package/src/components/flag/Flag.stories.tsx +33 -18
  23. package/src/components/flag/Flag.test.tsx +1 -8
  24. package/src/components/flex-box/FlexBox.stories.tsx +151 -238
  25. package/src/components/flex-box/FlexBox.test.tsx +9 -49
  26. package/src/components/generic-block/GenericBlock.stories.jsx +1 -1
  27. package/src/components/grid-column/GridColumn.stories.tsx +46 -0
  28. package/src/components/heading/Heading.stories.tsx +57 -95
  29. package/src/components/icon/Icon.stories.tsx +67 -70
  30. package/src/components/image-block/ImageBlock.stories.tsx +103 -47
  31. package/src/components/image-block/ImageBlock.test.tsx +12 -17
  32. package/src/components/inline-list/InlineList.stories.tsx +45 -29
  33. package/src/components/input-helper/InputHelper.stories.tsx +31 -25
  34. package/src/components/input-label/InputLabel.stories.tsx +33 -10
  35. package/src/components/lightbox/Lightbox.stories.tsx +39 -77
  36. package/src/components/lightbox/Lightbox.test.tsx +12 -17
  37. package/src/components/link/Link.stories.tsx +98 -128
  38. package/src/components/link-preview/LinkPreview.stories.tsx +48 -75
  39. package/src/components/list/List.stories.tsx +59 -84
  40. package/src/components/list/List.test.tsx +8 -17
  41. package/src/components/list/ListDivider.stories.tsx +9 -4
  42. package/src/components/list/ListDivider.test.tsx +12 -17
  43. package/src/components/list/ListItem.stories.tsx +97 -59
  44. package/src/components/list/ListItem.test.tsx +12 -17
  45. package/src/components/list/ListSubheader.stories.tsx +8 -5
  46. package/src/components/list/ListSubheader.test.tsx +12 -18
  47. package/src/components/message/Message.stories.tsx +51 -22
  48. package/src/components/mosaic/Mosaic.stories.tsx +78 -74
  49. package/src/components/mosaic/Mosaic.test.tsx +0 -31
  50. package/src/components/navigation/Navigation.stories.tsx +67 -0
  51. package/src/components/navigation/Navigation.test.tsx +58 -0
  52. package/src/components/navigation/Navigation.tsx +62 -0
  53. package/src/components/navigation/NavigationItem.test.tsx +37 -0
  54. package/src/components/navigation/NavigationItem.tsx +89 -0
  55. package/src/components/navigation/NavigationSection.test.tsx +126 -0
  56. package/src/components/navigation/NavigationSection.tsx +109 -0
  57. package/src/components/navigation/context.tsx +6 -0
  58. package/src/components/navigation/index.ts +1 -0
  59. package/src/components/notification/Notifications.stories.tsx +52 -47
  60. package/src/components/popover/Popover.stories.tsx +68 -201
  61. package/src/components/popover-dialog/PopoverDialog.stories.tsx +26 -65
  62. package/src/components/post-block/PostBlock.test.tsx +12 -17
  63. package/src/components/progress/ProgressCircular.stories.tsx +24 -12
  64. package/src/components/progress/ProgressLinear.stories.tsx +6 -2
  65. package/src/components/radio-button/RadioButton.stories.tsx +35 -24
  66. package/src/components/select/Select.stories.tsx +19 -23
  67. package/src/components/skeleton/SkeletonCircle.stories.tsx +37 -21
  68. package/src/components/skeleton/SkeletonCircle.test.tsx +12 -17
  69. package/src/components/skeleton/SkeletonRectangle.stories.tsx +74 -99
  70. package/src/components/skeleton/SkeletonRectangle.test.tsx +12 -17
  71. package/src/components/skeleton/SkeletonTypography.test.tsx +12 -17
  72. package/src/components/slider/Slider.stories.tsx +41 -25
  73. package/src/components/slider/Slider.test.tsx +12 -18
  74. package/src/components/slideshow/Slideshow.stories.tsx +31 -61
  75. package/src/components/slideshow/Slideshow.test.tsx +15 -23
  76. package/src/components/slideshow/SlideshowControls.stories.tsx +4 -6
  77. package/src/components/switch/Switch.stories.tsx +35 -32
  78. package/src/components/table/Table.test.tsx +12 -17
  79. package/src/components/tabs/Tabs.stories.tsx +4 -3
  80. package/src/components/text/Text.stories.tsx +130 -0
  81. package/src/components/text-field/TextField.stories.tsx +114 -148
  82. package/src/components/thumbnail/Thumbnail.stories.tsx +106 -255
  83. package/src/components/thumbnail/Thumbnail.test.tsx +12 -35
  84. package/src/components/tooltip/Tooltip.stories.tsx +51 -136
  85. package/src/components/user-block/UserBlock.stories.tsx +67 -56
  86. package/src/components/user-block/UserBlock.test.tsx +1 -5
  87. package/src/index.ts +1 -0
  88. package/src/stories/controls/color.ts +6 -0
  89. package/src/stories/controls/element.ts +6 -0
  90. package/src/stories/controls/focusPoint.ts +1 -0
  91. package/src/stories/controls/icons.ts +6 -0
  92. package/src/stories/{knobs → controls}/image.ts +6 -16
  93. package/src/stories/controls/selectArgType.ts +4 -0
  94. package/src/stories/controls/theme.ts +3 -0
  95. package/src/stories/controls/typography.ts +5 -0
  96. package/src/stories/controls/withUndefined.ts +1 -0
  97. package/src/stories/decorators/withChromaticForceScreenSize.tsx +8 -0
  98. package/src/stories/decorators/withCombinations.tsx +99 -0
  99. package/src/stories/decorators/withNestedProps.tsx +23 -0
  100. package/src/stories/{withResizableBox.tsx → decorators/withResizableBox.tsx} +6 -10
  101. package/src/stories/decorators/withValueOnChange.tsx +18 -0
  102. package/src/stories/decorators/withWrapper.tsx +19 -0
  103. package/src/stories/utils/CustomLink.tsx +8 -2
  104. package/src/stories/{knobs → utils}/lorem.ts +9 -9
  105. package/src/testing/utils/commonTestsSuiteRTL.ts +2 -3
  106. package/src/testing/utils/index.ts +0 -2
  107. package/src/untypped-modules.d.ts +0 -2
  108. package/src/utils/MaterialThemeSwitcher/MaterialThemeSwitcher.tsx +1 -1
  109. package/src/utils/ThemeContext.ts +4 -0
  110. package/src/utils/forwardRefPolymorphic.ts +9 -0
  111. package/src/utils/type.ts +28 -4
  112. package/src/components/alert-dialog/__snapshots__/AlertDialog.test.tsx.snap +0 -551
  113. package/src/components/avatar/__snapshots__/Avatar.test.tsx.snap +0 -681
  114. package/src/components/comment-block/__snapshots__/CommentBlock.test.tsx.snap +0 -92
  115. package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +0 -960
  116. package/src/components/expansion-panel/ExpansionPanel.stories.tsx +0 -65
  117. package/src/components/flag/__snapshots__/Flag.test.tsx.snap +0 -133
  118. package/src/components/flex-box/__snapshots__/FlexBox.test.tsx.snap +0 -492
  119. package/src/components/grid-column/GridColumn.stories.jsx +0 -56
  120. package/src/components/image-block/__snapshots__/ImageBlock.test.tsx.snap +0 -64
  121. package/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +0 -194
  122. package/src/components/list/__snapshots__/List.test.tsx.snap +0 -360
  123. package/src/components/list/__snapshots__/ListDivider.test.tsx.snap +0 -7
  124. package/src/components/list/__snapshots__/ListItem.test.tsx.snap +0 -160
  125. package/src/components/list/__snapshots__/ListSubheader.test.tsx.snap +0 -9
  126. package/src/components/mosaic/__snapshots__/Mosaic.test.tsx.snap +0 -357
  127. package/src/components/post-block/__snapshots__/PostBlock.test.tsx.snap +0 -139
  128. package/src/components/skeleton/__snapshots__/SkeletonCircle.test.tsx.snap +0 -54
  129. package/src/components/skeleton/__snapshots__/SkeletonRectangle.test.tsx.snap +0 -177
  130. package/src/components/skeleton/__snapshots__/SkeletonTypography.test.tsx.snap +0 -174
  131. package/src/components/slider/__snapshots__/Slider.test.tsx.snap +0 -122
  132. package/src/components/slideshow/__snapshots__/Slideshow.test.tsx.snap +0 -157
  133. package/src/components/table/__snapshots__/Table.test.tsx.snap +0 -263
  134. package/src/components/text/Text.stories.jsx +0 -75
  135. package/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap +0 -130
  136. package/src/components/user-block/__snapshots__/UserBlock.test.tsx.snap +0 -362
  137. package/src/stories/chromaticForceScreenSize.tsx +0 -7
  138. package/src/stories/knobs/buttonKnob.ts +0 -9
  139. package/src/stories/knobs/emphasisKnob.ts +0 -8
  140. package/src/stories/knobs/enumKnob.ts +0 -14
  141. package/src/stories/knobs/focusKnob.ts +0 -3
  142. package/src/stories/knobs/sizeKnob.ts +0 -5
  143. package/src/stories/knobs/thumbnailsKnob.ts +0 -9
  144. package/src/testing/utils/itShouldRenderStories.tsx +0 -103
@@ -1,198 +1,129 @@
1
1
  import React from 'react';
2
2
 
3
3
  import { mdiAbTesting } from '@lumx/icons';
4
- import {
5
- Alignment,
6
- AspectRatio,
7
- Badge,
8
- ColorPalette,
9
- FlexBox,
10
- Icon,
11
- Size,
12
- Thumbnail,
13
- ThumbnailVariant,
14
- } from '@lumx/react';
15
- import { IMAGE_SIZES, imageKnob, IMAGES } from '@lumx/react/stories/knobs/image';
16
- import { boolean, select, text } from '@storybook/addon-knobs';
17
- import { enumKnob } from '@lumx/react/stories/knobs/enumKnob';
18
- import { focusKnob } from '@lumx/react/stories/knobs/focusKnob';
19
- import { sizeKnob } from '@lumx/react/stories/knobs/sizeKnob';
20
- import { action } from '@storybook/addon-actions';
4
+ import { Alignment, AspectRatio, Badge, FlexBox, Icon, Size, Thumbnail, ThumbnailVariant } from '@lumx/react';
21
5
  import { CustomLink } from '@lumx/react/stories/utils/CustomLink';
6
+ import { IMAGE_SIZES, imageArgType, IMAGES } from '@lumx/react/stories/controls/image';
7
+ import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
8
+ import { withWrapper } from '@lumx/react/stories/decorators/withWrapper';
9
+ import { withNestedProps } from '@lumx/react/stories/decorators/withNestedProps';
10
+ import { withCombinations } from '@lumx/react/stories/decorators/withCombinations';
11
+ import { withUndefined } from '@lumx/react/stories/controls/withUndefined';
22
12
 
23
- export default { title: 'LumX components/thumbnail/Thumbnail' };
13
+ const aligns = [Alignment.center, Alignment.left, Alignment.right];
14
+ const variants = [ThumbnailVariant.squared, ThumbnailVariant.rounded];
24
15
 
25
- const Resizable = ({ initialSize: { width, height }, children }: any) => (
26
- <div style={{ border: '1px solid red', overflow: 'hidden', resize: 'both', width, height }}>{children}</div>
27
- );
16
+ export default {
17
+ title: 'LumX components/thumbnail/Thumbnail',
18
+ component: Thumbnail,
19
+ args: Thumbnail.defaultProps,
20
+ argTypes: {
21
+ image: imageArgType,
22
+ align: getSelectArgType(aligns),
23
+ variant: getSelectArgType(variants),
24
+ aspectRatio: getSelectArgType(AspectRatio),
25
+ fallback: { control: false },
26
+ 'focusPoint.x': { control: { type: 'range', max: 1, min: -1, step: 0.05 } },
27
+ 'focusPoint.y': { control: { type: 'range', max: 1, min: -1, step: 0.05 } },
28
+ },
29
+ decorators: [withNestedProps()],
30
+ };
28
31
 
29
- /** Default thumbnail props (editable via knobs) */
30
- export const Default = ({ theme }: any) => {
31
- const alt = text('Alternative text', 'Image alt text');
32
- const align = enumKnob(
33
- 'Alignment',
34
- [undefined, Alignment.center, Alignment.left, Alignment.right] as const,
35
- undefined,
36
- );
37
- const aspectRatio = enumKnob('Aspect ratio', [undefined, ...Object.values(AspectRatio)], undefined);
38
- const fillHeight = boolean('Fill Height', false);
39
- const focusPoint = { x: focusKnob('Focus X'), y: focusKnob('Focus Y') };
40
- const image = imageKnob('Image', IMAGES.landscape1);
41
- const variant = select('Variant', ThumbnailVariant, ThumbnailVariant.squared);
42
- const size = sizeKnob('Size', undefined);
43
- const onClick = boolean('clickable?', false) ? action('onClick') : undefined;
44
- const isLoading = boolean('Force loading', false);
45
- const forceError = boolean('Force error', false);
32
+ /** Simple thumbnail taking the size of the original image */
33
+ export const Simple = {
34
+ args: { image: IMAGES.landscape1s200 },
35
+ decorators: [
36
+ withWrapper({
37
+ style: { border: '1px dashed red', height: 500, width: 500, resize: 'both', overflow: 'hidden' },
38
+ }),
39
+ ],
40
+ };
46
41
 
47
- return (
48
- <Thumbnail
49
- alt={alt}
50
- align={align}
51
- aspectRatio={aspectRatio}
52
- fillHeight={fillHeight}
53
- focusPoint={focusPoint}
54
- image={forceError ? 'foo' : image}
55
- size={size}
56
- theme={theme}
57
- variant={variant}
58
- onClick={onClick}
59
- isLoading={isLoading}
60
- />
61
- );
42
+ /** Loading state*/
43
+ export const IsLoading = {
44
+ args: { ...Simple.args, isLoading: true },
62
45
  };
63
46
 
64
- export const WithBadge = () => {
65
- const thumbnailSize = sizeKnob('Size', Size.l);
66
- const variant = select('Variant', ThumbnailVariant, ThumbnailVariant.rounded);
67
- const badgeColor = select('Badge color', ColorPalette, ColorPalette.primary);
68
- const activateFallback = boolean('Activate fallback', false);
69
- const image = imageKnob();
70
- return (
71
- <Thumbnail
72
- alt="Image alt text"
73
- image={activateFallback ? '' : image}
74
- variant={variant}
75
- aspectRatio={AspectRatio.square}
76
- size={thumbnailSize}
77
- badge={
78
- <Badge color={badgeColor}>
79
- <Icon icon={mdiAbTesting} />
80
- </Badge>
81
- }
82
- />
83
- );
47
+ /** Thumbnail error fallback and size variants */
48
+ export const ErrorFallback = {
49
+ args: { image: 'foo' },
50
+ decorators: [
51
+ withCombinations({
52
+ combinations: {
53
+ cols: {
54
+ Default: {},
55
+ 'Icon fallback': { fallback: mdiAbTesting },
56
+ 'Image fallback': { fallback: <img src="/logo.svg" alt="logo" /> },
57
+ },
58
+ rows: {
59
+ Default: {},
60
+ 'Size xl & ratio wide': { size: Size.xl, aspectRatio: AspectRatio.wide },
61
+ 'Size l & ratio vertical': { size: Size.l, aspectRatio: AspectRatio.vertical },
62
+ },
63
+ },
64
+ }),
65
+ ],
84
66
  };
85
67
 
86
- export const WithCustomImageClassName = () => {
87
- const thumbnailSize = sizeKnob('Size', Size.l);
88
- const variant = select('Variant', ThumbnailVariant, ThumbnailVariant.rounded);
89
- const badgeColor = select('Badge color', ColorPalette, ColorPalette.primary);
90
- const activateFallback = boolean('Activate fallback', false);
91
- const image = imageKnob();
92
- return (
93
- <Thumbnail
94
- alt="Image alt text"
95
- image={activateFallback ? '' : image}
96
- variant={variant}
97
- aspectRatio={AspectRatio.square}
98
- size={thumbnailSize}
99
- badge={
100
- <Badge color={badgeColor}>
101
- <Icon icon={mdiAbTesting} />
102
- </Badge>
103
- }
104
- imgProps={{
105
- className: 'custom-image-class-name',
106
- }}
107
- />
108
- );
68
+ /** Simple thumbnail with badge */
69
+ export const WithBadge = {
70
+ ...Simple,
71
+ args: {
72
+ ...Simple.args,
73
+ size: Size.xl,
74
+ badge: (
75
+ <Badge color="green">
76
+ <Icon icon={mdiAbTesting} />
77
+ </Badge>
78
+ ),
79
+ },
109
80
  };
110
81
 
111
- export const FocusPoint = () => {
112
- const focusPoint = { x: focusKnob('Focus X ', -0.2), y: focusKnob('Focus Y', -0.3) };
113
- const aspectRatio = enumKnob('Aspect ratio', [undefined, ...Object.values(AspectRatio)], AspectRatio.wide);
114
- const fillHeight = aspectRatio === AspectRatio.free;
115
- return (
116
- <>
117
- <small>Focus point will delay the display of the image if the original image size is not accessible.</small>
118
- <Resizable initialSize={{ height: 200, width: 300 }}>
119
- <Thumbnail
120
- alt="Image"
121
- image={IMAGES.portrait1s200}
122
- aspectRatio={aspectRatio}
123
- fillHeight={fillHeight}
124
- focusPoint={focusPoint}
125
- style={{ width: '100%' }}
126
- />
127
- </Resizable>
82
+ /** Demonstrate the focus point X on a vertical thumbnail containing an horizontal image */
83
+ export const FocusPointVertical = {
84
+ args: {
85
+ aspectRatio: AspectRatio.vertical,
86
+ size: Size.xxl,
87
+ image: IMAGES.landscape1,
88
+ 'focusPoint.x': 1,
89
+ },
90
+ };
128
91
 
129
- <small>Providing the width & height in imgProps should avoid the delay shown above</small>
130
- <Resizable initialSize={{ height: 200, width: 300 }}>
131
- <Thumbnail
132
- alt="Image"
133
- image={IMAGES.portrait2}
134
- imgProps={IMAGE_SIZES.portrait2}
135
- fillHeight={fillHeight}
136
- aspectRatio={aspectRatio}
137
- focusPoint={focusPoint}
138
- style={{ width: '100%' }}
139
- />
140
- </Resizable>
141
- </>
142
- );
92
+ /** Demonstrate the focus point Y on a horizontal thumbnail containing an vertical image */
93
+ export const FocusPointHorizontal = {
94
+ args: {
95
+ aspectRatio: AspectRatio.horizontal,
96
+ size: Size.xxl,
97
+ image: IMAGES.portrait1,
98
+ 'focusPoint.y': 1,
99
+ },
143
100
  };
144
101
 
145
- export const Clickable = () => (
146
- <Thumbnail alt="Click me" image={imageKnob()} size={sizeKnob('Size', Size.xxl)} onClick={action('onClick')} />
147
- );
102
+ /** Setting `onClick` to turn the thumbnail into a button */
103
+ export const AsButton = {
104
+ args: Simple.args,
105
+ argTypes: { onClick: { action: true } },
106
+ };
148
107
 
149
- export const ClickableLink = () => (
150
- <Thumbnail
151
- alt="Click me"
152
- image={imageKnob()}
153
- size={sizeKnob('Size', Size.xxl)}
154
- linkProps={{ href: 'https://google.fr' }}
155
- />
156
- );
108
+ /** Setting `linkProps.href` to turn the thumbnail into a link */
109
+ export const AsLink = {
110
+ args: { ...Simple.args, linkProps: { href: 'https://example.com' } },
111
+ };
157
112
 
158
- export const ClickableCustomLink = () => (
159
- <Thumbnail
160
- alt="Click me"
161
- image={imageKnob()}
162
- size={sizeKnob('Size', Size.xxl)}
163
- linkAs={CustomLink}
164
- linkProps={{ href: 'https://google.fr', className: 'custom-class-name' }}
165
- />
166
- );
113
+ /** Setting `href` to turn the thumbnail into a link */
114
+ export const AsCustomLink = {
115
+ args: { ...Simple.args, linkAs: CustomLink, linkProps: { href: 'https://example.com' } },
116
+ };
167
117
 
168
- export const FillHeight = () => {
169
- const parentStyle = {
170
- width: 600,
171
- height: 240,
172
- border: '1px solid red',
173
- overflow: 'hidden',
174
- resize: 'both',
175
- } as const;
176
- return (
177
- <>
178
- <h2>Default</h2>
179
- <div style={parentStyle}>
180
- <Thumbnail alt="" image={IMAGES.landscape1s200} fillHeight />
181
- </div>
182
- <h2>Ratio wide</h2>
183
- <div style={parentStyle}>
184
- <Thumbnail alt="" image={IMAGES.landscape1s200} fillHeight aspectRatio="wide" />
185
- </div>
186
- <h2>Ratio vertical</h2>
187
- <div style={parentStyle}>
188
- <Thumbnail alt="" image={IMAGES.landscape1s200} fillHeight aspectRatio="vertical" />
189
- </div>
190
- <h2>Ratio free</h2>
191
- <div style={parentStyle}>
192
- <Thumbnail alt="" image={IMAGES.landscape1s200} fillHeight aspectRatio="free" />
193
- </div>
194
- </>
195
- );
118
+ /** Combinations of fillHeight and ratios */
119
+ export const FillHeightAndRatio = {
120
+ ...Simple,
121
+ args: { ...Simple.args, fillHeight: true },
122
+
123
+ decorators: [
124
+ ...Simple.decorators,
125
+ withCombinations({ combinations: { rows: { key: 'aspectRatio', options: withUndefined(AspectRatio) } } }),
126
+ ],
196
127
  };
197
128
 
198
129
  export const Original = () => (
@@ -428,83 +359,3 @@ export const Square = () => (
428
359
  </FlexBox>
429
360
  </>
430
361
  );
431
-
432
- export const IsLoading = ({ theme }: any) => (
433
- <FlexBox
434
- orientation="horizontal"
435
- vAlign="center"
436
- marginAuto={['left', 'right']}
437
- style={{ border: '1px solid red', width: 900, height: 700, resize: 'both', overflow: 'auto' }}
438
- >
439
- <Thumbnail
440
- theme={theme}
441
- alt="Image alt text"
442
- image={IMAGES.landscape2}
443
- isLoading={boolean('Force loading', true)}
444
- fillHeight={boolean('Fill Height', false)}
445
- size={sizeKnob('Size', undefined)}
446
- />
447
- </FlexBox>
448
- );
449
-
450
- export const ErrorFallbackVariants = ({ theme }: any) => {
451
- const isLoading = boolean('Force loading', false);
452
- const variant = select('Variant', ThumbnailVariant, undefined);
453
- const base = { alt: 'foo', image: 'foo', isLoading, variant, theme } as const;
454
- const imageFallback = <img src="/logo.svg" alt="logo" />;
455
- const imgProps = { width: 50, height: 50 };
456
-
457
- return (
458
- <>
459
- <h2>Default</h2>
460
- <FlexBox orientation="horizontal" gap="big">
461
- <Thumbnail {...base} />
462
- <Thumbnail {...base} fallback={mdiAbTesting} />
463
- <Thumbnail {...base} fallback={imageFallback} />
464
- </FlexBox>
465
- <h2>
466
- With original image size <small>(50x50)</small>
467
- </h2>
468
- <FlexBox orientation="horizontal" gap="big">
469
- <Thumbnail {...base} imgProps={imgProps} />
470
- <Thumbnail {...base} fallback={mdiAbTesting} imgProps={imgProps} />
471
- <Thumbnail {...base} fallback={imageFallback} imgProps={imgProps} />
472
- </FlexBox>
473
- <h2>With size</h2>
474
- <FlexBox orientation="horizontal" gap="big">
475
- <Thumbnail {...base} size="xl" />
476
- <Thumbnail {...base} size="xl" fallback={mdiAbTesting} />
477
- <Thumbnail {...base} size="xl" fallback={imageFallback} />
478
- </FlexBox>
479
- <h2>With size & ratio</h2>
480
- <FlexBox orientation="horizontal" gap="big">
481
- <Thumbnail {...base} size="xl" aspectRatio="wide" />
482
- <Thumbnail {...base} size="xl" aspectRatio="wide" fallback={mdiAbTesting} />
483
- <Thumbnail {...base} size="xl" aspectRatio="wide" fallback={imageFallback} />
484
- </FlexBox>
485
- <h2>
486
- With original size <small>(50x50)</small> & ratio
487
- </h2>
488
- <small>Unsupported use case (thumbnail size is undefined)</small>
489
- <FlexBox orientation="horizontal" gap="big">
490
- <Thumbnail {...base} imgProps={imgProps} aspectRatio="wide" />
491
- <Thumbnail {...base} imgProps={imgProps} aspectRatio="wide" fallback={mdiAbTesting} />
492
- <Thumbnail {...base} imgProps={imgProps} aspectRatio="wide" fallback={imageFallback} />
493
- </FlexBox>
494
- <h2>
495
- With original size <small>(50x50)</small> & ratio & constrained parent size
496
- </h2>
497
- <FlexBox orientation="horizontal" gap="big">
498
- <div className="parent" style={{ width: 220 }}>
499
- <Thumbnail {...base} imgProps={imgProps} aspectRatio="wide" />
500
- </div>
501
- <div className="parent" style={{ width: 220 }}>
502
- <Thumbnail {...base} imgProps={imgProps} aspectRatio="wide" fallback={mdiAbTesting} />
503
- </div>
504
- <div className="parent" style={{ width: 220 }}>
505
- <Thumbnail {...base} imgProps={imgProps} aspectRatio="wide" fallback={imageFallback} />
506
- </div>
507
- </FlexBox>
508
- </>
509
- );
510
- };
@@ -1,46 +1,23 @@
1
1
  import React from 'react';
2
2
 
3
- import { mount, shallow } from 'enzyme';
4
- import 'jest-enzyme';
5
- import { commonTestsSuite, itShouldRenderStories } from '@lumx/react/testing/utils';
6
-
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
5
+ import { render } from '@testing-library/react';
7
6
  import { Thumbnail, ThumbnailProps } from './Thumbnail';
8
- import {
9
- Clickable,
10
- ClickableCustomLink,
11
- ClickableLink,
12
- Default,
13
- WithBadge,
14
- WithCustomImageClassName,
15
- } from './Thumbnail.stories';
16
7
 
17
8
  const CLASSNAME = Thumbnail.className as string;
18
9
 
19
- /**
20
- * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
21
- */
22
- const setup = (props: Partial<ThumbnailProps> = {}, shallowRendering = true) => {
23
- const renderer: any = shallowRendering ? shallow : mount;
24
- const wrapper: any = renderer(<Thumbnail {...(props as any)} />);
25
- return { props, wrapper };
10
+ const setup = (props: Partial<ThumbnailProps> = {}) => {
11
+ render(<Thumbnail {...(props as any)} />);
12
+ const thumbnail = queryByClassName(document.body, CLASSNAME);
13
+ return { props, thumbnail };
26
14
  };
27
15
 
28
16
  describe(`<${Thumbnail.displayName}>`, () => {
29
- // 1. Test render via snapshot.
30
- describe('Snapshots and structure', () => {
31
- itShouldRenderStories(
32
- {
33
- Default,
34
- Clickable,
35
- ClickableLink,
36
- ClickableCustomLink,
37
- WithBadge,
38
- WithCustomImageClassName,
39
- },
40
- Thumbnail,
41
- );
42
- });
43
-
44
17
  // Common tests suite.
45
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: CLASSNAME });
18
+ commonTestsSuiteRTL(setup, {
19
+ baseClassName: CLASSNAME,
20
+ forwardClassName: 'thumbnail',
21
+ forwardAttributes: 'thumbnail',
22
+ });
46
23
  });