@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.
Files changed (271) hide show
  1. package/.eslintrc +9 -0
  2. package/.storybook/main.js +20 -0
  3. package/.storybook/preview-head.html +31 -0
  4. package/.storybook/preview.js +21 -0
  5. package/package.json +40 -37
  6. package/src/components/Alert/Alert.module.scss +88 -0
  7. package/src/components/Alert/Alert.spec.tsx +78 -0
  8. package/src/components/Alert/Alert.stories.tsx +73 -0
  9. package/src/components/Alert/Alert.tsx +94 -0
  10. package/src/components/Alert/index.ts +1 -0
  11. package/src/components/Badge/Badge.module.scss +23 -0
  12. package/src/components/Badge/Badge.spec.tsx +12 -0
  13. package/src/components/Badge/Badge.stories.tsx +24 -0
  14. package/src/components/Badge/Badge.tsx +24 -0
  15. package/src/components/Badge/index.ts +1 -0
  16. package/src/components/Button/Button.module.scss +257 -0
  17. package/src/components/Button/Button.spec.tsx +110 -0
  18. package/src/components/Button/Button.stories.tsx +152 -0
  19. package/src/components/Button/Button.tsx +88 -0
  20. package/src/components/Button/index.ts +2 -0
  21. package/src/components/ButtonGroup/ButtonGroup.module.scss +31 -0
  22. package/src/components/ButtonGroup/ButtonGroup.spec.tsx +61 -0
  23. package/src/components/ButtonGroup/ButtonGroup.stories.tsx +53 -0
  24. package/src/components/ButtonGroup/ButtonGroup.tsx +75 -0
  25. package/src/components/ButtonGroup/index.ts +1 -0
  26. package/src/components/Card/Card.module.scss +31 -0
  27. package/src/components/Card/Card.spec.tsx +38 -0
  28. package/src/components/Card/Card.stories.tsx +30 -0
  29. package/src/components/Card/Card.tsx +34 -0
  30. package/src/components/Card/index.ts +2 -0
  31. package/src/components/Checkbox/Checkbox.module.scss +99 -0
  32. package/src/components/Checkbox/Checkbox.tsx +39 -0
  33. package/src/components/Checkbox/CheckboxField.spec.tsx +58 -0
  34. package/src/components/Checkbox/CheckboxField.stories.tsx +30 -0
  35. package/src/components/Checkbox/CheckboxField.tsx +46 -0
  36. package/src/components/Checkbox/index.ts +2 -0
  37. package/src/components/FieldDescription/FieldDescription.module.scss +5 -0
  38. package/src/components/FieldDescription/FieldDescription.tsx +23 -0
  39. package/src/components/FieldDescription/index.ts +1 -0
  40. package/src/components/FieldError/FieldError.module.scss +5 -0
  41. package/src/components/FieldError/FieldError.tsx +23 -0
  42. package/src/components/FieldError/index.ts +1 -0
  43. package/src/components/FieldGroup/FieldGroup.module.scss +25 -0
  44. package/src/components/FieldGroup/FieldGroup.spec.tsx +42 -0
  45. package/src/components/FieldGroup/FieldGroup.stories.tsx +34 -0
  46. package/src/components/FieldGroup/FieldGroup.tsx +38 -0
  47. package/src/components/FieldGroup/index.ts +1 -0
  48. package/src/components/Form/Form.module.scss +22 -0
  49. package/src/components/Form/Form.spec.tsx +38 -0
  50. package/src/components/Form/Form.stories.tsx +42 -0
  51. package/src/components/Form/Form.tsx +46 -0
  52. package/src/components/Form/index.ts +2 -0
  53. package/src/components/FormGroup/FormGroup.module.scss +20 -0
  54. package/src/components/FormGroup/FormGroup.spec.tsx +34 -0
  55. package/src/components/FormGroup/FormGroup.stories.tsx +30 -0
  56. package/src/components/FormGroup/FormGroup.tsx +44 -0
  57. package/src/components/FormGroup/index.ts +1 -0
  58. package/src/components/Icon/Icon.module.scss +70 -0
  59. package/src/components/Icon/Icon.stories.tsx +53 -0
  60. package/src/components/Icon/Icon.tsx +118 -0
  61. package/src/components/Icon/index.ts +1 -0
  62. package/src/components/InputField/InputField.module.scss +37 -0
  63. package/src/components/InputField/InputField.spec.tsx +53 -0
  64. package/src/components/InputField/InputField.stories.tsx +73 -0
  65. package/src/components/InputField/InputField.tsx +72 -0
  66. package/src/components/InputField/index.ts +1 -0
  67. package/src/components/Link/Link.module.scss +18 -0
  68. package/src/components/Link/Link.stories.tsx +17 -0
  69. package/src/components/Link/Link.tsx +37 -0
  70. package/src/components/Link/index.ts +1 -0
  71. package/src/components/Loader/Loader.module.scss +66 -0
  72. package/src/components/Loader/Loader.spec.tsx +64 -0
  73. package/src/components/Loader/Loader.stories.tsx +25 -0
  74. package/src/components/Loader/Loader.tsx +48 -0
  75. package/src/components/Loader/index.ts +1 -0
  76. package/src/components/Modal/ActionModal.tsx +37 -0
  77. package/src/components/Modal/Modal.module.scss +131 -0
  78. package/src/components/Modal/Modal.stories.tsx +85 -0
  79. package/src/components/Modal/Modal.tsx +41 -0
  80. package/src/components/Modal/ModalBase.spec.tsx +58 -0
  81. package/src/components/Modal/ModalBase.tsx +66 -0
  82. package/src/components/Modal/ModalCloseButton.tsx +20 -0
  83. package/src/components/Modal/ModalPortal.tsx +35 -0
  84. package/src/components/Modal/index.ts +11 -0
  85. package/src/components/NumericInput/NumericInput.module.scss +110 -0
  86. package/src/components/NumericInput/NumericInput.spec.tsx +129 -0
  87. package/src/components/NumericInput/NumericInput.stories.tsx +56 -0
  88. package/src/components/NumericInput/NumericInput.tsx +161 -0
  89. package/src/components/NumericInput/NumericInputField.stories.tsx +58 -0
  90. package/src/components/NumericInput/NumericInputField.tsx +57 -0
  91. package/src/components/NumericInput/index.ts +2 -0
  92. package/src/components/Popover/Popover.module.scss +16 -0
  93. package/src/components/Popover/Popover.spec.tsx +39 -0
  94. package/src/components/Popover/Popover.stories.css +23 -0
  95. package/src/components/Popover/Popover.stories.tsx +164 -0
  96. package/src/components/Popover/Popover.tsx +124 -0
  97. package/src/components/Popover/index.ts +1 -0
  98. package/src/components/Progress/ProgressBar.module.scss +48 -0
  99. package/src/components/Progress/ProgressBar.spec.tsx +33 -0
  100. package/src/components/Progress/ProgressBar.stories.tsx +23 -0
  101. package/src/components/Progress/ProgressBar.tsx +62 -0
  102. package/src/components/Progress/ProgressCircle.module.scss +64 -0
  103. package/src/components/Progress/ProgressCircle.spec.tsx +34 -0
  104. package/src/components/Progress/ProgressCircle.stories.tsx +28 -0
  105. package/src/components/Progress/ProgressCircle.tsx +104 -0
  106. package/src/components/Progress/constants.ts +23 -0
  107. package/src/components/Progress/helpers.ts +23 -0
  108. package/src/components/Progress/index.ts +1 -0
  109. package/src/components/PromoBanner/PromoBanner.module.scss +121 -0
  110. package/src/components/PromoBanner/PromoBanner.spec.tsx +119 -0
  111. package/src/components/PromoBanner/PromoBanner.stories.tsx +125 -0
  112. package/src/components/PromoBanner/PromoBanner.tsx +99 -0
  113. package/src/components/PromoBanner/index.ts +1 -0
  114. package/src/components/RadioButton/RadioButton.module.scss +100 -0
  115. package/src/components/RadioButton/RadioButton.spec.tsx +70 -0
  116. package/src/components/RadioButton/RadioButton.stories.tsx +34 -0
  117. package/src/components/RadioButton/RadioButton.tsx +54 -0
  118. package/src/components/RadioButton/index.ts +1 -0
  119. package/src/components/Switch/Switch.module.scss +126 -0
  120. package/src/components/Switch/Switch.spec.tsx +40 -0
  121. package/src/components/Switch/Switch.stories.tsx +23 -0
  122. package/src/components/Switch/Switch.tsx +100 -0
  123. package/src/components/Switch/index.ts +1 -0
  124. package/src/components/Tab/Tab.module.scss +56 -0
  125. package/src/components/Tab/Tab.spec.tsx +34 -0
  126. package/src/components/Tab/Tab.stories.tsx +20 -0
  127. package/src/components/Tab/Tab.tsx +49 -0
  128. package/src/components/Tab/TabsWrapper.module.scss +11 -0
  129. package/src/components/Tab/TabsWrapper.spec.tsx +19 -0
  130. package/src/components/Tab/TabsWrapper.stories.tsx +46 -0
  131. package/src/components/Tab/TabsWrapper.tsx +24 -0
  132. package/src/components/Tab/index.ts +2 -0
  133. package/src/components/Tag/Tag.module.scss +131 -0
  134. package/src/components/Tag/Tag.spec.tsx +93 -0
  135. package/src/components/Tag/Tag.stories.tsx +151 -0
  136. package/src/components/Tag/Tag.tsx +129 -0
  137. package/src/components/Tag/index.ts +1 -0
  138. package/src/components/TagInput/EditableTag.tsx +54 -0
  139. package/src/components/TagInput/EditableTagContent.tsx +81 -0
  140. package/src/components/TagInput/EmailTagInput.tsx +31 -0
  141. package/src/components/TagInput/TagInput.module.scss +81 -0
  142. package/src/components/TagInput/TagInput.spec.tsx +58 -0
  143. package/src/components/TagInput/TagInput.stories.tsx +49 -0
  144. package/src/components/TagInput/TagInput.tsx +133 -0
  145. package/src/components/TagInput/index.ts +4 -0
  146. package/src/components/TextField/TextField.module.scss +90 -0
  147. package/src/components/TextField/TextField.spec.tsx +40 -0
  148. package/src/components/TextField/TextField.stories.tsx +60 -0
  149. package/src/components/TextField/TextField.tsx +100 -0
  150. package/src/components/TextField/index.ts +1 -0
  151. package/src/components/Toast/Toast.module.scss +218 -0
  152. package/src/components/Toast/Toast.spec.tsx +96 -0
  153. package/src/components/Toast/Toast.stories.tsx +64 -0
  154. package/src/components/Toast/Toast.tsx +121 -0
  155. package/src/components/Toast/ToastWrapper.spec.tsx +13 -0
  156. package/src/components/Toast/ToastWrapper.stories.tsx +55 -0
  157. package/src/components/Toast/ToastWrapper.tsx +87 -0
  158. package/src/components/Toast/index.ts +2 -0
  159. package/src/components/Typography/Heading.tsx +36 -0
  160. package/src/components/Typography/Text.tsx +49 -0
  161. package/src/components/Typography/Typography.module.scss +132 -0
  162. package/src/components/Typography/index.ts +2 -0
  163. package/src/index.scss +9 -0
  164. package/src/index.ts +32 -0
  165. package/src/stories/ColorTokens.stories.mdx +10 -0
  166. package/src/stories/Icons.stories.mdx +12 -0
  167. package/src/stories/Typography.stories.mdx +65 -0
  168. package/src/stories/components/ColorTokens.tsx +99 -0
  169. package/src/stories/components/IconsShowcase.tsx +25 -0
  170. package/src/stories/components/iconsShowcase.css +13 -0
  171. package/src/test/setup.ts +1 -0
  172. package/{dist/test-utils.d.ts → src/test/utils.ts} +3 -2
  173. package/src/themes/dark.scss +127 -0
  174. package/src/themes/designTokens.ts +126 -0
  175. package/src/themes/legacy.scss +128 -0
  176. package/src/themes/light.scss +127 -0
  177. package/src/utils/keyCodes.ts +12 -0
  178. package/src/utils/noop.ts +2 -0
  179. package/src/vite-env.d.ts +1 -0
  180. package/tsconfig.json +25 -0
  181. package/tsconfig.node.json +8 -0
  182. package/vite.config.ts +44 -0
  183. package/dist/components/Alert.d.ts +0 -19
  184. package/dist/components/Alert.spec.d.ts +0 -1
  185. package/dist/components/Badge.d.ts +0 -6
  186. package/dist/components/Badge.spec.d.ts +0 -1
  187. package/dist/components/Button.d.ts +0 -13
  188. package/dist/components/Button.spec.d.ts +0 -1
  189. package/dist/components/ButtonGroup.d.ts +0 -11
  190. package/dist/components/ButtonGroup.spec.d.ts +0 -1
  191. package/dist/components/Card.d.ts +0 -6
  192. package/dist/components/Card.spec.d.ts +0 -1
  193. package/dist/components/Checkbox.d.ts +0 -7
  194. package/dist/components/CheckboxField.d.ts +0 -7
  195. package/dist/components/CheckboxField.spec.d.ts +0 -1
  196. package/dist/components/FieldDescription.d.ts +0 -3
  197. package/dist/components/FieldError.d.ts +0 -3
  198. package/dist/components/FieldGroup.d.ts +0 -8
  199. package/dist/components/FieldGroup.spec.d.ts +0 -1
  200. package/dist/components/FieldLabel.d.ts +0 -3
  201. package/dist/components/Form.d.ts +0 -7
  202. package/dist/components/Form.spec.d.ts +0 -1
  203. package/dist/components/FormGroup.d.ts +0 -7
  204. package/dist/components/FormGroup.spec.d.ts +0 -1
  205. package/dist/components/Heading.d.ts +0 -11
  206. package/dist/components/Icon.d.ts +0 -69
  207. package/dist/components/Loader.d.ts +0 -10
  208. package/dist/components/Loader.spec.d.ts +0 -1
  209. package/dist/components/Modal/ActionModal.d.ts +0 -8
  210. package/dist/components/Modal/Modal.d.ts +0 -7
  211. package/dist/components/Modal/ModalBase.d.ts +0 -6
  212. package/dist/components/Modal/ModalBase.spec.d.ts +0 -1
  213. package/dist/components/Modal/ModalCloseButton.d.ts +0 -3
  214. package/dist/components/Modal/ModalPortal.d.ts +0 -7
  215. package/dist/components/ProgressBar.d.ts +0 -9
  216. package/dist/components/ProgressBar.spec.d.ts +0 -1
  217. package/dist/components/ProgressCircle.d.ts +0 -9
  218. package/dist/components/ProgressCircle.spec.d.ts +0 -1
  219. package/dist/components/PromoBanner.d.ts +0 -19
  220. package/dist/components/PromoBanner.spec.d.ts +0 -1
  221. package/dist/components/RadioButton.d.ts +0 -7
  222. package/dist/components/RadioButton.spec.d.ts +0 -1
  223. package/dist/components/Switch.d.ts +0 -17
  224. package/dist/components/Switch.spec.d.ts +0 -1
  225. package/dist/components/Tab.d.ts +0 -12
  226. package/dist/components/Tab.spec.d.ts +0 -1
  227. package/dist/components/TabsWrapper.d.ts +0 -3
  228. package/dist/components/TabsWrapper.spec.d.ts +0 -1
  229. package/dist/components/Text.d.ts +0 -15
  230. package/dist/components/Toast.d.ts +0 -22
  231. package/dist/components/Toast.spec.d.ts +0 -1
  232. package/dist/components/ToastWrapper.d.ts +0 -26
  233. package/dist/components/ToastWrapper.spec.d.ts +0 -1
  234. package/dist/components/constants.d.ts +0 -12
  235. package/dist/components/helpers.d.ts +0 -3
  236. package/dist/constants/keyCodes.d.ts +0 -3
  237. package/dist/index.css +0 -2
  238. package/dist/index.css.map +0 -1
  239. package/dist/index.d.ts +0 -8
  240. package/dist/index.js +0 -2
  241. package/dist/index.js.map +0 -1
  242. package/dist/index.modern.js +0 -2
  243. package/dist/index.modern.js.map +0 -1
  244. package/dist/index.module.js +0 -2
  245. package/dist/index.module.js.map +0 -1
  246. package/dist/index.umd.js +0 -2
  247. package/dist/index.umd.js.map +0 -1
  248. package/dist/stories/Alert.stories.d.ts +0 -14
  249. package/dist/stories/Badge.stories.d.ts +0 -16
  250. package/dist/stories/Button.stories.d.ts +0 -20
  251. package/dist/stories/ButtonGroup.stories.d.ts +0 -18
  252. package/dist/stories/Card.stories.d.ts +0 -10
  253. package/dist/stories/CheckboxField.stories.d.ts +0 -9
  254. package/dist/stories/FieldGroup.stories.d.ts +0 -9
  255. package/dist/stories/Form.stories.d.ts +0 -6
  256. package/dist/stories/FormGroup.stories.d.ts +0 -9
  257. package/dist/stories/Icon.stories.d.ts +0 -14
  258. package/dist/stories/Loader.stories.d.ts +0 -8
  259. package/dist/stories/Modal.stories.d.ts +0 -19
  260. package/dist/stories/ProgressCircle.stories.d.ts +0 -13
  261. package/dist/stories/Progressbar.stories.d.ts +0 -13
  262. package/dist/stories/PromoBanner.stories.d.ts +0 -13
  263. package/dist/stories/RadioButton.stories.d.ts +0 -9
  264. package/dist/stories/Switch.stories.d.ts +0 -12
  265. package/dist/stories/Tab.stories.d.ts +0 -10
  266. package/dist/stories/TabsWrapper.stories.d.ts +0 -15
  267. package/dist/stories/Toast.stories.d.ts +0 -15
  268. package/dist/stories/ToastWrapper.stories.d.ts +0 -40
  269. package/dist/stories/foundations/components/ColorTokens.d.ts +0 -2
  270. package/dist/stories/foundations/components/IconsShowcase.d.ts +0 -6
  271. package/dist/utils/noop.d.ts +0 -1
