@lumx/react 2.2.21 → 2.2.22-alpha-fix-generic-block.2

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 (109) hide show
  1. package/esm/_internal/AutocompleteMultiple.js.map +1 -1
  2. package/esm/_internal/Avatar2.js.map +1 -1
  3. package/esm/_internal/ButtonRoot.js.map +1 -1
  4. package/esm/_internal/Checkbox2.js.map +1 -1
  5. package/esm/_internal/Chip2.js.map +1 -1
  6. package/esm/_internal/ClickAwayProvider.js +43 -24
  7. package/esm/_internal/ClickAwayProvider.js.map +1 -1
  8. package/esm/_internal/CommentBlock.js.map +1 -1
  9. package/esm/_internal/Dialog2.js +6 -3
  10. package/esm/_internal/Dialog2.js.map +1 -1
  11. package/esm/_internal/Divider2.js.map +1 -1
  12. package/esm/_internal/DragHandle.js.map +1 -1
  13. package/esm/_internal/Dropdown2.js.map +1 -1
  14. package/esm/_internal/ExpansionPanel.js.map +1 -1
  15. package/esm/_internal/Flag2.js.map +1 -1
  16. package/esm/_internal/FlexBox.js.map +1 -1
  17. package/esm/_internal/GenericBlock.js +72 -37
  18. package/esm/_internal/GenericBlock.js.map +1 -1
  19. package/esm/_internal/Icon2.js.map +1 -1
  20. package/esm/_internal/ImageBlock.js.map +1 -1
  21. package/esm/_internal/InputHelper.js.map +1 -1
  22. package/esm/_internal/InputLabel.js.map +1 -1
  23. package/esm/_internal/Lightbox2.js +1 -1
  24. package/esm/_internal/Lightbox2.js.map +1 -1
  25. package/esm/_internal/LinkPreview.js.map +1 -1
  26. package/esm/_internal/Mosaic2.js.map +1 -1
  27. package/esm/_internal/Notification2.js.map +1 -1
  28. package/esm/_internal/Popover2.js +1 -1
  29. package/esm/_internal/Popover2.js.map +1 -1
  30. package/esm/_internal/PostBlock.js.map +1 -1
  31. package/esm/_internal/Progress2.js.map +1 -1
  32. package/esm/_internal/RadioGroup.js.map +1 -1
  33. package/esm/_internal/SelectMultiple.js.map +1 -1
  34. package/esm/_internal/SideNavigationItem.js.map +1 -1
  35. package/esm/_internal/SkeletonTypography.js.map +1 -1
  36. package/esm/_internal/Slider2.js.map +1 -1
  37. package/esm/_internal/Slides.js.map +1 -1
  38. package/esm/_internal/Switch2.js.map +1 -1
  39. package/esm/_internal/TabPanel.js.map +1 -1
  40. package/esm/_internal/TableRow.js.map +1 -1
  41. package/esm/_internal/TextField.js.map +1 -1
  42. package/esm/_internal/Thumbnail2.js.map +1 -1
  43. package/esm/_internal/Uploader2.js.map +1 -1
  44. package/esm/_internal/UserBlock.js.map +1 -1
  45. package/esm/_internal/_rollupPluginBabelHelpers.js +5 -1
  46. package/esm/_internal/_rollupPluginBabelHelpers.js.map +1 -1
  47. package/esm/_internal/generic-block.js +8 -0
  48. package/esm/_internal/generic-block.js.map +1 -1
  49. package/esm/_internal/type.js +11 -1
  50. package/esm/_internal/type.js.map +1 -1
  51. package/package.json +4 -4
  52. package/src/components/autocomplete/Autocomplete.tsx +6 -8
  53. package/src/components/avatar/Avatar.tsx +2 -4
  54. package/src/components/button/Button.test.tsx +1 -1
  55. package/src/components/button/ButtonRoot.tsx +3 -4
  56. package/src/components/button/IconButton.test.tsx +1 -1
  57. package/src/components/checkbox/Checkbox.tsx +2 -4
  58. package/src/components/chip/Chip.tsx +2 -4
  59. package/src/components/comment-block/CommentBlock.tsx +2 -4
  60. package/src/components/dialog/Dialog.stories.tsx +3 -3
  61. package/src/components/dialog/Dialog.tsx +11 -4
  62. package/src/components/divider/Divider.tsx +2 -5
  63. package/src/components/drag-handle/DragHandle.tsx +2 -5
  64. package/src/components/dropdown/Dropdown.tsx +4 -3
  65. package/src/components/expansion-panel/ExpansionPanel.tsx +2 -3
  66. package/src/components/flag/Flag.tsx +2 -4
  67. package/src/components/flex-box/FlexBox.stories.tsx +1 -1
  68. package/src/components/flex-box/FlexBox.tsx +1 -1
  69. package/src/components/generic-block/GenericBlock.stories.jsx +106 -0
  70. package/src/components/generic-block/GenericBlock.test.tsx +129 -5
  71. package/src/components/generic-block/GenericBlock.tsx +132 -44
  72. package/src/components/icon/Icon.tsx +2 -4
  73. package/src/components/image-block/ImageBlock.tsx +2 -4
  74. package/src/components/input-helper/InputHelper.tsx +2 -4
  75. package/src/components/input-label/InputLabel.tsx +2 -4
  76. package/src/components/lightbox/Lightbox.tsx +4 -6
  77. package/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +1 -1
  78. package/src/components/link-preview/LinkPreview.tsx +2 -4
  79. package/src/components/mosaic/Mosaic.tsx +2 -4
  80. package/src/components/notification/Notification.tsx +2 -4
  81. package/src/components/popover/Popover.tsx +1 -1
  82. package/src/components/popover/__snapshots__/Popover.test.tsx.snap +10 -10
  83. package/src/components/post-block/PostBlock.tsx +2 -4
  84. package/src/components/progress/Progress.tsx +2 -4
  85. package/src/components/radio-button/RadioButton.tsx +2 -4
  86. package/src/components/select/constants.ts +2 -5
  87. package/src/components/side-navigation/SideNavigation.tsx +2 -4
  88. package/src/components/skeleton/SkeletonCircle.tsx +2 -4
  89. package/src/components/skeleton/SkeletonRectangle.tsx +2 -4
  90. package/src/components/skeleton/SkeletonTypography.tsx +2 -4
  91. package/src/components/slider/Slider.tsx +2 -4
  92. package/src/components/slideshow/Slides.tsx +2 -7
  93. package/src/components/slideshow/SlideshowControls.tsx +2 -4
  94. package/src/components/switch/Switch.tsx +2 -4
  95. package/src/components/table/Table.tsx +2 -4
  96. package/src/components/tabs/TabList.tsx +2 -4
  97. package/src/components/text-field/TextField.tsx +6 -8
  98. package/src/components/thumbnail/Thumbnail.tsx +3 -5
  99. package/src/components/uploader/Uploader.tsx +2 -4
  100. package/src/components/user-block/UserBlock.tsx +2 -4
  101. package/src/hooks/useClickAway.tsx +5 -5
  102. package/src/testing/utils/commonTestsSuite.ts +2 -2
  103. package/src/utils/ClickAwayProvider/ClickAwayProvider.stories.jsx +58 -0
  104. package/src/utils/ClickAwayProvider/ClickAwayProvider.tsx +51 -19
  105. package/src/utils/type.ts +19 -2
  106. package/types.d.ts +105 -139
  107. package/src/components/generic-block/GenericBlock.stories.tsx +0 -149
  108. package/src/components/generic-block/__snapshots__/GenericBlock.test.tsx.snap +0 -92
  109. package/src/utils/ClickAwayProvider/ClickAwayProvider.stories.tsx +0 -75
