@lumx/react 3.1.5 → 3.2.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 (147) hide show
  1. package/_internal/types.d.ts +16 -5
  2. package/index.d.ts +45 -4
  3. package/index.js +632 -423
  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/Popover.tsx +7 -9
  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/select/SelectMultiple.stories.tsx +105 -2
  68. package/src/components/select/WithSelectContext.tsx +10 -4
  69. package/src/components/skeleton/SkeletonCircle.stories.tsx +37 -21
  70. package/src/components/skeleton/SkeletonCircle.test.tsx +12 -17
  71. package/src/components/skeleton/SkeletonRectangle.stories.tsx +74 -99
  72. package/src/components/skeleton/SkeletonRectangle.test.tsx +12 -17
  73. package/src/components/skeleton/SkeletonTypography.test.tsx +12 -17
  74. package/src/components/slider/Slider.stories.tsx +41 -25
  75. package/src/components/slider/Slider.test.tsx +12 -18
  76. package/src/components/slideshow/Slideshow.stories.tsx +31 -61
  77. package/src/components/slideshow/Slideshow.test.tsx +15 -23
  78. package/src/components/slideshow/SlideshowControls.stories.tsx +4 -6
  79. package/src/components/switch/Switch.stories.tsx +35 -32
  80. package/src/components/table/Table.test.tsx +12 -17
  81. package/src/components/tabs/Tabs.stories.tsx +4 -3
  82. package/src/components/text/Text.stories.tsx +130 -0
  83. package/src/components/text-field/TextField.stories.tsx +114 -148
  84. package/src/components/thumbnail/Thumbnail.stories.tsx +106 -255
  85. package/src/components/thumbnail/Thumbnail.test.tsx +12 -35
  86. package/src/components/tooltip/Tooltip.stories.tsx +51 -136
  87. package/src/components/user-block/UserBlock.stories.tsx +67 -56
  88. package/src/components/user-block/UserBlock.test.tsx +1 -5
  89. package/src/hooks/useFocusTrap.ts +2 -2
  90. package/src/index.ts +1 -0
  91. package/src/stories/controls/color.ts +6 -0
  92. package/src/stories/controls/element.ts +6 -0
  93. package/src/stories/controls/focusPoint.ts +1 -0
  94. package/src/stories/controls/icons.ts +6 -0
  95. package/src/stories/{knobs → controls}/image.ts +6 -16
  96. package/src/stories/controls/selectArgType.ts +4 -0
  97. package/src/stories/controls/theme.ts +3 -0
  98. package/src/stories/controls/typography.ts +5 -0
  99. package/src/stories/controls/withUndefined.ts +1 -0
  100. package/src/stories/decorators/withChromaticForceScreenSize.tsx +8 -0
  101. package/src/stories/decorators/withCombinations.tsx +99 -0
  102. package/src/stories/decorators/withNestedProps.tsx +23 -0
  103. package/src/stories/{withResizableBox.tsx → decorators/withResizableBox.tsx} +6 -10
  104. package/src/stories/decorators/withValueOnChange.tsx +18 -0
  105. package/src/stories/decorators/withWrapper.tsx +19 -0
  106. package/src/stories/utils/CustomLink.tsx +8 -2
  107. package/src/stories/{knobs → utils}/lorem.ts +9 -9
  108. package/src/testing/utils/commonTestsSuiteRTL.ts +2 -3
  109. package/src/testing/utils/index.ts +0 -2
  110. package/src/untypped-modules.d.ts +0 -2
  111. package/src/utils/MaterialThemeSwitcher/MaterialThemeSwitcher.tsx +1 -1
  112. package/src/utils/ThemeContext.ts +4 -0
  113. package/src/utils/forwardRefPolymorphic.ts +9 -0
  114. package/src/utils/type.ts +28 -4
  115. package/src/components/alert-dialog/__snapshots__/AlertDialog.test.tsx.snap +0 -558
  116. package/src/components/avatar/__snapshots__/Avatar.test.tsx.snap +0 -681
  117. package/src/components/comment-block/__snapshots__/CommentBlock.test.tsx.snap +0 -92
  118. package/src/components/dialog/__snapshots__/Dialog.test.tsx.snap +0 -1133
  119. package/src/components/expansion-panel/ExpansionPanel.stories.tsx +0 -65
  120. package/src/components/flag/__snapshots__/Flag.test.tsx.snap +0 -133
  121. package/src/components/flex-box/__snapshots__/FlexBox.test.tsx.snap +0 -492
  122. package/src/components/grid-column/GridColumn.stories.jsx +0 -56
  123. package/src/components/image-block/__snapshots__/ImageBlock.test.tsx.snap +0 -64
  124. package/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +0 -194
  125. package/src/components/list/__snapshots__/List.test.tsx.snap +0 -360
  126. package/src/components/list/__snapshots__/ListDivider.test.tsx.snap +0 -7
  127. package/src/components/list/__snapshots__/ListItem.test.tsx.snap +0 -160
  128. package/src/components/list/__snapshots__/ListSubheader.test.tsx.snap +0 -9
  129. package/src/components/mosaic/__snapshots__/Mosaic.test.tsx.snap +0 -357
  130. package/src/components/post-block/__snapshots__/PostBlock.test.tsx.snap +0 -139
  131. package/src/components/skeleton/__snapshots__/SkeletonCircle.test.tsx.snap +0 -54
  132. package/src/components/skeleton/__snapshots__/SkeletonRectangle.test.tsx.snap +0 -177
  133. package/src/components/skeleton/__snapshots__/SkeletonTypography.test.tsx.snap +0 -174
  134. package/src/components/slider/__snapshots__/Slider.test.tsx.snap +0 -122
  135. package/src/components/slideshow/__snapshots__/Slideshow.test.tsx.snap +0 -157
  136. package/src/components/table/__snapshots__/Table.test.tsx.snap +0 -263
  137. package/src/components/text/Text.stories.jsx +0 -75
  138. package/src/components/thumbnail/__snapshots__/Thumbnail.test.tsx.snap +0 -130
  139. package/src/components/user-block/__snapshots__/UserBlock.test.tsx.snap +0 -362
  140. package/src/stories/chromaticForceScreenSize.tsx +0 -7
  141. package/src/stories/knobs/buttonKnob.ts +0 -9
  142. package/src/stories/knobs/emphasisKnob.ts +0 -8
  143. package/src/stories/knobs/enumKnob.ts +0 -14
  144. package/src/stories/knobs/focusKnob.ts +0 -3
  145. package/src/stories/knobs/sizeKnob.ts +0 -5
  146. package/src/stories/knobs/thumbnailsKnob.ts +0 -9
  147. package/src/testing/utils/itShouldRenderStories.tsx +0 -103
