@lumx/react 3.1.5 → 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 (143) hide show
  1. package/_internal/types.d.ts +16 -5
  2. package/index.d.ts +45 -4
  3. package/index.js +609 -411
  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 +131 -293
  19. package/src/components/dialog/Dialog.test.tsx +0 -32
  20. package/src/components/dropdown/Dropdown.stories.tsx +1 -186
  21. package/src/components/flag/Flag.stories.tsx +33 -18
  22. package/src/components/flag/Flag.test.tsx +1 -8
  23. package/src/components/flex-box/FlexBox.stories.tsx +151 -238
  24. package/src/components/flex-box/FlexBox.test.tsx +9 -49
  25. package/src/components/generic-block/GenericBlock.stories.jsx +1 -1
  26. package/src/components/grid-column/GridColumn.stories.tsx +46 -0
  27. package/src/components/heading/Heading.stories.tsx +57 -95
  28. package/src/components/icon/Icon.stories.tsx +67 -70
  29. package/src/components/image-block/ImageBlock.stories.tsx +103 -47
  30. package/src/components/image-block/ImageBlock.test.tsx +12 -17
  31. package/src/components/inline-list/InlineList.stories.tsx +45 -29
  32. package/src/components/input-helper/InputHelper.stories.tsx +31 -25
  33. package/src/components/input-label/InputLabel.stories.tsx +33 -10
  34. package/src/components/lightbox/Lightbox.stories.tsx +39 -77
  35. package/src/components/lightbox/Lightbox.test.tsx +12 -17
  36. package/src/components/link/Link.stories.tsx +98 -128
  37. package/src/components/link-preview/LinkPreview.stories.tsx +48 -75
  38. package/src/components/list/List.stories.tsx +59 -84
  39. package/src/components/list/List.test.tsx +8 -17
  40. package/src/components/list/ListDivider.stories.tsx +9 -4
  41. package/src/components/list/ListDivider.test.tsx +12 -17
  42. package/src/components/list/ListItem.stories.tsx +97 -59
  43. package/src/components/list/ListItem.test.tsx +12 -17
  44. package/src/components/list/ListSubheader.stories.tsx +8 -5
  45. package/src/components/list/ListSubheader.test.tsx +12 -18
  46. package/src/components/message/Message.stories.tsx +51 -22
  47. package/src/components/mosaic/Mosaic.stories.tsx +78 -74
  48. package/src/components/mosaic/Mosaic.test.tsx +0 -31
  49. package/src/components/navigation/Navigation.stories.tsx +67 -0
  50. package/src/components/navigation/Navigation.test.tsx +58 -0
  51. package/src/components/navigation/Navigation.tsx +62 -0
  52. package/src/components/navigation/NavigationItem.test.tsx +37 -0
  53. package/src/components/navigation/NavigationItem.tsx +89 -0
  54. package/src/components/navigation/NavigationSection.test.tsx +126 -0
  55. package/src/components/navigation/NavigationSection.tsx +109 -0
  56. package/src/components/navigation/context.tsx +6 -0
  57. package/src/components/navigation/index.ts +1 -0
  58. package/src/components/notification/Notifications.stories.tsx +52 -47
  59. package/src/components/popover/Popover.stories.tsx +68 -201
  60. package/src/components/popover-dialog/PopoverDialog.stories.tsx +26 -65
  61. package/src/components/post-block/PostBlock.test.tsx +12 -17
  62. package/src/components/progress/ProgressCircular.stories.tsx +24 -12
  63. package/src/components/progress/ProgressLinear.stories.tsx +6 -2
  64. package/src/components/radio-button/RadioButton.stories.tsx +35 -24
  65. package/src/components/select/Select.stories.tsx +19 -23
  66. package/src/components/skeleton/SkeletonCircle.stories.tsx +37 -21
  67. package/src/components/skeleton/SkeletonCircle.test.tsx +12 -17
  68. package/src/components/skeleton/SkeletonRectangle.stories.tsx +74 -99
  69. package/src/components/skeleton/SkeletonRectangle.test.tsx +12 -17
  70. package/src/components/skeleton/SkeletonTypography.test.tsx +12 -17
  71. package/src/components/slider/Slider.stories.tsx +41 -25
  72. package/src/components/slider/Slider.test.tsx +12 -18
  73. package/src/components/slideshow/Slideshow.stories.tsx +31 -61
  74. package/src/components/slideshow/Slideshow.test.tsx +15 -23
  75. package/src/components/slideshow/SlideshowControls.stories.tsx +4 -6
  76. package/src/components/switch/Switch.stories.tsx +35 -32
  77. package/src/components/table/Table.test.tsx +12 -17
  78. package/src/components/tabs/Tabs.stories.tsx +4 -3
  79. package/src/components/text/Text.stories.tsx +130 -0
  80. package/src/components/text-field/TextField.stories.tsx +114 -148
  81. package/src/components/thumbnail/Thumbnail.stories.tsx +106 -255
  82. package/src/components/thumbnail/Thumbnail.test.tsx +12 -35
  83. package/src/components/tooltip/Tooltip.stories.tsx +51 -136
  84. package/src/components/user-block/UserBlock.stories.tsx +67 -56
  85. package/src/components/user-block/UserBlock.test.tsx +1 -5
  86. package/src/index.ts +1 -0
  87. package/src/stories/controls/color.ts +6 -0
  88. package/src/stories/controls/element.ts +6 -0
  89. package/src/stories/controls/focusPoint.ts +1 -0
  90. package/src/stories/controls/icons.ts +6 -0
  91. package/src/stories/{knobs → controls}/image.ts +6 -16
  92. package/src/stories/controls/selectArgType.ts +4 -0
  93. package/src/stories/controls/theme.ts +3 -0
  94. package/src/stories/controls/typography.ts +5 -0
  95. package/src/stories/controls/withUndefined.ts +1 -0
  96. package/src/stories/decorators/withChromaticForceScreenSize.tsx +8 -0
  97. package/src/stories/decorators/withCombinations.tsx +99 -0
  98. package/src/stories/decorators/withNestedProps.tsx +23 -0
  99. package/src/stories/{withResizableBox.tsx → decorators/withResizableBox.tsx} +6 -10
  100. package/src/stories/decorators/withValueOnChange.tsx +18 -0
  101. package/src/stories/decorators/withWrapper.tsx +19 -0
  102. package/src/stories/utils/CustomLink.tsx +8 -2
  103. package/src/stories/{knobs → utils}/lorem.ts +9 -9
  104. package/src/testing/utils/commonTestsSuiteRTL.ts +2 -3
  105. package/src/testing/utils/index.ts +0 -2
  106. package/src/untypped-modules.d.ts +0 -2
  107. package/src/utils/MaterialThemeSwitcher/MaterialThemeSwitcher.tsx +1 -1
  108. package/src/utils/ThemeContext.ts +4 -0
  109. package/src/utils/forwardRefPolymorphic.ts +9 -0
  110. package/src/utils/type.ts +28 -4
  111. package/src/components/alert-dialog/__snapshots__/AlertDialog.test.tsx.snap +0 -558
  112. package/src/components/avatar/__snapshots__/Avatar.test.tsx.snap +0 -681
  113. package/src/components/comment-block/__snapshots__/CommentBlock.test.tsx.snap +0 -92
  114. package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +0 -1133
  115. package/src/components/expansion-panel/ExpansionPanel.stories.tsx +0 -65
  116. package/src/components/flag/__snapshots__/Flag.test.tsx.snap +0 -133
  117. package/src/components/flex-box/__snapshots__/FlexBox.test.tsx.snap +0 -492
  118. package/src/components/grid-column/GridColumn.stories.jsx +0 -56
  119. package/src/components/image-block/__snapshots__/ImageBlock.test.tsx.snap +0 -64
  120. package/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +0 -194
  121. package/src/components/list/__snapshots__/List.test.tsx.snap +0 -360
  122. package/src/components/list/__snapshots__/ListDivider.test.tsx.snap +0 -7
  123. package/src/components/list/__snapshots__/ListItem.test.tsx.snap +0 -160
  124. package/src/components/list/__snapshots__/ListSubheader.test.tsx.snap +0 -9
  125. package/src/components/mosaic/__snapshots__/Mosaic.test.tsx.snap +0 -357
  126. package/src/components/post-block/__snapshots__/PostBlock.test.tsx.snap +0 -139
  127. package/src/components/skeleton/__snapshots__/SkeletonCircle.test.tsx.snap +0 -54
  128. package/src/components/skeleton/__snapshots__/SkeletonRectangle.test.tsx.snap +0 -177
  129. package/src/components/skeleton/__snapshots__/SkeletonTypography.test.tsx.snap +0 -174
  130. package/src/components/slider/__snapshots__/Slider.test.tsx.snap +0 -122
  131. package/src/components/slideshow/__snapshots__/Slideshow.test.tsx.snap +0 -157
  132. package/src/components/table/__snapshots__/Table.test.tsx.snap +0 -263
  133. package/src/components/text/Text.stories.jsx +0 -75
  134. package/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap +0 -130
  135. package/src/components/user-block/__snapshots__/UserBlock.test.tsx.snap +0 -362
  136. package/src/stories/chromaticForceScreenSize.tsx +0 -7
  137. package/src/stories/knobs/buttonKnob.ts +0 -9
  138. package/src/stories/knobs/emphasisKnob.ts +0 -8
  139. package/src/stories/knobs/enumKnob.ts +0 -14
  140. package/src/stories/knobs/focusKnob.ts +0 -3
  141. package/src/stories/knobs/sizeKnob.ts +0 -5
  142. package/src/stories/knobs/thumbnailsKnob.ts +0 -9
  143. package/src/testing/utils/itShouldRenderStories.tsx +0 -103
