@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,15 +1,38 @@
1
1
  import React from 'react';
2
2
 
3
- import { text } from '@storybook/addon-knobs';
4
-
5
3
  import { InputLabel } from './InputLabel';
6
4
 
7
- export default { title: 'LumX components/input-label/Input Label' };
5
+ export default {
6
+ title: 'LumX components/input-label/Input Label',
7
+ component: InputLabel,
8
+ args: {
9
+ ...InputLabel.defaultProps,
10
+ children: 'Label text',
11
+ },
12
+ argTypes: {
13
+ isRequired: { control: 'boolean' },
14
+ },
15
+ decorators: [
16
+ /**
17
+ * Associate label with an input
18
+ */
19
+ (Story: any, ctx: any) => (
20
+ <>
21
+ <input type="hidden" id="123" />
22
+ <Story args={{ ...ctx.args, htmlFor: '123' }} />
23
+ </>
24
+ ),
25
+ ],
26
+ };
27
+
28
+ /**
29
+ * Default input label
30
+ */
31
+ export const Default = {};
8
32
 
9
- export const SimpleLabel = ({ theme }: any) => (
10
- <div id="123">
11
- <InputLabel htmlFor="123" theme={theme}>
12
- {text('Label', 'The label')}
13
- </InputLabel>
14
- </div>
15
- );
33
+ /**
34
+ * Required input label
35
+ */
36
+ export const IsRequired = {
37
+ args: { isRequired: true },
38
+ };
@@ -1,83 +1,45 @@
1
+ /* eslint-disable react-hooks/rules-of-hooks,react/display-name */
1
2
  import React from 'react';
2
- import {
3
- ImageBlock,
4
- Slideshow,
5
- SlideshowItem,
6
- Toolbar,
7
- Divider,
8
- Alignment,
9
- TextField,
10
- Typography,
11
- Link,
12
- Lightbox,
13
- ThumbnailProps,
14
- } from '@lumx/react';
15
- import { thumbnailsKnob } from '@lumx/react/stories/knobs/thumbnailsKnob';
3
+ import { ImageBlock, Alignment, Lightbox, Button } from '@lumx/react';
4
+ import { useBooleanState } from '@lumx/react/hooks/useBooleanState';
5
+ import { LANDSCAPE_IMAGES } from '@lumx/react/stories/controls/image';
16
6
 
