@livechat/design-system-react-components 1.0.0-alpha.4 → 1.0.0-alpha.41

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 (288) hide show
  1. package/dist/dsrc.cjs.js +15 -0
  2. package/dist/dsrc.es.js +4418 -0
  3. package/dist/dsrc.umd.js +15 -0
  4. package/dist/shadow/shadow.css +27 -0
  5. package/dist/shadow/shadow.css.map +1 -0
  6. package/dist/shadow/spacing.css +18 -0
  7. package/dist/shadow/spacing.css.map +1 -0
  8. package/dist/spacing/shadow.css +27 -0
  9. package/dist/spacing/shadow.css.map +1 -0
  10. package/dist/spacing/spacing.css +18 -0
  11. package/dist/spacing/spacing.css.map +1 -0
  12. package/dist/src/components/Alert/Alert.d.ts +9 -0
  13. package/dist/src/components/Avatar/Avatar.d.ts +19 -0
  14. package/dist/src/components/Avatar/Avatar.helpers.d.ts +2 -0
  15. package/dist/src/components/Avatar/index.d.ts +1 -0
  16. package/dist/src/components/Badge/Badge.d.ts +9 -0
  17. package/dist/src/components/Badge/Badge.helpers.d.ts +1 -0
  18. package/dist/src/components/Button/Button.d.ts +13 -0
  19. package/dist/src/components/Button/index.d.ts +2 -0
  20. package/dist/src/components/Card/Card.d.ts +12 -0
  21. package/dist/src/components/Checkbox/Checkbox.d.ts +7 -0
  22. package/dist/src/components/Checkbox/index.d.ts +1 -0
  23. package/dist/src/components/DatePicker/DatePicker.d.ts +4 -0
  24. package/dist/src/components/DatePicker/DatePickerNavbar.d.ts +4 -0
  25. package/dist/src/components/DatePicker/RangeDatePicker.d.ts +16 -0
  26. package/dist/src/components/DatePicker/helpers.d.ts +39 -0
  27. package/dist/src/components/DatePicker/hooks.d.ts +6 -0
  28. package/dist/src/components/DatePicker/index.d.ts +2 -0
  29. package/dist/src/components/DatePicker/types.d.ts +100 -0
  30. package/dist/src/components/FieldDescription/FieldDescription.d.ts +3 -0
  31. package/dist/src/components/FieldError/FieldError.d.ts +3 -0
  32. package/dist/src/components/FieldGroup/FieldGroup.d.ts +8 -0
  33. package/dist/src/components/FileUploadProgress/FileUploadProgress.d.ts +15 -0
  34. package/dist/src/components/FileUploadProgress/FileUploadProgressActions.d.ts +9 -0
  35. package/dist/src/components/FileUploadProgress/index.d.ts +2 -0
  36. package/dist/src/components/Form/Form.d.ts +7 -0
  37. package/dist/src/components/FormField/FormField.d.ts +13 -0
  38. package/dist/src/components/FormField/index.d.ts +1 -0
  39. package/dist/src/components/FormGroup/FormGroup.d.ts +7 -0
  40. package/dist/src/components/Icon/Icon.d.ts +14 -0
  41. package/dist/src/components/Icon/index.d.ts +1 -0
  42. package/dist/src/components/Input/Input.d.ts +14 -0
  43. package/dist/src/components/Input/index.d.ts +1 -0
  44. package/{src/components/Link/Link.tsx → dist/src/components/Link/Link.d.ts} +3 -26
  45. package/dist/src/components/Loader/Loader.d.ts +10 -0
  46. package/dist/src/components/Modal/Modal.d.ts +9 -0
  47. package/dist/src/components/Modal/ModalBase.d.ts +7 -0
  48. package/dist/src/components/Modal/ModalCloseButton.d.ts +6 -0
  49. package/dist/src/components/Modal/ModalPortal.d.ts +7 -0
  50. package/{src/components/Modal/index.ts → dist/src/components/Modal/index.d.ts} +0 -3
  51. package/dist/src/components/NumericInput/NumericInput.d.ts +14 -0
  52. package/dist/src/components/NumericInput/index.d.ts +1 -0
  53. package/dist/src/components/Picker/Picker.d.ts +23 -0
  54. package/dist/src/components/Picker/PickerList.d.ts +23 -0
  55. package/dist/src/components/Picker/Trigger.d.ts +15 -0
  56. package/dist/src/components/Picker/TriggerBody.d.ts +16 -0
  57. package/dist/src/components/Picker/constants.d.ts +21 -0
  58. package/dist/src/components/Picker/index.d.ts +2 -0
  59. package/dist/src/components/Popover/Popover.d.ts +12 -0
  60. package/dist/src/components/Progress/ProgressBar.d.ts +9 -0
  61. package/dist/src/components/Progress/ProgressCircle.d.ts +9 -0
  62. package/dist/src/components/Progress/constants.d.ts +4 -0
  63. package/dist/src/components/Progress/helpers.d.ts +3 -0
  64. package/{src/components/Progress/index.ts → dist/src/components/Progress/index.d.ts} +1 -0
  65. package/dist/src/components/PromoBanner/PromoBanner.d.ts +13 -0
  66. package/dist/src/components/RadioButton/RadioButton.d.ts +7 -0
  67. package/dist/src/components/Search/Search.d.ts +12 -0
  68. package/dist/src/components/Search/index.d.ts +1 -0
  69. package/dist/src/components/SegmentedControl/SegmentedControl.d.ts +18 -0
  70. package/dist/src/components/SegmentedControl/index.d.ts +2 -0
  71. package/dist/src/components/Switch/Switch.d.ts +17 -0
  72. package/dist/src/components/Tab/Tab.d.ts +15 -0
  73. package/dist/src/components/Tab/TabsWrapper.d.ts +3 -0
  74. package/dist/src/components/Tag/Tag.d.ts +14 -0
  75. package/dist/src/components/TagInput/EditableTag.d.ts +11 -0
  76. package/dist/src/components/TagInput/EditableTagContent.d.ts +11 -0
  77. package/dist/src/components/TagInput/EmailTagInput.d.ts +5 -0
  78. package/dist/src/components/TagInput/TagInput.d.ts +13 -0
  79. package/dist/src/components/Textarea/Textarea.d.ts +6 -0
  80. package/dist/src/components/Textarea/index.d.ts +1 -0
  81. package/dist/src/components/Toast/Toast.d.ts +16 -0
  82. package/dist/src/components/Toast/ToastWrapper.d.ts +20 -0
  83. package/dist/src/components/Tooltip/Info.d.ts +8 -0
  84. package/dist/src/components/Tooltip/Interactive.d.ts +14 -0
  85. package/dist/src/components/Tooltip/Simple.d.ts +4 -0
  86. package/dist/src/components/Tooltip/SpotlightOverlay.d.ts +7 -0
  87. package/dist/src/components/Tooltip/Tooltip.d.ts +22 -0
  88. package/dist/src/components/Tooltip/UserGuide.d.ts +12 -0
  89. package/dist/src/components/Tooltip/helpers.d.ts +2 -0
  90. package/dist/src/components/Tooltip/index.d.ts +5 -0
  91. package/dist/src/components/Tooltip/virtualElementReference.d.ts +9 -0
  92. package/dist/src/components/Typography/Heading.d.ts +11 -0
  93. package/dist/src/components/Typography/Text.d.ts +15 -0
  94. package/dist/src/components/UploadBar/UploadBar.d.ts +16 -0
  95. package/dist/src/components/UploadBar/index.d.ts +1 -0
  96. package/dist/src/foundations/shadow-token.d.ts +5 -0
  97. package/dist/src/foundations/spacing-token.d.ts +16 -0
  98. package/{src/index.ts → dist/src/index.d.ts} +16 -7
  99. package/dist/src/themes/design-token.d.ts +226 -0
  100. package/dist/src/utils/constants.d.ts +1 -0
  101. package/dist/src/utils/index.d.ts +1 -0
  102. package/dist/src/utils/keyCodes.d.ts +12 -0
  103. package/dist/src/utils/noop.d.ts +1 -0
  104. package/dist/style.css +1 -0
  105. package/dist/themes/dark.css +253 -0
  106. package/dist/themes/dark.css.map +1 -0
  107. package/dist/themes/legacy.css +254 -0
  108. package/dist/themes/legacy.css.map +1 -0
  109. package/dist/themes/light.css +253 -0
  110. package/dist/themes/light.css.map +1 -0
  111. package/package.json +26 -13
  112. package/.eslintrc +0 -9
  113. package/.storybook/main.js +0 -20
  114. package/.storybook/preview-head.html +0 -31
  115. package/.storybook/preview.js +0 -21
  116. package/src/components/Alert/Alert.module.scss +0 -88
  117. package/src/components/Alert/Alert.spec.tsx +0 -78
  118. package/src/components/Alert/Alert.stories.tsx +0 -73
  119. package/src/components/Alert/Alert.tsx +0 -94
  120. package/src/components/Badge/Badge.module.scss +0 -23
  121. package/src/components/Badge/Badge.spec.tsx +0 -12
  122. package/src/components/Badge/Badge.stories.tsx +0 -24
  123. package/src/components/Badge/Badge.tsx +0 -24
  124. package/src/components/Button/Button.module.scss +0 -257
  125. package/src/components/Button/Button.spec.tsx +0 -110
  126. package/src/components/Button/Button.stories.tsx +0 -152
  127. package/src/components/Button/Button.tsx +0 -88
  128. package/src/components/Button/index.ts +0 -2
  129. package/src/components/ButtonGroup/ButtonGroup.module.scss +0 -31
  130. package/src/components/ButtonGroup/ButtonGroup.spec.tsx +0 -61
  131. package/src/components/ButtonGroup/ButtonGroup.stories.tsx +0 -53
  132. package/src/components/ButtonGroup/ButtonGroup.tsx +0 -75
  133. package/src/components/ButtonGroup/index.ts +0 -1
  134. package/src/components/Card/Card.module.scss +0 -31
  135. package/src/components/Card/Card.spec.tsx +0 -38
  136. package/src/components/Card/Card.stories.tsx +0 -30
  137. package/src/components/Card/Card.tsx +0 -34
  138. package/src/components/Checkbox/Checkbox.module.scss +0 -99
  139. package/src/components/Checkbox/Checkbox.tsx +0 -39
  140. package/src/components/Checkbox/CheckboxField.spec.tsx +0 -58
  141. package/src/components/Checkbox/CheckboxField.stories.tsx +0 -30
  142. package/src/components/Checkbox/CheckboxField.tsx +0 -46
  143. package/src/components/Checkbox/index.ts +0 -2
  144. package/src/components/FieldDescription/FieldDescription.module.scss +0 -5
  145. package/src/components/FieldDescription/FieldDescription.tsx +0 -23
  146. package/src/components/FieldError/FieldError.module.scss +0 -5
  147. package/src/components/FieldError/FieldError.tsx +0 -23
  148. package/src/components/FieldGroup/FieldGroup.module.scss +0 -25
  149. package/src/components/FieldGroup/FieldGroup.spec.tsx +0 -42
  150. package/src/components/FieldGroup/FieldGroup.stories.tsx +0 -34
  151. package/src/components/FieldGroup/FieldGroup.tsx +0 -38
  152. package/src/components/Form/Form.module.scss +0 -22
  153. package/src/components/Form/Form.spec.tsx +0 -38
  154. package/src/components/Form/Form.stories.tsx +0 -42
  155. package/src/components/Form/Form.tsx +0 -46
  156. package/src/components/FormGroup/FormGroup.module.scss +0 -20
  157. package/src/components/FormGroup/FormGroup.spec.tsx +0 -34
  158. package/src/components/FormGroup/FormGroup.stories.tsx +0 -30
  159. package/src/components/FormGroup/FormGroup.tsx +0 -44
  160. package/src/components/Icon/Icon.module.scss +0 -70
  161. package/src/components/Icon/Icon.stories.tsx +0 -53
  162. package/src/components/Icon/Icon.tsx +0 -118
  163. package/src/components/Icon/index.ts +0 -1
  164. package/src/components/InputField/InputField.module.scss +0 -37
  165. package/src/components/InputField/InputField.spec.tsx +0 -53
  166. package/src/components/InputField/InputField.stories.tsx +0 -73
  167. package/src/components/InputField/InputField.tsx +0 -72
  168. package/src/components/InputField/index.ts +0 -1
  169. package/src/components/Link/Link.module.scss +0 -18
  170. package/src/components/Link/Link.stories.tsx +0 -17
  171. package/src/components/Loader/Loader.module.scss +0 -66
  172. package/src/components/Loader/Loader.spec.tsx +0 -64
  173. package/src/components/Loader/Loader.stories.tsx +0 -25
  174. package/src/components/Loader/Loader.tsx +0 -48
  175. package/src/components/Modal/ActionModal.tsx +0 -37
  176. package/src/components/Modal/Modal.module.scss +0 -131
  177. package/src/components/Modal/Modal.stories.tsx +0 -85
  178. package/src/components/Modal/Modal.tsx +0 -41
  179. package/src/components/Modal/ModalBase.spec.tsx +0 -58
  180. package/src/components/Modal/ModalBase.tsx +0 -66
  181. package/src/components/Modal/ModalCloseButton.tsx +0 -20
  182. package/src/components/Modal/ModalPortal.tsx +0 -35
  183. package/src/components/NumericInput/NumericInput.module.scss +0 -110
  184. package/src/components/NumericInput/NumericInput.spec.tsx +0 -129
  185. package/src/components/NumericInput/NumericInput.stories.tsx +0 -56
  186. package/src/components/NumericInput/NumericInput.tsx +0 -161
  187. package/src/components/NumericInput/NumericInputField.stories.tsx +0 -58
  188. package/src/components/NumericInput/NumericInputField.tsx +0 -57
  189. package/src/components/NumericInput/index.ts +0 -2
  190. package/src/components/Popover/Popover.module.scss +0 -16
  191. package/src/components/Popover/Popover.spec.tsx +0 -39
  192. package/src/components/Popover/Popover.stories.css +0 -23
  193. package/src/components/Popover/Popover.stories.tsx +0 -164
  194. package/src/components/Popover/Popover.tsx +0 -124
  195. package/src/components/Progress/ProgressBar.module.scss +0 -48
  196. package/src/components/Progress/ProgressBar.spec.tsx +0 -33
  197. package/src/components/Progress/ProgressBar.stories.tsx +0 -23
  198. package/src/components/Progress/ProgressBar.tsx +0 -62
  199. package/src/components/Progress/ProgressCircle.module.scss +0 -64
  200. package/src/components/Progress/ProgressCircle.spec.tsx +0 -34
  201. package/src/components/Progress/ProgressCircle.stories.tsx +0 -28
  202. package/src/components/Progress/ProgressCircle.tsx +0 -104
  203. package/src/components/Progress/constants.ts +0 -23
  204. package/src/components/Progress/helpers.ts +0 -23
  205. package/src/components/PromoBanner/PromoBanner.module.scss +0 -121
  206. package/src/components/PromoBanner/PromoBanner.spec.tsx +0 -119
  207. package/src/components/PromoBanner/PromoBanner.stories.tsx +0 -125
  208. package/src/components/PromoBanner/PromoBanner.tsx +0 -99
  209. package/src/components/RadioButton/RadioButton.module.scss +0 -100
  210. package/src/components/RadioButton/RadioButton.spec.tsx +0 -70
  211. package/src/components/RadioButton/RadioButton.stories.tsx +0 -34
  212. package/src/components/RadioButton/RadioButton.tsx +0 -54
  213. package/src/components/Switch/Switch.module.scss +0 -126
  214. package/src/components/Switch/Switch.spec.tsx +0 -40
  215. package/src/components/Switch/Switch.stories.tsx +0 -23
  216. package/src/components/Switch/Switch.tsx +0 -100
  217. package/src/components/Tab/Tab.module.scss +0 -56
  218. package/src/components/Tab/Tab.spec.tsx +0 -34
  219. package/src/components/Tab/Tab.stories.tsx +0 -20
  220. package/src/components/Tab/Tab.tsx +0 -49
  221. package/src/components/Tab/TabsWrapper.module.scss +0 -11
  222. package/src/components/Tab/TabsWrapper.spec.tsx +0 -19
  223. package/src/components/Tab/TabsWrapper.stories.tsx +0 -46
  224. package/src/components/Tab/TabsWrapper.tsx +0 -24
  225. package/src/components/Tag/Tag.module.scss +0 -131
  226. package/src/components/Tag/Tag.spec.tsx +0 -93
  227. package/src/components/Tag/Tag.stories.tsx +0 -151
  228. package/src/components/Tag/Tag.tsx +0 -129
  229. package/src/components/TagInput/EditableTag.tsx +0 -54
  230. package/src/components/TagInput/EditableTagContent.tsx +0 -81
  231. package/src/components/TagInput/EmailTagInput.tsx +0 -31
  232. package/src/components/TagInput/TagInput.module.scss +0 -81
  233. package/src/components/TagInput/TagInput.spec.tsx +0 -58
  234. package/src/components/TagInput/TagInput.stories.tsx +0 -49
  235. package/src/components/TagInput/TagInput.tsx +0 -133
  236. package/src/components/TextField/TextField.module.scss +0 -90
  237. package/src/components/TextField/TextField.spec.tsx +0 -40
  238. package/src/components/TextField/TextField.stories.tsx +0 -60
  239. package/src/components/TextField/TextField.tsx +0 -100
  240. package/src/components/TextField/index.ts +0 -1
  241. package/src/components/Toast/Toast.module.scss +0 -218
  242. package/src/components/Toast/Toast.spec.tsx +0 -96
  243. package/src/components/Toast/Toast.stories.tsx +0 -64
  244. package/src/components/Toast/Toast.tsx +0 -121
  245. package/src/components/Toast/ToastWrapper.spec.tsx +0 -13
  246. package/src/components/Toast/ToastWrapper.stories.tsx +0 -55
  247. package/src/components/Toast/ToastWrapper.tsx +0 -87
  248. package/src/components/Typography/Heading.tsx +0 -36
  249. package/src/components/Typography/Text.tsx +0 -49
  250. package/src/components/Typography/Typography.module.scss +0 -132
  251. package/src/index.scss +0 -9
  252. package/src/stories/ColorTokens.stories.mdx +0 -10
  253. package/src/stories/Icons.stories.mdx +0 -12
  254. package/src/stories/Typography.stories.mdx +0 -65
  255. package/src/stories/components/ColorTokens.tsx +0 -99
  256. package/src/stories/components/IconsShowcase.tsx +0 -25
  257. package/src/stories/components/iconsShowcase.css +0 -13
  258. package/src/test/setup.ts +0 -1
  259. package/src/test/utils.ts +0 -3
  260. package/src/themes/dark.scss +0 -127
  261. package/src/themes/designTokens.ts +0 -126
  262. package/src/themes/legacy.scss +0 -128
  263. package/src/themes/light.scss +0 -127
  264. package/src/utils/keyCodes.ts +0 -12
  265. package/src/utils/noop.ts +0 -2
  266. package/tsconfig.json +0 -25
  267. package/tsconfig.node.json +0 -8
  268. package/vite.config.ts +0 -44
  269. /package/{src/components/Alert/index.ts → dist/src/components/Alert/index.d.ts} +0 -0
  270. /package/{src/components/Badge/index.ts → dist/src/components/Badge/index.d.ts} +0 -0
  271. /package/{src/components/Card/index.ts → dist/src/components/Card/index.d.ts} +0 -0
  272. /package/{src/components/FieldDescription/index.ts → dist/src/components/FieldDescription/index.d.ts} +0 -0
  273. /package/{src/components/FieldError/index.ts → dist/src/components/FieldError/index.d.ts} +0 -0
  274. /package/{src/components/FieldGroup/index.ts → dist/src/components/FieldGroup/index.d.ts} +0 -0
  275. /package/{src/components/Form/index.ts → dist/src/components/Form/index.d.ts} +0 -0
  276. /package/{src/components/FormGroup/index.ts → dist/src/components/FormGroup/index.d.ts} +0 -0
  277. /package/{src/components/Link/index.ts → dist/src/components/Link/index.d.ts} +0 -0
  278. /package/{src/components/Loader/index.ts → dist/src/components/Loader/index.d.ts} +0 -0
  279. /package/{src/components/Popover/index.ts → dist/src/components/Popover/index.d.ts} +0 -0
  280. /package/{src/components/PromoBanner/index.ts → dist/src/components/PromoBanner/index.d.ts} +0 -0
  281. /package/{src/components/RadioButton/index.ts → dist/src/components/RadioButton/index.d.ts} +0 -0
  282. /package/{src/components/Switch/index.ts → dist/src/components/Switch/index.d.ts} +0 -0
  283. /package/{src/components/Tab/index.ts → dist/src/components/Tab/index.d.ts} +0 -0
  284. /package/{src/components/Tag/index.ts → dist/src/components/Tag/index.d.ts} +0 -0
  285. /package/{src/components/TagInput/index.ts → dist/src/components/TagInput/index.d.ts} +0 -0
  286. /package/{src/components/Toast/index.ts → dist/src/components/Toast/index.d.ts} +0 -0
  287. /package/{src/components/Typography/index.ts → dist/src/components/Typography/index.d.ts} +0 -0
  288. /package/{src → dist/src}/vite-env.d.ts +0 -0