@@ -1,16 +1,32 @@
1
1
  import React, { useRef } from 'react';
2
2
 
3
3
  import { mdiAccount, mdiOpenInNew } from '@lumx/icons';
4
- import { Icon, ListDivider, ListSubheader, Size } from '@lumx/react';
5
- import { action } from '@storybook/addon-actions';
6
- import { select, text } from '@storybook/addon-knobs';
4
+ import { Icon, ListDivider, ListProps, ListSubheader, Size } from '@lumx/react';
5
+ import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
7
6
 
8
7
  import { List } from './List';
9
8
  import { ListItem } from './ListItem';
9
+ import ListItemStories from './ListItem.stories';
10
10
 
11
- export default { title: 'LumX components/list/List' };
11
+ export default {
12
+ title: 'LumX components/list/List',
13
+ component: List,
14
+ args: List.defaultProps,
15
+ argTypes: {
16
+ itemPadding: getSelectArgType<ListProps['itemPadding']>([Size.big, Size.huge]),
17
+ onListItemSelected: { action: true },
18
+ 'children.onItemSelected': { action: true },
19
+ 'children.size': ListItemStories.argTypes.size,
20
+ },
21
+ };
22
+
23
+ const CustomListItem = (props: any) => <ListItem {...props}>Custom list item</ListItem>;
12
24
 