17
- export default { title: 'LumX components/lightbox/Lightbox' };
18
-
19
- interface RowItemProps {
20
- image: ThumbnailProps;
21
- }
22
-
23
- const RowItem: React.FC<RowItemProps> = ({ image }) => {
24
- const [isOpen, setOpen] = React.useState(false);
25
- const { image: url, alt: name } = image;
26
- const linkRef = React.useRef(null);
27
-
28
- return (
29
- <>
30
- <Toolbar
31
- label={
32
- // eslint-disable-next-line jsx-a11y/anchor-is-valid
33
- <Link ref={linkRef} typography={Typography.subtitle1} onClick={() => setOpen(true)}>
34
- {name}
35
- </Link>
36
- }
37
- />
38
- <Lightbox
39
- closeButtonProps={{ label: 'Close' }}
40
- isOpen={isOpen}
41
- onClose={() => setOpen(false)}
42
- parentElement={linkRef}
43
- >
44
- <Slideshow
45
- activeIndex={0}
46
- fillHeight
47
- slideshowControlsProps={{
48
- nextButtonProps: { label: 'Next' },
49
- previousButtonProps: { label: 'Previous' },
50
- }}
51
- >
52
- <SlideshowItem key={name}>
53
- <ImageBlock align={Alignment.center} alt={name} fillHeight image={url} />
54
- </SlideshowItem>
55
- </Slideshow>
56
- </Lightbox>
57
- </>
58
- );
7
+ export default {
8
+ title: 'LumX components/lightbox/Lightbox',
9
+ component: Lightbox,
10
+ args: Lightbox.defaultProps,
11
+ argTypes: {
12
+ children: { control: false },
13
+ },
14
+ render: (props: any) => {
15
+ const buttonRef = React.useRef<HTMLButtonElement>(null);
16
+ const [isOpen, close, open] = useBooleanState(true);
17
+ return (
18
+ <>
19
+ <Button ref={buttonRef} onClick={open}>
20
+ Open lightbox
21
+ </Button>
22
+ <Lightbox {...props} parentElement={buttonRef} isOpen={isOpen} onClose={close} />
23
+ </>
24
+ );
25
+ },
59
26
  };
60
27
 
61
- export const Focus = () => {
62
- const [textFieldValue, setTextFieldValue] = React.useState('');
63
- const images: ThumbnailProps[] = thumbnailsKnob(12);
28
+ /**
29
+ * Base LightBox with image block
30
+ */
31
+ export const ImageBlock_ = {
32
+ args: {
33
+ children: <ImageBlock align={Alignment.center} alt="" fillHeight image={LANDSCAPE_IMAGES.landscape1} />,
34
+ },
35
+ };
64
36
 
65
- return (
66
- <>
67
- <TextField
68
- value={textFieldValue}
69
- onChange={setTextFieldValue}
70
- className="lumx-spacing-margin-vertical-big"
71
- />
72
- {images.map((image, index) => {
73
- const itemPosition = index + 1;
74
- return (
75
- <div key={itemPosition}>
76
- <RowItem image={image} />
77
- <Divider />
78
- </div>
79
- );
80
- })}
81
- </>
82
- );
37
+ /**
38
+ * LightBox with image block and close button
39
+ */
40
+ export const WithCloseButton = {
41
+ args: {
42
+ ...ImageBlock_.args,
43
+ closeButtonProps: { label: 'Close' },
44
+ },
83
45
  };
@@ -1,30 +1,25 @@
1
1
  import React from 'react';
2
- import { mount, shallow } from 'enzyme';
3
2
  import 'jest-enzyme';
4
- import { commonTestsSuite, itShouldRenderStories } from '@lumx/react/testing/utils';
3
+ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
5
4
 
5
+ import { queryByClassName } from '@lumx/react/testing/utils/queries';
6
+ import { render } from '@testing-library/react';
6
7
  import { Lightbox, LightboxProps } from './Lightbox';
7
- import * as stories from '../../stories/generated/Lightbox/Demos.stories';
8
8
 
9
9
  const CLASSNAME = Lightbox.className as string;
10
10
 
11
- /**
12
- * Mounts the component and returns common DOM elements / data needed in multiple tests further down.
13
- */
14
- const setup = (props: Partial<LightboxProps> = {}, shallowRendering = true) => {
15
- const renderer: any = shallowRendering ? shallow : mount;
11
+ const setup = (props: Partial<LightboxProps> = {}) => {
16
12
  const propsOverride = { isOpen: true, ...props } as any;
17
- const wrapper: any = renderer(<Lightbox {...propsOverride} />);
18
- const lightbox = wrapper.find(`.${CLASSNAME}`);
19
- return { props, wrapper, lightbox };
13
+ const { container } = render(<Lightbox {...propsOverride} />);
14
+ const lightbox = queryByClassName(document.body, CLASSNAME);
15
+ return { props, container, lightbox };
20
16
  };
21
17
 
22
18
  describe(`<${Lightbox.displayName}>`, () => {
23
- // 1. Test render via snapshot.
24
- describe('Snapshots and structure', () => {
25
- itShouldRenderStories(stories, Lightbox, { props: { defaultIsOpen: true } });
26
- });
27
-
28
19
  // Common tests suite.
29
- commonTestsSuite(setup, { className: 'lightbox', prop: 'lightbox' }, { className: CLASSNAME });
20
+ commonTestsSuiteRTL(setup, {
21
+ baseClassName: CLASSNAME,
22
+ forwardClassName: 'lightbox',
23
+ forwardAttributes: 'lightbox',
24
+ });
30
25
  });
@@ -1,141 +1,111 @@
1
- /* eslint-disable jsx-a11y/anchor-is-valid */
2
- import { mdiChevronDown, mdiLink } from '@lumx/icons';
3
- import {
4
- ColorPalette,
5
- ColorVariant,
6
- Link,
7
- Typography,
8
- TypographyCustom,
9
- TypographyInterface,
10
- TypographyTitleCustom,
11
- } from '@lumx/react';
12
- import { boolean, select, text } from '@storybook/addon-knobs';
13
- import React, { Fragment } from 'react';
14
-
15
- export default { title: 'LumX components/link/Link' };
16
-
17
- const onClick = () => console.log('clicked link');
1
+ import { ColorPalette, ColorVariant, Link, Typography, TypographyInterface, TypographyTitleCustom } from '@lumx/react';
2
+ import React from 'react';
3
+ import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
4
+ import { colorArgType, colorVariantArgType } from '@lumx/react/stories/controls/color';
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';
8
+ import { CustomLink } from '@lumx/react/stories/utils/CustomLink';
18
9
 
19
10
  const linkTypographies = { ...TypographyInterface, ...TypographyTitleCustom };
20
11
 
21
- export const SimpleLink = () => (
22
- <>
23
- <Link
24
- href={text('href', 'https://example.com', 'Link 1')}
25
- target={boolean('target: _blank', false, 'Link 1') ? '_blank' : ''}
26
- color={select('Color', ColorPalette, ColorPalette.blue, 'Link 1')}
27
- colorVariant={select('Color Variant', ColorVariant, ColorVariant.N, 'Link 1')}
28
- typography={select('Typography', linkTypographies, Typography.body2, 'Link 1')}
29
- >
30
- {text('Value', 'Here is a first link', 'Link 1')}
31
- </Link>
32
- <br />
33
- <Link
34
- href={text('href', 'https://google.fr', 'Link 2')}
35
- target={boolean('target: _blank', false, 'Link 2') ? '_blank' : ''}
36
- color={select('Color', ColorPalette, ColorPalette.blue, 'Link 2')}
37
- colorVariant={select('Color Variant', ColorVariant, ColorVariant.N, 'Link 2')}
38
- typography={select('Typography', linkTypographies, Typography.body1, 'Link 2')}
39
- >
40
- {text('Value', 'Here is a second link', 'Link 2')}
41
- </Link>
42
- <br />
43
- <Link
44
- href={text('href', 'https://google.co.jp', 'Link 3')}
45
- target={boolean('target: _blank', false, 'Link 3') ? '_blank' : ''}
46
- color={select('Color', ColorPalette, ColorPalette.blue, 'Link 3')}
47
- colorVariant={select('Color Variant', ColorVariant, ColorVariant.N, 'Link 3')}
48
- typography={select('Typography', linkTypographies, Typography.caption, 'Link 3')}
49
- >
50
- {text('Value', 'Here is a third link', 'Link 3')}
51
- </Link>
52
- </>
53
- );
12
+ export default {
13
+ title: 'LumX components/link/Link',
14
+ component: Link,
15
+ argTypes: {
16
+ typography: getSelectArgType(linkTypographies),
17
+ color: colorArgType,
18
+ colorVariant: colorVariantArgType,
19
+ rightIcon: iconArgType,
20
+ leftIcon: iconArgType,
21
+ },
22
+ args: { ...Link.defaultProps, children: 'Link' },
23
+ };
54
24
 
55
- export const WithoutHref = () => (
56
- // The constrained width should show that the button does not have centered text align.
57
- <div style={{ border: '1px solid red', width: 100, height: 100, resize: 'both', overflow: 'auto' }}>
58
- <Link onClick={onClick}>Link without href (renders as a button for a11y)</Link>
59
- </div>
60
- );
25
+ /**
26
+ * Default link
27
+ */
28
+ export const Default = {
29
+ args: { href: 'https://example.com', target: '_blank' },
30
+ };
61
31
 
62
- export const WithCustomLink = () => {
63
- const CustomLink: React.FC = ({ children, ...props }) =>
64
- React.createElement('a', { ...props, style: { color: 'red' } }, children);
32
+ /**
33
+ * Disabled
34
+ */
35
+ export const Disabled = {
36
+ args: { ...Default.args, children: 'Link (disabled)', isDisabled: true },
37
+ };
65
38
 
66
- return (
67
- <Link linkAs={CustomLink} href="https://example.com">
68
- Custom link
69
- </Link>
70
- );
39
+ /**
40
+ * Using onClick transforms the link into a <button> in DOM
41
+ */
42
+ export const ButtonLink = {
43
+ argTypes: { onClick: { action: true } },
44
+ args: { children: 'Button link' },
71
45
  };
72
46
 
73
- export const DisabledLink = () => (
74
- // eslint-disable-next-line jsx-a11y/anchor-is-valid
75
- <Link onClick={onClick} disabled>
76
- Disabled link
77
- </Link>
78
- );
47
+ /**
48
+ * Button link disabled
49
+ */
50
+ export const ButtonLinkDisabled = {
51
+ args: { ...ButtonLink.args, children: 'Button link (disabled)', isDisabled: true },
52
+ };
79
53
 
80
- export const WithCustomizableTypography = () => (
81
- <>
82
- <style>{`
83
- :root {
84
- --lumx-typography-custom-title1-font-size: 5px;
85
- }
86
- `}</style>
87
- <Link typography={Typography.custom.title1} href="https://example.com">
88
- Link with customizable `body` typography
89
- </Link>
90
- </>
91
- );
54
+ /**
55
+ * Use custom component instead of <a> or <button>
56
+ */
57
+ export const LinkAs = {
58
+ args: { linkAs: CustomLink },
59
+ };
92
60
 
93
- export const AllTypography = () => {
94
- const typographies = [undefined, ...Object.values(TypographyInterface), ...Object.values(TypographyCustom)];
95
- return (
96
- <table>
97
- {typographies.map((typography) => (
98
- <tr key={typography}>
99
- <td>{typography}</td>
100
- <td>
101
- <Link
102
- leftIcon={mdiChevronDown}
103
- rightIcon={mdiLink}
104
- typography={typography}
105
- href="https://example.com"
106
- >
107
- Link text
108
- </Link>
109
- </td>
110
- </tr>
111
- ))}
112
- </table>
113
- );
61
+ /**
62
+ * Use a custom typography and customize it via CSS variable
63
+ */
64
+ export const WithCustomizableTypography = {
65
+ typography: Typography.custom.title1,
66
+ // eslint-disable-next-line react/display-name
67
+ render: (props: any) => (
68
+ // Injecting CSS variable to customize the font size
69
+ <>
70
+ <style>{`
71
+ :root {
72
+ --lumx-typography-custom-title1-font-size: 5px;
73
+ }
74
+ `}</style>
75
+ <Link {...props} />
76
+ </>
77
+ ),
78
+ };
79
+ /**
80
+ * Show all typographies
81
+ */
82
+ export const AllTypography = {
83
+ argTypes: {
84
+ typography: { control: false },
85
+ },
86
+ decorators: [
87
+ withCombinations({
88
+ combinations: {
89
+ rows: { key: 'typography', options: withUndefined(linkTypographies) },
90
+ },
91
+ }),
92
+ ],
114
93
  };
115
94
 
116
- export const AllColor = () => {
117
- const colorVariants = [undefined, ...Object.values(ColorVariant)];
118
- const colors = [undefined, ...Object.values(ColorPalette)];
119
- return (
120
- <table style={{ borderCollapse: 'separate', borderSpacing: 5 }}>
121
- <tr>
122
- <td />
123
- {colorVariants.map((colorVariant) => (
124
- <td key={colorVariant}>{colorVariant}</td>
125
- ))}
126
- </tr>
127
- {colors.map((color) => (
128
- <tr key={color}>
129
- <td>{color}</td>
130
- {colorVariants.map((colorVariant) => (
131
- <td key={colorVariant}>
132
- <Link href="https://example.com" color={color} colorVariant={colorVariant}>
133
- Some text
134
- </Link>
135
- </td>
136
- ))}
137
- </tr>
138
- ))}
139
- </table>
140
- );
95
+ /**
96
+ * Show all color combinations
97
+ */
98
+ export const AllColors = {
99
+ argTypes: {
100
+ color: { control: false },
101
+ colorVariant: { control: false },
102
+ },
103
+ decorators: [
104
+ withCombinations({
105
+ combinations: {
106
+ rows: { key: 'color', options: withUndefined(ColorPalette) },
107
+ cols: { key: 'colorVariant', options: withUndefined(ColorVariant) },
108
+ },
109
+ }),
110
+ ],
141
111
  };
@@ -1,88 +1,61 @@
1
- /* istanbul ignore file */
2
- import { landscapeImageKnob, portraitImageKnob } from '@lumx/react/stories/knobs/image';
3
- import { text } from '@storybook/addon-knobs';
4
- import React from 'react';
5
- import { Size } from '..';
6
- import { LinkPreview } from './LinkPreview';
7
-
8
- export default { title: 'LumX components/link-preview/Link preview' };
9
-
10
- const LONG_LOREM_IPSUM = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ut quam sollicitudin, viverra quam eget, pretium tellus. Praesent sit amet augue in odio varius accumsan vitae quis nunc. Aliquam iaculis neque at augue laoreet, eu sagittis dolor tempus. Nullam sit amet bibendum velit, in pharetra lorem. Aliquam semper accumsan placerat. Sed felis risus, efficitur non eros non, rhoncus viverra lectus. Aliquam eget interdum tellus. Praesent non ex ut urna tempus facilisis. Sed tellus tortor, pharetra vel velit sit amet, aliquet condimentum quam. Sed dictum nibh eget nibh ullamcorper dignissim. Vestibulum elementum at mauris sit amet iaculis. Maecenas pretium luctus enim vel commodo. Cras accumsan sagittis eros, vel maximus sem molestie id. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
11
-
12
- Mauris ultrices pellentesque vestibulum. Etiam vel turpis at eros condimentum feugiat nec sit amet diam. Fusce pellentesque vulputate est sed ultrices. Etiam arcu tellus, dignissim non dui mattis, suscipit pellentesque erat. Aliquam congue magna nec varius suscipit. Sed mattis fringilla viverra. Donec pulvinar ex ac augue feugiat, a vulputate mauris suscipit. Morbi eget lorem purus. In pretium ligula non ex auctor, ornare dignissim orci dictum. Nulla ornare, risus non tincidunt blandit, massa massa mollis velit, id vulputate mi ligula ut metus. Vestibulum mattis tincidunt lorem, ac commodo felis ultricies interdum. Proin fermentum eu nibh a suscipit. Morbi eu pretium sapien. Pellentesque pretium purus eros, eget feugiat nisl dapibus at.`;
13
-
14
- /**
15
- * LinkPreview story
16
- * @return regular LinkPreview.
17
- */
18
- export const RegularLinkPreview = ({ theme }: any) => (
19
- <LinkPreview
20
- title={text('Title', 'Link title')}
21
- description={text('Description', LONG_LOREM_IPSUM)}
22
- link={text('URL', 'https://google.com')}
23
- theme={theme}
24
- thumbnailProps={{ image: portraitImageKnob(), alt: 'Portrait' }}
25
- />
26
- );
1
+ import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
2
+ import { headingElementArgType } from '@lumx/react/stories/controls/element';
3
+ import { loremIpsum } from '@lumx/react/stories/utils/lorem';
4
+ import { LANDSCAPE_IMAGES } from '@lumx/react/stories/controls/image';
5
+ import { withNestedProps } from '@lumx/react/stories/decorators/withNestedProps';
6
+ import { withWrapper } from '@lumx/react/stories/decorators/withWrapper';
27
7
 
28
- /**
29
- * LinkPreview story
30
- * @return regular LinkPreview without thumbnail.
31
- */
32
- export const NoThumbnail = ({ theme }: any) => (
33
- <LinkPreview
34
- title={text('Title', 'Link title')}
35
- description={text('Description', LONG_LOREM_IPSUM)}
36
- link={text('URL', 'https://google.com')}
37
- theme={theme}
38
- />
39
- );
8
+ import { Size } from '..';
9
+ import { LinkPreview, LinkPreviewProps } from './LinkPreview';
10
+
11
+ export default {
12
+ title: 'LumX components/link-preview/Link preview',
13
+ component: LinkPreview,
14
+ decorators: [withNestedProps()],
15
+ args: {
16
+ ...LinkPreview.defaultProps,
17
+ title: '',
18
+ description: '',
19
+ link: 'https://example.com',
20
+ },
21
+ argTypes: {
22
+ size: getSelectArgType<LinkPreviewProps['size']>([Size.regular, Size.big]),
23
+ titleHeading: { if: { arg: 'title' }, ...headingElementArgType },
24
+ },
25
+ };
40
26
 
41
27
  /**
42
- * LinkPreview story
43
- * @return regular LinkPreview without thumbnail, title and description.
28
+ * Default link preview with only the required props (link)
44
29
  */
45
- export const OnlyUrl = ({ theme }: any) => <LinkPreview link={text('URL', 'https://google.com')} theme={theme} />;
30
+ export const Default = {};
46
31
 
47
32
  /**
48
- * LinkPreview story
49
- * @return big LinkPreview.
33
+ * Link preview with title and description
50
34
  */
51
- export const BigLinkPreview = ({ theme }: any) => (
52
- <div style={{ width: 400 }}>
53
- <LinkPreview
54
- title={text('Title', 'Link title')}
55
- description={text('Description', LONG_LOREM_IPSUM)}
56
- link={text('URL', 'https://google.com')}
57
- theme={theme}
58
- thumbnailProps={{ image: landscapeImageKnob(), alt: 'Landscape' }}
59
- size={Size.big}
60
- />
61
- </div>
62
- );
35
+ export const TitleAndDescription = {
36
+ args: {
37
+ title: 'Link title',
38
+ description: loremIpsum('short'),
39
+ },
40
+ };
63
41
 
64
42
  /**
65
- * LinkPreview story
66
- * @return big LinkPreview without thumbnail.
43
+ * Link preview with title, description and thumbnail
67
44
  */
68
- export const BigWithoutThumbnail = ({ theme }: any) => (
69
- <div style={{ width: 400 }}>
70
- <LinkPreview
71
- title={text('Title', 'Link title')}
72
- description={text('Description', LONG_LOREM_IPSUM)}
73
- link={text('URL', 'https://google.com')}
74
- theme={theme}
75
- size={Size.big}
76
- />
77
- </div>
78
- );
45
+ export const AllFields = {
46
+ args: {
47
+ ...TitleAndDescription.args,
48
+ 'thumbnailProps.image': LANDSCAPE_IMAGES.landscape1,
49
+ },
50
+ };
79
51
 
80
52
  /**
81
- * LinkPreview story
82
- * @return big LinkPreview without thumbnail, title and description.
53
+ * Big link preview with title, description and thumbnail
83
54
  */
84
- export const BigWithOnlyUrl = ({ theme }: any) => (
85
- <div style={{ width: 400 }}>
86
- <LinkPreview link={text('URL', 'https://google.com')} theme={theme} size={Size.big} />
87
- </div>
88
- );
55
+ export const Big = {
56
+ decorators: [withWrapper({ style: { width: '400px' } })],
57
+ args: {
58
+ ...AllFields.args,
59
+ size: Size.big,
60
+ },
61
+ };