@@ -1,36 +1,39 @@
1
- import { Switch, Alignment } from '@lumx/react';
2
- import { text } from '@storybook/addon-knobs';
3
- import noop from 'lodash/noop';
4
- import React from 'react';
1
+ import { Alignment, Switch, SwitchProps } from '@lumx/react';
2
+ import { withValueOnChange } from '@lumx/react/stories/decorators/withValueOnChange';
3
+ import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
5
4
 
6
- export default { title: 'LumX components/switch/Switch' };
5
+ export default {
6
+ title: 'LumX components/switch/Switch',
7
+ component: Switch,
8
+ args: {
9
+ ...Switch.defaultProps,
10
+ children: 'Switch label',
11
+ name: 'switch-html-name',
12
+ value: 'switch-html-value',
13
+ isChecked: false,
14
+ },
15
+ argTypes: {
16
+ position: getSelectArgType<SwitchProps['position']>([Alignment.left, Alignment.right]),
17
+ onChange: { action: true },
18
+ },
19
+ decorators: [withValueOnChange({ valueProp: 'isChecked' })],
20
+ };
7
21
 
8
- export const NotCheckedSwitch = ({ theme }: any) => (
9
- <Switch isChecked={false} onChange={noop} theme={theme}>
10
- {text('text', 'The switch')}
11
- </Switch>
12
- );
22
+ /**
23
+ * Default switch
24
+ */
25
+ export const Default = {};
13
26
 
14
- export const CheckedSwitch = ({ theme }: any) => (
15
- <Switch isChecked onChange={noop} theme={theme}>
16
- {text('text', 'The switch')}
17
- </Switch>
18
- );
27
+ /**
28
+ * Switch disabled
29
+ */
30
+ export const Disabled = {
31
+ args: { isDisabled: true },
32
+ };
19
33
 
