@livechat/design-system-react-components 1.0.0-alpha.2 → 1.0.0-alpha.4
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/.eslintrc +9 -0
- package/.storybook/main.js +20 -0
- package/.storybook/preview-head.html +31 -0
- package/.storybook/preview.js +21 -0
- package/package.json +40 -37
- package/src/components/Alert/Alert.module.scss +88 -0
- package/src/components/Alert/Alert.spec.tsx +78 -0
- package/src/components/Alert/Alert.stories.tsx +73 -0
- package/src/components/Alert/Alert.tsx +94 -0
- package/src/components/Alert/index.ts +1 -0
- package/src/components/Badge/Badge.module.scss +23 -0
- package/src/components/Badge/Badge.spec.tsx +12 -0
- package/src/components/Badge/Badge.stories.tsx +24 -0
- package/src/components/Badge/Badge.tsx +24 -0
- package/src/components/Badge/index.ts +1 -0
- package/src/components/Button/Button.module.scss +257 -0
- package/src/components/Button/Button.spec.tsx +110 -0
- package/src/components/Button/Button.stories.tsx +152 -0
- package/src/components/Button/Button.tsx +88 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/ButtonGroup/ButtonGroup.module.scss +31 -0
- package/src/components/ButtonGroup/ButtonGroup.spec.tsx +61 -0
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +53 -0
- package/src/components/ButtonGroup/ButtonGroup.tsx +75 -0
- package/src/components/ButtonGroup/index.ts +1 -0
- package/src/components/Card/Card.module.scss +31 -0
- package/src/components/Card/Card.spec.tsx +38 -0
- package/src/components/Card/Card.stories.tsx +30 -0
- package/src/components/Card/Card.tsx +34 -0
- package/src/components/Card/index.ts +2 -0
- package/src/components/Checkbox/Checkbox.module.scss +99 -0
- package/src/components/Checkbox/Checkbox.tsx +39 -0
- package/src/components/Checkbox/CheckboxField.spec.tsx +58 -0
- package/src/components/Checkbox/CheckboxField.stories.tsx +30 -0
- package/src/components/Checkbox/CheckboxField.tsx +46 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/FieldDescription/FieldDescription.module.scss +5 -0
- package/src/components/FieldDescription/FieldDescription.tsx +23 -0
- package/src/components/FieldDescription/index.ts +1 -0
- package/src/components/FieldError/FieldError.module.scss +5 -0
- package/src/components/FieldError/FieldError.tsx +23 -0
- package/src/components/FieldError/index.ts +1 -0
- package/src/components/FieldGroup/FieldGroup.module.scss +25 -0
- package/src/components/FieldGroup/FieldGroup.spec.tsx +42 -0
- package/src/components/FieldGroup/FieldGroup.stories.tsx +34 -0
- package/src/components/FieldGroup/FieldGroup.tsx +38 -0
- package/src/components/FieldGroup/index.ts +1 -0
- package/src/components/Form/Form.module.scss +22 -0
- package/src/components/Form/Form.spec.tsx +38 -0
- package/src/components/Form/Form.stories.tsx +42 -0
- package/src/components/Form/Form.tsx +46 -0
- package/src/components/Form/index.ts +2 -0
- package/src/components/FormGroup/FormGroup.module.scss +20 -0
- package/src/components/FormGroup/FormGroup.spec.tsx +34 -0
- package/src/components/FormGroup/FormGroup.stories.tsx +30 -0
- package/src/components/FormGroup/FormGroup.tsx +44 -0
- package/src/components/FormGroup/index.ts +1 -0
- package/src/components/Icon/Icon.module.scss +70 -0
- package/src/components/Icon/Icon.stories.tsx +53 -0
- package/src/components/Icon/Icon.tsx +118 -0
- package/src/components/Icon/index.ts +1 -0
- package/src/components/InputField/InputField.module.scss +37 -0
- package/src/components/InputField/InputField.spec.tsx +53 -0
- package/src/components/InputField/InputField.stories.tsx +73 -0
- package/src/components/InputField/InputField.tsx +72 -0
- package/src/components/InputField/index.ts +1 -0
- package/src/components/Link/Link.module.scss +18 -0
- package/src/components/Link/Link.stories.tsx +17 -0
- package/src/components/Link/Link.tsx +37 -0
- package/src/components/Link/index.ts +1 -0
- package/src/components/Loader/Loader.module.scss +66 -0
- package/src/components/Loader/Loader.spec.tsx +64 -0
- package/src/components/Loader/Loader.stories.tsx +25 -0
- package/src/components/Loader/Loader.tsx +48 -0
- package/src/components/Loader/index.ts +1 -0
- package/src/components/Modal/ActionModal.tsx +37 -0
- package/src/components/Modal/Modal.module.scss +131 -0
- package/src/components/Modal/Modal.stories.tsx +85 -0
- package/src/components/Modal/Modal.tsx +41 -0
- package/src/components/Modal/ModalBase.spec.tsx +58 -0
- package/src/components/Modal/ModalBase.tsx +66 -0
- package/src/components/Modal/ModalCloseButton.tsx +20 -0
- package/src/components/Modal/ModalPortal.tsx +35 -0
- package/src/components/Modal/index.ts +11 -0
- package/src/components/NumericInput/NumericInput.module.scss +110 -0
- package/src/components/NumericInput/NumericInput.spec.tsx +129 -0
- package/src/components/NumericInput/NumericInput.stories.tsx +56 -0
- package/src/components/NumericInput/NumericInput.tsx +161 -0
- package/src/components/NumericInput/NumericInputField.stories.tsx +58 -0
- package/src/components/NumericInput/NumericInputField.tsx +57 -0
- package/src/components/NumericInput/index.ts +2 -0
- package/src/components/Popover/Popover.module.scss +16 -0
- package/src/components/Popover/Popover.spec.tsx +39 -0
- package/src/components/Popover/Popover.stories.css +23 -0
- package/src/components/Popover/Popover.stories.tsx +164 -0
- package/src/components/Popover/Popover.tsx +124 -0
- package/src/components/Popover/index.ts +1 -0
- package/src/components/Progress/ProgressBar.module.scss +48 -0
- package/src/components/Progress/ProgressBar.spec.tsx +33 -0
- package/src/components/Progress/ProgressBar.stories.tsx +23 -0
- package/src/components/Progress/ProgressBar.tsx +62 -0
- package/src/components/Progress/ProgressCircle.module.scss +64 -0
- package/src/components/Progress/ProgressCircle.spec.tsx +34 -0
- package/src/components/Progress/ProgressCircle.stories.tsx +28 -0
- package/src/components/Progress/ProgressCircle.tsx +104 -0
- package/src/components/Progress/constants.ts +23 -0
- package/src/components/Progress/helpers.ts +23 -0
- package/src/components/Progress/index.ts +1 -0
- package/src/components/PromoBanner/PromoBanner.module.scss +121 -0
- package/src/components/PromoBanner/PromoBanner.spec.tsx +119 -0
- package/src/components/PromoBanner/PromoBanner.stories.tsx +125 -0
- package/src/components/PromoBanner/PromoBanner.tsx +99 -0
- package/src/components/PromoBanner/index.ts +1 -0
- package/src/components/RadioButton/RadioButton.module.scss +100 -0
- package/src/components/RadioButton/RadioButton.spec.tsx +70 -0
- package/src/components/RadioButton/RadioButton.stories.tsx +34 -0
- package/src/components/RadioButton/RadioButton.tsx +54 -0
- package/src/components/RadioButton/index.ts +1 -0
- package/src/components/Switch/Switch.module.scss +126 -0
- package/src/components/Switch/Switch.spec.tsx +40 -0
- package/src/components/Switch/Switch.stories.tsx +23 -0
- package/src/components/Switch/Switch.tsx +100 -0
- package/src/components/Switch/index.ts +1 -0
- package/src/components/Tab/Tab.module.scss +56 -0
- package/src/components/Tab/Tab.spec.tsx +34 -0
- package/src/components/Tab/Tab.stories.tsx +20 -0
- package/src/components/Tab/Tab.tsx +49 -0
- package/src/components/Tab/TabsWrapper.module.scss +11 -0
- package/src/components/Tab/TabsWrapper.spec.tsx +19 -0
- package/src/components/Tab/TabsWrapper.stories.tsx +46 -0
- package/src/components/Tab/TabsWrapper.tsx +24 -0
- package/src/components/Tab/index.ts +2 -0
- package/src/components/Tag/Tag.module.scss +131 -0
- package/src/components/Tag/Tag.spec.tsx +93 -0
- package/src/components/Tag/Tag.stories.tsx +151 -0
- package/src/components/Tag/Tag.tsx +129 -0
- package/src/components/Tag/index.ts +1 -0
- package/src/components/TagInput/EditableTag.tsx +54 -0
- package/src/components/TagInput/EditableTagContent.tsx +81 -0
- package/src/components/TagInput/EmailTagInput.tsx +31 -0
- package/src/components/TagInput/TagInput.module.scss +81 -0
- package/src/components/TagInput/TagInput.spec.tsx +58 -0
- package/src/components/TagInput/TagInput.stories.tsx +49 -0
- package/src/components/TagInput/TagInput.tsx +133 -0
- package/src/components/TagInput/index.ts +4 -0
- package/src/components/TextField/TextField.module.scss +90 -0
- package/src/components/TextField/TextField.spec.tsx +40 -0
- package/src/components/TextField/TextField.stories.tsx +60 -0
- package/src/components/TextField/TextField.tsx +100 -0
- package/src/components/TextField/index.ts +1 -0
- package/src/components/Toast/Toast.module.scss +218 -0
- package/src/components/Toast/Toast.spec.tsx +96 -0
- package/src/components/Toast/Toast.stories.tsx +64 -0
- package/src/components/Toast/Toast.tsx +121 -0
- package/src/components/Toast/ToastWrapper.spec.tsx +13 -0
- package/src/components/Toast/ToastWrapper.stories.tsx +55 -0
- package/src/components/Toast/ToastWrapper.tsx +87 -0
- package/src/components/Toast/index.ts +2 -0
- package/src/components/Typography/Heading.tsx +36 -0
- package/src/components/Typography/Text.tsx +49 -0
- package/src/components/Typography/Typography.module.scss +132 -0
- package/src/components/Typography/index.ts +2 -0
- package/src/index.scss +9 -0
- package/src/index.ts +32 -0
- package/src/stories/ColorTokens.stories.mdx +10 -0
- package/src/stories/Icons.stories.mdx +12 -0
- package/src/stories/Typography.stories.mdx +65 -0
- package/src/stories/components/ColorTokens.tsx +99 -0
- package/src/stories/components/IconsShowcase.tsx +25 -0
- package/src/stories/components/iconsShowcase.css +13 -0
- package/src/test/setup.ts +1 -0
- package/{dist/test-utils.d.ts → src/test/utils.ts} +3 -2
- package/src/themes/dark.scss +127 -0
- package/src/themes/designTokens.ts +126 -0
- package/src/themes/legacy.scss +128 -0
- package/src/themes/light.scss +127 -0
- package/src/utils/keyCodes.ts +12 -0
- package/src/utils/noop.ts +2 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +8 -0
- package/vite.config.ts +44 -0
- package/dist/components/Alert.d.ts +0 -19
- package/dist/components/Alert.spec.d.ts +0 -1
- package/dist/components/Badge.d.ts +0 -6
- package/dist/components/Badge.spec.d.ts +0 -1
- package/dist/components/Button.d.ts +0 -13
- package/dist/components/Button.spec.d.ts +0 -1
- package/dist/components/ButtonGroup.d.ts +0 -11
- package/dist/components/ButtonGroup.spec.d.ts +0 -1
- package/dist/components/Card.d.ts +0 -6
- package/dist/components/Card.spec.d.ts +0 -1
- package/dist/components/Checkbox.d.ts +0 -7
- package/dist/components/CheckboxField.d.ts +0 -7
- package/dist/components/CheckboxField.spec.d.ts +0 -1
- package/dist/components/FieldDescription.d.ts +0 -3
- package/dist/components/FieldError.d.ts +0 -3
- package/dist/components/FieldGroup.d.ts +0 -8
- package/dist/components/FieldGroup.spec.d.ts +0 -1
- package/dist/components/FieldLabel.d.ts +0 -3
- package/dist/components/Form.d.ts +0 -7
- package/dist/components/Form.spec.d.ts +0 -1
- package/dist/components/FormGroup.d.ts +0 -7
- package/dist/components/FormGroup.spec.d.ts +0 -1
- package/dist/components/Heading.d.ts +0 -11
- package/dist/components/Icon.d.ts +0 -69
- package/dist/components/Loader.d.ts +0 -10
- package/dist/components/Loader.spec.d.ts +0 -1
- package/dist/components/Modal/ActionModal.d.ts +0 -8
- package/dist/components/Modal/Modal.d.ts +0 -7
- package/dist/components/Modal/ModalBase.d.ts +0 -6
- package/dist/components/Modal/ModalBase.spec.d.ts +0 -1
- package/dist/components/Modal/ModalCloseButton.d.ts +0 -3
- package/dist/components/Modal/ModalPortal.d.ts +0 -7
- package/dist/components/ProgressBar.d.ts +0 -9
- package/dist/components/ProgressBar.spec.d.ts +0 -1
- package/dist/components/ProgressCircle.d.ts +0 -9
- package/dist/components/ProgressCircle.spec.d.ts +0 -1
- package/dist/components/PromoBanner.d.ts +0 -19
- package/dist/components/PromoBanner.spec.d.ts +0 -1
- package/dist/components/RadioButton.d.ts +0 -7
- package/dist/components/RadioButton.spec.d.ts +0 -1
- package/dist/components/Switch.d.ts +0 -17
- package/dist/components/Switch.spec.d.ts +0 -1
- package/dist/components/Tab.d.ts +0 -12
- package/dist/components/Tab.spec.d.ts +0 -1
- package/dist/components/TabsWrapper.d.ts +0 -3
- package/dist/components/TabsWrapper.spec.d.ts +0 -1
- package/dist/components/Text.d.ts +0 -15
- package/dist/components/Toast.d.ts +0 -22
- package/dist/components/Toast.spec.d.ts +0 -1
- package/dist/components/ToastWrapper.d.ts +0 -26
- package/dist/components/ToastWrapper.spec.d.ts +0 -1
- package/dist/components/constants.d.ts +0 -12
- package/dist/components/helpers.d.ts +0 -3
- package/dist/constants/keyCodes.d.ts +0 -3
- package/dist/index.css +0 -2
- package/dist/index.css.map +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -2
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/stories/Alert.stories.d.ts +0 -14
- package/dist/stories/Badge.stories.d.ts +0 -16
- package/dist/stories/Button.stories.d.ts +0 -20
- package/dist/stories/ButtonGroup.stories.d.ts +0 -18
- package/dist/stories/Card.stories.d.ts +0 -10
- package/dist/stories/CheckboxField.stories.d.ts +0 -9
- package/dist/stories/FieldGroup.stories.d.ts +0 -9
- package/dist/stories/Form.stories.d.ts +0 -6
- package/dist/stories/FormGroup.stories.d.ts +0 -9
- package/dist/stories/Icon.stories.d.ts +0 -14
- package/dist/stories/Loader.stories.d.ts +0 -8
- package/dist/stories/Modal.stories.d.ts +0 -19
- package/dist/stories/ProgressCircle.stories.d.ts +0 -13
- package/dist/stories/Progressbar.stories.d.ts +0 -13
- package/dist/stories/PromoBanner.stories.d.ts +0 -13
- package/dist/stories/RadioButton.stories.d.ts +0 -9
- package/dist/stories/Switch.stories.d.ts +0 -12
- package/dist/stories/Tab.stories.d.ts +0 -10
- package/dist/stories/TabsWrapper.stories.d.ts +0 -15
- package/dist/stories/Toast.stories.d.ts +0 -15
- package/dist/stories/ToastWrapper.stories.d.ts +0 -40
- package/dist/stories/foundations/components/ColorTokens.d.ts +0 -2
- package/dist/stories/foundations/components/IconsShowcase.d.ts +0 -6
- package/dist/utils/noop.d.ts +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
import { Error } from '@livechat/design-system-icons/react/material';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Modal as ModalComponent,
|
|
7
|
+
ModalProps,
|
|
8
|
+
ActionModal as ActionModalComponent,
|
|
9
|
+
ActionModalProps,
|
|
10
|
+
ModalPortal as ModalPortalComponent,
|
|
11
|
+
ModalPortalProps,
|
|
12
|
+
ModalBase,
|
|
13
|
+
} from './index';
|
|
14
|
+
import { Button } from '../Button';
|
|
15
|
+
import { Icon, IconSizeName } from '../Icon';
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
title: 'Components/Modal',
|
|
19
|
+
component: ModalComponent,
|
|
20
|
+
} as ComponentMeta<typeof ModalComponent>;
|
|
21
|
+
|
|
22
|
+
export const Modal = ({
|
|
23
|
+
children,
|
|
24
|
+
...args
|
|
25
|
+
}: ModalProps): React.ReactElement => (
|
|
26
|
+
<ModalComponent {...args}>{children}</ModalComponent>
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
Modal.args = {
|
|
30
|
+
heading: 'Modal',
|
|
31
|
+
children: 'Modal content',
|
|
32
|
+
closeOnEscPress: true,
|
|
33
|
+
style: { width: '600px', height: '400px' },
|
|
34
|
+
footer: (
|
|
35
|
+
<React.Fragment>
|
|
36
|
+
<Button size="medium" kind="secondary" style={{ marginRight: '8px' }}>
|
|
37
|
+
Secondary
|
|
38
|
+
</Button>
|
|
39
|
+
<Button kind="primary" size="medium">
|
|
40
|
+
Primary
|
|
41
|
+
</Button>
|
|
42
|
+
</React.Fragment>
|
|
43
|
+
),
|
|
44
|
+
} as ModalProps;
|
|
45
|
+
|
|
46
|
+
export const ActionModal = ({
|
|
47
|
+
children,
|
|
48
|
+
...args
|
|
49
|
+
}: ActionModalProps): React.ReactElement => (
|
|
50
|
+
<ActionModalComponent {...args}>{children}</ActionModalComponent>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
ActionModal.args = {
|
|
54
|
+
heading: 'Danger! Danger!',
|
|
55
|
+
style: { width: '410px' },
|
|
56
|
+
closeOnEscPress: true,
|
|
57
|
+
children:
|
|
58
|
+
'You’re about to do something that cannot be undone. Are you sure you want to continue?',
|
|
59
|
+
actions: (
|
|
60
|
+
<React.Fragment>
|
|
61
|
+
<Button size="medium" kind="secondary" style={{ marginRight: '8px' }}>
|
|
62
|
+
Wait, go back
|
|
63
|
+
</Button>
|
|
64
|
+
<Button kind="destructive" size="medium">
|
|
65
|
+
Yes, delete
|
|
66
|
+
</Button>
|
|
67
|
+
</React.Fragment>
|
|
68
|
+
),
|
|
69
|
+
icon: <Icon source={Error} size={IconSizeName.XLarge} />,
|
|
70
|
+
} as ActionModalProps;
|
|
71
|
+
|
|
72
|
+
export const ModalPortal = ({
|
|
73
|
+
children,
|
|
74
|
+
...args
|
|
75
|
+
}: ModalPortalProps): React.ReactElement => (
|
|
76
|
+
<ModalPortalComponent {...args}>{children}</ModalPortalComponent>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
ModalPortal.args = {
|
|
80
|
+
children: (
|
|
81
|
+
<ModalBase onClose={() => ({})} style={{ width: '600px', height: '400px' }}>
|
|
82
|
+
<div style={{ margin: 'auto' }}>Modal Portal content</div>
|
|
83
|
+
</ModalBase>
|
|
84
|
+
),
|
|
85
|
+
} as ModalPortalProps;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
import { ModalBaseProps, ModalBase } from './ModalBase';
|
|
4
|
+
import { Heading } from '../Typography';
|
|
5
|
+
|
|
6
|
+
import styles from './Modal.module.scss';
|
|
7
|
+
|
|
8
|
+
export interface ModalProps extends ModalBaseProps {
|
|
9
|
+
heading?: React.ReactNode;
|
|
10
|
+
footer?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const baseClass = 'modal';
|
|
14
|
+
|
|
15
|
+
export const Modal: React.FC<ModalProps> = ({
|
|
16
|
+
children,
|
|
17
|
+
className = '',
|
|
18
|
+
heading,
|
|
19
|
+
footer,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const mergedClassNames = cx(styles[baseClass], className);
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<ModalBase className={mergedClassNames} {...props}>
|
|
26
|
+
{heading && (
|
|
27
|
+
<div className={styles[`${baseClass}__header`]}>
|
|
28
|
+
<Heading
|
|
29
|
+
size="sm"
|
|
30
|
+
as="div"
|
|
31
|
+
className={styles[`${baseClass}__heading`]}
|
|
32
|
+
>
|
|
33
|
+
{heading}
|
|
34
|
+
</Heading>
|
|
35
|
+
</div>
|
|
36
|
+
)}
|
|
37
|
+
<div className={styles[`${baseClass}__body`]}>{children}</div>
|
|
38
|
+
{footer && <div className={styles[`${baseClass}__footer`]}>{footer}</div>}
|
|
39
|
+
</ModalBase>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
3
|
+
import { render, vi } from 'test-utils';
|
|
4
|
+
import { ModalBase } from './ModalBase';
|
|
5
|
+
|
|
6
|
+
describe('<ModalBase /> component', () => {
|
|
7
|
+
it('should allow for custom class', () => {
|
|
8
|
+
const onClose = vi.fn();
|
|
9
|
+
const { container } = render(
|
|
10
|
+
<ModalBase onClose={onClose} className="my-css-class">
|
|
11
|
+
test
|
|
12
|
+
</ModalBase>
|
|
13
|
+
);
|
|
14
|
+
expect(container.firstChild?.firstChild).toHaveClass('my-css-class');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should call onClose method on overlay click', () => {
|
|
18
|
+
const onClose = vi.fn();
|
|
19
|
+
const { queryByTestId } = render(
|
|
20
|
+
<ModalBase onClose={onClose}>test</ModalBase>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const overlay = queryByTestId('lc-modal-overlay');
|
|
24
|
+
|
|
25
|
+
if (overlay) {
|
|
26
|
+
userEvent.click(overlay);
|
|
27
|
+
}
|
|
28
|
+
expect(onClose).toBeCalledTimes(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should call onClose method on close modal button press', () => {
|
|
32
|
+
const onClose = vi.fn();
|
|
33
|
+
const { getByRole } = render(<ModalBase onClose={onClose}>test</ModalBase>);
|
|
34
|
+
|
|
35
|
+
userEvent.click(getByRole('button'));
|
|
36
|
+
expect(onClose).toBeCalledTimes(1);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should call onClose on escape button pressed by default', () => {
|
|
40
|
+
const onClose = vi.fn();
|
|
41
|
+
render(<ModalBase onClose={onClose}>test</ModalBase>);
|
|
42
|
+
|
|
43
|
+
userEvent.keyboard('[Escape]');
|
|
44
|
+
expect(onClose).toBeCalledTimes(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should not call onClose on escape button pressed when closeOnEscPress is disabled', () => {
|
|
48
|
+
const onClose = vi.fn();
|
|
49
|
+
render(
|
|
50
|
+
<ModalBase onClose={onClose} closeOnEscPress={false}>
|
|
51
|
+
test
|
|
52
|
+
</ModalBase>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
userEvent.keyboard('[Escape]');
|
|
56
|
+
expect(onClose).not.toBeCalled();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
import { ModalCloseButton } from './ModalCloseButton';
|
|
4
|
+
import { KeyCodes } from '../../utils/keyCodes';
|
|
5
|
+
|
|
6
|
+
import styles from './Modal.module.scss';
|
|
7
|
+
|
|
8
|
+
export interface ModalBaseProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
onClose(): void;
|
|
10
|
+
closeOnEscPress?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const baseClass = 'modal-base';
|
|
14
|
+
|
|
15
|
+
export const ModalBase: React.FC<ModalBaseProps> = ({
|
|
16
|
+
children,
|
|
17
|
+
className = '',
|
|
18
|
+
onClose,
|
|
19
|
+
closeOnEscPress = true,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const mergedClassNames = cx(styles[baseClass], className);
|
|
23
|
+
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
if (!closeOnEscPress) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const onKeyUp = (event: KeyboardEvent) => {
|
|
30
|
+
if (event.key === KeyCodes.esc) {
|
|
31
|
+
onClose();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
document.addEventListener('keyup', onKeyUp, true);
|
|
36
|
+
return () => document.removeEventListener('keyup', onKeyUp, true);
|
|
37
|
+
}, [closeOnEscPress]);
|
|
38
|
+
|
|
39
|
+
const onOverlayClick = (event: React.MouseEvent<HTMLDivElement>) => {
|
|
40
|
+
if (event.target === event.currentTarget) {
|
|
41
|
+
onClose();
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const onCloseButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
event.stopPropagation();
|
|
48
|
+
onClose();
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div
|
|
53
|
+
data-testid="lc-modal-overlay"
|
|
54
|
+
onMouseDown={onOverlayClick}
|
|
55
|
+
className={cx(
|
|
56
|
+
styles[`${baseClass}__overlay`],
|
|
57
|
+
styles[`${baseClass}__overlay--visible`]
|
|
58
|
+
)}
|
|
59
|
+
>
|
|
60
|
+
<div className={mergedClassNames} {...props}>
|
|
61
|
+
<ModalCloseButton onClick={onCloseButtonClick} />
|
|
62
|
+
{children}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Close } from '@livechat/design-system-icons/react/material';
|
|
3
|
+
import { Icon, IconSizeName } from '../Icon';
|
|
4
|
+
|
|
5
|
+
import styles from './Modal.module.scss';
|
|
6
|
+
|
|
7
|
+
export type ModalCloseButtonProps = React.HTMLAttributes<HTMLButtonElement>;
|
|
8
|
+
|
|
9
|
+
export const ModalCloseButton: React.FC<ModalCloseButtonProps> = ({
|
|
10
|
+
onClick,
|
|
11
|
+
}) => (
|
|
12
|
+
<button
|
|
13
|
+
title="Close modal"
|
|
14
|
+
className={styles['modal-base__close']}
|
|
15
|
+
onClick={onClick}
|
|
16
|
+
type="button"
|
|
17
|
+
>
|
|
18
|
+
<Icon source={Close} size={IconSizeName.Large} />
|
|
19
|
+
</button>
|
|
20
|
+
);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as ReactDOM from 'react-dom';
|
|
3
|
+
|
|
4
|
+
export interface ModalPortalProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
zIndex: number;
|
|
7
|
+
parentElementName: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const ModalPortal: React.FC<ModalPortalProps> = ({
|
|
11
|
+
children,
|
|
12
|
+
className = '',
|
|
13
|
+
parentElementName = 'body',
|
|
14
|
+
zIndex,
|
|
15
|
+
}) => {
|
|
16
|
+
const [container] = React.useState(() => document.createElement('div'));
|
|
17
|
+
|
|
18
|
+
if (className) {
|
|
19
|
+
container.classList.add(className);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (zIndex) {
|
|
23
|
+
container.style.zIndex = zIndex.toString();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
document.querySelector(parentElementName)?.appendChild(container);
|
|
28
|
+
return () => {
|
|
29
|
+
document.querySelector(parentElementName)?.removeChild(container);
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
// Fragment added to fix TS complaining about createPortal any type
|
|
34
|
+
return <>{ReactDOM.createPortal(children, container)}</>;
|
|
35
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { ActionModal } from './ActionModal';
|
|
2
|
+
export { Modal } from './Modal';
|
|
3
|
+
export { ModalBase } from './ModalBase';
|
|
4
|
+
export { ModalCloseButton } from './ModalCloseButton';
|
|
5
|
+
export { ModalPortal } from './ModalPortal';
|
|
6
|
+
|
|
7
|
+
export type { ActionModalProps } from './ActionModal';
|
|
8
|
+
export type { ModalProps } from './Modal';
|
|
9
|
+
export type { ModalBaseProps } from './ModalBase';
|
|
10
|
+
export type { ModalCloseButtonProps } from './ModalCloseButton';
|
|
11
|
+
export type { ModalPortalProps } from './ModalPortal';
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
.numeric-input {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
height: 36px;
|
|
4
|
+
position: relative;
|
|
5
|
+
width: 64px;
|
|
6
|
+
|
|
7
|
+
&__increment,
|
|
8
|
+
&__decrement {
|
|
9
|
+
align-items: center;
|
|
10
|
+
background: transparent;
|
|
11
|
+
border: 0;
|
|
12
|
+
border-left: 1px solid var(--border-default);
|
|
13
|
+
box-sizing: border-box;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
display: flex;
|
|
16
|
+
height: 50%;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
padding: 0;
|
|
19
|
+
position: absolute;
|
|
20
|
+
right: 1px;
|
|
21
|
+
top: 1px;
|
|
22
|
+
width: 23px;
|
|
23
|
+
|
|
24
|
+
&:hover,
|
|
25
|
+
&:focus {
|
|
26
|
+
outline: 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
& &__increment {
|
|
31
|
+
&:disabled {
|
|
32
|
+
border-color: var(--border-disabled);
|
|
33
|
+
cursor: not-allowed;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
& &__decrement {
|
|
38
|
+
border-top: 1px solid var(--border-default);
|
|
39
|
+
bottom: 1px;
|
|
40
|
+
top: auto;
|
|
41
|
+
|
|
42
|
+
&:disabled {
|
|
43
|
+
border-color: var(--border-disabled);
|
|
44
|
+
cursor: not-allowed;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
input {
|
|
49
|
+
appearance: textfield;
|
|
50
|
+
background-clip: padding-box;
|
|
51
|
+
border: 1px solid var(--border-default);
|
|
52
|
+
border-radius: 4px;
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
color: var(--content-default);
|
|
55
|
+
height: 100%;
|
|
56
|
+
line-height: 36px;
|
|
57
|
+
padding: 0 28px 0 4px;
|
|
58
|
+
text-align: right;
|
|
59
|
+
transition: border 0.25s ease-in-out;
|
|
60
|
+
width: 100%;
|
|
61
|
+
will-change: border-color;
|
|
62
|
+
|
|
63
|
+
&::-webkit-outer-spin-button,
|
|
64
|
+
&::-webkit-inner-spin-button {
|
|
65
|
+
appearance: none;
|
|
66
|
+
margin: 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&:hover {
|
|
70
|
+
border-color: var(--border-hover);
|
|
71
|
+
outline: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&:focus {
|
|
75
|
+
border-color: var(--color-action-default);
|
|
76
|
+
outline: 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&:disabled {
|
|
80
|
+
color: var(--content-disabled);
|
|
81
|
+
cursor: not-allowed;
|
|
82
|
+
|
|
83
|
+
&:hover {
|
|
84
|
+
border-color: var(--border-disabled);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&--disabled {
|
|
90
|
+
background-color: var(--surface-basic-disabled);
|
|
91
|
+
color: var(--content-default);
|
|
92
|
+
cursor: not-allowed;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&.numeric-input--no-controls {
|
|
96
|
+
input {
|
|
97
|
+
padding: 0 4px;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
&.numeric-input--error {
|
|
102
|
+
input {
|
|
103
|
+
&,
|
|
104
|
+
&:hover,
|
|
105
|
+
&:focus {
|
|
106
|
+
border-color: var(--color-negative-default);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, fireEvent, vi } from 'test-utils';
|
|
3
|
+
import noop from '../../utils/noop';
|
|
4
|
+
import { NumericInputProps, NumericInput } from './NumericInput';
|
|
5
|
+
|
|
6
|
+
const renderComponent = (props: Partial<NumericInputProps>) => {
|
|
7
|
+
const finalProps = Object.assign(
|
|
8
|
+
{},
|
|
9
|
+
{ onChange: noop },
|
|
10
|
+
props
|
|
11
|
+
) as NumericInputProps;
|
|
12
|
+
return render(<NumericInput {...finalProps} className="my-css-class" />);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('<NumericInput> component', () => {
|
|
16
|
+
it('should allow for custom class', () => {
|
|
17
|
+
const { container } = renderComponent({
|
|
18
|
+
value: '0',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(container.firstChild).toHaveClass('my-css-class');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should display buttons by default', () => {
|
|
25
|
+
const { queryByRole } = renderComponent({
|
|
26
|
+
value: '0',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
expect(
|
|
30
|
+
queryByRole('button', {
|
|
31
|
+
name: /Increment value/i,
|
|
32
|
+
})
|
|
33
|
+
).toBeVisible();
|
|
34
|
+
|
|
35
|
+
expect(
|
|
36
|
+
queryByRole('button', {
|
|
37
|
+
name: /Decrement value/i,
|
|
38
|
+
})
|
|
39
|
+
).toBeVisible();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should not display buttons', () => {
|
|
43
|
+
const { queryByRole } = renderComponent({
|
|
44
|
+
value: '0',
|
|
45
|
+
noControls: true,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(
|
|
49
|
+
queryByRole('button', {
|
|
50
|
+
name: /Increment value/i,
|
|
51
|
+
})
|
|
52
|
+
).toBeFalsy();
|
|
53
|
+
|
|
54
|
+
expect(
|
|
55
|
+
queryByRole('button', {
|
|
56
|
+
name: /Decrement value/i,
|
|
57
|
+
})
|
|
58
|
+
).toBeFalsy();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('all elements should be disabled', () => {
|
|
62
|
+
const { queryByRole } = renderComponent({
|
|
63
|
+
value: '0',
|
|
64
|
+
disabled: true,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(queryByRole('textbox')).toBeDisabled();
|
|
68
|
+
|
|
69
|
+
expect(
|
|
70
|
+
queryByRole('button', {
|
|
71
|
+
name: /Increment value/i,
|
|
72
|
+
})
|
|
73
|
+
).toBeDisabled();
|
|
74
|
+
|
|
75
|
+
expect(
|
|
76
|
+
queryByRole('button', {
|
|
77
|
+
name: /Decrement value/i,
|
|
78
|
+
})
|
|
79
|
+
).toBeDisabled();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should call onChange when button click', () => {
|
|
83
|
+
const onChange = vi.fn();
|
|
84
|
+
const { getByRole } = renderComponent({
|
|
85
|
+
value: '0',
|
|
86
|
+
onChange,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
fireEvent.click(
|
|
90
|
+
getByRole('button', {
|
|
91
|
+
name: /Increment value/i,
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
95
|
+
|
|
96
|
+
fireEvent.click(
|
|
97
|
+
getByRole('button', {
|
|
98
|
+
name: /Decrement value/i,
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
expect(onChange).toHaveBeenCalledTimes(2);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('should disable Increment button when limit reached', () => {
|
|
105
|
+
const { getByRole } = renderComponent({
|
|
106
|
+
value: '10',
|
|
107
|
+
max: 10,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(
|
|
111
|
+
getByRole('button', {
|
|
112
|
+
name: /Increment value/i,
|
|
113
|
+
})
|
|
114
|
+
).toBeDisabled();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should disable Decrement button when limit reached', () => {
|
|
118
|
+
const { getByRole } = renderComponent({
|
|
119
|
+
value: '-10',
|
|
120
|
+
min: -10,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(
|
|
124
|
+
getByRole('button', {
|
|
125
|
+
name: /Decrement value/i,
|
|
126
|
+
})
|
|
127
|
+
).toBeDisabled();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta, Story } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
NumericInputProps,
|
|
6
|
+
NumericInput as NumericInputComponent,
|
|
7
|
+
} from './NumericInput';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Forms (WIP)/NumericInput',
|
|
11
|
+
component: NumericInputComponent,
|
|
12
|
+
argTypes: {
|
|
13
|
+
value: {
|
|
14
|
+
control: {
|
|
15
|
+
disable: true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
} as ComponentMeta<typeof NumericInputComponent>;
|
|
20
|
+
|
|
21
|
+
const StoryTemplate: Story<NumericInputProps> = (args: NumericInputProps) => {
|
|
22
|
+
const [value, setValue] = React.useState('0');
|
|
23
|
+
return (
|
|
24
|
+
<div>
|
|
25
|
+
<NumericInputComponent
|
|
26
|
+
{...args}
|
|
27
|
+
value={value}
|
|
28
|
+
onChange={(v) => setValue(v as string)}
|
|
29
|
+
/>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const NumericInput = StoryTemplate.bind({});
|
|
35
|
+
NumericInput.args = {};
|
|
36
|
+
|
|
37
|
+
export const NumericInputWithMinAndMaxValues = StoryTemplate.bind({});
|
|
38
|
+
NumericInputWithMinAndMaxValues.args = {
|
|
39
|
+
min: -10,
|
|
40
|
+
max: 10,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const NumericInputWithNoControls = StoryTemplate.bind({});
|
|
44
|
+
NumericInputWithNoControls.args = {
|
|
45
|
+
noControls: true,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const NumericInputWithDisabled = StoryTemplate.bind({});
|
|
49
|
+
NumericInputWithDisabled.args = {
|
|
50
|
+
disabled: true,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const NumericInputWithError = StoryTemplate.bind({});
|
|
54
|
+
NumericInputWithError.args = {
|
|
55
|
+
error: 'Error',
|
|
56
|
+
};
|