13
- export const KeyboardNavigation = () => {
25
+ export const KeyboardNavigation = ({
26
+ 'children.onItemSelected': childrenOnItemSelected,
27
+ 'children.size': childrenSize,
28
+ ...props
29
+ }: any) => {
14
30
  const listRef = useRef<any>();
15
31
  const firstItemRef = useRef<any>();
16
32
 
@@ -22,10 +38,6 @@ export const KeyboardNavigation = () => {
22
38
  return firstItemRef.current?.focus();
23
39
  };
24
40
 
25
- const CustomListItem = () => {
26
- return <ListItem onItemSelected={action('onItemSelected custom list item')}>Custom list item</ListItem>;
27
- };
28
-
29
41
  return (
30
42
  <>
31
43
  <button type="button" onClick={focusList}>
@@ -34,27 +46,31 @@ export const KeyboardNavigation = () => {
34
46
  <button type="button" onClick={focusFirsItem}>
35
47
  focus first item
36
48
  </button>
37
- <List onListItemSelected={action('List onListItemSelected')} ref={listRef}>
38
- <ListItem linkRef={firstItemRef} onItemSelected={action('onItemSelected: Clickable item 1')}>
49
+ <List ref={listRef} {...props}>
50
+ <ListItem size={childrenSize} linkRef={firstItemRef} onItemSelected={childrenOnItemSelected}>
39
51
  Clickable item 1
40
52
  </ListItem>
41
53
  <ListDivider />
42
- <ListItem linkProps={{ href: '#' }}>Link item 1</ListItem>
54
+ <ListItem size={childrenSize} linkProps={{ href: '#' }}>
55
+ Link item 1
56
+ </ListItem>
43
57
  <>
44
- <ListItem>Non clickable (=non navigable) item</ListItem>
58
+ <ListItem size={childrenSize}>Non clickable (=non navigable) item</ListItem>
45
59
  <ListSubheader>Header</ListSubheader>
46
- <ListItem linkProps={{ href: '#' }}>Link item 2</ListItem>
60
+ <ListItem size={childrenSize} linkProps={{ href: '#' }}>
61
+ Link item 2
62
+ </ListItem>
47
63
  <ListSubheader>Header</ListSubheader>
48
64
  </>
49
- <ListItem linkProps={{ href: '#' }} isDisabled>
65
+ <ListItem size={childrenSize} linkProps={{ href: '#' }} isDisabled>
50
66
  Disabled link item
51
67
  </ListItem>
52
- <ListItem onItemSelected={action('onItemSelected')} isDisabled>
68
+ <ListItem size={childrenSize} onItemSelected={childrenOnItemSelected} isDisabled>
53
69
  Disabled button item
54
70
  </ListItem>
55
- <CustomListItem />
71
+ <CustomListItem size={childrenSize} onItemSelected={childrenOnItemSelected} />
56
72
  {[
57
- <ListItem key="1" linkProps={{ href: '#' }}>
73
+ <ListItem size={childrenSize} key="1" linkProps={{ href: '#' }}>
58
74
  Link item 4
59
75
  </ListItem>,
60
76
  ]}
@@ -68,74 +84,33 @@ export const KeyboardNavigation = () => {
68
84
  );
69
85
  };
70
86
 
71
- export const WithItemPadding = () => {
72
- const listItemSize = select('list item size', [Size.tiny, Size.regular, Size.big, Size.huge], Size.big);
73
- const listItem = (
87
+ export const AsLink = () => (
88
+ <List>
74
89
  <ListItem
90
+ before={<Icon icon={mdiAccount} />}
75
91
  className="lumx-color-background-dark-L6"
76
- size={listItemSize}
77
- linkProps={{ href: text('link href', '#') }}
92
+ linkProps={{ href: '#' }}
78
93
  >
79
- <div>Two-line item</div>
80
- <div className="lumx-color-font-dark-L2">Secondary text</div>
94
+ <span>My first link</span>
81
95
  </ListItem>
82
- );
83
- return (
84
- <>
85
- Default item padding:
86
- <List>
87
- {listItem}
88
- {listItem}
89
- </List>
90
- Big item padding:
91
- <List itemPadding={Size.big}>
92
- {listItem}
93
- {listItem}
94
- </List>
95
- Huge item padding:
96
- <List itemPadding={Size.huge}>
97
- {listItem}
98
- {listItem}
99
- </List>
100
- </>
101
- );
102
- };
103
-
104
- export const AsLink = () => {
105
- return (
106
- <div className="demo-grid">
107
- <List>
108
- <ListItem
109
- before={<Icon icon={mdiAccount} />}
110
- className="lumx-color-background-dark-L6"
111
- linkProps={{ href: '#' }}
112
- >
113
- <span>My first link</span>
114
- </ListItem>
115
- <ListItem
116
- className="lumx-color-background-dark-L6"
117
- after={<Icon icon={mdiOpenInNew} />}
118
- linkProps={{ href: 'http://www.google.com', target: '_blank' }}
119
- >
120
- <span>Google</span>
121
- </ListItem>
122
- </List>
123
- </div>
124
- );
125
- };
126
-
127
- export const WithCustomChildren = () => {
128
- const CustomListItem = () => {
129
- return <ListItem onItemSelected={action('onItemSelected custom list item')}>Custom list item</ListItem>;
130
- };
96
+ <ListItem
97
+ className="lumx-color-background-dark-L6"
98
+ after={<Icon icon={mdiOpenInNew} />}
99
+ linkProps={{ href: 'https://example.com', target: '_blank' }}
100
+ >
101
+ <span>Google</span>
102
+ </ListItem>
103
+ </List>
104
+ );
131
105
 
132
- return (
133
- <div className="demo-grid">
134
- <List>
135
- <CustomListItem />
136
- <CustomListItem />
137
- <CustomListItem />
138
- </List>
139
- </div>
140
- );
141
- };
106
+ export const WithCustomChildren = ({
107
+ 'children.onItemSelected': childrenOnItemSelected,
108
+ 'children.size': childrenSize,
109
+ ...props
110
+ }: any) => (
111
+ <List {...props}>
112
+ <CustomListItem size={childrenSize} onItemSelected={childrenOnItemSelected} />
113
+ <CustomListItem size={childrenSize} onItemSelected={childrenOnItemSelected} />
114
+ <CustomListItem size={childrenSize} onItemSelected={childrenOnItemSelected} />
115
+ </List>
116
+ );
@@ -1,29 +1,20 @@
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';
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
6
4
 
5
+ import { render } from '@testing-library/react';
6
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
7
7
  import { List, ListProps } from './List';
8
- import * as stories from './List.stories';
9
8
 
10
9
  const CLASSNAME = List.className as string;
11
10
 
12
- /**
13
- * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
14
- */
15
- const setup = (props: Partial<ListProps> = {}, shallowRendering = true) => {
16
- const renderer: any = shallowRendering ? shallow : mount;
17
- const wrapper: any = renderer(<List {...(props as any)} />);
18
- return { props, wrapper };
11
+ const setup = (props: Partial<ListProps> = {}) => {
12
+ render(<List {...(props as any)} />);
13
+ const list = queryByClassName(document.body, CLASSNAME);
14
+ return { props, list };
19
15
  };
20
16
 
21
17
  describe(`<${List.displayName}>`, () => {
22
- // 1. Test render via snapshot.
23
- describe('Snapshots and structure', () => {
24
- itShouldRenderStories(stories, List);
25
- });
26
-
27
18
  // Common tests suite.
28
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: CLASSNAME });
19
+ commonTestsSuiteRTL(setup, { baseClassName: CLASSNAME, forwardClassName: 'list', forwardAttributes: 'list' });
29
20
  });
@@ -1,7 +1,12 @@
1
- import React from 'react';
2
-
1
+ import { withWrapper } from '@lumx/react/stories/decorators/withWrapper';
2
+ import { List } from '@lumx/react';
3
3
  import { ListDivider } from './ListDivider';
4
4
 
5
- export default { title: 'LumX components/list/ListDivider' };
5
+ export default {
6
+ title: 'LumX components/list/ListDivider',
7
+ component: ListDivider,
8
+ args: ListDivider.defaultProps,
9
+ decorators: [withWrapper({}, List)],
10
+ };
6
11
 
7
- export const Default = () => <ListDivider />;
12
+ export const Default = {};
@@ -1,29 +1,24 @@
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';
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
6
4
 
5
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
6
+ import { render } from '@testing-library/react';
7
7
  import { ListDivider, ListDividerProps } from './ListDivider';
8
- import * as stories from './ListDivider.stories';
9
8
 
10
9
  const CLASSNAME = ListDivider.className as string;
11
10
 
12
- /**
13
- * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
14
- */
15
- const setup = (props: Partial<ListDividerProps> = {}, shallowRendering = true) => {
16
- const renderer: any = shallowRendering ? shallow : mount;
17
- const wrapper: any = renderer(<ListDivider {...(props as any)} />);
18
- return { props, wrapper };
11
+ const setup = (props: Partial<ListDividerProps> = {}) => {
12
+ render(<ListDivider {...(props as any)} />);
13
+ const listDivider = queryByClassName(document.body, CLASSNAME);
14
+ return { props, listDivider };
19
15
  };
20
16
 
21
17
  describe(`<${ListDivider.displayName}>`, () => {
22
- // 1. Test render via snapshot.
23
- describe('Snapshots and structure', () => {
24
- itShouldRenderStories(stories, ListDivider);
25
- });
26
-
27
18
  // Common tests suite.
28
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: CLASSNAME });
19
+ commonTestsSuiteRTL(setup, {
20
+ baseClassName: CLASSNAME,
21
+ forwardClassName: 'listDivider',
22
+ forwardAttributes: 'listDivider',
23
+ });
29
24
  });
@@ -1,62 +1,100 @@
1
- import React from 'react';
2
-
3
- import { Size } from '@lumx/react';
4
- import { select, text } from '@storybook/addon-knobs';
5
- import { action } from '@storybook/addon-actions';
1
+ import { List, ListItemSize, Size } from '@lumx/react';
6
2
 
3
+ import { withWrapper } from '@lumx/react/stories/decorators/withWrapper';
4
+ import { CustomLink } from '@lumx/react/stories/utils/CustomLink';
5
+ import { withCombinations } from '@lumx/react/stories/decorators/withCombinations';
6
+ import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
7
7
  import { ListItem } from './ListItem';
8
8
 
9
- export default { title: 'LumX components/list/ListItem' };
10
-
11
- export const NonClickable = ({ theme }: any) => <ListItem theme={theme}>{text('text', 'Text')}</ListItem>;
12
-
13
- export const Link = ({ theme }: any) => (
14
- <ListItem theme={theme} linkProps={{ href: '#' }}>
15
- {text('text', 'Text')}
16
- </ListItem>
17
- );
18
-
19
- export const Button = ({ theme }: any) => (
20
- <ListItem theme={theme} onItemSelected={action('onItemSelected')}>
21
- {text('text', 'Text')}
22
- </ListItem>
23
- );
24
-
25
- export const LinkDisabled = ({ theme }: any) => (
26
- <ListItem theme={theme} linkProps={{ href: '#' }} isDisabled>
27
- {text('text', 'Text')}
28
- </ListItem>
29
- );
30
-
31
- export const ButtonDisabled = ({ theme }: any) => (
32
- <ListItem theme={theme} onItemSelected={action('onItemSelected')} isDisabled>
33
- {text('text', 'Text')}
34
- </ListItem>
35
- );
36
-
37
- export const Selected = ({ theme }: any) => (
38
- <ListItem theme={theme} linkProps={{ href: '#' }} isSelected>
39
- {text('text', 'Text')}
40
- </ListItem>
41
- );
42
-
43
- export const Highlighted = ({ theme }: any) => (
44
- <ListItem theme={theme} linkProps={{ href: '#' }} isHighlighted>
45
- {text('text', 'Text')}
46
- </ListItem>
47
- );
48
-
49
- export const Sizes = ({ theme }: any) => (
50
- <ListItem theme={theme} size={select('size', [Size.tiny, Size.regular, Size.big, Size.huge], Size.tiny)}>
51
- {text('text', 'Text')}
52
- </ListItem>
53
- );
54
-
55
- const CustomLink: React.FC = ({ children, ...props }) =>
56
- React.createElement('a', { ...props, style: { color: 'red' }, href: 'http://google.com' }, children);
57
-
58
- export const WithCustomLink = ({ theme }: any) => (
59
- <ListItem theme={theme} linkAs={CustomLink}>
60
- My custom link
61
- </ListItem>
62
- );
9
+ const sizes: ListItemSize[] = [Size.tiny, Size.regular, Size.big];
10
+
11
+ export default {
12
+ title: 'LumX components/list/ListItem',
13
+ component: ListItem,
14
+ args: ListItem.defaultProps,
15
+ argTypes: {
16
+ size: getSelectArgType(sizes),
17
+ },
18
+ decorators: [withWrapper({}, List)],
19
+ };
20
+
21
+ /**
22
+ * Default list item with text
23
+ */
24
+ export const NonClickable = {
25
+ args: { children: 'List item' },
26
+ };
27
+
28
+ /**
29
+ * Button list item (onClick)
30
+ */
31
+ export const Button = {
32
+ args: {
33
+ children: 'List item button',
34
+ },
35
+ argTypes: {
36
+ onItemSelected: { action: true },
37
+ },
38
+ };
39
+
40
+ /**
41
+ * Disabled button
42
+ */
43
+ export const ButtonDisabled = {
44
+ ...Button,
45
+ args: {
46
+ ...Button.args,
47
+ isDisabled: true,
48
+ },
49
+ };
50
+
51
+ /**
52
+ * Link list item (href)
53
+ */
54
+ export const Link = {
55
+ args: {
56
+ linkProps: { href: '#' },
57
+ children: 'List item link',
58
+ },
59
+ };
60
+
61
+ /**
62
+ * Disabled link
63
+ */
64
+ export const LinkDisabled = {
65
+ args: {
66
+ ...Link.args,
67
+ isDisabled: true,
68
+ },
69
+ };
70
+
71
+ /**
72
+ * Inject a custom link component
73
+ */
74
+ export const CustomLink_ = {
75
+ args: {
76
+ linkAs: CustomLink,
77
+ children: 'List item custom link',
78
+ },
79
+ };
80
+
81
+ /**
82
+ * Combination of size and states
83
+ */
84
+ export const SizeAndStates = {
85
+ ...Button,
86
+ decorators: [
87
+ withWrapper({}, List),
88
+ withCombinations({
89
+ combinations: {
90
+ rows: { key: 'size', options: sizes },
91
+ cols: {
92
+ Default: {},
93
+ Disabled: { isDisabled: true },
94
+ Selected: { isSelected: true },
95
+ Highlighted: { isHighlighted: true },
96
+ },
97
+ },
98
+ }),
99
+ ],
100
+ };
@@ -1,29 +1,24 @@
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';
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
6
4
 
5
+ import { render } from '@testing-library/react';
6
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
7
7
  import { ListItem, ListItemProps } from './ListItem';
8
- import * as stories from './ListItem.stories';
9
8
 
10
9
  const CLASSNAME = ListItem.className as string;
11
10
 
12
- /**
13
- * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
14
- */
15
- const setup = (props: Partial<ListItemProps> = {}, shallowRendering = true) => {
16
- const renderer: any = shallowRendering ? shallow : mount;
17
- const wrapper: any = renderer(<ListItem {...(props as any)} />);
18
- return { props, wrapper };
11
+ const setup = (props: Partial<ListItemProps> = {}) => {
12
+ render(<ListItem {...(props as any)} />);
13
+ const listItem = queryByClassName(document.body, CLASSNAME);
14
+ return { props, listItem };
19
15
  };
20
16
 
21
17
  describe(`<${ListItem.displayName}>`, () => {
22
- // 1. Test render via snapshot.
23
- describe('Snapshots and structure', () => {
24
- itShouldRenderStories(stories, ListItem);
25
- });
26
-
27
18
  // Common tests suite.
28
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: CLASSNAME });
19
+ commonTestsSuiteRTL(setup, {
20
+ baseClassName: CLASSNAME,
21
+ forwardClassName: 'listItem',
22
+ forwardAttributes: 'listItem',
23
+ });
29
24
  });