@@ -1,110 +0,0 @@
1
- import * as React from 'react';
2
-
3
- import { render } from 'test-utils';
4
- import { Icon } from '../Icon';
5
-
6
- import { Button } from './Button';
7
- import styles from './Button.module.scss';
8
-
9
- describe('<Button> component', () => {
10
- function renderButton(props = {}) {
11
- const result = render(<Button {...props} />);
12
-
13
- return {
14
- ...result,
15
- btnEl: result.container.firstChild,
16
- };
17
- }
18
-
19
- it('should have default set of classNames', () => {
20
- const { btnEl } = renderButton();
21
-
22
- const expectedClasses = ['btn', 'btn--basic', 'btn--medium'].map(
23
- (cls) => styles[cls]
24
- );
25
- const notExpectedClasses = [
26
- 'btn--loading',
27
- 'btn--full-width',
28
- 'btn--icon-only',
29
- ].map((cls) => styles[cls]);
30
-
31
- expect(btnEl).toHaveClass(...expectedClasses);
32
- expect(btnEl).not.toHaveClass(...notExpectedClasses);
33
- });
34
-
35
- it('should allow to pass custom className', () => {
36
- const { btnEl } = renderButton({ className: 'my-class' });
37
-
38
- expect(btnEl).toHaveClass('my-class');
39
- });
40
-
41
- it('should not show loader by deafult', () => {
42
- const { container, btnEl } = renderButton();
43
-
44
- expect(btnEl).not.toHaveClass(styles['btn--loading']);
45
- expect(
46
- container.querySelector(`.${styles['btn__loader']}`)
47
- ).not.toBeInTheDocument();
48
- });
49
-
50
- it('should show loader when "loading" prop is true', () => {
51
- const { container, btnEl } = renderButton({ loading: true });
52
-
53
- expect(btnEl).toHaveClass(styles['btn--loading']);
54
- expect(container.querySelector(`.${styles['btn__loader']}`)).toBeVisible();
55
- });
56
-
57
- it('should not show icon by default', () => {
58
- const { container } = renderButton();
59
-
60
- expect(
61
- container.querySelector(`.${styles['btn__icon']}`)
62
- ).not.toBeInTheDocument();
63
- });
64
-
65
- it('should show icon component when "icon" prop has been passed', () => {
66
- const { container } = renderButton({
67
- icon: <Icon source="span" />,
68
- });
69
-
70
- const iconEl = container.querySelector(`.${styles['btn__icon']}`);
71
-
72
- expect(iconEl).toBeVisible();
73
- expect(iconEl).toHaveClass(styles['btn__icon--left']);
74
- });
75
-
76
- it('should show icon component on right side', () => {
77
- const { container } = renderButton({
78
- icon: <Icon source="span" />,
79
- iconPosition: 'right',
80
- });
81
-
82
- const iconEl = container.querySelector(`.${styles['btn__icon']}`);
83
-
84
- expect(iconEl).toBeVisible();
85
- expect(iconEl).toHaveClass(styles['btn__icon--right']);
86
- });
87
-
88
- it('should allow to take "fullWidth"', () => {
89
- const { btnEl } = renderButton({ fullWidth: true });
90
-
91
- expect(btnEl).toHaveClass(styles['btn--full-width']);
92
- });
93
-
94
- it('should allow for "icon-only" content', () => {
95
- const { btnEl } = renderButton({
96
- children: null,
97
- icon: <Icon source="span" />,
98
- });
99
-
100
- expect(btnEl).toHaveClass(styles['btn--icon-only']);
101
- });
102
-
103
- it('should render as an anchor element if href is passed', () => {
104
- const { btnEl: linkEl } = renderButton({ href: 'https://example.com' });
105
- const { btnEl } = renderButton({ href: '' });
106
-
107
- expect((btnEl as HTMLElement).tagName).toBe('BUTTON');
108
- expect((linkEl as HTMLElement).tagName).toBe('A');
109
- });
110
- });
@@ -1,152 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentMeta } from '@storybook/react';
3
-
4
- import * as MaterialIcons from '@livechat/design-system-icons/react/material';
5
-
6
- import { Icon } from '../Icon';
7
- import { Button, ButtonProps } from './Button';
8
-
9
- const icons = Object.fromEntries(
10
- Object.entries(MaterialIcons).map(([key, source]) => [
11
- key,
12
- <Icon source={source as React.FC} />,
13
- ])
14
- );
15
-
16
- const iterator = Object.keys(icons);
17
-
18
- export default {
19
- title: 'Components/Button',
20
- component: Button,
21
- argTypes: {
22
- icon: {
23
- options: ['None', ...iterator],
24
- mapping: Object.assign(icons, { None: null }),
25
- control: {
26
- type: 'select',
27
- labels: iterator,
28
- },
29
- },
30
- },
31
- parameters: {
32
- controls: {
33
- sort: 'alpha',
34
- },
35
- },
36
- } as ComponentMeta<typeof Button>;
37
-
38
- export const button = (args: ButtonProps): React.ReactElement => (
39
- <Button {...args} />
40
- );
41
- button.args = {
42
- loading: false,
43
- disabled: false,
44
- size: 'medium',
45
- kind: 'primary',
46
- children: 'Button Text',
47
- fullWidth: false,
48
- iconPosition: 'left',
49
- icon: 'None',
50
- };
51
-
52
- export const kinds = (): React.ReactElement => (
53
- <div>
54
- <div className="spacer">
55
- <Button>Basic</Button>
56
- <Button kind="primary">Primary</Button>
57
- <Button kind="secondary">Secondary</Button>
58
- <Button kind="destructive">Destructive</Button>
59
- <Button kind="text">Text</Button>
60
- <Button kind="plain">Plain</Button>
61
- <Button kind="plain-light">Plain light</Button>
62
- </div>
63
- </div>
64
- );
65
-
66
- export const states = (): React.ReactElement => (
67
- <div>
68
- <div className="spacer">
69
- <Button disabled>Disabled</Button>
70
- <Button disabled kind="primary">
71
- Disabled
72
- </Button>
73
- <Button disabled kind="secondary">
74
- Disabled
75
- </Button>
76
- <Button disabled kind="destructive">
77
- Disabled
78
- </Button>
79
- <Button disabled kind="text">
80
- Disabled
81
- </Button>
82
- <Button disabled kind="plain">
83
- Disabled
84
- </Button>
85
- <Button disabled kind="plain-light">
86
- Disabled
87
- </Button>
88
- </div>
89
- <div className="spacer">
90
- <Button loading>Loading</Button>
91
- <Button loading kind="primary">
92
- Loading
93
- </Button>
94
- <Button loading kind="secondary">
95
- Loading
96
- </Button>
97
- <Button loading kind="destructive">
98
- Loading
99
- </Button>
100
- <Button loading kind="text">
101
- Loading
102
- </Button>
103
- <Button loading kind="plain">
104
- Loading
105
- </Button>
106
- <Button loading kind="plain-light">
107
- Loading
108
- </Button>
109
- </div>
110
- </div>
111
- );
112
-
113
- export const sizes = (): React.ReactElement => (
114
- <>
115
- <div className="spacer">
116
- <Button size="compact" kind="primary">
117
- Compact
118
- </Button>
119
- <Button size="medium" kind="primary">
120
- Medium (default)
121
- </Button>
122
- <Button size="large" kind="primary">
123
- Large
124
- </Button>
125
- </div>
126
- <div className="spacer">
127
- <Button
128
- icon={<Icon source={MaterialIcons.AddCircle} />}
129
- size="compact"
130
- kind="primary"
131
- />
132
- <Button
133
- icon={<Icon source={MaterialIcons.AddCircle} />}
134
- size="medium"
135
- kind="primary"
136
- />
137
- <Button
138
- icon={<Icon source={MaterialIcons.AddCircle} />}
139
- size="large"
140
- kind="primary"
141
- />
142
- </div>
143
- </>
144
- );
145
-
146
- export const buttonAsLink = (args: ButtonProps): React.ReactElement => (
147
- <Button href="https://livechat.com" target="_blank" kind="primary" {...args}>
148
- Button as an external link to livechat.com
149
- </Button>
150
- );
151
-
152
- buttonAsLink.args = { ...button.args, href: 'https://livechat.com' };
@@ -1,88 +0,0 @@
1
- import * as React from 'react';
2
- import cx from 'clsx';
3
- import { Loader } from '../Loader';
4
-
5
- import styles from './Button.module.scss';
6
-
7
- export type ButtonSize = 'compact' | 'medium' | 'large';
8
-
9
- export type ButtonProps = {
10
- kind?:
11
- | 'basic'
12
- | 'primary'
13
- | 'secondary'
14
- | 'destructive'
15
- | 'text'
16
- | 'plain'
17
- | 'plain-light';
18
- size?: ButtonSize;
19
- disabled?: boolean;
20
- loading?: boolean;
21
- fullWidth?: boolean;
22
- loaderLabel?: string;
23
- icon?: React.ReactElement;
24
- iconPosition?: 'left' | 'right';
25
- } & React.ButtonHTMLAttributes<HTMLButtonElement> &
26
- React.AnchorHTMLAttributes<HTMLAnchorElement>;
27
-
28
- const baseClass = 'btn';
29
-
30
- export const Button: React.FC<ButtonProps> = ({
31
- loading = false,
32
- disabled = false,
33
- type = 'button',
34
- fullWidth = false,
35
- kind = 'basic',
36
- size = 'medium',
37
- icon = null,
38
- iconPosition = 'left',
39
- loaderLabel,
40
- className,
41
- children,
42
- href,
43
- ...props
44
- }) => {
45
- const isDisabled = loading || disabled;
46
-
47
- const Component = href ? 'a' : 'button';
48
-
49
- const mergedClassNames = cx(
50
- className,
51
- styles[baseClass],
52
- styles[`${baseClass}--${kind}`],
53
- styles[`${baseClass}--${size}`],
54
- {
55
- [styles[`${baseClass}--loading`]]: loading,
56
- [styles[`${baseClass}--full-width`]]: fullWidth,
57
- [styles[`${baseClass}--icon-only`]]: !children && icon,
58
- [styles[`${baseClass}--disabled`]]: isDisabled,
59
- }
60
- );
61
-
62
- return (
63
- <Component
64
- className={mergedClassNames}
65
- disabled={isDisabled}
66
- type={type}
67
- href={isDisabled ? undefined : href}
68
- {...props}
69
- >
70
- {loading && (
71
- <Loader
72
- size="small"
73
- label={loaderLabel}
74
- className={styles[`${baseClass}__loader`]}
75
- />
76
- )}
77
- {icon &&
78
- React.cloneElement(icon, {
79
- className: cx(
80
- styles[`${baseClass}__icon`],
81
- styles[`${baseClass}__icon--${iconPosition}`]
82
- ),
83
- disabled,
84
- })}
85
- <div className={styles[`${baseClass}__content`]}>{children}</div>
86
- </Component>
87
- );
88
- };
@@ -1,2 +0,0 @@
1
- export { Button } from './Button';
2
- export type { ButtonSize, ButtonProps } from './Button';
@@ -1,31 +0,0 @@
1
- .btn-group {
2
- border: 1px solid var(--border-subtle);
3
- border-radius: 4px;
4
- display: inline-flex;
5
- flex-direction: row;
6
- padding: 3px;
7
- vertical-align: middle;
8
-
9
- .btn {
10
- border-color: transparent;
11
- color: var(--content-default);
12
-
13
- &--active {
14
- background-color: var(--surface-basic-active);
15
- }
16
-
17
- &--compact {
18
- height: 24px;
19
- }
20
- &--medium {
21
- height: 28px;
22
- }
23
- &--large {
24
- height: 34px;
25
- }
26
- }
27
-
28
- .btn + .btn {
29
- margin-left: 2px;
30
- }
31
- }
@@ -1,61 +0,0 @@
1
- import * as React from 'react';
2
- import { render, userEvent, vi } from 'test-utils';
3
- import noop from '../../utils/noop';
4
- import { Button } from '../Button';
5
- import { ButtonGroup } from './ButtonGroup';
6
-
7
- import styles from './ButtonGroup.module.scss';
8
-
9
- describe('<ButtonGroup> component', () => {
10
- function renderComponent(props = {}, onButtonClick = noop) {
11
- return render(
12
- <ButtonGroup {...props}>
13
- <Button onClick={onButtonClick}>First button</Button>
14
- <Button>Second button</Button>
15
- </ButtonGroup>
16
- );
17
- }
18
-
19
- it('should have custom css class', () => {
20
- const className = 'my-custom-class';
21
- const {
22
- container: { firstChild: el },
23
- } = renderComponent({ className });
24
-
25
- expect(el).toHaveClass(className);
26
- });
27
-
28
- it('should allow for controlled version of component by passing "currentIndex" prop', () => {
29
- const { getAllByRole } = renderComponent({ currentIndex: 1 });
30
-
31
- const [firstButton, secondButton] = getAllByRole('button');
32
-
33
- expect(firstButton).not.toHaveClass(styles['btn--active']);
34
- expect(secondButton).toHaveClass(styles['btn--active']);
35
- });
36
-
37
- it('should not have active button by default in unconrolled version', () => {
38
- const { getAllByRole } = renderComponent();
39
-
40
- const [firstButton, secondButton] = getAllByRole('button');
41
-
42
- expect(firstButton).not.toHaveClass(styles['btn--active']);
43
- expect(secondButton).not.toHaveClass(styles['btn--active']);
44
- });
45
-
46
- it('should call "onIndexChange" with index of current selected button on click', () => {
47
- const onIndexChange = vi.fn();
48
- const onButtonClick = vi.fn();
49
- const { getAllByRole } = renderComponent({ onIndexChange }, onButtonClick);
50
-
51
- const [firstButton] = getAllByRole('button');
52
-
53
- expect(firstButton).not.toHaveClass(styles['btn--active']);
54
-
55
- userEvent.click(firstButton);
56
-
57
- expect(onIndexChange).toHaveBeenCalledWith(0, expect.anything());
58
- expect(onButtonClick).toHaveBeenCalled();
59
- expect(firstButton).toHaveClass(styles['btn--active']);
60
- });
61
- });
@@ -1,53 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentMeta } from '@storybook/react';
3
-
4
- import {
5
- ButtonGroup as ButtonGroupComponent,
6
- ButtonGroupProps,
7
- } from './ButtonGroup';
8
-
9
- import { Button } from '../Button';
10
-
11
- export default {
12
- title: 'Components/Button Group',
13
- component: ButtonGroupComponent,
14
- } as ComponentMeta<typeof ButtonGroupComponent>;
15
-
16
- export const controlled = (args: ButtonGroupProps): React.ReactElement => {
17
- return (
18
- <ButtonGroupComponent {...args}>
19
- <Button>First option</Button>
20
- <Button>Second option</Button>
21
- </ButtonGroupComponent>
22
- );
23
- };
24
-
25
- controlled.args = {
26
- currentIndex: 1,
27
- };
28
-
29
- export const uncontrolledEmptySelection = (
30
- args: ButtonGroupProps
31
- ): React.ReactElement => {
32
- return (
33
- <ButtonGroupComponent {...args}>
34
- <Button>First option</Button>
35
- <Button>Second option</Button>
36
- </ButtonGroupComponent>
37
- );
38
- };
39
-
40
- export const uncontrolledWithInitialSelection = (
41
- args: ButtonGroupProps
42
- ): React.ReactElement => {
43
- return (
44
- <ButtonGroupComponent {...args}>
45
- <Button>First option</Button>
46
- <Button>Second option</Button>
47
- </ButtonGroupComponent>
48
- );
49
- };
50
-
51
- uncontrolledWithInitialSelection.args = {
52
- initialIndex: 1,
53
- };
@@ -1,75 +0,0 @@
1
- import * as React from 'react';
2
- import cx from 'clsx';
3
-
4
- import { ButtonSize, ButtonProps } from '../Button';
5
-
6
- import styles from './ButtonGroup.module.scss';
7
-
8
- import noop from '../../utils/noop';
9
-
10
- const baseClass = 'btn-group';
11
-
12
- export interface ButtonGroupProps extends React.HTMLAttributes<HTMLDivElement> {
13
- currentIndex?: number;
14
- initialIndex?: number;
15
- fullWidth?: boolean;
16
- size?: ButtonSize;
17
- children: ReadonlyArray<
18
- React.ReactElement<React.PropsWithChildren<ButtonProps>>
19
- >;
20
- onIndexChange?: (
21
- currentIndex: number,
22
- event: React.MouseEvent<HTMLButtonElement>
23
- ) => void;
24
- }
25
-
26
- export const ButtonGroup: React.FC<ButtonGroupProps> = ({
27
- size = 'medium',
28
- fullWidth = false,
29
- onIndexChange = noop,
30
- className,
31
- children,
32
- currentIndex,
33
- initialIndex = -1,
34
- ...restProps
35
- }) => {
36
- const mergedClassName = cx(styles[baseClass], className);
37
- const [currentStateIndex, setCurrentStateIndex] =
38
- React.useState(initialIndex);
39
-
40
- const isControlled = typeof currentIndex === 'number';
41
-
42
- const _currentIndex = isControlled ? currentIndex : currentStateIndex;
43
-
44
- const handleClick = (index: number, event: any) => {
45
- if (!isControlled) {
46
- setCurrentStateIndex(index);
47
- }
48
-
49
- onIndexChange(index, event);
50
- };
51
-
52
- return (
53
- <div role="group" className={mergedClassName} {...restProps}>
54
- {React.Children.map(children, (child, i) =>
55
- React.cloneElement(child, {
56
- fullWidth,
57
- size,
58
- kind: 'secondary',
59
- type: 'button',
60
- onClick: (event: any) => {
61
- handleClick(i, event);
62
- if (child.props.onClick) {
63
- child.props.onClick(event);
64
- }
65
- },
66
- className: cx(
67
- styles['btn'],
68
- styles[`btn--${size as string}`],
69
- i === _currentIndex && styles['btn--active']
70
- ),
71
- })
72
- )}
73
- </div>
74
- );
75
- };
@@ -1 +0,0 @@
1
- export { ButtonGroup } from './ButtonGroup';
@@ -1,31 +0,0 @@
1
- .card {
2
- background-color: var(--surface-basic-default);
3
- border: solid 1px var(--border-subtle);
4
- border-radius: 4px;
5
- color: var(--content-default);
6
- margin-top: 8px;
7
- overflow: hidden;
8
- padding: 16px;
9
-
10
- &__title {
11
- align-items: center;
12
- display: flex;
13
- margin-bottom: 14px;
14
- }
15
-
16
- &__text {
17
- color: var(--content-default);
18
- overflow: hidden;
19
- text-overflow: ellipsis;
20
- white-space: nowrap;
21
- width: 100%;
22
- }
23
-
24
- &__img {
25
- border-radius: 4px;
26
- display: inline-block;
27
- height: 24px;
28
- margin-right: 10px;
29
- width: 24px;
30
- }
31
- }
@@ -1,38 +0,0 @@
1
- import * as React from 'react';
2
- import { render } from 'test-utils';
3
- import { Card } from './Card';
4
-
5
- describe('<Card /> component', () => {
6
- it('should render only title if image is not provided', () => {
7
- const { getByText, getByRole } = render(<Card title="Hello" />);
8
- expect(getByText('Hello')).toBeVisible();
9
- expect(() => getByRole('img')).toThrow();
10
- });
11
-
12
- it('should render title and image if provided', () => {
13
- const { getByText, getByRole } = render(
14
- <Card title="Hello" img="https://via.placeholder.com/100" />
15
- );
16
- expect(getByText('Hello')).toBeVisible();
17
- expect(getByRole('img')).toBeVisible();
18
- });
19
-
20
- it('should render text children', () => {
21
- const { getByText } = render(<Card title="Hello">Lorem ipsum</Card>);
22
- expect(getByText('Lorem ipsum')).toBeVisible();
23
- });
24
-
25
- it('should render nested elements as children', () => {
26
- const { getByRole } = render(
27
- <Card title="Hello">
28
- <div>
29
- <h3>Lorem ipsum</h3>
30
- </div>
31
- </Card>
32
- );
33
-
34
- const heading = getByRole('heading');
35
- expect(heading).toBeVisible();
36
- expect(heading).toHaveTextContent('Lorem ipsum');
37
- });
38
- });
@@ -1,30 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentMeta } from '@storybook/react';
3
-
4
- import { Card as CardComponent, CardProps } from '../Card';
5
-
6
- export default {
7
- title: 'Components/Card',
8
- component: CardComponent,
9
- } as ComponentMeta<typeof CardComponent>;
10
-
11
- type ICardArgs = CardProps;
12
-
13
- export const Card = (args: ICardArgs): React.ReactElement => {
14
- return (
15
- <div style={{ width: '300px' }}>
16
- <CardComponent {...args} />
17
- </div>
18
- );
19
- };
20
-
21
- Card.args = {
22
- title: 'Title goes here',
23
- img: 'https://via.placeholder.com/100',
24
- children: (
25
- <p style={{ margin: 0 }}>
26
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
27
- tempor incididunt ut labore
28
- </p>
29
- ),
30
- } as ICardArgs;