@@ -1,7 +1,7 @@
1
1
  import { Color, ColorPalette, Size, Theme } from '@lumx/react';
2
2
  import { useStopPropagation } from '@lumx/react/hooks/useStopPropagation';
3
3
 
4
- import { Comp, GenericProps, getRootClassName, handleBasicClasses, onEnterPressed } from '@lumx/react/utils';
4
+ import { Comp, GenericProps, getRootClassName, handleBasicClasses, HasTheme, onEnterPressed } from '@lumx/react/utils';
5
5
 
6
6
  import classNames from 'classnames';
7
7
 
@@ -16,7 +16,7 @@ type ChipSize = Extract<Size, 's' | 'm'>;
16
16
  /**
17
17
  * Defines the props of the component.
18
18
  */
19
- export interface ChipProps extends GenericProps {
19
+ export interface ChipProps extends GenericProps, HasTheme {
20
20
  /** A component to be rendered after the content. */
21
21
  after?: ReactNode;
22
22
  /** A component to be rendered before the content. */
@@ -33,8 +33,6 @@ export interface ChipProps extends GenericProps {
33
33
  isSelected?: boolean;
34
34
  /** Size variant. */
35
35
  size?: ChipSize;
36
- /** Theme adapting the component to light or dark background. */
37
- theme?: Theme;
38
36
  /** On "after" element clicked callback. */
39
37
  onAfterClick?: MouseEventHandler;
40
38
  /** On "before" element clicked callback. */
@@ -3,7 +3,7 @@ import React, { Children, forwardRef, KeyboardEvent, KeyboardEventHandler, React
3
3
  import classNames from 'classnames';
4
4
 
5
5
  import { Avatar, Size, Theme, Tooltip } from '@lumx/react';
6
- import { Comp, GenericProps, getRootClassName, handleBasicClasses, ValueOf } from '@lumx/react/utils';
6
+ import { Comp, GenericProps, getRootClassName, handleBasicClasses, HasTheme, ValueOf } from '@lumx/react/utils';
7
7
 
8
8
  import isFunction from 'lodash/isFunction';
9
9
  import { AvatarProps } from '../avatar/Avatar';
@@ -20,7 +20,7 @@ export type CommentBlockVariant = ValueOf<typeof CommentBlockVariant>;
20
20
  /**
21
21
  * Defines the props of the component.
22
22
  */
23
- export interface CommentBlockProps extends GenericProps {
23
+ export interface CommentBlockProps extends GenericProps, HasTheme {
24
24
  /** Action toolbar content. */
25
25
  actions?: ReactNode;
26
26
  /** Props to pass to the avatar. */
@@ -49,8 +49,6 @@ export interface CommentBlockProps extends GenericProps {
49
49
  onMouseLeave?(): void;
50
50
  /** Comment content. */
51
51
  text: ReactNode | string;
52
- /** Theme adapting the component to light or dark background. */
53
- theme?: Theme;
54
52
  /** Comment variant. */
55
53
  variant?: CommentBlockVariant;
56
54
  }
@@ -1,4 +1,3 @@
1
- import noop from 'lodash/noop';
2
1
  import { mdiClose } from '@lumx/icons';
3
2
  import {
4
3
  AlertDialog,
@@ -302,6 +301,7 @@ export const DialogFocusTrap = ({ theme }: any) => {
302
301
  setValue(item);
303
302
  };
304
303
  const [date, setDate] = useState<Date | undefined>(new Date('2020-05-18'));
304
+ const [date2, setDate2] = useState<Date | undefined>();
305
305
 
306
306
  const datePickerDialogButtonRef = useRef<HTMLButtonElement>(null);
307
307
  const [isDatePickerDialogOpen, closeDatePickerDialog, openDatePickerDialog] = useBooleanState(false);
@@ -381,8 +381,8 @@ export const DialogFocusTrap = ({ theme }: any) => {
381
381
  label="Start date"
382
382
  placeholder="Pick a date"
383
383
  theme={theme}
384
- onChange={noop}
385
- value={undefined}
384
+ onChange={setDate2}
385
+ value={date2}
386
386
  nextButtonProps={{ label: 'Next month' }}
387
387
  previousButtonProps={{ label: 'Previous month' }}
388
388
  defaultMonth={new Date('2020-05-18')}
@@ -1,4 +1,4 @@
1
- import React, { Children, forwardRef, ReactElement, ReactNode, RefObject, useMemo, useRef, useState } from 'react';
1
+ import React, { Children, forwardRef, ReactElement, ReactNode, Ref, RefObject, useMemo, useRef, useState } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
 
4
4
  import classNames from 'classnames';
@@ -42,7 +42,7 @@ export interface DialogProps extends GenericProps {
42
42
  /** Reference to the parent element that triggered modal opening (will get back focus on close). */
43
43
  parentElement?: RefObject<HTMLElement>;
44
44
  /** Reference to the dialog content element. */
45
- contentRef?: RefObject<HTMLDivElement>;
45
+ contentRef?: Ref<HTMLDivElement>;
46
46
  /** Reference to the of the element that should get the focus when the dialogs opens. By default, the first child will take focus. */
47
47
  focusElement?: RefObject<HTMLElement>;
48
48
  /** Whether to keep the dialog open on clickaway or escape press. */
@@ -176,10 +176,13 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
176
176
  // eslint-disable-next-line react-hooks/rules-of-hooks
177
177
  const clickAwayRefs = useRef([wrapperRef]);
178
178
 
179
+ // eslint-disable-next-line react-hooks/rules-of-hooks
180
+ const rootRef = useRef<HTMLDivElement>(null);
181
+
179
182
  return isOpen || isVisible
180
183
  ? createPortal(
181
184
  <div
182
- ref={ref}
185
+ ref={mergeRefs(rootRef, ref)}
183
186
  {...forwardedProps}
184
187
  className={classNames(
185
188
  className,
@@ -196,7 +199,11 @@ export const Dialog: Comp<DialogProps, HTMLDivElement> = forwardRef((props, ref)
196
199
  <div className={`${CLASSNAME}__overlay`} />
197
200
 
198
201
  <section className={`${CLASSNAME}__container`} role="dialog" aria-modal="true" {...dialogProps}>
199
- <ClickAwayProvider callback={!preventAutoClose && onClose} refs={clickAwayRefs}>
202
+ <ClickAwayProvider
203
+ callback={!preventAutoClose && onClose}
204
+ childrenRefs={clickAwayRefs}
205
+ parentRef={rootRef}
206
+ >
200
207
  <div className={`${CLASSNAME}__wrapper`} ref={wrapperRef}>
201
208
  {(header || headerChildContent) && (
202
209
  <header
@@ -3,15 +3,12 @@ import React, { forwardRef } from 'react';
3
3
  import classNames from 'classnames';
4
4
 
5
5
  import { Theme } from '@lumx/react';
6
- import { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';
6
+ import { Comp, GenericProps, getRootClassName, handleBasicClasses, HasTheme } from '@lumx/react/utils';
7
7
 
8
8
  /**
9
9
  * Defines the props of the component.
10
10
  */
11
- export interface DividerProps extends GenericProps {
12
- /** Theme adapting the component to light or dark background. */
13
- theme?: Theme;
14
- }
11
+ export interface DividerProps extends GenericProps, HasTheme {}
15
12
 
16
13
  /**
17
14
  * Component display name.
@@ -4,15 +4,12 @@ import classNames from 'classnames';
4
4
 
5
5
  import { mdiDragVertical } from '@lumx/icons';
6
6
  import { ColorPalette, Icon, Size, Theme } from '@lumx/react';
7
- import { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';
7
+ import { Comp, GenericProps, getRootClassName, handleBasicClasses, HasTheme } from '@lumx/react/utils';
8
8
 
9
9
  /**
10
10
  * Defines the props of the component.
11
11
  */
12
- export interface DragHandleProps extends GenericProps {
13
- /** Theme adapting the component to light or dark background. */
14
- theme?: Theme;
15
- }
12
+ export interface DragHandleProps extends GenericProps, HasTheme {}
16
13
 
17
14
  /**
18
15
  * Component display name.
@@ -3,7 +3,7 @@ import React, { cloneElement, forwardRef, useMemo, useRef } from 'react';
3
3
  import classNames from 'classnames';
4
4
 
5
5
  import { List, ListProps } from '@lumx/react/components/list/List';
6
- import { Offset, Placement, Popover } from '@lumx/react/components/popover/Popover';
6
+ import { Offset, Placement, Popover, PopoverProps } from '@lumx/react/components/popover/Popover';
7
7
  import { useInfiniteScroll } from '@lumx/react/hooks/useInfiniteScroll';
8
8
  import { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent } from '@lumx/react/utils';
9
9
 
@@ -11,10 +11,11 @@ import { Comp, GenericProps, getRootClassName, handleBasicClasses, isComponent }
11
11
  * Defines the props of the component.
12
12
  */
13
13
  export interface DropdownProps extends GenericProps {
14
- /** Reference to the element around which the dropdown is placed.
14
+ /**
15
+ * Reference to the element around which the dropdown is placed.
15
16
  * @see {@link PopoverProps#anchorRef}
16
17
  */
17
- anchorRef: React.RefObject<HTMLElement>;
18
+ anchorRef: PopoverProps['anchorRef'];
18
19
  /** Dropdown content. */
19
20
  children: React.ReactNode;
20
21
  /**
@@ -15,6 +15,7 @@ import {
15
15
  GenericProps,
16
16
  getRootClassName,
17
17
  handleBasicClasses,
18
+ HasTheme,
18
19
  isComponent,
19
20
  partitionMulti,
20
21
  } from '@lumx/react/utils';
@@ -22,7 +23,7 @@ import {
22
23
  /**
23
24
  * Defines the props of the component.
24
25
  */
25
- export interface ExpansionPanelProps extends GenericProps {
26
+ export interface ExpansionPanelProps extends GenericProps, HasTheme {
26
27
  /** Whether the expansion panel has a background. */
27
28
  hasBackground?: boolean;
28
29
  /** Whether the header has a divider. */
@@ -31,8 +32,6 @@ export interface ExpansionPanelProps extends GenericProps {
31
32
  isOpen?: boolean;
32
33
  /** Label text (overwritten if a `<header>` is provided in the children). */
33
34
  label?: string;
34
- /** Theme adapting the component to light or dark background. */
35
- theme?: Theme;
36
35
  /** On open callback. */
37
36
  onOpen?: Callback;
38
37
  /** On close callback. */
@@ -2,11 +2,9 @@ import React, { forwardRef } from 'react';
2
2
  import classNames from 'classnames';
3
3
 
4
4
  import { ColorPalette, Icon, Size, Theme } from '@lumx/react';
5
- import { Comp, GenericProps, getRootClassName, handleBasicClasses } from '@lumx/react/utils';
5
+ import { Comp, GenericProps, getRootClassName, handleBasicClasses, HasTheme } from '@lumx/react/utils';
6
6
 
7
- export interface FlagProps extends GenericProps {
8
- /** Theme adapting the component to light or dark background. */
9
- theme?: Theme;
7
+ export interface FlagProps extends GenericProps, HasTheme {
10
8
  /** Color of the component. */
11
9
  color?: ColorPalette;
12
10
  /** Icon to use before the label. */
@@ -18,7 +18,7 @@ const flexViewKnobConfigs: Array<
18
18
  ['fillSpace', boolean],
19
19
  ['noShrink', boolean],
20
20
  ['wrap', boolean],
21
- ['gap', select, [DEFAULT_PROPS.gap, Size.regular, Size.medium, Size.big, Size.huge]],
21
+ ['gap', select, [DEFAULT_PROPS.gap, Size.tiny, Size.regular, Size.medium, Size.big, Size.huge]],
22
22
  ['hAlign', select, [DEFAULT_PROPS.hAlign, Alignment.center, Alignment.top, Alignment.bottom]],
23
23
  ['vAlign', select, [DEFAULT_PROPS.vAlign, Alignment.center, Alignment.right, Alignment.left]],
24
24
  ['orientation', select, [undefined, Orientation.horizontal, Orientation.vertical]],
@@ -6,7 +6,7 @@ import React, { forwardRef, ReactNode } from 'react';
6
6
  import { Size } from '..';
7
7
 
8
8
  export type MarginAutoAlignment = Extract<Alignment, 'top' | 'bottom' | 'right' | 'left'>;
9
- export type GapSize = Extract<Size, 'regular' | 'medium' | 'big' | 'huge'>;
9
+ export type GapSize = Extract<Size, 'tiny' | 'regular' | 'medium' | 'big' | 'huge'>;
10
10
 
11
11
  /**
12
12
  * Defines the props of the component.
@@ -0,0 +1,106 @@
1
+ import React from 'react';
2
+ import { mdiPencil } from '@lumx/icons';
3
+ import { GenericBlock, Button, Icon, Size } from '@lumx/react';
4
+
5
+ export default { title: 'LumX components/generic-block/GenericBlock' };
6
+
7
+ const redBorderStyle = { border: '1px solid red' };
8
+
9
+ export const SectionsInProps = ({ theme }) => (
10
+ <GenericBlock
11
+ figure={<Icon icon={mdiPencil} size={Size.m} />}
12
+ actionsProps={{ style: redBorderStyle }}
13
+ figureProps={{ style: redBorderStyle }}
14
+ contentProps={{ style: redBorderStyle }}
15
+ actions={<Button theme={theme}>Button</Button>}
16
+ >
17
+ Content
18
+ </GenericBlock>
19
+ );
20
+
21
+ export const SectionsInChildren = ({ theme }) => (
22
+ <GenericBlock>
23
+ <GenericBlock.Figure style={redBorderStyle}>
24
+ <Icon icon={mdiPencil} size={Size.m} />
25
+ </GenericBlock.Figure>
26
+ <GenericBlock.Content style={redBorderStyle}>Content</GenericBlock.Content>
27
+ <GenericBlock.Actions style={redBorderStyle}>
28
+ <Button theme={theme}>Button</Button>
29
+ </GenericBlock.Actions>
30
+ </GenericBlock>
31
+ );
32
+
33
+ const Template = ({ theme, ...props }) => (
34
+ <GenericBlock {...props}>
35
+ <GenericBlock.Figure style={redBorderStyle} {...props.figureProps}>
36
+ <Icon icon={mdiPencil} size={Size.m} />
37
+ </GenericBlock.Figure>
38
+ <GenericBlock.Content style={redBorderStyle} {...props.contentProps}>
39
+ {props.content || 'Content'}
40
+ </GenericBlock.Content>
41
+ <GenericBlock.Actions style={redBorderStyle} {...props.actionsProps}>
42
+ <Button theme={theme}>Button</Button>
43
+ </GenericBlock.Actions>
44
+ </GenericBlock>
45
+ );
46
+
47
+ export const Vertical = Template.bind({});
48
+ Vertical.args = {
49
+ orientation: 'vertical',
50
+ };
51
+
52
+ export const VerticalAlignCenter = Template.bind({});
53
+ VerticalAlignCenter.args = {
54
+ orientation: 'vertical',
55
+ vAlign: 'center',
56
+ };
57
+
58
+ export const VerticalOverflow = Template.bind({});
59
+ VerticalOverflow.args = {
60
+ orientation: 'vertical',
61
+ style: { width: 300 },
62
+ content: (
63
+ <span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>
64
+ _________________________________________________________________
65
+ </span>
66
+ ),
67
+ };
68
+
69
+ export const Horizontal = Template.bind({});
70
+ Horizontal.args = {
71
+ orientation: 'horizontal',
72
+ };
73
+
74
+ export const HorizontalAlignRightBottom = Template.bind({});
75
+ HorizontalAlignRightBottom.args = {
76
+ orientation: 'horizontal',
77
+ vAlign: 'right',
78
+ hAlign: 'bottom',
79
+ };
80
+
81
+ export const HorizontalOverflow = Template.bind({});
82
+ HorizontalOverflow.args = {
83
+ orientation: 'horizontal',
84
+ style: { width: 300 },
85
+ content: (
86
+ <span style={{ overflow: 'hidden', textOverflow: 'ellipsis' }}>
87
+ _________________________________________________________________
88
+ </span>
89
+ ),
90
+ };
91
+
92
+ export const GapSizes = ({ theme }) =>
93
+ [Size.regular, Size.big, Size.huge].map((gap) => (
94
+ <GenericBlock key={gap} orientation="vertical" gap={gap} style={{ marginBottom: 40 }}>
95
+ <GenericBlock.Figure style={redBorderStyle}>
96
+ <Icon icon={mdiPencil} size={Size.m} />
97
+ </GenericBlock.Figure>
98
+ <GenericBlock.Content style={redBorderStyle}>
99
+ <h2>{gap} gap size</h2>
100
+ <p>block description</p>
101
+ </GenericBlock.Content>
102
+ <GenericBlock.Actions style={redBorderStyle}>
103
+ <Button theme={theme}>Button</Button>
104
+ </GenericBlock.Actions>
105
+ </GenericBlock>
106
+ ));
@@ -1,10 +1,9 @@
1
- import React from 'react';
1
+ import React, { createRef } from 'react';
2
2
  import { mount, shallow } from 'enzyme';
3
3
  import 'jest-enzyme';
4
- import { commonTestsSuite, itShouldRenderStories } from '@lumx/react/testing/utils';
4
+ import { commonTestsSuite } from '@lumx/react/testing/utils';
5
5
 
6
- import { GenericBlock, GenericBlockProps } from './GenericBlock';
7
- import * as stories from '../../stories/generated/GenericBlock/Demos.stories';
6
+ import { GenericBlock, GenericBlockProps } from '.';
8
7
 
9
8
  const CLASSNAME = GenericBlock.className as string;
10
9
 
@@ -20,7 +19,132 @@ const setup = (props: Partial<GenericBlockProps> = {}, shallowRendering = true)
20
19
  describe(`<${GenericBlock.displayName}>`, () => {
21
20
  // 1. Test render via snapshot.
22
21
  describe('Snapshots and structure', () => {
23
- itShouldRenderStories(stories, GenericBlock);
22
+ it('should render default', () => {
23
+ const wrapper = shallow(
24
+ <GenericBlock figure="figure" actions="actions">
25
+ Content
26
+ </GenericBlock>,
27
+ );
28
+
29
+ expect(wrapper.prop('gap')).toBe('big');
30
+ expect(wrapper.prop('orientation')).toBe('horizontal');
31
+
32
+ const figure = wrapper.find('.lumx-generic-block__figure');
33
+ expect(figure).toHaveLength(1);
34
+
35
+ const content = wrapper.find('.lumx-generic-block__content');
36
+ expect(content).toHaveLength(1);
37
+ expect(content.prop('fillSpace')).toBe(true);
38
+ expect(content.prop('orientation')).toBe('vertical');
39
+
40
+ const actions = wrapper.find('.lumx-generic-block__actions');
41
+ expect(actions).toHaveLength(1);
42
+ });
43
+
44
+ it('should forward vAlign & hAlign', () => {
45
+ const wrapper = shallow(
46
+ <GenericBlock figure="figure" actions="actions" vAlign="left" hAlign="bottom">
47
+ Content
48
+ </GenericBlock>,
49
+ );
50
+
51
+ expect(wrapper.prop('vAlign')).toBe('left');
52
+ expect(wrapper.prop('hAlign')).toBe('bottom');
53
+
54
+ const figure = wrapper.find('.lumx-generic-block__figure');
55
+ expect(figure).toHaveLength(1);
56
+ expect(figure.prop('vAlign')).toBe('left');
57
+ expect(figure.prop('hAlign')).toBe('bottom');
58
+
59
+ const content = wrapper.find('.lumx-generic-block__content');
60
+ expect(content).toHaveLength(1);
61
+ expect(content.prop('vAlign')).toBe('left');
62
+ expect(content.prop('hAlign')).toBe('bottom');
63
+
64
+ const actions = wrapper.find('.lumx-generic-block__actions');
65
+ expect(actions).toHaveLength(1);
66
+ expect(actions.prop('vAlign')).toBe('left');
67
+ expect(actions.prop('hAlign')).toBe('bottom');
68
+ });
69
+
70
+ it('should combine figure props', () => {
71
+ const wrapper = shallow(
72
+ <GenericBlock figure="Figure 1" figureProps={{ className: 'figure1', vAlign: 'left' }}>
73
+ <GenericBlock.Figure className="figure2" fillSpace>
74
+ Figure 2
75
+ </GenericBlock.Figure>
76
+ </GenericBlock>,
77
+ );
78
+
79
+ const figure = wrapper.find('.lumx-generic-block__figure');
80
+ expect(figure).toHaveClassName('figure1');
81
+ expect(figure).toHaveClassName('figure2');
82
+ expect(figure.prop('fillSpace')).toBe(true);
83
+ expect(figure.prop('vAlign')).toBe('left');
84
+ expect(figure).toHaveText('Figure 1Figure 2');
85
+
86
+ expect(wrapper.find('.lumx-generic-block__content')).toHaveLength(0);
87
+ expect(wrapper.find('.lumx-generic-block__actions')).toHaveLength(0);
88
+ });
89
+
90
+ it('should combine content props', () => {
91
+ const wrapper = shallow(
92
+ <GenericBlock contentProps={{ className: 'content1', vAlign: 'left' }}>
93
+ Content 1
94
+ <GenericBlock.Content className="content2" fillSpace>
95
+ Content 2
96
+ </GenericBlock.Content>
97
+ </GenericBlock>,
98
+ );
99
+
100
+ const content = wrapper.find('.lumx-generic-block__content');
101
+ expect(content).toHaveClassName('content1');
102
+ expect(content).toHaveClassName('content2');
103
+ expect(content.prop('fillSpace')).toBe(true);
104
+ expect(content.prop('vAlign')).toBe('left');
105
+ expect(content).toHaveText('Content 2Content 1');
106
+
107
+ expect(wrapper.find('.lumx-generic-block__figure')).toHaveLength(0);
108
+ expect(wrapper.find('.lumx-generic-block__actions')).toHaveLength(0);
109
+ });
110
+
111
+ it('should combine actions props', () => {
112
+ const wrapper = shallow(
113
+ <GenericBlock actions="Actions 1" actionsProps={{ className: 'actions1', vAlign: 'left' }}>
114
+ <GenericBlock.Actions className="actions2" fillSpace>
115
+ Actions 2
116
+ </GenericBlock.Actions>
117
+ </GenericBlock>,
118
+ );
119
+
120
+ const actions = wrapper.find('.lumx-generic-block__actions');
121
+ expect(actions).toHaveClassName('actions1');
122
+ expect(actions).toHaveClassName('actions2');
123
+ expect(actions.prop('fillSpace')).toBe(true);
124
+ expect(actions.prop('vAlign')).toBe('left');
125
+ expect(actions).toHaveText('Actions 1Actions 2');
126
+
127
+ expect(wrapper.find('.lumx-generic-block__figure')).toHaveLength(0);
128
+ expect(wrapper.find('.lumx-generic-block__content')).toHaveLength(0);
129
+ });
130
+
131
+ it('should forward refs', () => {
132
+ const rootRef = createRef<HTMLDivElement>();
133
+ const figureRef = createRef<HTMLDivElement>();
134
+ const contentRef = createRef<HTMLDivElement>();
135
+ const actionsRef = createRef<HTMLDivElement>();
136
+ shallow(
137
+ <GenericBlock ref={rootRef}>
138
+ <GenericBlock.Figure ref={figureRef} />
139
+ <GenericBlock.Content ref={contentRef} />
140
+ <GenericBlock.Actions ref={actionsRef} />
141
+ </GenericBlock>,
142
+ );
143
+ expect(rootRef.current).toBeDefined();
144
+ expect(figureRef.current).toBeDefined();
145
+ expect(contentRef.current).toBeDefined();
146
+ expect(actionsRef.current).toBeDefined();
147
+ });
24
148
  });
25
149
 
26
150
  // Common tests suite.