@@ -1,8 +1,11 @@
1
- import React from 'react';
2
-
3
1
  import { ListSubheader } from '@lumx/react';
4
- import { text } from '@storybook/addon-knobs';
5
2
 
6
- export default { title: 'LumX components/list/ListSubheader' };
3
+ export default {
4
+ title: 'LumX components/list/ListSubheader',
5
+ component: ListSubheader,
6
+ args: ListSubheader.defaultProps,
7
+ };
7
8
 
8
- export const Default = () => <ListSubheader>{text('text', 'Text')}</ListSubheader>;
9
+ export const Default = {
10
+ args: { children: 'List subheader text' },
11
+ };
@@ -1,29 +1,23 @@
1
1
  import React from 'react';
2
- import { commonTestsSuite, itShouldRenderStories } from '@lumx/react/testing/utils';
3
-
4
- import { mount, shallow } from 'enzyme';
5
- import 'jest-enzyme';
6
2
 
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { render } from '@testing-library/react';
5
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
7
6
  import { ListSubheader, ListSubheaderProps } from './ListSubheader';
8
- import * as stories from './ListSubheader.stories';
9
7
 
10
8
  const CLASSNAME = ListSubheader.className as string;
11
9
 
12
- /**
13
- * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
14
- */
15
- const setup = (props: Partial<ListSubheaderProps> = {}, shallowRendering = true) => {
16
- const renderer: any = shallowRendering ? shallow : mount;
17
- const wrapper: any = renderer(<ListSubheader {...(props as any)} />);
18
- return { props, wrapper };
10
+ const setup = (props: Partial<ListSubheaderProps> = {}) => {
11
+ render(<ListSubheader {...(props as any)} />);
12
+ const listSubheader = queryByClassName(document.body, CLASSNAME);
13
+ return { props, listSubheader };
19
14
  };
20
15
 
21
16
  describe(`<${ListSubheader.displayName}>`, () => {
22
- // 1. Test render via snapshot.
23
- describe('Snapshots and structure', () => {
24
- itShouldRenderStories(stories, ListSubheader);
25
- });
26
-
27
17
  // Common tests suite.
28
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: CLASSNAME });
18
+ commonTestsSuiteRTL(setup, {
19
+ baseClassName: CLASSNAME,
20
+ forwardClassName: 'listSubheader',
21
+ forwardAttributes: 'listSubheader',
22
+ });
29
23
  });
