@livechat/design-system-react-components 1.0.0-alpha.4 → 1.0.0-alpha.5
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/dist/dsrc.cjs.js +1 -0
- package/dist/dsrc.es.js +2213 -0
- package/dist/dsrc.umd.js +1 -0
- package/dist/src/components/Alert/Alert.d.ts +19 -0
- package/{src/components/Alert/index.ts → dist/src/components/Alert/index.d.ts} +0 -0
- package/dist/src/components/Badge/Badge.d.ts +5 -0
- package/{src/components/Badge/index.ts → dist/src/components/Badge/index.d.ts} +0 -0
- package/dist/src/components/Button/Button.d.ts +13 -0
- package/{src/components/Button/index.ts → dist/src/components/Button/index.d.ts} +0 -0
- package/dist/src/components/ButtonGroup/ButtonGroup.d.ts +11 -0
- package/{src/components/ButtonGroup/index.ts → dist/src/components/ButtonGroup/index.d.ts} +0 -0
- package/dist/src/components/Card/Card.d.ts +6 -0
- package/{src/components/Card/index.ts → dist/src/components/Card/index.d.ts} +0 -0
- package/dist/src/components/Checkbox/Checkbox.d.ts +7 -0
- package/dist/src/components/Checkbox/CheckboxField.d.ts +7 -0
- package/{src/components/Checkbox/index.ts → dist/src/components/Checkbox/index.d.ts} +0 -0
- package/dist/src/components/FieldDescription/FieldDescription.d.ts +3 -0
- package/{src/components/FieldDescription/index.ts → dist/src/components/FieldDescription/index.d.ts} +0 -0
- package/dist/src/components/FieldError/FieldError.d.ts +3 -0
- package/{src/components/FieldError/index.ts → dist/src/components/FieldError/index.d.ts} +0 -0
- package/dist/src/components/FieldGroup/FieldGroup.d.ts +8 -0
- package/{src/components/FieldGroup/index.ts → dist/src/components/FieldGroup/index.d.ts} +0 -0
- package/dist/src/components/Form/Form.d.ts +7 -0
- package/{src/components/Form/index.ts → dist/src/components/Form/index.d.ts} +0 -0
- package/dist/src/components/FormGroup/FormGroup.d.ts +7 -0
- package/{src/components/FormGroup/index.ts → dist/src/components/FormGroup/index.d.ts} +0 -0
- package/dist/src/components/Icon/Icon.d.ts +70 -0
- package/{src/components/Icon/index.ts → dist/src/components/Icon/index.d.ts} +0 -0
- package/dist/src/components/InputField/InputField.d.ts +15 -0
- package/{src/components/InputField/index.ts → dist/src/components/InputField/index.d.ts} +0 -0
- package/{src/components/Link/Link.tsx → dist/src/components/Link/Link.d.ts} +3 -26
- package/{src/components/Link/index.ts → dist/src/components/Link/index.d.ts} +0 -0
- package/dist/src/components/Loader/Loader.d.ts +10 -0
- package/{src/components/Loader/index.ts → dist/src/components/Loader/index.d.ts} +0 -0
- package/dist/src/components/Modal/ActionModal.d.ts +8 -0
- package/dist/src/components/Modal/Modal.d.ts +7 -0
- package/dist/src/components/Modal/ModalBase.d.ts +6 -0
- package/dist/src/components/Modal/ModalCloseButton.d.ts +3 -0
- package/dist/src/components/Modal/ModalPortal.d.ts +7 -0
- package/{src/components/Modal/index.ts → dist/src/components/Modal/index.d.ts} +0 -1
- package/dist/src/components/NumericInput/NumericInput.d.ts +14 -0
- package/dist/src/components/NumericInput/NumericInputField.d.ts +19 -0
- package/{src/components/NumericInput/index.ts → dist/src/components/NumericInput/index.d.ts} +0 -0
- package/dist/src/components/Popover/Popover.d.ts +15 -0
- package/{src/components/Popover/index.ts → dist/src/components/Popover/index.d.ts} +0 -0
- package/dist/src/components/Progress/ProgressCircle.d.ts +9 -0
- package/dist/src/components/Progress/constants.d.ts +12 -0
- package/dist/src/components/Progress/helpers.d.ts +3 -0
- package/{src/components/Progress/index.ts → dist/src/components/Progress/index.d.ts} +0 -0
- package/dist/src/components/PromoBanner/PromoBanner.d.ts +19 -0
- package/{src/components/PromoBanner/index.ts → dist/src/components/PromoBanner/index.d.ts} +0 -0
- package/dist/src/components/RadioButton/RadioButton.d.ts +7 -0
- package/{src/components/RadioButton/index.ts → dist/src/components/RadioButton/index.d.ts} +0 -0
- package/dist/src/components/Switch/Switch.d.ts +20 -0
- package/{src/components/Switch/index.ts → dist/src/components/Switch/index.d.ts} +0 -0
- package/dist/src/components/Tab/Tab.d.ts +12 -0
- package/dist/src/components/Tab/TabsWrapper.d.ts +3 -0
- package/{src/components/Tab/index.ts → dist/src/components/Tab/index.d.ts} +0 -0
- package/dist/src/components/Tag/Tag.d.ts +12 -0
- package/{src/components/Tag/index.ts → dist/src/components/Tag/index.d.ts} +0 -0
- package/dist/src/components/TagInput/EditableTag.d.ts +11 -0
- package/dist/src/components/TagInput/EditableTagContent.d.ts +11 -0
- package/dist/src/components/TagInput/EmailTagInput.d.ts +5 -0
- package/dist/src/components/TagInput/TagInput.d.ts +12 -0
- package/{src/components/TagInput/index.ts → dist/src/components/TagInput/index.d.ts} +0 -0
- package/dist/src/components/TextField/TextField.d.ts +13 -0
- package/{src/components/TextField/index.ts → dist/src/components/TextField/index.d.ts} +0 -0
- package/dist/src/components/Toast/Toast.d.ts +22 -0
- package/dist/src/components/Toast/ToastWrapper.d.ts +27 -0
- package/{src/components/Toast/index.ts → dist/src/components/Toast/index.d.ts} +0 -0
- package/dist/src/components/Typography/Heading.d.ts +11 -0
- package/dist/src/components/Typography/Text.d.ts +15 -0
- package/{src/components/Typography/index.ts → dist/src/components/Typography/index.d.ts} +0 -0
- package/{src/index.ts → dist/src/index.d.ts} +0 -3
- package/dist/src/themes/designTokens.d.ts +126 -0
- package/dist/src/utils/keyCodes.d.ts +12 -0
- package/dist/src/utils/noop.d.ts +1 -0
- package/{src → dist/src}/vite-env.d.ts +0 -0
- package/dist/style.css +1 -0
- package/{src/themes/dark.scss → dist/themes/dark.css} +2 -0
- package/dist/themes/dark.css.map +1 -0
- package/{src/themes/legacy.scss → dist/themes/legacy.css} +2 -0
- package/dist/themes/legacy.css.map +1 -0
- package/{src/themes/light.scss → dist/themes/light.css} +2 -0
- package/dist/themes/light.css.map +1 -0
- package/package.json +5 -2
- package/.eslintrc +0 -9
- package/.storybook/main.js +0 -20
- package/.storybook/preview-head.html +0 -31
- package/.storybook/preview.js +0 -21
- package/src/components/Alert/Alert.module.scss +0 -88
- package/src/components/Alert/Alert.spec.tsx +0 -78
- package/src/components/Alert/Alert.stories.tsx +0 -73
- package/src/components/Alert/Alert.tsx +0 -94
- package/src/components/Badge/Badge.module.scss +0 -23
- package/src/components/Badge/Badge.spec.tsx +0 -12
- package/src/components/Badge/Badge.stories.tsx +0 -24
- package/src/components/Badge/Badge.tsx +0 -24
- package/src/components/Button/Button.module.scss +0 -257
- package/src/components/Button/Button.spec.tsx +0 -110
- package/src/components/Button/Button.stories.tsx +0 -152
- package/src/components/Button/Button.tsx +0 -88
- package/src/components/ButtonGroup/ButtonGroup.module.scss +0 -31
- package/src/components/ButtonGroup/ButtonGroup.spec.tsx +0 -61
- package/src/components/ButtonGroup/ButtonGroup.stories.tsx +0 -53
- package/src/components/ButtonGroup/ButtonGroup.tsx +0 -75
- package/src/components/Card/Card.module.scss +0 -31
- package/src/components/Card/Card.spec.tsx +0 -38
- package/src/components/Card/Card.stories.tsx +0 -30
- package/src/components/Card/Card.tsx +0 -34
- package/src/components/Checkbox/Checkbox.module.scss +0 -99
- package/src/components/Checkbox/Checkbox.tsx +0 -39
- package/src/components/Checkbox/CheckboxField.spec.tsx +0 -58
- package/src/components/Checkbox/CheckboxField.stories.tsx +0 -30
- package/src/components/Checkbox/CheckboxField.tsx +0 -46
- package/src/components/FieldDescription/FieldDescription.module.scss +0 -5
- package/src/components/FieldDescription/FieldDescription.tsx +0 -23
- package/src/components/FieldError/FieldError.module.scss +0 -5
- package/src/components/FieldError/FieldError.tsx +0 -23
- package/src/components/FieldGroup/FieldGroup.module.scss +0 -25
- package/src/components/FieldGroup/FieldGroup.spec.tsx +0 -42
- package/src/components/FieldGroup/FieldGroup.stories.tsx +0 -34
- package/src/components/FieldGroup/FieldGroup.tsx +0 -38
- package/src/components/Form/Form.module.scss +0 -22
- package/src/components/Form/Form.spec.tsx +0 -38
- package/src/components/Form/Form.stories.tsx +0 -42
- package/src/components/Form/Form.tsx +0 -46
- package/src/components/FormGroup/FormGroup.module.scss +0 -20
- package/src/components/FormGroup/FormGroup.spec.tsx +0 -34
- package/src/components/FormGroup/FormGroup.stories.tsx +0 -30
- package/src/components/FormGroup/FormGroup.tsx +0 -44
- package/src/components/Icon/Icon.module.scss +0 -70
- package/src/components/Icon/Icon.stories.tsx +0 -53
- package/src/components/Icon/Icon.tsx +0 -118
- package/src/components/InputField/InputField.module.scss +0 -37
- package/src/components/InputField/InputField.spec.tsx +0 -53
- package/src/components/InputField/InputField.stories.tsx +0 -73
- package/src/components/InputField/InputField.tsx +0 -72
- package/src/components/Link/Link.module.scss +0 -18
- package/src/components/Link/Link.stories.tsx +0 -17
- package/src/components/Loader/Loader.module.scss +0 -66
- package/src/components/Loader/Loader.spec.tsx +0 -64
- package/src/components/Loader/Loader.stories.tsx +0 -25
- package/src/components/Loader/Loader.tsx +0 -48
- package/src/components/Modal/ActionModal.tsx +0 -37
- package/src/components/Modal/Modal.module.scss +0 -131
- package/src/components/Modal/Modal.stories.tsx +0 -85
- package/src/components/Modal/Modal.tsx +0 -41
- package/src/components/Modal/ModalBase.spec.tsx +0 -58
- package/src/components/Modal/ModalBase.tsx +0 -66
- package/src/components/Modal/ModalCloseButton.tsx +0 -20
- package/src/components/Modal/ModalPortal.tsx +0 -35
- package/src/components/NumericInput/NumericInput.module.scss +0 -110
- package/src/components/NumericInput/NumericInput.spec.tsx +0 -129
- package/src/components/NumericInput/NumericInput.stories.tsx +0 -56
- package/src/components/NumericInput/NumericInput.tsx +0 -161
- package/src/components/NumericInput/NumericInputField.stories.tsx +0 -58
- package/src/components/NumericInput/NumericInputField.tsx +0 -57
- package/src/components/Popover/Popover.module.scss +0 -16
- package/src/components/Popover/Popover.spec.tsx +0 -39
- package/src/components/Popover/Popover.stories.css +0 -23
- package/src/components/Popover/Popover.stories.tsx +0 -164
- package/src/components/Popover/Popover.tsx +0 -124
- package/src/components/Progress/ProgressBar.module.scss +0 -48
- package/src/components/Progress/ProgressBar.spec.tsx +0 -33
- package/src/components/Progress/ProgressBar.stories.tsx +0 -23
- package/src/components/Progress/ProgressBar.tsx +0 -62
- package/src/components/Progress/ProgressCircle.module.scss +0 -64
- package/src/components/Progress/ProgressCircle.spec.tsx +0 -34
- package/src/components/Progress/ProgressCircle.stories.tsx +0 -28
- package/src/components/Progress/ProgressCircle.tsx +0 -104
- package/src/components/Progress/constants.ts +0 -23
- package/src/components/Progress/helpers.ts +0 -23
- package/src/components/PromoBanner/PromoBanner.module.scss +0 -121
- package/src/components/PromoBanner/PromoBanner.spec.tsx +0 -119
- package/src/components/PromoBanner/PromoBanner.stories.tsx +0 -125
- package/src/components/PromoBanner/PromoBanner.tsx +0 -99
- package/src/components/RadioButton/RadioButton.module.scss +0 -100
- package/src/components/RadioButton/RadioButton.spec.tsx +0 -70
- package/src/components/RadioButton/RadioButton.stories.tsx +0 -34
- package/src/components/RadioButton/RadioButton.tsx +0 -54
- package/src/components/Switch/Switch.module.scss +0 -126
- package/src/components/Switch/Switch.spec.tsx +0 -40
- package/src/components/Switch/Switch.stories.tsx +0 -23
- package/src/components/Switch/Switch.tsx +0 -100
- package/src/components/Tab/Tab.module.scss +0 -56
- package/src/components/Tab/Tab.spec.tsx +0 -34
- package/src/components/Tab/Tab.stories.tsx +0 -20
- package/src/components/Tab/Tab.tsx +0 -49
- package/src/components/Tab/TabsWrapper.module.scss +0 -11
- package/src/components/Tab/TabsWrapper.spec.tsx +0 -19
- package/src/components/Tab/TabsWrapper.stories.tsx +0 -46
- package/src/components/Tab/TabsWrapper.tsx +0 -24
- package/src/components/Tag/Tag.module.scss +0 -131
- package/src/components/Tag/Tag.spec.tsx +0 -93
- package/src/components/Tag/Tag.stories.tsx +0 -151
- package/src/components/Tag/Tag.tsx +0 -129
- package/src/components/TagInput/EditableTag.tsx +0 -54
- package/src/components/TagInput/EditableTagContent.tsx +0 -81
- package/src/components/TagInput/EmailTagInput.tsx +0 -31
- package/src/components/TagInput/TagInput.module.scss +0 -81
- package/src/components/TagInput/TagInput.spec.tsx +0 -58
- package/src/components/TagInput/TagInput.stories.tsx +0 -49
- package/src/components/TagInput/TagInput.tsx +0 -133
- package/src/components/TextField/TextField.module.scss +0 -90
- package/src/components/TextField/TextField.spec.tsx +0 -40
- package/src/components/TextField/TextField.stories.tsx +0 -60
- package/src/components/TextField/TextField.tsx +0 -100
- package/src/components/Toast/Toast.module.scss +0 -218
- package/src/components/Toast/Toast.spec.tsx +0 -96
- package/src/components/Toast/Toast.stories.tsx +0 -64
- package/src/components/Toast/Toast.tsx +0 -121
- package/src/components/Toast/ToastWrapper.spec.tsx +0 -13
- package/src/components/Toast/ToastWrapper.stories.tsx +0 -55
- package/src/components/Toast/ToastWrapper.tsx +0 -87
- package/src/components/Typography/Heading.tsx +0 -36
- package/src/components/Typography/Text.tsx +0 -49
- package/src/components/Typography/Typography.module.scss +0 -132
- package/src/index.scss +0 -9
- package/src/stories/ColorTokens.stories.mdx +0 -10
- package/src/stories/Icons.stories.mdx +0 -12
- package/src/stories/Typography.stories.mdx +0 -65
- package/src/stories/components/ColorTokens.tsx +0 -99
- package/src/stories/components/IconsShowcase.tsx +0 -25
- package/src/stories/components/iconsShowcase.css +0 -13
- package/src/test/setup.ts +0 -1
- package/src/test/utils.ts +0 -3
- package/src/themes/designTokens.ts +0 -126
- package/src/utils/keyCodes.ts +0 -12
- package/src/utils/noop.ts +0 -2
- package/tsconfig.json +0 -25
- package/tsconfig.node.json +0 -8
- package/vite.config.ts +0 -44
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
.tag {
|
|
2
|
-
align-items: center;
|
|
3
|
-
background-color: var(--surface-secondary-default);
|
|
4
|
-
border-color: var(--border-default);
|
|
5
|
-
border-radius: 4px;
|
|
6
|
-
border-style: none;
|
|
7
|
-
border-width: 1px;
|
|
8
|
-
box-sizing: border-box;
|
|
9
|
-
color: var(--content-default);
|
|
10
|
-
display: inline-flex;
|
|
11
|
-
position: relative;
|
|
12
|
-
|
|
13
|
-
/* TODO: Replace colors below with decor tokens when ready */
|
|
14
|
-
&--success {
|
|
15
|
-
background-color: #d1f4d5;
|
|
16
|
-
border-color: #005321;
|
|
17
|
-
color: #005321;
|
|
18
|
-
|
|
19
|
-
.tag__remove {
|
|
20
|
-
color: #005321;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
&--error {
|
|
25
|
-
background-color: var(--surface-feedback-negative);
|
|
26
|
-
border-color: var(--color-negative-active);
|
|
27
|
-
color: var(--color-negative-active);
|
|
28
|
-
|
|
29
|
-
.tag__remove {
|
|
30
|
-
color: var(--color-negative-active);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
&--warning {
|
|
35
|
-
background-color: #ffe9bc;
|
|
36
|
-
border-color: #755b00;
|
|
37
|
-
color: #755b00;
|
|
38
|
-
|
|
39
|
-
.tag__remove {
|
|
40
|
-
color: #755b00;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
&--info {
|
|
45
|
-
background-color: var(--surface-feedback-info);
|
|
46
|
-
border-color: var(--color-action-active);
|
|
47
|
-
color: var(--color-action-active);
|
|
48
|
-
|
|
49
|
-
.tag__remove {
|
|
50
|
-
color: var(--color-action-active);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
&--medium {
|
|
55
|
-
padding: 1px 8px;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
&--large {
|
|
59
|
-
padding: 5px 12px;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
&--outline {
|
|
63
|
-
background-color: transparent;
|
|
64
|
-
border-style: solid;
|
|
65
|
-
|
|
66
|
-
&.tag--medium {
|
|
67
|
-
padding: 0 7px;
|
|
68
|
-
}
|
|
69
|
-
&.tag--large {
|
|
70
|
-
padding: 4px 11px;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.icon {
|
|
74
|
-
background-color: transparent;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
&--text-white {
|
|
79
|
-
color: #fff;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
&--text-black {
|
|
83
|
-
color: #000;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
&--with-icon {
|
|
87
|
-
&.tag--medium {
|
|
88
|
-
padding-left: 4px;
|
|
89
|
-
}
|
|
90
|
-
&.tag--large {
|
|
91
|
-
padding-left: 6px;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
&--dismissible {
|
|
96
|
-
&.tag--medium {
|
|
97
|
-
padding-right: 4px;
|
|
98
|
-
}
|
|
99
|
-
&.tag--large {
|
|
100
|
-
padding-right: 6px;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
&__icon {
|
|
105
|
-
margin-right: 4px;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
&__avatar {
|
|
109
|
-
border-radius: 50%;
|
|
110
|
-
height: 20px;
|
|
111
|
-
margin-right: 4px;
|
|
112
|
-
width: 20px;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
&__remove {
|
|
116
|
-
align-items: center;
|
|
117
|
-
background-color: transparent;
|
|
118
|
-
border-style: none;
|
|
119
|
-
box-shadow: none;
|
|
120
|
-
color: var(--content-subtle);
|
|
121
|
-
cursor: pointer;
|
|
122
|
-
display: flex;
|
|
123
|
-
justify-content: center;
|
|
124
|
-
outline: none;
|
|
125
|
-
padding: 0 0 0 4px;
|
|
126
|
-
|
|
127
|
-
&:hover {
|
|
128
|
-
color: var(--content-default);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { render, userEvent, vi } from 'test-utils';
|
|
3
|
-
import noop from '../../utils/noop';
|
|
4
|
-
import { Tag } from './Tag';
|
|
5
|
-
|
|
6
|
-
import styles from './Tag.module.scss';
|
|
7
|
-
|
|
8
|
-
const baseClass = 'tag';
|
|
9
|
-
const tagIndex = 0;
|
|
10
|
-
const props = {
|
|
11
|
-
onRemove: noop,
|
|
12
|
-
index: tagIndex,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
describe('<Tag> component', () => {
|
|
16
|
-
it('should have error class when error occurs', () => {
|
|
17
|
-
const { container } = render(
|
|
18
|
-
<Tag {...props} kind="error">
|
|
19
|
-
tag1
|
|
20
|
-
</Tag>
|
|
21
|
-
);
|
|
22
|
-
expect(container.firstChild).toHaveClass(styles[`${baseClass}--error`]);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should show remove button when dismissible props is enabled', () => {
|
|
26
|
-
const { getByRole } = render(
|
|
27
|
-
<Tag {...props} dismissible>
|
|
28
|
-
tag1
|
|
29
|
-
</Tag>
|
|
30
|
-
);
|
|
31
|
-
expect(getByRole('button')).toBeTruthy();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should apply specific CSS class for black custom color', () => {
|
|
35
|
-
const { container } = render(
|
|
36
|
-
<Tag {...props} customColor="#000000">
|
|
37
|
-
tag1
|
|
38
|
-
</Tag>
|
|
39
|
-
);
|
|
40
|
-
expect(container.firstChild).toHaveClass(styles['tag--text-white']);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should apply specific CSS class for white custom color', () => {
|
|
44
|
-
const { container } = render(
|
|
45
|
-
<Tag {...props} customColor="#FFFFFF">
|
|
46
|
-
tag1
|
|
47
|
-
</Tag>
|
|
48
|
-
);
|
|
49
|
-
expect(container.firstChild).toHaveClass(styles['tag--text-black']);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should have proper background color for red custom color', () => {
|
|
53
|
-
const { container } = render(
|
|
54
|
-
<Tag {...props} customColor="#ff0000">
|
|
55
|
-
tag1
|
|
56
|
-
</Tag>
|
|
57
|
-
);
|
|
58
|
-
expect(container.firstChild).toHaveStyle(`background-color: #ff0000`);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should apply specific CSS styling for red custom color with outline', () => {
|
|
62
|
-
const { container } = render(
|
|
63
|
-
<Tag {...props} outline customColor="#ff0000">
|
|
64
|
-
tag1
|
|
65
|
-
</Tag>
|
|
66
|
-
);
|
|
67
|
-
expect(container.firstChild).toHaveStyle(`background-color: transparent`);
|
|
68
|
-
expect(container.firstChild).toHaveStyle(`color: #ff0000`);
|
|
69
|
-
expect(container.firstChild).toHaveStyle(`border-color: #ff0000`);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should show avatar when both avatar and icon are provided', () => {
|
|
73
|
-
const { getByTestId, queryByTestId } = render(
|
|
74
|
-
<Tag {...props} avatar="http://test.img" icon="arrow-left">
|
|
75
|
-
tag1
|
|
76
|
-
</Tag>
|
|
77
|
-
);
|
|
78
|
-
expect(getByTestId('lc-tag-avatar')).toBeDefined();
|
|
79
|
-
expect(queryByTestId('lc-tag-icon')).not.toBeInTheDocument();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should call remove method on remove button press', () => {
|
|
83
|
-
const onRemove = vi.fn();
|
|
84
|
-
const { getByRole } = render(
|
|
85
|
-
<Tag {...props} onRemove={onRemove} dismissible>
|
|
86
|
-
tag1
|
|
87
|
-
</Tag>
|
|
88
|
-
);
|
|
89
|
-
const removeButton = getByRole('button');
|
|
90
|
-
userEvent.click(removeButton);
|
|
91
|
-
expect(onRemove).toBeCalledTimes(1);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,129 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
};
|