@lumx/react 2.2.21 → 2.2.22
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.
- package/esm/_internal/AutocompleteMultiple.js.map +1 -1
- package/esm/_internal/Avatar2.js.map +1 -1
- package/esm/_internal/ButtonRoot.js.map +1 -1
- package/esm/_internal/Checkbox2.js.map +1 -1
- package/esm/_internal/Chip2.js.map +1 -1
- package/esm/_internal/ClickAwayProvider.js +43 -24
- package/esm/_internal/ClickAwayProvider.js.map +1 -1
- package/esm/_internal/CommentBlock.js.map +1 -1
- package/esm/_internal/Dialog2.js +6 -3
- package/esm/_internal/Dialog2.js.map +1 -1
- package/esm/_internal/Divider2.js.map +1 -1
- package/esm/_internal/DragHandle.js.map +1 -1
- package/esm/_internal/Dropdown2.js.map +1 -1
- package/esm/_internal/ExpansionPanel.js.map +1 -1
- package/esm/_internal/Flag2.js.map +1 -1
- package/esm/_internal/GenericBlock.js +70 -15
- package/esm/_internal/GenericBlock.js.map +1 -1
- package/esm/_internal/Icon2.js.map +1 -1
- package/esm/_internal/ImageBlock.js.map +1 -1
- package/esm/_internal/InputHelper.js.map +1 -1
- package/esm/_internal/InputLabel.js.map +1 -1
- package/esm/_internal/Lightbox2.js +1 -1
- package/esm/_internal/Lightbox2.js.map +1 -1
- package/esm/_internal/LinkPreview.js.map +1 -1
- package/esm/_internal/Mosaic2.js.map +1 -1
- package/esm/_internal/Notification2.js.map +1 -1
- package/esm/_internal/Popover2.js +1 -1
- package/esm/_internal/Popover2.js.map +1 -1
- package/esm/_internal/PostBlock.js.map +1 -1
- package/esm/_internal/Progress2.js.map +1 -1
- package/esm/_internal/RadioGroup.js.map +1 -1
- package/esm/_internal/SelectMultiple.js.map +1 -1
- package/esm/_internal/SideNavigationItem.js.map +1 -1
- package/esm/_internal/SkeletonTypography.js.map +1 -1
- package/esm/_internal/Slider2.js.map +1 -1
- package/esm/_internal/Slides.js.map +1 -1
- package/esm/_internal/Switch2.js.map +1 -1
- package/esm/_internal/TabPanel.js.map +1 -1
- package/esm/_internal/TableRow.js.map +1 -1
- package/esm/_internal/TextField.js.map +1 -1
- package/esm/_internal/Thumbnail2.js.map +1 -1
- package/esm/_internal/Uploader2.js.map +1 -1
- package/esm/_internal/UserBlock.js.map +1 -1
- package/esm/_internal/_rollupPluginBabelHelpers.js +5 -1
- package/esm/_internal/_rollupPluginBabelHelpers.js.map +1 -1
- package/esm/_internal/generic-block.js +8 -0
- package/esm/_internal/generic-block.js.map +1 -1
- package/esm/_internal/type.js +11 -1
- package/esm/_internal/type.js.map +1 -1
- package/package.json +4 -4
- package/src/components/autocomplete/Autocomplete.tsx +6 -8
- package/src/components/avatar/Avatar.tsx +2 -4
- package/src/components/button/Button.test.tsx +1 -1
- package/src/components/button/ButtonRoot.tsx +3 -4
- package/src/components/button/IconButton.test.tsx +1 -1
- package/src/components/checkbox/Checkbox.tsx +2 -4
- package/src/components/chip/Chip.tsx +2 -4
- package/src/components/comment-block/CommentBlock.tsx +2 -4
- package/src/components/dialog/Dialog.stories.tsx +3 -3
- package/src/components/dialog/Dialog.tsx +11 -4
- package/src/components/divider/Divider.tsx +2 -5
- package/src/components/drag-handle/DragHandle.tsx +2 -5
- package/src/components/dropdown/Dropdown.tsx +4 -3
- package/src/components/expansion-panel/ExpansionPanel.tsx +2 -3
- package/src/components/flag/Flag.tsx +2 -4
- package/src/components/generic-block/GenericBlock.stories.tsx +65 -124
- package/src/components/generic-block/GenericBlock.test.tsx +111 -4
- package/src/components/generic-block/GenericBlock.tsx +107 -18
- package/src/components/icon/Icon.tsx +2 -4
- package/src/components/image-block/ImageBlock.tsx +2 -4
- package/src/components/input-helper/InputHelper.tsx +2 -4
- package/src/components/input-label/InputLabel.tsx +2 -4
- package/src/components/lightbox/Lightbox.tsx +4 -6
- package/src/components/lightbox/__snapshots__/Lightbox.test.tsx.snap +1 -1
- package/src/components/link-preview/LinkPreview.tsx +2 -4
- package/src/components/mosaic/Mosaic.tsx +2 -4
- package/src/components/notification/Notification.tsx +2 -4
- package/src/components/popover/Popover.tsx +1 -1
- package/src/components/popover/__snapshots__/Popover.test.tsx.snap +10 -10
- package/src/components/post-block/PostBlock.tsx +2 -4
- package/src/components/progress/Progress.tsx +2 -4
- package/src/components/radio-button/RadioButton.tsx +2 -4
- package/src/components/select/constants.ts +2 -5
- package/src/components/side-navigation/SideNavigation.tsx +2 -4
- package/src/components/skeleton/SkeletonCircle.tsx +2 -4
- package/src/components/skeleton/SkeletonRectangle.tsx +2 -4
- package/src/components/skeleton/SkeletonTypography.tsx +2 -4
- package/src/components/slider/Slider.tsx +2 -4
- package/src/components/slideshow/Slides.tsx +2 -7
- package/src/components/slideshow/SlideshowControls.tsx +2 -4
- package/src/components/switch/Switch.tsx +2 -4
- package/src/components/table/Table.tsx +2 -4
- package/src/components/tabs/TabList.tsx +2 -4
- package/src/components/text-field/TextField.tsx +6 -8
- package/src/components/thumbnail/Thumbnail.tsx +3 -5
- package/src/components/uploader/Uploader.tsx +2 -4
- package/src/components/user-block/UserBlock.tsx +2 -4
- package/src/hooks/useClickAway.tsx +5 -5
- package/src/testing/utils/commonTestsSuite.ts +2 -2
- package/src/utils/ClickAwayProvider/ClickAwayProvider.stories.jsx +58 -0
- package/src/utils/ClickAwayProvider/ClickAwayProvider.tsx +51 -19
- package/src/utils/type.ts +19 -2
- package/types.d.ts +104 -138
- package/src/components/generic-block/__snapshots__/GenericBlock.test.tsx.snap +0 -92
- 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={
|
|
385
|
-
value={
|
|
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?:
|
|
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
|
|
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
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Reference to the element around which the dropdown is placed.
|
|
15
16
|
* @see {@link PopoverProps#anchorRef}
|
|
16
17
|
*/
|
|
17
|
-
anchorRef:
|
|
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. */
|
|
@@ -1,149 +1,90 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { mdiPencil } from '@lumx/icons';
|
|
3
3
|
import { GenericBlock, Button, Icon, Size, Orientation, Alignment } from '@lumx/react';
|
|
4
|
+
import { HasTheme } from '@lumx/react/utils';
|
|
4
5
|
|
|
5
6
|
export default { title: 'LumX components/generic-block/GenericBlock' };
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
const redBorderStyle = { border: '1px solid red' };
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fill sections using props
|
|
12
|
+
*/
|
|
13
|
+
export const SectionsInProps = ({ theme }: HasTheme) => (
|
|
8
14
|
<GenericBlock
|
|
9
|
-
orientation={Orientation.horizontal}
|
|
10
15
|
figure={<Icon icon={mdiPencil} size={Size.m} />}
|
|
11
|
-
actionsProps={{
|
|
12
|
-
|
|
13
|
-
}}
|
|
14
|
-
figureProps={{
|
|
15
|
-
style: { border: '1px solid red' },
|
|
16
|
-
}}
|
|
17
|
-
contentProps={{
|
|
18
|
-
style: { border: '1px solid red' },
|
|
19
|
-
}}
|
|
16
|
+
actionsProps={{ style: redBorderStyle }}
|
|
17
|
+
figureProps={{ style: redBorderStyle }}
|
|
18
|
+
contentProps={{ style: redBorderStyle }}
|
|
20
19
|
actions={<Button theme={theme}>Button</Button>}
|
|
21
20
|
>
|
|
22
21
|
Content
|
|
23
22
|
</GenericBlock>
|
|
24
23
|
);
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
contentProps={{
|
|
39
|
-
style: { border: '1px solid red' },
|
|
40
|
-
}}
|
|
41
|
-
actions={<Button theme={theme}>Centered button</Button>}
|
|
42
|
-
>
|
|
43
|
-
Content
|
|
25
|
+
/**
|
|
26
|
+
* Fill sections using child section components.
|
|
27
|
+
*/
|
|
28
|
+
export const SectionsInChildren = ({ theme }: HasTheme) => (
|
|
29
|
+
<GenericBlock>
|
|
30
|
+
<GenericBlock.Figure style={redBorderStyle}>
|
|
31
|
+
<Icon icon={mdiPencil} size={Size.m} />
|
|
32
|
+
</GenericBlock.Figure>
|
|
33
|
+
<GenericBlock.Content style={redBorderStyle}>Content</GenericBlock.Content>
|
|
34
|
+
<GenericBlock.Actions style={redBorderStyle}>
|
|
35
|
+
<Button theme={theme}>Button</Button>
|
|
36
|
+
</GenericBlock.Actions>
|
|
44
37
|
</GenericBlock>
|
|
45
38
|
);
|
|
46
39
|
|
|
47
|
-
export const
|
|
48
|
-
<GenericBlock
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
style: { border: '1px solid red' },
|
|
57
|
-
}}
|
|
58
|
-
contentProps={{
|
|
59
|
-
style: { border: '1px solid red' },
|
|
60
|
-
}}
|
|
61
|
-
actions={<Button theme={theme}>Centered button</Button>}
|
|
62
|
-
>
|
|
63
|
-
Content
|
|
40
|
+
export const Vertical = ({ theme }: HasTheme) => (
|
|
41
|
+
<GenericBlock orientation={Orientation.vertical}>
|
|
42
|
+
<GenericBlock.Figure style={redBorderStyle}>
|
|
43
|
+
<Icon icon={mdiPencil} size={Size.m} />
|
|
44
|
+
</GenericBlock.Figure>
|
|
45
|
+
<GenericBlock.Content style={redBorderStyle}>Content</GenericBlock.Content>
|
|
46
|
+
<GenericBlock.Actions fillSpace style={redBorderStyle}>
|
|
47
|
+
<Button theme={theme}>Button</Button>
|
|
48
|
+
</GenericBlock.Actions>
|
|
64
49
|
</GenericBlock>
|
|
65
50
|
);
|
|
66
51
|
|
|
67
|
-
export const
|
|
68
|
-
<GenericBlock
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
style: { border: '1px solid red' },
|
|
77
|
-
}}
|
|
78
|
-
contentProps={{
|
|
79
|
-
style: { border: '1px solid red' },
|
|
80
|
-
}}
|
|
81
|
-
actions={<Button theme={theme}>Button</Button>}
|
|
82
|
-
>
|
|
83
|
-
Content
|
|
52
|
+
export const Horizontal = ({ theme }: HasTheme) => (
|
|
53
|
+
<GenericBlock orientation={Orientation.horizontal}>
|
|
54
|
+
<GenericBlock.Figure style={redBorderStyle}>
|
|
55
|
+
<Icon icon={mdiPencil} size={Size.m} />
|
|
56
|
+
</GenericBlock.Figure>
|
|
57
|
+
<GenericBlock.Content style={redBorderStyle}>Content</GenericBlock.Content>
|
|
58
|
+
<GenericBlock.Actions style={redBorderStyle}>
|
|
59
|
+
<Button theme={theme}>Button</Button>
|
|
60
|
+
</GenericBlock.Actions>
|
|
84
61
|
</GenericBlock>
|
|
85
62
|
);
|
|
86
63
|
|
|
87
|
-
export const
|
|
88
|
-
|
|
89
|
-
<GenericBlock
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
style: { border: '1px solid red' },
|
|
99
|
-
}}
|
|
100
|
-
contentProps={{
|
|
101
|
-
style: { border: '1px solid red' },
|
|
102
|
-
}}
|
|
103
|
-
actions={<Button theme={theme}>Button</Button>}
|
|
104
|
-
>
|
|
105
|
-
<h2>Small gap size</h2>
|
|
106
|
-
<p>For small blocks</p>
|
|
107
|
-
</GenericBlock>
|
|
108
|
-
|
|
109
|
-
<GenericBlock
|
|
110
|
-
orientation={Orientation.vertical}
|
|
111
|
-
figure={<Icon icon={mdiPencil} size={Size.m} />}
|
|
112
|
-
gap={Size.big}
|
|
113
|
-
style={{ marginBottom: 40 }}
|
|
114
|
-
actionsProps={{
|
|
115
|
-
style: { border: '1px solid red' },
|
|
116
|
-
}}
|
|
117
|
-
figureProps={{
|
|
118
|
-
style: { border: '1px solid red' },
|
|
119
|
-
}}
|
|
120
|
-
contentProps={{
|
|
121
|
-
style: { border: '1px solid red' },
|
|
122
|
-
}}
|
|
123
|
-
actions={<Button theme={theme}>Button</Button>}
|
|
124
|
-
>
|
|
125
|
-
<h2>Medium gap size</h2>
|
|
126
|
-
<p>For medium blocks</p>
|
|
127
|
-
</GenericBlock>
|
|
64
|
+
export const HorizontalTop = ({ theme }: HasTheme) => (
|
|
65
|
+
<GenericBlock orientation={Orientation.horizontal} hAlign={Alignment.top}>
|
|
66
|
+
<GenericBlock.Figure style={redBorderStyle}>
|
|
67
|
+
<Icon icon={mdiPencil} size={Size.m} />
|
|
68
|
+
</GenericBlock.Figure>
|
|
69
|
+
<GenericBlock.Content style={redBorderStyle}>Content</GenericBlock.Content>
|
|
70
|
+
<GenericBlock.Actions style={redBorderStyle}>
|
|
71
|
+
<Button theme={theme}>Button</Button>
|
|
72
|
+
</GenericBlock.Actions>
|
|
73
|
+
</GenericBlock>
|
|
74
|
+
);
|
|
128
75
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}}
|
|
143
|
-
actions={<Button theme={theme}>Button</Button>}
|
|
144
|
-
>
|
|
145
|
-
<h2>Big gap size</h2>
|
|
146
|
-
<p>For large blocks</p>
|
|
76
|
+
export const GapSizes = ({ theme }: HasTheme) =>
|
|
77
|
+
[Size.regular, Size.big, Size.huge].map((gap) => (
|
|
78
|
+
<GenericBlock key={gap} orientation={Orientation.vertical} gap={gap} style={{ marginBottom: 40 }}>
|
|
79
|
+
<GenericBlock.Figure style={redBorderStyle}>
|
|
80
|
+
<Icon icon={mdiPencil} size={Size.m} />
|
|
81
|
+
</GenericBlock.Figure>
|
|
82
|
+
<GenericBlock.Content style={redBorderStyle}>
|
|
83
|
+
<h2>{gap} gap size</h2>
|
|
84
|
+
<p>block description</p>
|
|
85
|
+
</GenericBlock.Content>
|
|
86
|
+
<GenericBlock.Actions style={redBorderStyle}>
|
|
87
|
+
<Button theme={theme}>Button</Button>
|
|
88
|
+
</GenericBlock.Actions>
|
|
147
89
|
</GenericBlock>
|
|
148
|
-
|
|
149
|
-
);
|
|
90
|
+
));
|
|
@@ -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
|
|
4
|
+
import { commonTestsSuite } from '@lumx/react/testing/utils';
|
|
5
5
|
|
|
6
6
|
import { GenericBlock, GenericBlockProps } from './GenericBlock';
|
|
7
|
-
import * as stories from '../../stories/generated/GenericBlock/Demos.stories';
|
|
8
7
|
|
|
9
8
|
const CLASSNAME = GenericBlock.className as string;
|
|
10
9
|
|
|
@@ -20,7 +19,115 @@ 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
|
-
|
|
22
|
+
it('should render default', () => {
|
|
23
|
+
const wrapper = shallow(<GenericBlock>Content</GenericBlock>);
|
|
24
|
+
|
|
25
|
+
expect(wrapper.prop('gap')).toBe('regular');
|
|
26
|
+
expect(wrapper.prop('hAlign')).toBe('center');
|
|
27
|
+
expect(wrapper.prop('orientation')).toBe('vertical');
|
|
28
|
+
expect(wrapper.prop('vAlign')).toBe('center');
|
|
29
|
+
|
|
30
|
+
const figure = wrapper.find('.lumx-generic-block__figure');
|
|
31
|
+
expect(figure).toBeDefined();
|
|
32
|
+
|
|
33
|
+
const content = wrapper.find('.lumx-generic-block__content');
|
|
34
|
+
expect(content.prop('fillSpace')).toBe(true);
|
|
35
|
+
expect(content.prop('vAlign')).toBe('center');
|
|
36
|
+
expect(content.prop('orientation')).toBe('vertical');
|
|
37
|
+
|
|
38
|
+
const actions = wrapper.find('.lumx-generic-block__actions');
|
|
39
|
+
expect(actions.prop('vAlign')).toBe('center');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should render horizontal', () => {
|
|
43
|
+
const wrapper = shallow(<GenericBlock orientation="horizontal">Content</GenericBlock>);
|
|
44
|
+
|
|
45
|
+
expect(wrapper.prop('gap')).toBe('regular');
|
|
46
|
+
expect(wrapper.prop('hAlign')).toBe('center');
|
|
47
|
+
expect(wrapper.prop('orientation')).toBe('horizontal');
|
|
48
|
+
expect(wrapper.prop('vAlign')).toBe('center');
|
|
49
|
+
|
|
50
|
+
const figure = wrapper.find('.lumx-generic-block__figure');
|
|
51
|
+
expect(figure).toBeDefined();
|
|
52
|
+
|
|
53
|
+
const content = wrapper.find('.lumx-generic-block__content');
|
|
54
|
+
expect(content.prop('fillSpace')).toBe(true);
|
|
55
|
+
expect(content.prop('vAlign')).toBe('left');
|
|
56
|
+
expect(content.prop('orientation')).toBe('vertical');
|
|
57
|
+
|
|
58
|
+
const actions = wrapper.find('.lumx-generic-block__actions');
|
|
59
|
+
expect(actions.prop('vAlign')).toBe('right');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should combine figure props', () => {
|
|
63
|
+
const wrapper = shallow(
|
|
64
|
+
<GenericBlock figure="Figure 1" figureProps={{ className: 'figure1', vAlign: 'left' }}>
|
|
65
|
+
<GenericBlock.Figure className="figure2" fillSpace>
|
|
66
|
+
Figure 2
|
|
67
|
+
</GenericBlock.Figure>
|
|
68
|
+
</GenericBlock>,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const figure = wrapper.find('.lumx-generic-block__figure');
|
|
72
|
+
expect(figure).toHaveClassName('figure1');
|
|
73
|
+
expect(figure).toHaveClassName('figure2');
|
|
74
|
+
expect(figure.prop('fillSpace')).toBe(true);
|
|
75
|
+
expect(figure.prop('vAlign')).toBe('left');
|
|
76
|
+
expect(figure).toHaveText('Figure 1Figure 2');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should combine content props', () => {
|
|
80
|
+
const wrapper = shallow(
|
|
81
|
+
<GenericBlock contentProps={{ className: 'content1', vAlign: 'left' }}>
|
|
82
|
+
Content 1
|
|
83
|
+
<GenericBlock.Content className="content2" fillSpace>
|
|
84
|
+
Content 2
|
|
85
|
+
</GenericBlock.Content>
|
|
86
|
+
</GenericBlock>,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const content = wrapper.find('.lumx-generic-block__content');
|
|
90
|
+
expect(content).toHaveClassName('content1');
|
|
91
|
+
expect(content).toHaveClassName('content2');
|
|
92
|
+
expect(content.prop('fillSpace')).toBe(true);
|
|
93
|
+
expect(content.prop('vAlign')).toBe('left');
|
|
94
|
+
expect(content).toHaveText('Content 2Content 1');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should combine actions props', () => {
|
|
98
|
+
const wrapper = shallow(
|
|
99
|
+
<GenericBlock actions="Actions 1" actionsProps={{ className: 'actions1', vAlign: 'left' }}>
|
|
100
|
+
<GenericBlock.Actions className="actions2" fillSpace>
|
|
101
|
+
Actions 2
|
|
102
|
+
</GenericBlock.Actions>
|
|
103
|
+
</GenericBlock>,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const actions = wrapper.find('.lumx-generic-block__actions');
|
|
107
|
+
expect(actions).toHaveClassName('actions1');
|
|
108
|
+
expect(actions).toHaveClassName('actions2');
|
|
109
|
+
expect(actions.prop('fillSpace')).toBe(true);
|
|
110
|
+
expect(actions.prop('vAlign')).toBe('left');
|
|
111
|
+
expect(actions).toHaveText('Actions 1Actions 2');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should forward refs', () => {
|
|
115
|
+
const rootRef = createRef<HTMLDivElement>();
|
|
116
|
+
const figureRef = createRef<HTMLDivElement>();
|
|
117
|
+
const contentRef = createRef<HTMLDivElement>();
|
|
118
|
+
const actionsRef = createRef<HTMLDivElement>();
|
|
119
|
+
shallow(
|
|
120
|
+
<GenericBlock ref={rootRef}>
|
|
121
|
+
<GenericBlock.Figure ref={figureRef} />
|
|
122
|
+
<GenericBlock.Content ref={contentRef} />
|
|
123
|
+
<GenericBlock.Actions ref={actionsRef} />
|
|
124
|
+
</GenericBlock>,
|
|
125
|
+
);
|
|
126
|
+
expect(rootRef.current).toBeDefined();
|
|
127
|
+
expect(figureRef.current).toBeDefined();
|
|
128
|
+
expect(contentRef.current).toBeDefined();
|
|
129
|
+
expect(actionsRef.current).toBeDefined();
|
|
130
|
+
});
|
|
24
131
|
});
|
|
25
132
|
|
|
26
133
|
// Common tests suite.
|