@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,96 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, fireEvent, vi } from 'test-utils';
|
|
3
|
+
import { ToastProps, Toast, Variants } from './Toast';
|
|
4
|
+
|
|
5
|
+
import styles from './Toast.module.scss';
|
|
6
|
+
|
|
7
|
+
const renderComponent = (props: ToastProps) => {
|
|
8
|
+
return render(
|
|
9
|
+
<Toast {...props} className="my-css-class">
|
|
10
|
+
This example content
|
|
11
|
+
</Toast>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('<Toast> component', () => {
|
|
16
|
+
it('should allow for custom class', () => {
|
|
17
|
+
const { container } = renderComponent({});
|
|
18
|
+
|
|
19
|
+
expect(container.firstChild).toHaveClass('my-css-class');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should render as info by default', () => {
|
|
23
|
+
const { container } = renderComponent({});
|
|
24
|
+
|
|
25
|
+
expect(container.firstChild).toHaveClass(styles['toast--info']);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should render as success', () => {
|
|
29
|
+
const { container } = renderComponent({ variant: Variants.Success });
|
|
30
|
+
|
|
31
|
+
expect(container.firstChild).toHaveClass(styles['toast--success']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should render as warning', () => {
|
|
35
|
+
const { container } = renderComponent({ variant: Variants.Warning });
|
|
36
|
+
|
|
37
|
+
expect(container.firstChild).toHaveClass(styles['toast--warning']);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should render as error', () => {
|
|
41
|
+
const { container } = renderComponent({ variant: Variants.Error });
|
|
42
|
+
|
|
43
|
+
expect(container.firstChild).toHaveClass(styles['toast--error']);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should render as notification', () => {
|
|
47
|
+
const { container } = renderComponent({
|
|
48
|
+
variant: Variants.Notification,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(container.firstChild).toHaveClass(styles['toast--notification']);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should render with action button and call action function', () => {
|
|
55
|
+
const handler = vi.fn();
|
|
56
|
+
const { getByText } = renderComponent({
|
|
57
|
+
action: {
|
|
58
|
+
label: 'Example action',
|
|
59
|
+
handler,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(getByText('Example action')).toBeVisible();
|
|
64
|
+
fireEvent.click(getByText('Example action'));
|
|
65
|
+
expect(handler).toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should call action function with onClose function', () => {
|
|
69
|
+
const handler = vi.fn();
|
|
70
|
+
const onClose = vi.fn();
|
|
71
|
+
const { getByText } = renderComponent({
|
|
72
|
+
action: {
|
|
73
|
+
label: 'Example action',
|
|
74
|
+
handler,
|
|
75
|
+
closeOnClick: true,
|
|
76
|
+
},
|
|
77
|
+
onClose,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
fireEvent.click(getByText('Example action'));
|
|
81
|
+
expect(handler).toHaveBeenCalled();
|
|
82
|
+
expect(onClose).toHaveBeenCalled();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should render with close button and call onClose function', () => {
|
|
86
|
+
const onClose = vi.fn();
|
|
87
|
+
const { getByLabelText } = renderComponent({
|
|
88
|
+
removable: true,
|
|
89
|
+
onClose,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(getByLabelText('Close toast')).toBeVisible();
|
|
93
|
+
fireEvent.click(getByLabelText('Close toast'));
|
|
94
|
+
expect(onClose).toHaveBeenCalled();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta, Story } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { ToastProps, Toast as ToastComponent, Variants } from './Toast';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Components/Toast',
|
|
8
|
+
component: ToastComponent,
|
|
9
|
+
parameters: {
|
|
10
|
+
componentSubtitle: `
|
|
11
|
+
Toast is a small message that by default shows up in the top middle of the screen.
|
|
12
|
+
It disappears on its own after a few seconds. It provides a feedback about an operation
|
|
13
|
+
for user.
|
|
14
|
+
`,
|
|
15
|
+
},
|
|
16
|
+
} as ComponentMeta<typeof ToastComponent>;
|
|
17
|
+
|
|
18
|
+
interface IToastArgs extends ToastProps {
|
|
19
|
+
label: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const StoryTemplate: Story<IToastArgs> = (args: IToastArgs) => (
|
|
23
|
+
<div>
|
|
24
|
+
<ToastComponent {...args}>Example text</ToastComponent>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const Toast = StoryTemplate.bind({});
|
|
29
|
+
Toast.args = {};
|
|
30
|
+
|
|
31
|
+
export const SuccessToast = StoryTemplate.bind({});
|
|
32
|
+
SuccessToast.args = {
|
|
33
|
+
variant: Variants.Success,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const WarningToast = StoryTemplate.bind({});
|
|
37
|
+
WarningToast.args = {
|
|
38
|
+
variant: Variants.Warning,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const ErrorToast = StoryTemplate.bind({});
|
|
42
|
+
ErrorToast.args = {
|
|
43
|
+
variant: Variants.Error,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const InfoToast = StoryTemplate.bind({});
|
|
47
|
+
InfoToast.args = {
|
|
48
|
+
variant: Variants.Info,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const NotificationToast = StoryTemplate.bind({});
|
|
52
|
+
NotificationToast.args = {
|
|
53
|
+
variant: Variants.Notification,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const ToastWithActionAndRemovable = StoryTemplate.bind({});
|
|
57
|
+
ToastWithActionAndRemovable.args = {
|
|
58
|
+
action: {
|
|
59
|
+
label: 'Action',
|
|
60
|
+
handler: () => alert('onAction click'),
|
|
61
|
+
},
|
|
62
|
+
removable: true,
|
|
63
|
+
onClose: () => alert('onClose click'),
|
|
64
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
Close,
|
|
6
|
+
Info,
|
|
7
|
+
Warning,
|
|
8
|
+
CheckCircleSolid,
|
|
9
|
+
Error,
|
|
10
|
+
} from '@livechat/design-system-icons/react/material';
|
|
11
|
+
import { Icon, IconSizeName, IconTypeName } from '../Icon';
|
|
12
|
+
|
|
13
|
+
import styles from './Toast.module.scss';
|
|
14
|
+
|
|
15
|
+
const baseClass = 'toast';
|
|
16
|
+
|
|
17
|
+
export const enum Variants {
|
|
18
|
+
Success = 'success',
|
|
19
|
+
Warning = 'warning',
|
|
20
|
+
Error = 'error',
|
|
21
|
+
Info = 'info',
|
|
22
|
+
Notification = 'notification',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ToastAction {
|
|
26
|
+
handler: () => void;
|
|
27
|
+
label: string;
|
|
28
|
+
closeOnClick?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ToastProps {
|
|
32
|
+
action?: ToastAction;
|
|
33
|
+
className?: string;
|
|
34
|
+
removable?: boolean;
|
|
35
|
+
variant?: Variants;
|
|
36
|
+
onClose?: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const IconConfig = {
|
|
40
|
+
[Variants.Success]: {
|
|
41
|
+
source: CheckCircleSolid,
|
|
42
|
+
iconType: IconTypeName.Inverted,
|
|
43
|
+
},
|
|
44
|
+
[Variants.Warning]: {
|
|
45
|
+
source: Warning,
|
|
46
|
+
},
|
|
47
|
+
[Variants.Error]: {
|
|
48
|
+
source: Error,
|
|
49
|
+
iconType: IconTypeName.Inverted,
|
|
50
|
+
},
|
|
51
|
+
[Variants.Info]: {
|
|
52
|
+
source: Info,
|
|
53
|
+
iconType: IconTypeName.Inverted,
|
|
54
|
+
},
|
|
55
|
+
[Variants.Notification]: {
|
|
56
|
+
source: Info,
|
|
57
|
+
iconType: IconTypeName.Link,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const Toast: React.FC<ToastProps> = ({
|
|
62
|
+
action,
|
|
63
|
+
className,
|
|
64
|
+
children,
|
|
65
|
+
removable,
|
|
66
|
+
variant = Variants.Info,
|
|
67
|
+
onClose,
|
|
68
|
+
}) => {
|
|
69
|
+
const mergedClassNames = cx(
|
|
70
|
+
styles[baseClass],
|
|
71
|
+
styles[`${baseClass}--${variant}`],
|
|
72
|
+
className
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const onActionClick = (action: ToastAction) => {
|
|
76
|
+
if (action && action.closeOnClick && onClose) {
|
|
77
|
+
action.handler();
|
|
78
|
+
return onClose();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return action.handler();
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div className={mergedClassNames}>
|
|
86
|
+
<div className={styles[`${baseClass}__icon`]}>
|
|
87
|
+
<Icon {...IconConfig[variant]} />
|
|
88
|
+
</div>
|
|
89
|
+
<div className={styles[`${baseClass}__content`]}>{children}</div>
|
|
90
|
+
{(action || removable) && (
|
|
91
|
+
<div className={styles[`${baseClass}__actions`]}>
|
|
92
|
+
{action && (
|
|
93
|
+
<button
|
|
94
|
+
className={styles[`${baseClass}__actions-custom`]}
|
|
95
|
+
onClick={() => onActionClick(action)}
|
|
96
|
+
>
|
|
97
|
+
{action.label}
|
|
98
|
+
</button>
|
|
99
|
+
)}
|
|
100
|
+
{removable && (
|
|
101
|
+
<div
|
|
102
|
+
className={styles[`${baseClass}__actions-close`]}
|
|
103
|
+
aria-label="Close toast"
|
|
104
|
+
onClick={onClose}
|
|
105
|
+
>
|
|
106
|
+
<Icon
|
|
107
|
+
source={Close}
|
|
108
|
+
size={IconSizeName.Small}
|
|
109
|
+
iconType={
|
|
110
|
+
[Variants.Warning, Variants.Notification].includes(variant)
|
|
111
|
+
? IconTypeName.Primary
|
|
112
|
+
: IconTypeName.Inverted
|
|
113
|
+
}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render } from 'test-utils';
|
|
3
|
+
import { ToastWrapper } from './ToastWrapper';
|
|
4
|
+
|
|
5
|
+
describe('<ToastWrapper> component', () => {
|
|
6
|
+
it('should allow for custom class', () => {
|
|
7
|
+
const { container } = render(
|
|
8
|
+
<ToastWrapper toasts={[]} className="my-css-class" />
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
expect(container.firstChild).toHaveClass('my-css-class');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ToastWrapperProps,
|
|
6
|
+
ToastWrapper as ToastWrapperComponent,
|
|
7
|
+
} from './ToastWrapper';
|
|
8
|
+
import { Variants } from './Toast';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Components/Toast Wrapper',
|
|
12
|
+
component: ToastWrapperComponent,
|
|
13
|
+
parameters: {
|
|
14
|
+
componentSubtitle: `
|
|
15
|
+
You can use ToastWrapper component to position your toasts.
|
|
16
|
+
`,
|
|
17
|
+
},
|
|
18
|
+
} as ComponentMeta<typeof ToastWrapperComponent>;
|
|
19
|
+
|
|
20
|
+
export const ToastWrapper = (args: ToastWrapperProps): React.ReactElement => (
|
|
21
|
+
<div style={{ width: '100%', height: 700, position: 'relative' }}>
|
|
22
|
+
<ToastWrapperComponent {...args} />
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
ToastWrapper.args = {
|
|
27
|
+
fixed: false,
|
|
28
|
+
toasts: [
|
|
29
|
+
{
|
|
30
|
+
id: '1',
|
|
31
|
+
variant: Variants.Success,
|
|
32
|
+
content: <div>First toast with DOM element as content</div>,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: '2',
|
|
36
|
+
variant: Variants.Info,
|
|
37
|
+
content: 'Second toast with string as content and with removable prop',
|
|
38
|
+
removable: true,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: '3',
|
|
42
|
+
variant: Variants.Warning,
|
|
43
|
+
content: 'Third toast with action',
|
|
44
|
+
action: {
|
|
45
|
+
label: 'Action',
|
|
46
|
+
handler: () => alert('Third toast action click'),
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: '4',
|
|
51
|
+
variant: Variants.Error,
|
|
52
|
+
content: 'Fourth toast',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
4
|
+
|
|
5
|
+
import { ToastProps, Toast } from './Toast';
|
|
6
|
+
|
|
7
|
+
import styles from './Toast.module.scss';
|
|
8
|
+
|
|
9
|
+
export enum HorizontalPosition {
|
|
10
|
+
Left = 'left',
|
|
11
|
+
Center = 'center',
|
|
12
|
+
Right = 'right',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export enum VerticalPosition {
|
|
16
|
+
Top = 'top',
|
|
17
|
+
Bottom = 'bottom',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const ANIMATION_TIME = 200;
|
|
21
|
+
|
|
22
|
+
const baseClass = 'toast-wrapper';
|
|
23
|
+
|
|
24
|
+
interface Toast extends ToastProps {
|
|
25
|
+
id: string;
|
|
26
|
+
content: React.ReactElement | string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ToastWrapperProps {
|
|
30
|
+
className?: string;
|
|
31
|
+
toasts: Toast[];
|
|
32
|
+
fixed?: boolean;
|
|
33
|
+
block?: boolean;
|
|
34
|
+
animationType?: string;
|
|
35
|
+
verticalPosition?: VerticalPosition;
|
|
36
|
+
horizontalPosition?: HorizontalPosition;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ToastWrapper: React.FC<ToastWrapperProps> = ({
|
|
40
|
+
className,
|
|
41
|
+
toasts = [],
|
|
42
|
+
fixed = true,
|
|
43
|
+
block = false,
|
|
44
|
+
animationType = 'slide',
|
|
45
|
+
verticalPosition = 'top',
|
|
46
|
+
horizontalPosition = 'center',
|
|
47
|
+
}) => {
|
|
48
|
+
const mergedClassNames = cx(
|
|
49
|
+
styles[baseClass],
|
|
50
|
+
{
|
|
51
|
+
[styles[`${baseClass}--fixed`]]: fixed,
|
|
52
|
+
[styles[`${baseClass}--block`]]: !fixed && block,
|
|
53
|
+
[styles[`${baseClass}--horizontal-${horizontalPosition}`]]:
|
|
54
|
+
horizontalPosition,
|
|
55
|
+
[styles[`${baseClass}--vertical-${verticalPosition}`]]: verticalPosition,
|
|
56
|
+
},
|
|
57
|
+
className
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className={mergedClassNames}>
|
|
62
|
+
<TransitionGroup component={null}>
|
|
63
|
+
{toasts.map(({ id, variant, content, removable, action, onClose }) => (
|
|
64
|
+
<CSSTransition
|
|
65
|
+
key={id}
|
|
66
|
+
classNames={{
|
|
67
|
+
enter: styles[`toast-appear--${animationType}`],
|
|
68
|
+
enterActive: styles[`toast-appear-active--${animationType}`],
|
|
69
|
+
exit: styles[`toast-exit--${animationType}`],
|
|
70
|
+
exitActive: styles[`toast-exit-active--${animationType}`],
|
|
71
|
+
}}
|
|
72
|
+
timeout={ANIMATION_TIME}
|
|
73
|
+
>
|
|
74
|
+
<Toast
|
|
75
|
+
variant={variant}
|
|
76
|
+
onClose={onClose}
|
|
77
|
+
removable={removable}
|
|
78
|
+
action={action}
|
|
79
|
+
>
|
|
80
|
+
{content}
|
|
81
|
+
</Toast>
|
|
82
|
+
</CSSTransition>
|
|
83
|
+
))}
|
|
84
|
+
</TransitionGroup>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
|
|
4
|
+
import styles from './Typography.module.scss';
|
|
5
|
+
|
|
6
|
+
enum sizeToElement {
|
|
7
|
+
xl = 'h1',
|
|
8
|
+
lg = 'h2',
|
|
9
|
+
md = 'h3',
|
|
10
|
+
sm = 'h4',
|
|
11
|
+
xs = 'h5',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type TSize = 'xl' | 'lg' | 'md' | 'sm' | 'xs';
|
|
15
|
+
|
|
16
|
+
interface IProps {
|
|
17
|
+
size?: TSize;
|
|
18
|
+
/** DOM element name that will be rendered */
|
|
19
|
+
as?: string;
|
|
20
|
+
/** Optional custom className */
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const Heading: React.FC<IProps> = ({
|
|
25
|
+
as,
|
|
26
|
+
size = 'md',
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}) => {
|
|
31
|
+
return React.createElement(
|
|
32
|
+
as || sizeToElement[size],
|
|
33
|
+
{ className: cx(styles[`heading-${size}`], className), ...props },
|
|
34
|
+
children
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import cx from 'clsx';
|
|
3
|
+
|
|
4
|
+
import styles from './Typography.module.scss';
|
|
5
|
+
|
|
6
|
+
type TSize = 'md' | 'sm' | 'xs';
|
|
7
|
+
|
|
8
|
+
interface IProps {
|
|
9
|
+
/** DOM element name that will be rendered */
|
|
10
|
+
as?: string;
|
|
11
|
+
size?: TSize;
|
|
12
|
+
/** Optional custom className */
|
|
13
|
+
className?: string;
|
|
14
|
+
caps?: boolean;
|
|
15
|
+
bold?: boolean;
|
|
16
|
+
underline?: boolean;
|
|
17
|
+
strike?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const Text: React.FC<IProps> = ({
|
|
21
|
+
as = 'p',
|
|
22
|
+
size = 'md',
|
|
23
|
+
caps = false,
|
|
24
|
+
bold = false,
|
|
25
|
+
underline = false,
|
|
26
|
+
strike = false,
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}) => {
|
|
31
|
+
const baseClassPrefix = caps ? 'caps' : `paragraph-${size}`;
|
|
32
|
+
|
|
33
|
+
return React.createElement(
|
|
34
|
+
as,
|
|
35
|
+
{
|
|
36
|
+
className: cx(
|
|
37
|
+
{
|
|
38
|
+
[styles[`${baseClassPrefix}`]]: true,
|
|
39
|
+
[styles[`${baseClassPrefix}--bold`]]: bold,
|
|
40
|
+
[styles[`${baseClassPrefix}--strike`]]: strike,
|
|
41
|
+
[styles[`${baseClassPrefix}--underline`]]: underline,
|
|
42
|
+
},
|
|
43
|
+
className
|
|
44
|
+
),
|
|
45
|
+
...props,
|
|
46
|
+
},
|
|
47
|
+
children
|
|
48
|
+
);
|
|
49
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
@mixin heading-xl {
|
|
2
|
+
font-size: 32px;
|
|
3
|
+
font-style: normal;
|
|
4
|
+
font-weight: 600;
|
|
5
|
+
letter-spacing: 0;
|
|
6
|
+
line-height: 40px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@mixin heading-lg {
|
|
10
|
+
font-size: 24px;
|
|
11
|
+
font-style: normal;
|
|
12
|
+
font-weight: 600;
|
|
13
|
+
letter-spacing: 0;
|
|
14
|
+
line-height: 32px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@mixin heading-md {
|
|
18
|
+
font-size: 20px;
|
|
19
|
+
font-style: normal;
|
|
20
|
+
font-weight: 600;
|
|
21
|
+
letter-spacing: 0;
|
|
22
|
+
line-height: 28px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@mixin heading-sm {
|
|
26
|
+
font-size: 18px;
|
|
27
|
+
font-style: normal;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
letter-spacing: 0;
|
|
30
|
+
line-height: 24px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@mixin heading-xs {
|
|
34
|
+
font-size: 16px;
|
|
35
|
+
font-style: normal;
|
|
36
|
+
font-weight: 600;
|
|
37
|
+
letter-spacing: 0;
|
|
38
|
+
line-height: 24px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@mixin caps {
|
|
42
|
+
font-size: 12px;
|
|
43
|
+
font-style: normal;
|
|
44
|
+
font-weight: 400;
|
|
45
|
+
letter-spacing: 0.2px;
|
|
46
|
+
line-height: 20px;
|
|
47
|
+
text-transform: uppercase;
|
|
48
|
+
|
|
49
|
+
&--bold {
|
|
50
|
+
font-weight: 600;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@mixin paragraph-md {
|
|
55
|
+
font-size: 15px;
|
|
56
|
+
font-style: normal;
|
|
57
|
+
font-weight: 400;
|
|
58
|
+
letter-spacing: 0;
|
|
59
|
+
line-height: 22px;
|
|
60
|
+
|
|
61
|
+
&--bold {
|
|
62
|
+
font-weight: 600;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
&--underline {
|
|
66
|
+
text-decoration-line: underline;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&--strike {
|
|
70
|
+
text-decoration-line: line-through;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@mixin paragraph-sm {
|
|
75
|
+
font-size: 14px;
|
|
76
|
+
font-style: normal;
|
|
77
|
+
font-weight: 400;
|
|
78
|
+
letter-spacing: 0;
|
|
79
|
+
line-height: 20px;
|
|
80
|
+
|
|
81
|
+
&--bold {
|
|
82
|
+
font-weight: 600;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@mixin paragraph-xs {
|
|
87
|
+
font-size: 12px;
|
|
88
|
+
font-style: normal;
|
|
89
|
+
font-weight: 400;
|
|
90
|
+
letter-spacing: 0.2px;
|
|
91
|
+
line-height: 16px;
|
|
92
|
+
|
|
93
|
+
&--bold {
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.heading-xl {
|
|
99
|
+
@include heading-xl;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.heading-lg {
|
|
103
|
+
@include heading-lg;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.heading-md {
|
|
107
|
+
@include heading-md;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.heading-sm {
|
|
111
|
+
@include heading-sm;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
.heading-xs {
|
|
115
|
+
@include heading-xs;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.caps {
|
|
119
|
+
@include caps;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.paragraph-md {
|
|
123
|
+
@include paragraph-md;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.paragraph-sm {
|
|
127
|
+
@include paragraph-sm;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.paragraph-xs {
|
|
131
|
+
@include paragraph-xs;
|
|
132
|
+
}
|
package/src/index.scss
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
@use './themes/legacy';
|
|
2
|
+
|
|
3
|
+
*[class^='lc-'] {
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
font-family: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, Segoe UI,
|
|
6
|
+
Helvetica Neue, Arial, sans-serif;
|
|
7
|
+
-webkit-font-smoothing: antialiased;
|
|
8
|
+
-moz-osx-font-smoothing: grayscale;
|
|
9
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import './index.scss';
|
|
2
|
+
|
|
3
|
+
export { DesignTokens } from './themes/designTokens';
|
|
4
|
+
|
|
5
|
+
export * from './components/Alert';
|
|
6
|
+
export * from './components/Badge';
|
|
7
|
+
export * from './components/Button';
|
|
8
|
+
export * from './components/ButtonGroup';
|
|
9
|
+
export * from './components/Card';
|
|
10
|
+
export * from './components/Checkbox';
|
|
11
|
+
export * from './components/FieldDescription';
|
|
12
|
+
export * from './components/FieldError';
|
|
13
|
+
export * from './components/FieldGroup';
|
|
14
|
+
export * from './components/Form';
|
|
15
|
+
export * from './components/FormGroup';
|
|
16
|
+
export * from './components/Icon';
|
|
17
|
+
export * from './components/InputField';
|
|
18
|
+
export * from './components/Link';
|
|
19
|
+
export * from './components/Loader';
|
|
20
|
+
export * from './components/Modal';
|
|
21
|
+
export * from './components/NumericInput';
|
|
22
|
+
export * from './components/Popover';
|
|
23
|
+
export * from './components/Progress';
|
|
24
|
+
export * from './components/PromoBanner';
|
|
25
|
+
export * from './components/RadioButton';
|
|
26
|
+
export * from './components/Switch';
|
|
27
|
+
export * from './components/Tab';
|
|
28
|
+
export * from './components/Tag';
|
|
29
|
+
export * from './components/TagInput';
|
|
30
|
+
export * from './components/TextField';
|
|
31
|
+
export * from './components/Toast';
|
|
32
|
+
export * from './components/Typography';
|