@@ -1,27 +1,56 @@
1
1
  import { Kind, Message } from '@lumx/react';
2
- import { boolean, text } from '@storybook/addon-knobs';
3
- import React from 'react';
4
- import { enumKnob } from '@lumx/react/stories/knobs/enumKnob';
5
2
  import { mdiDelete } from '@lumx/icons/';
3
+ import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
4
+ import { loremIpsum } from '@lumx/react/stories/utils/lorem';
5
+ import { iconArgType } from '@lumx/react/stories/controls/icons';
6
+ import { withCombinations } from '@lumx/react/stories/decorators/withCombinations';
7
+ import { withUndefined } from '@lumx/react/stories/controls/withUndefined';
6
8
 
7
- export default { title: 'LumX components/message/Message' };
9
+ export default {
10
+ title: 'LumX components/message/Message',
11
+ component: Message,
12
+ argTypes: {
13
+ kind: getSelectArgType(Kind),
14
+ hasBackground: { control: 'boolean' },
15
+ icon: iconArgType,
16
+ },
17
+ args: { ...Message.defaultProps, children: loremIpsum('tiny') },
18
+ };
8
19
 
9
- export const Default = () => (
10
- <Message
11
- kind={enumKnob('Kind of message', [undefined, ...Object.values(Kind)], undefined)}
12
- hasBackground={boolean('Has background', false)}
13
- >
14
- {text(
15
- 'Message',
16
- `Message text quisque tincidunt lobortis dui non auctor.Donec porta,
17
- ligula volutpat vehicula aliquet, dui sapien tempus felis, sed.`,
18
- )}
19
- </Message>
20
- );
20
+ /**
21
+ * Default message
22
+ */
23
+ export const Default = {};
21
24
 
22
- export const CustomIcon = () => (
23
- <Message icon={mdiDelete} kind="info" hasBackground>
24
- Lorem ipsum quisque tincidunt lobortis dui non auctor.Donec porta, ligula volutpat vehicula aliquet, dui sapien
25
- tempus felis, sed.
26
- </Message>
27
- );
25
+ /**
26
+ * All `kind` variants
27
+ */
28
+ export const AllKinds = {
29
+ ...Default,
30
+ decorators: [
31
+ withCombinations({
32
+ combinations: {
33
+ rows: { key: 'kind', options: withUndefined(Kind) },
34
+ },
35
+ }),
36
+ ],
37
+ };
38
+
39
+ /**
40
+ * All `kind` variants with `hasBackground`
41
+ */
42
+ export const AllKindsWithBackground = {
43
+ ...AllKinds,
44
+ args: {
45
+ hasBackground: true,
46
+ },
47
+ };
48
+
49
+ /**
50
+ * With custom icon
51
+ */
52
+ export const CustomIcon = {
53
+ args: {
54
+ icon: mdiDelete,
55
+ },
56
+ };