@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
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import over from 'lodash/over';
3
+ import identity from 'lodash/identity';
4
+
5
+ export const withValueOnChange = ({
6
+ valueProp = 'value',
7
+ valueTransform = identity,
8
+ }: {
9
+ valueProp?: string;
10
+ valueTransform?: (v: any) => any;
11
+ } = {}) => {
12
+ // eslint-disable-next-line react/display-name
13
+ return (Story: any, ctx: any) => {
14
+ const [value, onChange] = React.useState(ctx.args[valueProp]);
15
+ const args = { ...ctx.args, onChange: over([onChange, ctx.args.onChange]), [valueProp]: valueTransform(value) };
16
+ return <Story args={args} />;
17
+ };
18
+ };
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * SB decorator adding a wrapping div around the story
5
+ */
6
+ export const withWrapper = <E extends React.ElementType = 'div'>(
7
+ props: Omit<React.ComponentProps<E>, 'children'>,
8
+ as?: E,
9
+ ) => {
10
+ // eslint-disable-next-line react/display-name
11
+ return (Story: any) => {
12
+ const Wrapper = as || 'div';
13
+ return (
14
+ <Wrapper {...props}>
15
+ <Story />
16
+ </Wrapper>
17
+ );
18
+ };
19
+ };
@@ -1,7 +1,13 @@
1
- /* eslint-disable jsx-a11y/anchor-has-content,jsx-a11y/anchor-is-valid */
2
1
  import React from 'react';
3
2
 
4
3
  /**
5
4
  * Example custom link that can be used in linkAs props.
6
5
  */
7
- export const CustomLink: any = ({ ...props }) => <a href="#" data-custom-link {...props} />;
6
+ export const CustomLink = React.forwardRef<HTMLAnchorElement, { to: string; children?: React.ReactNode }>(
7
+ ({ to = '#', children, ...props }, ref) => (
8
+ <a ref={ref} href={to} data-custom-link {...props}>
9
+ {children}
10
+ </a>
11
+ ),
12
+ );
13
+ CustomLink.displayName = 'CustomLink';
@@ -1,19 +1,17 @@
1
- const shortText = `
2
- Nihil hic munitissimus habendi senatus locus, nihil horum? At nos hinc posthac, sitientis piros
3
- Afros. Magna pars studiorum, prodita quaerimus. Integer legentibus erat a ante historiarum
4
- dapibus. Praeterea iter est quasdam res quas ex communi. Ullamco laboris nisi ut aliquid ex ea
1
+ const tiny = `Lorem ipsum quisque tincidunt lobortis dui non auctor. Donec porta, ligula volutpat
2
+ vehicula aliquet, dui sapien tempus felis, sed.`;
3
+ const short = `${tiny} Ullamco laboris nisi ut aliquid ex ea
5
4
  commodi consequat. Inmensae subtilitatis, obscuris et malesuada fames. Me non paenitet nullum
6
5
  festiviorem excogitasse ad hoc. Cum ceteris in veneratione tui montes, nascetur mus. Etiam
7
6
  habebis sem dicantur magna mollis euismod. Quis aute iure reprehenderit in voluptate velit esse.
8
7
  Phasellus laoreet lorem vel dolor tempus vehicula. Ambitioni dedisse scripsisse iudicaretur.
9
8
  Paullum deliquit, ponderibus modulisque suis ratio utitur. Ab illo tempore, ab est sed
10
- immemorabili. Nec dubitamus multa iter quae et nos invenerat. Tu quoque, Brute, fili mi, nihil
9
+ immemorabili. Nec dubitamus multa iter quae et nos invenerat.`;
10
+ const long = `${short} Tu quoque, Brute, fili mi, nihil
11
11
  timor populi, nihil! Morbi fringilla convallis sapien, id pulvinar odio volutpat. Cras mattis
12
12
  iudicium purus sit amet fermentum. Vivamus sagittis lacus vel augue laoreet rutrum faucibus.
13
13
  Quisque ut dolor gravida, placerat libero vel, euismod. Unam incolunt Belgae, aliam Aquitani,
14
- tertiam. Cras mattis iudicium purus sit amet fermentum`;
15
- const longText = `
16
- ${shortText}. Prima luce, cum quibus mons aliud
14
+ tertiam. Cras mattis iudicium purus sit amet fermentum. Prima luce, cum quibus mons aliud
17
15
  consensu ab eo. Vivamus sagittis lacus vel augue laoreet rutrum faucibus. Petierunt uti sibi
18
16
  concilium totius Galliae in diem certam indicere. Etiam habebis sem dicantur magna mollis
19
17
  euismod. A communi observantia non est recedendum. Ut enim ad minim veniam, quis nostrud
@@ -56,4 +54,6 @@ Plura mihi bona sunt, inclinet, amari petere vellent. Quae vero auctorem tractat
56
54
  dicuntur. Me non paenitet nullum festiviorem excogitasse ad hoc. Unam incolunt Belgae, aliam