@@ -0,0 +1,100 @@
1
+ import * as React from 'react';
2
+ import cx from 'clsx';
3
+
4
+ import noop from '../../utils/noop';
5
+
6
+ import styles from './Switch.module.scss';
7
+
8
+ const baseClass = 'switch';
9
+
10
+ export const enum SwitchSize {
11
+ Basic = 'basic',
12
+ Compact = 'compact',
13
+ }
14
+
15
+ export const enum SwitchStyles {
16
+ Enabled = 'enabled',
17
+ Disabled = 'disabled',
18
+ }
19
+
20
+ export interface SwitchProps {
21
+ className?: string;
22
+ defaultOn?: boolean;
23
+ disabled?: boolean;
24
+ innerRef?: React.LegacyRef<HTMLInputElement> | undefined;
25
+ name?: string;
26
+ on?: boolean;
27
+ onChange?(e: React.FormEvent, value: boolean): void;
28
+ size?: SwitchSize;
29
+ }
30
+
31
+ export const Switch: React.FC<SwitchProps> = ({
32
+ className = '',
33
+ defaultOn = false,
34
+ disabled = false,
35
+ name = baseClass,
36
+ on,
37
+ onChange = noop,
38
+ size = SwitchSize.Basic,
39
+ innerRef,
40
+ ...props
41
+ }) => {
42
+ const getEnabledValue = () => {
43
+ return on !== undefined ? on : defaultOn;
44
+ };
45
+ const [enabled, setEnabled] = React.useState(getEnabledValue());
46
+
47
+ React.useEffect(() => {
48
+ if (on !== undefined) {
49
+ setEnabled(on);
50
+ }
51
+ }, [on]);
52
+
53
+ const valueStyles = enabled ? SwitchStyles.Enabled : SwitchStyles.Disabled;
54
+ const mergedClassNames = cx(
55
+ styles[baseClass],
56
+ styles[`${baseClass}--${size}`],
57
+ className
58
+ );
59
+
60
+ const handleChange = (e: React.FormEvent) => {
61
+ const hasOnChangePassed = onChange !== noop;
62
+ if (hasOnChangePassed) {
63
+ onChange(e, enabled);
64
+ return;
65
+ }
66
+ e.stopPropagation();
67
+ setEnabled((prevEnabled) => !prevEnabled);
68
+ };
69
+
70
+ return (
71
+ <span className={mergedClassNames}>
72
+ <input
73
+ type="checkbox"
74
+ className={styles[`${baseClass}__input`]}
75
+ onChange={handleChange}
76
+ checked={enabled}
77
+ name={name}
78
+ ref={innerRef}
79
+ disabled={disabled}
80
+ test-id="foo"
81
+ {...props}
82
+ />
83
+ <span className={styles[`${baseClass}__container`]}>
84
+ <span
85
+ className={cx(
86
+ styles[`${baseClass}__track`],
87
+ styles[`${baseClass}__track--${valueStyles}`]
88
+ )}
89
+ />
90
+ <span
91
+ className={cx(
92
+ styles[`${baseClass}__slider`],
93
+ styles[`${baseClass}__slider--${size}`],
94
+ styles[`${baseClass}__slider--${size}--${valueStyles}`]
95
+ )}
96
+ />
97
+ </span>
98
+ </span>
99
+ );
100
+ };
@@ -0,0 +1 @@
1
+ export { Switch } from './Switch';
@@ -0,0 +1,56 @@
1
+ .tab {
2
+ align-items: center;
3
+ background: none;
4
+ border: 0;
5
+ color: var(--content-default);
6
+ cursor: pointer;
7
+ display: flex;
8
+ flex-direction: row;
9
+ margin: 0 8px 11px;
10
+ outline: none;
11
+ overflow: visible;
12
+ padding: 0 12px 1px;
13
+ position: relative;
14
+ transition: color 0.25s;
15
+
16
+ &__description {
17
+ color: var(--content-subtle);
18
+ display: inline-block;
19
+ padding-left: 3px;
20
+ transition: color 0.25s;
21
+ }
22
+
23
+ &::before {
24
+ background-color: var(--color-action-default);
25
+ bottom: 0;
26
+ content: '';
27
+ display: block;
28
+ height: 0;
29
+ left: 0;
30
+ position: absolute;
31
+ right: 0;
32
+ z-index: 1;
33
+ }
34
+
35
+ &--selected {
36
+ color: var(--color-action-default);
37
+
38
+ .tab__description {
39
+ color: var(--color-action-default);
40
+ }
41
+
42
+ &::before {
43
+ bottom: -12px;
44
+ height: 3px;
45
+ }
46
+ }
47
+
48
+ &:hover {
49
+ color: var(--color-action-default);
50
+ text-decoration: none;
51
+
52
+ .tab__description {
53
+ color: var(--color-action-default);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+ import { render } from 'test-utils';
3
+ import { Tab } from './Tab';
4
+
5
+ import styles from './Tab.module.scss';
6
+
7
+ describe('<Tab /> component', () => {
8
+ it('should render unselected Tab by default', () => {
9
+ const { getByText } = render(<Tab>Hello</Tab>);
10
+ expect(getByText('Hello')).not.toHaveClass(styles['tab--selected']);
11
+ });
12
+
13
+ it("should render selected Tab if 'isSelected' is provided", () => {
14
+ const { getByText } = render(<Tab isSelected>Hello</Tab>);
15
+ expect(getByText('Hello')).toHaveClass(styles['tab--selected']);
16
+ });
17
+
18
+ it('should render properly formatted description', () => {
19
+ const { getByText } = render(<Tab description="1">Hello</Tab>);
20
+ expect(getByText('(1)')).toBeVisible();
21
+ });
22
+
23
+ it('should render with button element by default', () => {
24
+ const { getByRole } = render(<Tab>Hello</Tab>);
25
+ expect(getByRole('button')).toHaveTextContent('Hello');
26
+ });
27
+
28
+ it("should render with anchor element if 'href' is provided", () => {
29
+ const { getByRole } = render(<Tab href="http://example.com">Hello</Tab>);
30
+ const link = getByRole('link');
31
+ expect(link).toHaveTextContent('Hello');
32
+ expect(link).toHaveAttribute('href', 'http://example.com');
33
+ });
34
+ });
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import { ComponentMeta } from '@storybook/react';
3
+
4
+ import { Tab as TabComponent, TabProps } from './Tab';
5
+
6
+ export default {
7
+ title: 'Components/Tabs',
8
+ component: TabComponent,
9
+ } as ComponentMeta<typeof TabComponent>;
10
+
11
+ type ITabArgs = TabProps;
12
+
13
+ export const Tab = (args: ITabArgs): React.ReactElement => {
14
+ return <TabComponent {...args} />;
15
+ };
16
+
17
+ Tab.args = {
18
+ children: 'Lorem ipsum',
19
+ description: '1',
20
+ } as ITabArgs;
@@ -0,0 +1,49 @@
1
+ import * as React from 'react';
2
+ import cx from 'clsx';
3
+ import { Text } from '../Typography';
4
+
5
+ import styles from './Tab.module.scss';
6
+
7
+ type HTMLProps =
8
+ | (React.AnchorHTMLAttributes<HTMLAnchorElement> & { href: string })
9
+ | (React.ButtonHTMLAttributes<HTMLButtonElement> & { href?: never });
10
+
11
+ export type TabProps = HTMLProps & {
12
+ description?: React.ReactNode;
13
+ isSelected?: boolean;
14
+ };
15
+
16
+ const baseClass = 'tab';
17
+
18
+ export const Tab: React.FC<TabProps> = ({
19
+ children,
20
+ className,
21
+ description,
22
+ isSelected,
23
+ ...restProps
24
+ }) => {
25
+ return (
26
+ <Text
27
+ {...restProps}
28
+ as={restProps.href ? 'a' : 'button'}
29
+ size="md"
30
+ bold={isSelected}
31
+ className={cx(
32
+ styles[baseClass],
33
+ className,
34
+ isSelected && styles[`${baseClass}--selected`]
35
+ )}
36
+ >
37
+ {children}
38
+ {description && (
39
+ <Text
40
+ as="span"
41
+ size="md"
42
+ className={styles[`${baseClass}__description`]}
43
+ >
44
+ ({description})
45
+ </Text>
46
+ )}
47
+ </Text>
48
+ );
49
+ };
@@ -0,0 +1,11 @@
1
+ .tabs {
2
+ border-bottom: 1px solid var(--border-subtle);
3
+ position: relative;
4
+
5
+ &__list {
6
+ display: flex;
7
+ flex-direction: row;
8
+ margin: 0 -8px;
9
+ position: relative;
10
+ }
11
+ }
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { render } from 'test-utils';
3
+ import { TabsWrapper, TabsList } from './TabsWrapper';
4
+
5
+ describe('<TabsWrapper /> component', () => {
6
+ it('should render nested elements as children', () => {
7
+ const { getByRole } = render(
8
+ <TabsWrapper>
9
+ <TabsList>
10
+ <h3>Hello</h3>
11
+ </TabsList>
12
+ </TabsWrapper>
13
+ );
14
+
15
+ const heading = getByRole('heading');
16
+ expect(heading).toBeVisible();
17
+ expect(heading).toHaveTextContent('Hello');
18
+ });
19
+ });
@@ -0,0 +1,46 @@
1
+ import * as React from 'react';
2
+ import { ComponentMeta } from '@storybook/react';
3
+
4
+ import { TabsList, TabsWrapper as TabsWrapperComponenet } from './TabsWrapper';
5
+ import { Tab } from './Tab';
6
+
7
+ export default {
8
+ title: 'Components/Tabs',
9
+ component: TabsWrapperComponenet,
10
+ } as ComponentMeta<typeof TabsWrapperComponenet>;
11
+
12
+ type ITabArgs = {
13
+ items: Array<{
14
+ id: string;
15
+ title: string;
16
+ count: number;
17
+ }>;
18
+ };
19
+
20
+ export const TabsWrapper = ({ items }: ITabArgs): React.ReactElement => {
21
+ const [selectedTab, setSelectedTab] = React.useState(items[0].id);
22
+
23
+ return (
24
+ <TabsWrapperComponenet>
25
+ <TabsList>
26
+ {items.map(({ id, title, count }) => (
27
+ <Tab
28
+ key={id}
29
+ description={count}
30
+ isSelected={selectedTab === id}
31
+ onClick={() => setSelectedTab(id)}
32
+ >
33
+ {title}
34
+ </Tab>
35
+ ))}
36
+ </TabsList>
37
+ </TabsWrapperComponenet>
38
+ );
39
+ };
40
+
41
+ TabsWrapper.args = {
42
+ items: [
43
+ { id: 'agents', title: 'Agents', count: 1 },
44
+ { id: 'groups', title: 'Groups', count: 3 },
45
+ ],
46
+ } as ITabArgs;
@@ -0,0 +1,24 @@
1
+ import * as React from 'react';
2
+ import cx from 'clsx';
3
+
4
+ import styles from './TabsWrapper.module.scss';
5
+
6
+ const baseClass = 'tabs';
7
+
8
+ export const TabsWrapper: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
9
+ className,
10
+ children,
11
+ }) => {
12
+ return <div className={cx(styles[baseClass], className)}>{children}</div>;
13
+ };
14
+
15
+ export const TabsList: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
16
+ className,
17
+ children,
18
+ }) => {
19
+ return (
20
+ <div className={cx(styles[`${baseClass}__list`], className)}>
21
+ {children}
22
+ </div>
23
+ );
24
+ };
@@ -0,0 +1,2 @@
1
+ export * from './Tab';
2
+ export * from './TabsWrapper';
@@ -0,0 +1,131 @@
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
+ }
@@ -0,0 +1,93 @@
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
+ });