@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,151 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
import * as MaterialIcons from '@livechat/design-system-icons/react/material';
|
|
4
|
+
|
|
5
|
+
import { Tag as TagComponent, TagProps } from './Tag';
|
|
6
|
+
|
|
7
|
+
const iterator = Object.keys(MaterialIcons);
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
title: 'Components/Tag',
|
|
11
|
+
component: TagComponent,
|
|
12
|
+
argTypes: {
|
|
13
|
+
icon: {
|
|
14
|
+
options: iterator,
|
|
15
|
+
mapping: MaterialIcons,
|
|
16
|
+
control: {
|
|
17
|
+
type: 'select',
|
|
18
|
+
labels: iterator,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
} as ComponentMeta<typeof TagComponent>;
|
|
23
|
+
|
|
24
|
+
export const Tag = ({ children, ...args }: TagProps): React.ReactElement => {
|
|
25
|
+
return <TagComponent {...args}>{children}</TagComponent>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
Tag.args = {
|
|
29
|
+
kind: 'default',
|
|
30
|
+
outline: false,
|
|
31
|
+
size: 'medium',
|
|
32
|
+
children: 'Example tag',
|
|
33
|
+
dismissible: false,
|
|
34
|
+
} as TagProps;
|
|
35
|
+
|
|
36
|
+
const avatar =
|
|
37
|
+
'https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?s=200';
|
|
38
|
+
|
|
39
|
+
export const kinds = ({ children, ...args }: TagProps): React.ReactElement => {
|
|
40
|
+
return (
|
|
41
|
+
<div className="spacer" style={{ display: 'flex' }}>
|
|
42
|
+
<TagComponent {...args} kind="default">
|
|
43
|
+
{children}
|
|
44
|
+
</TagComponent>
|
|
45
|
+
<TagComponent {...args} kind="info">
|
|
46
|
+
{children}
|
|
47
|
+
</TagComponent>
|
|
48
|
+
<TagComponent {...args} kind="warning">
|
|
49
|
+
{children}
|
|
50
|
+
</TagComponent>
|
|
51
|
+
<TagComponent {...args} kind="success">
|
|
52
|
+
{children}
|
|
53
|
+
</TagComponent>
|
|
54
|
+
<TagComponent {...args} kind="error">
|
|
55
|
+
{children}
|
|
56
|
+
</TagComponent>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
kinds.args = {
|
|
62
|
+
children: 'Example tag',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const kindsWithOutline = ({
|
|
66
|
+
children,
|
|
67
|
+
...args
|
|
68
|
+
}: TagProps): React.ReactElement => {
|
|
69
|
+
return (
|
|
70
|
+
<div className="spacer" style={{ display: 'flex' }}>
|
|
71
|
+
<TagComponent {...args} kind="default" outline>
|
|
72
|
+
{children}
|
|
73
|
+
</TagComponent>
|
|
74
|
+
<TagComponent {...args} kind="info" outline>
|
|
75
|
+
{children}
|
|
76
|
+
</TagComponent>
|
|
77
|
+
<TagComponent {...args} kind="warning" outline>
|
|
78
|
+
{children}
|
|
79
|
+
</TagComponent>
|
|
80
|
+
<TagComponent {...args} kind="success" outline>
|
|
81
|
+
{children}
|
|
82
|
+
</TagComponent>
|
|
83
|
+
<TagComponent {...args} kind="error" outline>
|
|
84
|
+
{children}
|
|
85
|
+
</TagComponent>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
kindsWithOutline.args = {
|
|
91
|
+
children: 'Example tag',
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const kindsWithIcon = ({
|
|
95
|
+
children,
|
|
96
|
+
...args
|
|
97
|
+
}: TagProps): React.ReactElement => {
|
|
98
|
+
return (
|
|
99
|
+
<div className="spacer" style={{ display: 'flex' }}>
|
|
100
|
+
<TagComponent {...args} kind="default">
|
|
101
|
+
{children}
|
|
102
|
+
</TagComponent>
|
|
103
|
+
<TagComponent {...args} kind="info">
|
|
104
|
+
{children}
|
|
105
|
+
</TagComponent>
|
|
106
|
+
<TagComponent {...args} kind="warning">
|
|
107
|
+
{children}
|
|
108
|
+
</TagComponent>
|
|
109
|
+
<TagComponent {...args} kind="success">
|
|
110
|
+
{children}
|
|
111
|
+
</TagComponent>
|
|
112
|
+
<TagComponent {...args} kind="error">
|
|
113
|
+
{children}
|
|
114
|
+
</TagComponent>
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
kindsWithIcon.args = {
|
|
120
|
+
children: 'Example tag',
|
|
121
|
+
icon: MaterialIcons.Smiles,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const kindsWithAvatar = ({
|
|
125
|
+
children,
|
|
126
|
+
...args
|
|
127
|
+
}: TagProps): React.ReactElement => {
|
|
128
|
+
return (
|
|
129
|
+
<div className="spacer" style={{ display: 'flex' }}>
|
|
130
|
+
<TagComponent {...args} kind="default" avatar={avatar}>
|
|
131
|
+
{children}
|
|
132
|
+
</TagComponent>
|
|
133
|
+
<TagComponent {...args} kind="info" avatar={avatar}>
|
|
134
|
+
{children}
|
|
135
|
+
</TagComponent>
|
|
136
|
+
<TagComponent {...args} kind="warning" avatar={avatar}>
|
|
137
|
+
{children}
|
|
138
|
+
</TagComponent>
|
|
139
|
+
<TagComponent {...args} kind="success" avatar={avatar}>
|
|
140
|
+
{children}
|
|
141
|
+
</TagComponent>
|
|
142
|
+
<TagComponent {...args} kind="error" avatar={avatar}>
|
|
143
|
+
{children}
|
|
144
|
+
</TagComponent>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
kindsWithAvatar.args = {
|
|
150
|
+
children: 'Example tag',
|
|
151
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Close } from '@livechat/design-system-icons/react/material';
|
|
3
|
+
import cx from 'clsx';
|
|
4
|
+
import { getContrast } from 'polished';
|
|
5
|
+
|
|
6
|
+
import { Text } from '../Typography';
|
|
7
|
+
import { Icon, IconSizeName } from '../Icon';
|
|
8
|
+
|
|
9
|
+
import styles from './Tag.module.scss';
|
|
10
|
+
|
|
11
|
+
const baseClass = 'tag';
|
|
12
|
+
|
|
13
|
+
export interface TagProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
14
|
+
kind?: 'default' | 'info' | 'warning' | 'success' | 'error';
|
|
15
|
+
size?: 'medium' | 'large';
|
|
16
|
+
customColor?: string;
|
|
17
|
+
dismissible?: boolean;
|
|
18
|
+
outline?: boolean;
|
|
19
|
+
onRemove?(): void;
|
|
20
|
+
icon?: React.FC<React.SVGProps<SVGSVGElement>> | string;
|
|
21
|
+
avatar?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const getCustomTextClass = (customColor?: string) => {
|
|
25
|
+
if (!customColor) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
return getContrast(customColor, '#FFFFFF') > 4.5
|
|
29
|
+
? 'text-white'
|
|
30
|
+
: 'text-black';
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const Tag: React.FC<TagProps> = ({
|
|
34
|
+
className = '',
|
|
35
|
+
children,
|
|
36
|
+
dismissible = false,
|
|
37
|
+
size = 'medium',
|
|
38
|
+
kind = 'default',
|
|
39
|
+
onRemove,
|
|
40
|
+
outline = false,
|
|
41
|
+
icon,
|
|
42
|
+
avatar,
|
|
43
|
+
customColor,
|
|
44
|
+
...restProps
|
|
45
|
+
}) => {
|
|
46
|
+
const mergedClassNames = cx(
|
|
47
|
+
styles[baseClass],
|
|
48
|
+
className,
|
|
49
|
+
styles[`${baseClass}--${size}`],
|
|
50
|
+
styles[`${baseClass}--${kind}`],
|
|
51
|
+
{
|
|
52
|
+
[styles[`${baseClass}--dismissible`]]: dismissible,
|
|
53
|
+
[styles[`${baseClass}--outline`]]: outline,
|
|
54
|
+
[styles[`${baseClass}--with-icon`]]: !!icon || !!avatar,
|
|
55
|
+
[styles[`${baseClass}--${getCustomTextClass(customColor)}`]]:
|
|
56
|
+
!!customColor,
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const getCustomColorStyles = () => {
|
|
61
|
+
if (!customColor) {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
if (outline) {
|
|
65
|
+
return {
|
|
66
|
+
style: {
|
|
67
|
+
backgroundColor: 'transparent',
|
|
68
|
+
color: customColor,
|
|
69
|
+
borderColor: customColor,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return { style: { backgroundColor: customColor } };
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const getIconCustomColor = () => {
|
|
77
|
+
if (!customColor) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
if (outline) {
|
|
81
|
+
return customColor;
|
|
82
|
+
}
|
|
83
|
+
return getContrast(customColor, '#FFFFFF') > 4.5 ? '#FFFFFF' : '#000000';
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Text
|
|
88
|
+
className={mergedClassNames}
|
|
89
|
+
{...restProps}
|
|
90
|
+
{...getCustomColorStyles()}
|
|
91
|
+
as="div"
|
|
92
|
+
size="md"
|
|
93
|
+
>
|
|
94
|
+
{avatar && (
|
|
95
|
+
<img
|
|
96
|
+
className={styles[`${baseClass}__avatar`]}
|
|
97
|
+
src={avatar}
|
|
98
|
+
alt="tag-avatar"
|
|
99
|
+
data-testid="lc-tag-avatar"
|
|
100
|
+
/>
|
|
101
|
+
)}{' '}
|
|
102
|
+
{/*TODO replace with Avatar component*/}
|
|
103
|
+
{icon && !avatar && (
|
|
104
|
+
<Icon
|
|
105
|
+
data-testid="lc-tag-icon"
|
|
106
|
+
className={styles[`${baseClass}__icon`]}
|
|
107
|
+
source={icon}
|
|
108
|
+
size={IconSizeName.Small}
|
|
109
|
+
customColor={getIconCustomColor()}
|
|
110
|
+
/>
|
|
111
|
+
)}
|
|
112
|
+
{children}
|
|
113
|
+
{dismissible && (
|
|
114
|
+
<button
|
|
115
|
+
title="Remove"
|
|
116
|
+
onClick={onRemove}
|
|
117
|
+
type="button"
|
|
118
|
+
className={styles[`${baseClass}__remove`]}
|
|
119
|
+
>
|
|
120
|
+
<Icon
|
|
121
|
+
source={Close}
|
|
122
|
+
size={IconSizeName.Medium}
|
|
123
|
+
customColor={getIconCustomColor()}
|
|
124
|
+
/>
|
|
125
|
+
</button>
|
|
126
|
+
)}
|
|
127
|
+
</Text>
|
|
128
|
+
);
|
|
129
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Tag } from './Tag';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { EditableTagContent } from './EditableTagContent';
|
|
3
|
+
import { Tag } from '../Tag';
|
|
4
|
+
|
|
5
|
+
import styles from './TagInput.module.scss';
|
|
6
|
+
|
|
7
|
+
const baseClass = 'tag-input__tag';
|
|
8
|
+
|
|
9
|
+
export interface EditableTagProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
10
|
+
inputRef: React.RefObject<HTMLInputElement>;
|
|
11
|
+
index: number;
|
|
12
|
+
update: (idx: number, value: string) => void;
|
|
13
|
+
remove: (idx: number) => void;
|
|
14
|
+
validator?: (val: string) => boolean;
|
|
15
|
+
children: string;
|
|
16
|
+
size: 'medium' | 'large';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const EditableTag: React.FC<EditableTagProps> = ({
|
|
20
|
+
children,
|
|
21
|
+
index,
|
|
22
|
+
remove,
|
|
23
|
+
validator,
|
|
24
|
+
inputRef,
|
|
25
|
+
update,
|
|
26
|
+
size,
|
|
27
|
+
}) => {
|
|
28
|
+
const isValid = React.useMemo(() => {
|
|
29
|
+
return validator !== undefined ? validator(children) : true;
|
|
30
|
+
}, [children, validator]);
|
|
31
|
+
|
|
32
|
+
const innerEditableRef = React.useRef<HTMLInputElement>(null);
|
|
33
|
+
|
|
34
|
+
const removeTag = () => remove(index);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Tag
|
|
38
|
+
kind={isValid ? 'default' : 'error'}
|
|
39
|
+
dismissible
|
|
40
|
+
size={size}
|
|
41
|
+
onRemove={removeTag}
|
|
42
|
+
>
|
|
43
|
+
<EditableTagContent
|
|
44
|
+
value={children}
|
|
45
|
+
inputRef={inputRef}
|
|
46
|
+
innerEditableRef={innerEditableRef}
|
|
47
|
+
className={styles[`${baseClass}__content`]}
|
|
48
|
+
change={(newValue) => update(index, newValue)}
|
|
49
|
+
remove={removeTag}
|
|
50
|
+
validator={validator}
|
|
51
|
+
/>
|
|
52
|
+
</Tag>
|
|
53
|
+
);
|
|
54
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { KeyCodes } from '../../utils/keyCodes';
|
|
3
|
+
import escape from 'lodash.escape';
|
|
4
|
+
|
|
5
|
+
export interface EditableTagContentProps {
|
|
6
|
+
value: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
innerEditableRef: React.RefObject<HTMLDivElement>;
|
|
9
|
+
inputRef: React.RefObject<HTMLInputElement>;
|
|
10
|
+
change: (value: string) => void;
|
|
11
|
+
remove: () => void;
|
|
12
|
+
validator?: (value: string) => boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const EditableTagContent: React.FC<EditableTagContentProps> = ({
|
|
16
|
+
className = '',
|
|
17
|
+
innerEditableRef,
|
|
18
|
+
inputRef,
|
|
19
|
+
change,
|
|
20
|
+
remove,
|
|
21
|
+
value,
|
|
22
|
+
}) => {
|
|
23
|
+
const [removed, setRemoved] = React.useState(false);
|
|
24
|
+
|
|
25
|
+
const getRef = () => innerEditableRef.current;
|
|
26
|
+
|
|
27
|
+
const getValue = () => {
|
|
28
|
+
const ref = getRef();
|
|
29
|
+
return ref ? ref.innerText : '';
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const focusInputRef = () => {
|
|
33
|
+
if (inputRef && inputRef.current) {
|
|
34
|
+
inputRef.current.focus();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
39
|
+
if (e.key === KeyCodes.enter) {
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
focusInputRef();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (e.key === KeyCodes.backspace && getValue() === '') {
|
|
46
|
+
setRemoved(true);
|
|
47
|
+
remove();
|
|
48
|
+
focusInputRef();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const onBlur = () => {
|
|
53
|
+
const ref = getRef();
|
|
54
|
+
if (removed || !ref) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (ref.innerText === '') {
|
|
58
|
+
remove();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
change(ref.innerText);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const onPaste = (e: React.ClipboardEvent<HTMLDivElement>) => {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
const text = e.clipboardData.getData('text/plain');
|
|
67
|
+
document.execCommand('insertHTML', false, escape(text));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div
|
|
72
|
+
ref={innerEditableRef}
|
|
73
|
+
className={className}
|
|
74
|
+
contentEditable={true}
|
|
75
|
+
onPaste={onPaste}
|
|
76
|
+
onBlur={onBlur}
|
|
77
|
+
onKeyDown={onKeyDown}
|
|
78
|
+
dangerouslySetInnerHTML={{ __html: escape(value) }}
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { TagInputProps, TagInput } from './TagInput';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
export type EmailTagInputProps = Omit<TagInputProps, 'validator'>;
|
|
5
|
+
|
|
6
|
+
export const emailRegex =
|
|
7
|
+
/^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])$/i; // eslint-disable-line no-control-regex
|
|
8
|
+
|
|
9
|
+
const defaultPlaceholder = 'name@company.com';
|
|
10
|
+
const emailValidator = (value: string) => {
|
|
11
|
+
return emailRegex.test(value);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const EmailTagInput: React.FC<EmailTagInputProps> = ({
|
|
15
|
+
tags,
|
|
16
|
+
onChange,
|
|
17
|
+
error,
|
|
18
|
+
placeholder = defaultPlaceholder,
|
|
19
|
+
size,
|
|
20
|
+
}) => {
|
|
21
|
+
return (
|
|
22
|
+
<TagInput
|
|
23
|
+
tags={tags}
|
|
24
|
+
error={error}
|
|
25
|
+
onChange={onChange}
|
|
26
|
+
placeholder={placeholder}
|
|
27
|
+
validator={emailValidator}
|
|
28
|
+
size={size}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
.tag-input {
|
|
2
|
+
align-items: center;
|
|
3
|
+
background-clip: padding-box;
|
|
4
|
+
border: 1px solid var(--border-default);
|
|
5
|
+
border-radius: 4px;
|
|
6
|
+
box-sizing: border-box;
|
|
7
|
+
color: var(--content-default);
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-wrap: wrap;
|
|
10
|
+
font-size: 15px;
|
|
11
|
+
overflow-y: auto;
|
|
12
|
+
padding: 4px;
|
|
13
|
+
transition: border 0.25s ease-in-out;
|
|
14
|
+
width: 100%;
|
|
15
|
+
will-change: border-color;
|
|
16
|
+
|
|
17
|
+
&::placeholder {
|
|
18
|
+
color: var(--content-disabled);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&:hover {
|
|
22
|
+
border-color: var(--border-hover);
|
|
23
|
+
outline: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
&:focus-within {
|
|
27
|
+
border-color: var(--color-action-default);
|
|
28
|
+
outline: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&--error,
|
|
32
|
+
&--error:focus-within {
|
|
33
|
+
border-color: var(--color-negative-default);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&:disabled {
|
|
37
|
+
color: var(--content-disabled);
|
|
38
|
+
cursor: not-allowed;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
* {
|
|
42
|
+
box-sizing: border-box;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
> * {
|
|
46
|
+
margin: 2px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@at-root #{&}__input {
|
|
50
|
+
appearance: none;
|
|
51
|
+
background: transparent;
|
|
52
|
+
border-style: none;
|
|
53
|
+
box-shadow: none;
|
|
54
|
+
color: var(--content-default);
|
|
55
|
+
flex-grow: 1;
|
|
56
|
+
font-size: 15px;
|
|
57
|
+
margin: 0 4px;
|
|
58
|
+
outline: 0;
|
|
59
|
+
padding: 0 0 0 4px;
|
|
60
|
+
width: auto;
|
|
61
|
+
|
|
62
|
+
&--medium {
|
|
63
|
+
line-height: 28px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&--large {
|
|
67
|
+
line-height: 36px;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&:focus {
|
|
71
|
+
border-style: none;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@at-root #{&}__tag__content {
|
|
76
|
+
border-style: none;
|
|
77
|
+
outline: 0;
|
|
78
|
+
padding: 0;
|
|
79
|
+
white-space: nowrap;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render, fireEvent, userEvent, vi } from 'test-utils';
|
|
3
|
+
import noop from '../../utils/noop';
|
|
4
|
+
|
|
5
|
+
import { TagInput } from './TagInput';
|
|
6
|
+
import styles from './TagInput.module.scss';
|
|
7
|
+
|
|
8
|
+
const baseClass = 'tag-input';
|
|
9
|
+
|
|
10
|
+
describe('<TagInput> component', () => {
|
|
11
|
+
it('should have error class when error occurs', () => {
|
|
12
|
+
const { container } = render(
|
|
13
|
+
<TagInput onChange={noop} error={'test error'} />
|
|
14
|
+
);
|
|
15
|
+
expect(container.firstChild).toHaveClass(styles[`${baseClass}--error`]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should call onChange method on enter press', () => {
|
|
19
|
+
const onChange = vi.fn();
|
|
20
|
+
const { getByRole } = render(<TagInput onChange={onChange} />);
|
|
21
|
+
const tagText = 'tagText';
|
|
22
|
+
const input = getByRole('textbox');
|
|
23
|
+
userEvent.type(input, `${tagText}{enter}`);
|
|
24
|
+
expect(onChange).toBeCalledWith([tagText]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should call onChange method on separator provided', () => {
|
|
28
|
+
const onChange = vi.fn();
|
|
29
|
+
const { getByRole } = render(<TagInput onChange={onChange} />);
|
|
30
|
+
const tagText = 'tagText';
|
|
31
|
+
const tagSeparator = ';';
|
|
32
|
+
const input = getByRole('textbox');
|
|
33
|
+
userEvent.type(input, `${tagText}${tagSeparator}`);
|
|
34
|
+
expect(onChange).toBeCalledWith([tagText]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should not call onChange method on enter press when tag separator is not provided', () => {
|
|
38
|
+
const onChange = vi.fn();
|
|
39
|
+
const { getByRole } = render(<TagInput onChange={onChange} />);
|
|
40
|
+
const tagText = 'tagText';
|
|
41
|
+
const input = getByRole('textbox');
|
|
42
|
+
userEvent.type(input, tagText);
|
|
43
|
+
expect(onChange).not.toBeCalled();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should call onChange method on text paste', () => {
|
|
47
|
+
const onChange = vi.fn();
|
|
48
|
+
const { getByRole } = render(<TagInput onChange={onChange} />);
|
|
49
|
+
const pastedText = 'tag1;tag2,tag3 tag4';
|
|
50
|
+
const input = getByRole('textbox');
|
|
51
|
+
fireEvent.paste(input, {
|
|
52
|
+
clipboardData: {
|
|
53
|
+
getData: () => pastedText,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
expect(onChange).toBeCalledWith(['tag1', 'tag2', 'tag3', 'tag4']);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
TagInput as TagInputComponent,
|
|
6
|
+
TagInputProps,
|
|
7
|
+
EmailTagInput as EmailTagInputComponent,
|
|
8
|
+
EmailTagInputProps,
|
|
9
|
+
} from './index';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Forms (WIP)/Tag Input',
|
|
13
|
+
component: TagInputComponent,
|
|
14
|
+
argTypes: {
|
|
15
|
+
tags: {
|
|
16
|
+
control: {
|
|
17
|
+
disable: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
} as ComponentMeta<typeof TagInputComponent>;
|
|
22
|
+
|
|
23
|
+
export const TagInput = ({ ...args }: TagInputProps): React.ReactElement => {
|
|
24
|
+
const [tags, setTags] = React.useState(['tag1', 'tag2']);
|
|
25
|
+
return (
|
|
26
|
+
<div>
|
|
27
|
+
<TagInputComponent {...args} tags={tags} onChange={setTags} />
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
TagInput.args = {
|
|
33
|
+
placeholder: 'Tag input placeholder',
|
|
34
|
+
} as TagInputProps;
|
|
35
|
+
|
|
36
|
+
export const EmailTagInput = ({
|
|
37
|
+
...args
|
|
38
|
+
}: EmailTagInputProps): React.ReactElement => {
|
|
39
|
+
const [tags, setTags] = React.useState(['one@test.com', 'two@test.com']);
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
<EmailTagInputComponent {...args} tags={tags} onChange={setTags} />
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
EmailTagInput.args = {
|
|
48
|
+
placeholder: 'name@company.com',
|
|
49
|
+
} as TagInputProps;
|