57
55
  Aquitani, tertiam.`;
58
56
 
59
- export const loremIpsum = (type: 'short' | 'long'): string => (type === 'short' ? shortText : longText);
57
+ const types = { tiny, short, long } as const;
58
+
59
+ export const loremIpsum = (type: keyof typeof types): string => types[type];
@@ -5,7 +5,6 @@ import { queryByClassName } from '@lumx/react/testing/utils/queries';
5
5
 
6
6
  interface CommonSetup {
7
7
  props: GenericProps;
8
- container: HTMLElement;
9
8
  }
10
9
 
11
10
  interface Options<S extends CommonSetup> {
@@ -28,8 +27,8 @@ export function commonTestsSuiteRTL<S extends CommonSetup>(setup: SetupFunction<
28
27
  const { baseClassName, forwardClassName, forwardAttributes } = options;
29
28
  describe('Common tests suite', () => {
30
29
  it('should render with base class name', () => {
31
- const { container } = setup();
32
- expect(queryByClassName(container, baseClassName)).toBeInTheDocument();
30
+ setup();
31
+ expect(queryByClassName(document.body, baseClassName)).toBeInTheDocument();
33
32
  });
34
33
 
35
34
  if (forwardClassName) {
@@ -1,4 +1,2 @@
1
1
  export * from './commonTestsSuite';
2
2
  export * from './commonTestsSuiteRTL';
3
-
4
- export * from './itShouldRenderStories';
@@ -3,5 +3,3 @@
3
3
  */
4
4
  declare module 'test-data-bot';
5
5
  declare module '*.jpg';
6
- declare module '@storybook/addon-knobs';
7
- declare module '@storybook/addon-actions';
@@ -9,7 +9,7 @@ const globalState = {
9
9
  };
10
10
 
11
11
  /** Toggle apply the material CSS override. */
12
- async function toggleMaterialTheme(wasEnabled: boolean) {
12
+ export async function toggleMaterialTheme(wasEnabled: boolean) {
13
13
  globalState.isEnabled = !wasEnabled;
14
14
 
15
15
  // Inject the material theme CSS file.
@@ -0,0 +1,4 @@
1
+ import { createContext } from 'react';
2
+ import { Theme } from '..';
3
+
4
+ export const ThemeContext = createContext<Theme | undefined>(undefined);
@@ -0,0 +1,9 @@
1
+ import React, { ElementType } from 'react';
2
+ import { ComponentRef } from '@lumx/react/utils/type';
3
+
4
+ /** Same as `React.forwardRef` but inferring Ref type from the `as` prop. */
5
+ export function forwardRefPolymorphic<E extends ElementType, P extends { as?: E }>(
6
+ render: (props: P, ref: ComponentRef<E>) => React.ReactElement | null,
7
+ ) {
8
+ return React.forwardRef(render as any) as (props: P & { ref?: ComponentRef<E> }) => React.ReactElement | null;
9
+ }
package/src/utils/type.ts CHANGED
@@ -38,6 +38,13 @@ export type HeadingElement = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
38
38
  /** Union type of all text elements */
39
39
  export type TextElement = 'span' | 'p' | HeadingElement;
40
40
 
41
+ export type HasPolymorphicAs<E extends React.ElementType> = React.ComponentPropsWithoutRef<E> & {
42
+ /**
43
+ * Customize the rendered component.
44
+ */
45
+ as?: E;
46
+ };
47
+
41
48
  export interface HasTheme {
42
49
  /**
43
50
  * Theme adapting the component to light or dark background.
@@ -45,14 +52,17 @@ export interface HasTheme {
45
52
  theme?: Theme;
46
53
  }
47
54
 
48
- /**
49
- * Define a generic props types.
50
- */
51
- export interface GenericProps {
55
+ export interface HasClassName {
52
56
  /**
53
57
  * Class name forwarded to the root element of the component.
54
58
  */
55
59
  className?: string;
60
+ }
61
+
62
+ /**
63
+ * Define a generic props types.
64
+ */
65
+ export interface GenericProps extends HasClassName {
56
66
  /**
57
67
  * Any prop (particularly any supported prop for a HTML element).
58
68
  */
@@ -111,3 +121,17 @@ export type HasAriaLabelOrLabelledBy<T = string | undefined> = T extends string
111
121
  'aria-label': string;
112
122
  'aria-labelledby'?: undefined;
113
123
  };
124
+
125
+ /**
126
+ * Extract ref type for a component or JSX intrinsic element
127
+ *
128
+ * @example ComponentRef<'div'> => React.Ref<HTMLDivElement>
129
+ * @example ComponentRef<Button> => React.Ref<HTMLButtonElement
130
+ */
131
+ export type ComponentRef<C> = C extends keyof JSX.IntrinsicElements
132
+ ? JSX.IntrinsicElements[C]['ref']
133
+ : C extends Comp<any, infer T>
134
+ ? React.Ref<T>
135
+ : C extends React.JSXElementConstructor<{ ref?: infer R }>
136
+ ? R
137
+ : never;