20
- export const DisabledCheckedSwitch = ({ theme }: any) => (
21
- <Switch isChecked isDisabled onChange={noop} theme={theme}>
22
- {text('text', 'The switch')}
23
- </Switch>
24
- );
25
-
26
- export const DisabledSwitch = ({ theme }: any) => (
27
- <Switch isDisabled onChange={noop} theme={theme}>
28
- {text('text', 'The switch')}
29
- </Switch>
30
- );
31
-
32
- export const RightPositionSwitch = ({ theme }: any) => (
33
- <Switch position={Alignment.right} onChange={noop} theme={theme}>
34
- {text('text', 'The switch')}
35
- </Switch>
36
- );
34
+ /**
35
+ * Switch positioned to the right
36
+ */
37
+ export const PositionRight = {
38
+ args: { position: Alignment.right },
39
+ };
@@ -1,28 +1,23 @@
1
1
  import React from 'react';
2
- import { mount, shallow } from 'enzyme';
3
- import 'jest-enzyme';
4
- import { commonTestsSuite, itShouldRenderStories } from '@lumx/react/testing/utils';
5
2
 
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
5
+ import { render } from '@testing-library/react';
6
6
  import { Table, TableProps } from './Table';
7
- import * as stories from '../../stories/generated/Table/Demos.stories';
8
7
 
9
8
  const CLASSNAME = Table.className as string;
10
9
 
11
- /**
12
- * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
13
- */
14
- const setup = (props: Partial<TableProps> = {}, shallowRendering = true) => {
15
- const renderer: any = shallowRendering ? shallow : mount;
16
- const wrapper: any = renderer(<Table {...(props as any)} />);
17
- return { props, wrapper };
10
+ const setup = (props: Partial<TableProps> = {}) => {
11
+ render(<Table {...(props as any)} />);
12
+ const table = queryByClassName(document.body, CLASSNAME);
13
+ return { props, table };
18
14
  };
19
15
 
20
16
  describe(`<${Table.displayName}>`, () => {
21
- // 1. Test render via snapshot.
22
- describe('Snapshots and structure', () => {
23
- itShouldRenderStories(stories, Table);
24
- });
25
-
26
17
  // Common tests suite.
27
- commonTestsSuite(setup, { className: 'wrapper', prop: 'wrapper' }, { className: CLASSNAME });
18
+ commonTestsSuiteRTL(setup, {
19
+ baseClassName: CLASSNAME,
20
+ forwardClassName: 'table',
21
+ forwardAttributes: 'table',
22
+ });
28
23
  });
@@ -1,5 +1,4 @@
1
1
  import { Button, Dialog, Tab, TabList, TabPanel, TabProvider } from '@lumx/react';
2
- import { number } from '@storybook/addon-knobs';
3
2
  import get from 'lodash/get';
4
3
  import times from 'lodash/times';
5
4
  import React, { useState } from 'react';
@@ -114,8 +113,7 @@ export const SplitTabListAndTabPanels = ({ theme }: any) => {
114
113
  };
115
114
 
116
115
  /* Dynamically generate tabs. */
117
- export const DynamicTabs = ({ theme }: any) => {
118
- const tabCount = number('Tab count', 3);
116
+ export const DynamicTabs = ({ theme, tabCount }: any) => {
119
117
  return (
120
118
  <TabProvider>
121
119
  <TabList theme={theme} aria-label="Tab list">
@@ -132,3 +130,6 @@ export const DynamicTabs = ({ theme }: any) => {
132
130
  </TabProvider>
133
131
  );
134
132
  };
133
+ DynamicTabs.args = {
134
+ tabCount: 3,
135
+ };
@@ -0,0 +1,130 @@
1
+ import { ALL_TYPOGRAPHY, allTypographyArgType } from '@lumx/react/stories/controls/typography';
2
+ import React from 'react';
3
+
4
+ import { colorArgType, colorVariantArgType } from '@lumx/react/stories/controls/color';
5
+ import { textElementArgType } from '@lumx/react/stories/controls/element';
6
+ import { withUndefined } from '@lumx/react/stories/controls/withUndefined';
7
+ import { loremIpsum } from '@lumx/react/stories/utils/lorem';
8
+ import { withCombinations } from '@lumx/react/stories/decorators/withCombinations';
9
+ import { ColorPalette, ColorVariant, Icon } from '@lumx/react';
10
+ import { mdiEarth, mdiHeart } from '@lumx/icons';
11
+ import { withResizableBox } from '@lumx/react/stories/decorators/withResizableBox';
12
+
13
+ import { Text } from './Text';
14
+
15
+ export default {
16
+ title: 'LumX components/text/Text',
17
+ component: Text,
18
+ args: Text.defaultProps,
19
+ argTypes: {
20
+ children: { control: false },
21
+ as: textElementArgType,
22
+ typography: allTypographyArgType,
23
+ color: colorArgType,
24
+ colorVariant: colorVariantArgType,
25
+ },
26
+ };
27
+
28
+ /**
29
+ * Default text component as a paragraph
30
+ */
31
+ export const Default = {
32
+ args: {
33
+ as: 'p',
34
+ children: 'Some text',
35
+ },
36
+ };
37
+
38
+ /**
39
+ * Text containing icons (should match font size)
40
+ */
41
+ export const WithIcon = {
42
+ args: {
43
+ ...Default.args,
44
+ children: (
45
+ <>
46
+ Some text <Icon icon={mdiHeart} /> with icons <Icon icon={mdiEarth} />
47
+ </>
48
+ ),
49
+ },
50
+ };
51
+
52
+ /**
53
+ * Long text should wrap by default
54
+ */
55
+ export const LongText = {
56
+ args: {
57
+ ...Default.args,
58
+ children: loremIpsum('tiny'),
59
+ },
60
+ decorators: [withResizableBox()],
61
+ };
62
+
63
+ /**
64
+ * Long text without wrapping
65
+ */
66
+ export const NoWrap = {
67
+ ...LongText,
68
+ args: {
69
+ ...LongText.args,
70
+ noWrap: true,
71
+ },
72
+ };
73
+
74
+ /**
75
+ * Long text with single line truncate ellipsis
76
+ */
77
+ export const Truncate = {
78
+ ...LongText,
79
+ args: {
80
+ ...LongText.args,
81
+ truncate: true,
82
+ },
83
+ };
84
+
85
+ /**
86
+ * Long text with multi line truncate ellipsis
87
+ */
88
+ export const TruncateMultiline = {
89
+ ...LongText,
90
+ args: {
91
+ ...LongText.args,
92
+ truncate: { lines: 2 },
93
+ },
94
+ };
95
+
96
+ /**
97
+ * All typographies
98
+ */
99
+ export const AllTypography = {
100
+ ...WithIcon,
101
+ argTypes: {
102
+ typography: { control: false },
103
+ },
104
+ decorators: [
105
+ withCombinations({
106
+ combinations: {
107
+ rows: { key: 'typography', options: withUndefined(ALL_TYPOGRAPHY) },
108
+ },
109
+ }),
110
+ ],
111
+ };
112
+
113
+ /**
114
+ * All combinations of color and color variants
115
+ */
116
+ export const AllColors = {
117
+ ...WithIcon,
118
+ argTypes: {
119
+ color: { control: false },
120
+ colorVariant: { control: false },
121
+ },
122
+ decorators: [
123
+ withCombinations({
124
+ combinations: {
125
+ rows: { key: 'color', options: withUndefined(ColorPalette) },
126
+ cols: { key: 'colorVariant', options: withUndefined(ColorVariant) },
127
+ },
128
+ }),
129
+ ],
130
+ };
@@ -1,169 +1,135 @@
1
1
  import React from 'react';
2
2
  import { mdiTranslate } from '@lumx/icons/';
3
- import { Emphasis, IconButton, Size, TextField } from '@lumx/react';
4
- import { boolean, number, text } from '@storybook/addon-knobs';
5
- import { buttonSize } from '@lumx/react/stories/knobs/buttonKnob';
6
- import { emphasis } from '@lumx/react/stories/knobs/emphasisKnob';
3
+ import { Chip, IconButton, TextField } from '@lumx/react';
4
+ import { withValueOnChange } from '@lumx/react/stories/decorators/withValueOnChange';
5
+ import { loremIpsum } from '@lumx/react/stories/utils/lorem';
7
6
 
8
- export default { title: 'LumX components/text-field/TextField' };
7
+ export default {
8
+ title: 'LumX components/text-field/TextField',
9
+ component: TextField,
10
+ args: TextField.defaultProps,
11
+ argTypes: {
12
+ clearButtonProps: { control: false },
13
+ chips: { control: false },
14
+ afterElement: { control: false },
15
+ },
16
+ decorators: [withValueOnChange({})],
17
+ };
18
+
19
+ /**
20
+ * Default text field
21
+ */
22
+ export const Default = {
23
+ args: {
24
+ value: '',
25
+ },
26
+ };
27
+
28
+ /**
29
+ * With placeholder
30
+ */
31
+ export const Placeholder = {
32
+ args: {
33
+ value: '',
34
+ placeholder: 'Texfield placeholder',
35
+ },
36
+ };
9
37
 
10
- export const TextField_ = ({ theme }: any) => {
11
- const [value, onChange] = React.useState('Value');
12
- return (
13
- <TextField
14
- value={value}
15
- onChange={onChange}
16
- label={text('Label', 'Label')}
17
- placeholder={text('Placeholder', 'Placeholder')}
18
- theme={theme}
19
- />
20
- );
38
+ /**
39
+ * With label and helper
40
+ */
41
+ export const LabelAndHelper = {
42
+ args: {
43
+ ...Default.args,
44
+ label: 'Textfield label',
45
+ helper: loremIpsum('tiny'),
46
+ },
21
47
  };
22
48
 
23
- export const Clearable = ({ theme }: any) => {
24
- const [value, onChange] = React.useState('Value');
25
- return (
26
- <TextField
27
- value={value}
28
- onChange={onChange}
29
- label={text('Label', 'Label')}
30
- clearButtonProps={{ label: 'Clear' }}
31
- theme={theme}
32
- />
33
- );
49
+ /**
50
+ * With clear button
51
+ */
52
+ export const Clearable = {
53
+ args: {
54
+ value: 'Some value',
55
+ clearButtonProps: { label: 'Clear' },
56
+ },
34
57
  };
35
58
 
36
- export const States = ({ theme }: any) => {
37
- const [value1, onChange1] = React.useState('Value');
38
- const [value2, onChange2] = React.useState('Value');
39
- return (
40
- <>
41
- <TextField
42
- label="Has error"
43
- hasError
44
- error="Error message"
45
- theme={theme}
46
- value={value1}
47
- onChange={onChange1}
48
- />
49
- <TextField label="Is valid" isValid theme={theme} value={value2} onChange={onChange2} />
50
- </>
51
- );
59
+ /**
60
+ * As number field
61
+ */
62
+ export const NumberField = {
63
+ args: {
64
+ value: '0',
65
+ type: 'number',
66
+ },
52
67
  };
53
68
 
54
- export const NumberField = ({ theme }: any) => {
55
- const [value, onChange] = React.useState('0');
56
- return <TextField value={value} onChange={onChange} label={text('Label', 'Label')} theme={theme} type="number" />;
69
+ /**
70
+ * Multiline textarea
71
+ */
72
+ export const TextareaField = {
73
+ args: {
74
+ value: loremIpsum('tiny'),
75
+ multiline: true,
76
+ minimumRows: 2,
77
+ },
57
78
  };
58
79
 
59
- export const WithHelper = ({ theme }: any) => {
60
- const [value, onChange] = React.useState('Value');
61
- return (
62
- <TextField
63
- value={value}
64
- onChange={onChange}
65
- label={text('Label', 'Label')}
66
- placeholder={text('Placeholder', 'Placeholder')}
67
- theme={theme}
68
- helper={<span>{text('Helper', 'Helper')}</span>}
69
- />
70
- );
80
+ /**
81
+ * Error state
82
+ */
83
+ export const Error = {
84
+ args: {
85
+ ...LabelAndHelper.args,
86
+ hasError: true,
87
+ error: 'Error message',
88
+ },
71
89
  };
72
90
 
73
- export const TextArea = ({ theme }: any) => {
74
- const [value, setValue] = React.useState('Value');
75
- return (
76
- <TextField
77
- value={value}
78
- label={text('Label', 'Label')}
79
- placeholder={text('Placeholder', 'Placeholder')}
80
- multiline
81
- minimumRows={number('Minimum number of rows', 1, { min: 0, max: 100 })}
82
- theme={theme}
83
- onChange={setValue}
84
- helper={<span>{text('Helper', 'Helper')}</span>}
85
- />
86
- );
91
+ /**
92
+ * Valid state
93
+ */
94
+ export const Valid = {
95
+ args: {
96
+ ...LabelAndHelper.args,
97
+ isValid: true,
98
+ },
87
99
  };
88
100
 
89
- export const TextAreaWithManyLines = ({ theme }: any) => {
90
- const myvalue = `I
91
- am
92
- a
93
- multiline
94
- text`;
95
- const [value, setValue] = React.useState(myvalue);
96
- return (
97
- <TextField
98
- value={value}
99
- label={text('Label', 'Label')}
100
- placeholder={text('Placeholder', 'Placeholder')}
101
- multiline
102
- minimumRows={number('Minimum number of rows', 2, { min: 0, max: 100 })}
103
- theme={theme}
104
- onChange={setValue}
105
- helper={<span>{text('Helper', 'Helper')}</span>}
106
- />
107
- );
101
+ /**
102
+ * Max length with character counter
103
+ */
104
+ export const MaxLength = {
105
+ args: {
106
+ ...LabelAndHelper.args,
107
+ value: 'Textfield value',
108
+ maxLength: 195,
109
+ },
108
110
  };
109
111
 
110
- export const WithAfterElement = ({ theme }: any) => {
111
- const [value, onChange] = React.useState('Value');
112
- const multiline = boolean('Multiline', true);
113
- const minimumRows = number('Minimum number of rows', 2, { min: 0, max: 100 });
114
- const isClearable = boolean('Clearable', true);
115
- const hasError = boolean('Has error', true);
116
- return (
117
- <TextField
118
- value={value}
119
- label={text('Label', 'Label')}
120
- placeholder={text('Placeholder', 'Placeholder')}
121
- theme={theme}
122
- onChange={onChange}
123
- multiline={multiline}
124
- minimumRows={minimumRows}
125
- hasError={hasError}
126
- maxLength={200}
127
- clearButtonProps={isClearable ? { label: 'Clear' } : undefined}
128
- helper={<span>{text('Helper', 'Helper')}</span>}
129
- afterElement={
130
- <IconButton
131
- label="foo"
132
- emphasis={emphasis('Button emphasis', Emphasis.medium, 'After element')}
133
- size={buttonSize('Button size', Size.s, 'After element')}
134
- icon={mdiTranslate}
135
- />
136
- }
137
- />
138
- );
112
+ /**
113
+ * Custom element at the end
114
+ */
115
+ export const WithAfterElement = {
116
+ args: {
117
+ value: '',
118
+ afterElement: <IconButton label="translate" emphasis="medium" size="s" icon={mdiTranslate} />,
119
+ },
139
120
  };
140
121
 
141
- export const WithMaxLengthNoLabel = ({ theme }: any) => {
142
- const [value, onChange] = React.useState('Value');
143
- const multiline = boolean('Multiline', true);
144
- const minimumRows = number('Minimum number of rows', 2, { min: 0, max: 100 });
145
- const isClearable = boolean('Clearable', true);
146
- const hasError = boolean('Has error', true);
147
- return (
148
- <TextField
149
- value={value}
150
- placeholder={text('Placeholder', 'Placeholder')}
151
- theme={theme}
152
- onChange={onChange}
153
- multiline={multiline}
154
- minimumRows={minimumRows}
155
- hasError={hasError}
156
- maxLength={200}
157
- clearButtonProps={isClearable ? { label: 'Clear' } : undefined}
158
- helper={<span>{text('Helper', 'Helper')}</span>}
159
- afterElement={
160
- <IconButton
161
- label="foo"
162
- emphasis={emphasis('Button emphasis', Emphasis.medium, 'After element')}
163
- size={buttonSize('Button size', Size.s, 'After element')}
164
- icon={mdiTranslate}
165
- />
166
- }
167
- />
168
- );
122
+ /**
123
+ * Chips at the start
124
+ */
125
+ export const WithChips = {
126
+ args: {
127
+ value: '',
128
+ chips: (
129
+ <>
130
+ <Chip size="s">Chip 1</Chip>
131
+ <Chip size="s">Chip 2</Chip>
132
+ </>
133
+ ),
134
+ },
169
135
  };