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

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 (233) hide show
  1. package/dist/dsrc.cjs.js +1 -0
  2. package/dist/dsrc.es.js +2213 -0
  3. package/dist/dsrc.umd.js +1 -0
  4. package/dist/src/components/Alert/Alert.d.ts +19 -0
  5. package/{src/components/Alert/index.ts → dist/src/components/Alert/index.d.ts} +0 -0
  6. package/dist/src/components/Badge/Badge.d.ts +5 -0
  7. package/{src/components/Badge/index.ts → dist/src/components/Badge/index.d.ts} +0 -0
  8. package/dist/src/components/Button/Button.d.ts +13 -0
  9. package/{src/components/Button/index.ts → dist/src/components/Button/index.d.ts} +0 -0
  10. package/dist/src/components/ButtonGroup/ButtonGroup.d.ts +11 -0
  11. package/{src/components/ButtonGroup/index.ts → dist/src/components/ButtonGroup/index.d.ts} +0 -0
  12. package/dist/src/components/Card/Card.d.ts +6 -0
  13. package/{src/components/Card/index.ts → dist/src/components/Card/index.d.ts} +0 -0
  14. package/dist/src/components/Checkbox/Checkbox.d.ts +7 -0
  15. package/dist/src/components/Checkbox/CheckboxField.d.ts +7 -0
  16. package/{src/components/Checkbox/index.ts → dist/src/components/Checkbox/index.d.ts} +0 -0
  17. package/dist/src/components/FieldDescription/FieldDescription.d.ts +3 -0
  18. package/{src/components/FieldDescription/index.ts → dist/src/components/FieldDescription/index.d.ts} +0 -0
  19. package/dist/src/components/FieldError/FieldError.d.ts +3 -0
  20. package/{src/components/FieldError/index.ts → dist/src/components/FieldError/index.d.ts} +0 -0
  21. package/dist/src/components/FieldGroup/FieldGroup.d.ts +8 -0
  22. package/{src/components/FieldGroup/index.ts → dist/src/components/FieldGroup/index.d.ts} +0 -0
  23. package/dist/src/components/Form/Form.d.ts +7 -0
  24. package/{src/components/Form/index.ts → dist/src/components/Form/index.d.ts} +0 -0
  25. package/dist/src/components/FormGroup/FormGroup.d.ts +7 -0
  26. package/{src/components/FormGroup/index.ts → dist/src/components/FormGroup/index.d.ts} +0 -0
  27. package/dist/src/components/Icon/Icon.d.ts +70 -0
  28. package/{src/components/Icon/index.ts → dist/src/components/Icon/index.d.ts} +0 -0
  29. package/dist/src/components/InputField/InputField.d.ts +15 -0
  30. package/{src/components/InputField/index.ts → dist/src/components/InputField/index.d.ts} +0 -0
  31. package/{src/components/Link/Link.tsx → dist/src/components/Link/Link.d.ts} +3 -26
  32. package/{src/components/Link/index.ts → dist/src/components/Link/index.d.ts} +0 -0
  33. package/dist/src/components/Loader/Loader.d.ts +10 -0
  34. package/{src/components/Loader/index.ts → dist/src/components/Loader/index.d.ts} +0 -0
  35. package/dist/src/components/Modal/ActionModal.d.ts +8 -0
  36. package/dist/src/components/Modal/Modal.d.ts +7 -0
  37. package/dist/src/components/Modal/ModalBase.d.ts +6 -0
  38. package/dist/src/components/Modal/ModalCloseButton.d.ts +3 -0
  39. package/dist/src/components/Modal/ModalPortal.d.ts +7 -0
  40. package/{src/components/Modal/index.ts → dist/src/components/Modal/index.d.ts} +0 -1
  41. package/dist/src/components/NumericInput/NumericInput.d.ts +14 -0
  42. package/dist/src/components/NumericInput/NumericInputField.d.ts +19 -0
  43. package/{src/components/NumericInput/index.ts → dist/src/components/NumericInput/index.d.ts} +0 -0
  44. package/dist/src/components/Popover/Popover.d.ts +15 -0
  45. package/{src/components/Popover/index.ts → dist/src/components/Popover/index.d.ts} +0 -0
  46. package/dist/src/components/Progress/ProgressCircle.d.ts +9 -0
  47. package/dist/src/components/Progress/constants.d.ts +12 -0
  48. package/dist/src/components/Progress/helpers.d.ts +3 -0
  49. package/{src/components/Progress/index.ts → dist/src/components/Progress/index.d.ts} +0 -0
  50. package/dist/src/components/PromoBanner/PromoBanner.d.ts +19 -0
  51. package/{src/components/PromoBanner/index.ts → dist/src/components/PromoBanner/index.d.ts} +0 -0
  52. package/dist/src/components/RadioButton/RadioButton.d.ts +7 -0
  53. package/{src/components/RadioButton/index.ts → dist/src/components/RadioButton/index.d.ts} +0 -0
  54. package/dist/src/components/Switch/Switch.d.ts +20 -0
  55. package/{src/components/Switch/index.ts → dist/src/components/Switch/index.d.ts} +0 -0
  56. package/dist/src/components/Tab/Tab.d.ts +12 -0
  57. package/dist/src/components/Tab/TabsWrapper.d.ts +3 -0
  58. package/{src/components/Tab/index.ts → dist/src/components/Tab/index.d.ts} +0 -0
  59. package/dist/src/components/Tag/Tag.d.ts +12 -0
  60. package/{src/components/Tag/index.ts → dist/src/components/Tag/index.d.ts} +0 -0
  61. package/dist/src/components/TagInput/EditableTag.d.ts +11 -0
  62. package/dist/src/components/TagInput/EditableTagContent.d.ts +11 -0
  63. package/dist/src/components/TagInput/EmailTagInput.d.ts +5 -0
  64. package/dist/src/components/TagInput/TagInput.d.ts +12 -0
  65. package/{src/components/TagInput/index.ts → dist/src/components/TagInput/index.d.ts} +0 -0
  66. package/dist/src/components/TextField/TextField.d.ts +13 -0
  67. package/{src/components/TextField/index.ts → dist/src/components/TextField/index.d.ts} +0 -0
  68. package/dist/src/components/Toast/Toast.d.ts +22 -0
  69. package/dist/src/components/Toast/ToastWrapper.d.ts +27 -0
  70. package/{src/components/Toast/index.ts → dist/src/components/Toast/index.d.ts} +0 -0
  71. package/dist/src/components/Typography/Heading.d.ts +11 -0
  72. package/dist/src/components/Typography/Text.d.ts +15 -0
  73. package/{src/components/Typography/index.ts → dist/src/components/Typography/index.d.ts} +0 -0
  74. package/{src/index.ts → dist/src/index.d.ts} +0 -3
  75. package/dist/src/themes/designTokens.d.ts +126 -0
  76. package/dist/src/utils/keyCodes.d.ts +12 -0
  77. package/dist/src/utils/noop.d.ts +1 -0
  78. package/{src → dist/src}/vite-env.d.ts +0 -0
  79. package/dist/style.css +1 -0
  80. package/{src/themes/dark.scss → dist/themes/dark.css} +2 -0
  81. package/dist/themes/dark.css.map +1 -0
  82. package/{src/themes/legacy.scss → dist/themes/legacy.css} +2 -0
  83. package/dist/themes/legacy.css.map +1 -0
  84. package/{src/themes/light.scss → dist/themes/light.css} +2 -0
  85. package/dist/themes/light.css.map +1 -0
  86. package/package.json +8 -5
  87. package/.eslintrc +0 -9
  88. package/.storybook/main.js +0 -20
  89. package/.storybook/preview-head.html +0 -31
  90. package/.storybook/preview.js +0 -21
  91. package/src/components/Alert/Alert.module.scss +0 -88
  92. package/src/components/Alert/Alert.spec.tsx +0 -78
  93. package/src/components/Alert/Alert.stories.tsx +0 -73
  94. package/src/components/Alert/Alert.tsx +0 -94
  95. package/src/components/Badge/Badge.module.scss +0 -23
  96. package/src/components/Badge/Badge.spec.tsx +0 -12
  97. package/src/components/Badge/Badge.stories.tsx +0 -24
  98. package/src/components/Badge/Badge.tsx +0 -24
  99. package/src/components/Button/Button.module.scss +0 -257
  100. package/src/components/Button/Button.spec.tsx +0 -110
  101. package/src/components/Button/Button.stories.tsx +0 -152
  102. package/src/components/Button/Button.tsx +0 -88
  103. package/src/components/ButtonGroup/ButtonGroup.module.scss +0 -31
  104. package/src/components/ButtonGroup/ButtonGroup.spec.tsx +0 -61
  105. package/src/components/ButtonGroup/ButtonGroup.stories.tsx +0 -53
  106. package/src/components/ButtonGroup/ButtonGroup.tsx +0 -75
  107. package/src/components/Card/Card.module.scss +0 -31
  108. package/src/components/Card/Card.spec.tsx +0 -38
  109. package/src/components/Card/Card.stories.tsx +0 -30
  110. package/src/components/Card/Card.tsx +0 -34
  111. package/src/components/Checkbox/Checkbox.module.scss +0 -99
  112. package/src/components/Checkbox/Checkbox.tsx +0 -39
  113. package/src/components/Checkbox/CheckboxField.spec.tsx +0 -58
  114. package/src/components/Checkbox/CheckboxField.stories.tsx +0 -30
  115. package/src/components/Checkbox/CheckboxField.tsx +0 -46
  116. package/src/components/FieldDescription/FieldDescription.module.scss +0 -5
  117. package/src/components/FieldDescription/FieldDescription.tsx +0 -23
  118. package/src/components/FieldError/FieldError.module.scss +0 -5
  119. package/src/components/FieldError/FieldError.tsx +0 -23
  120. package/src/components/FieldGroup/FieldGroup.module.scss +0 -25
  121. package/src/components/FieldGroup/FieldGroup.spec.tsx +0 -42
  122. package/src/components/FieldGroup/FieldGroup.stories.tsx +0 -34
  123. package/src/components/FieldGroup/FieldGroup.tsx +0 -38
  124. package/src/components/Form/Form.module.scss +0 -22
  125. package/src/components/Form/Form.spec.tsx +0 -38
  126. package/src/components/Form/Form.stories.tsx +0 -42
  127. package/src/components/Form/Form.tsx +0 -46
  128. package/src/components/FormGroup/FormGroup.module.scss +0 -20
  129. package/src/components/FormGroup/FormGroup.spec.tsx +0 -34
  130. package/src/components/FormGroup/FormGroup.stories.tsx +0 -30
  131. package/src/components/FormGroup/FormGroup.tsx +0 -44
  132. package/src/components/Icon/Icon.module.scss +0 -70
  133. package/src/components/Icon/Icon.stories.tsx +0 -53
  134. package/src/components/Icon/Icon.tsx +0 -118
  135. package/src/components/InputField/InputField.module.scss +0 -37
  136. package/src/components/InputField/InputField.spec.tsx +0 -53
  137. package/src/components/InputField/InputField.stories.tsx +0 -73
  138. package/src/components/InputField/InputField.tsx +0 -72
  139. package/src/components/Link/Link.module.scss +0 -18
  140. package/src/components/Link/Link.stories.tsx +0 -17
  141. package/src/components/Loader/Loader.module.scss +0 -66
  142. package/src/components/Loader/Loader.spec.tsx +0 -64
  143. package/src/components/Loader/Loader.stories.tsx +0 -25
  144. package/src/components/Loader/Loader.tsx +0 -48
  145. package/src/components/Modal/ActionModal.tsx +0 -37
  146. package/src/components/Modal/Modal.module.scss +0 -131
  147. package/src/components/Modal/Modal.stories.tsx +0 -85
  148. package/src/components/Modal/Modal.tsx +0 -41
  149. package/src/components/Modal/ModalBase.spec.tsx +0 -58
  150. package/src/components/Modal/ModalBase.tsx +0 -66
  151. package/src/components/Modal/ModalCloseButton.tsx +0 -20
  152. package/src/components/Modal/ModalPortal.tsx +0 -35
  153. package/src/components/NumericInput/NumericInput.module.scss +0 -110
  154. package/src/components/NumericInput/NumericInput.spec.tsx +0 -129
  155. package/src/components/NumericInput/NumericInput.stories.tsx +0 -56
  156. package/src/components/NumericInput/NumericInput.tsx +0 -161
  157. package/src/components/NumericInput/NumericInputField.stories.tsx +0 -58
  158. package/src/components/NumericInput/NumericInputField.tsx +0 -57
  159. package/src/components/Popover/Popover.module.scss +0 -16
  160. package/src/components/Popover/Popover.spec.tsx +0 -39
  161. package/src/components/Popover/Popover.stories.css +0 -23
  162. package/src/components/Popover/Popover.stories.tsx +0 -164
  163. package/src/components/Popover/Popover.tsx +0 -124
  164. package/src/components/Progress/ProgressBar.module.scss +0 -48
  165. package/src/components/Progress/ProgressBar.spec.tsx +0 -33
  166. package/src/components/Progress/ProgressBar.stories.tsx +0 -23
  167. package/src/components/Progress/ProgressBar.tsx +0 -62
  168. package/src/components/Progress/ProgressCircle.module.scss +0 -64
  169. package/src/components/Progress/ProgressCircle.spec.tsx +0 -34
  170. package/src/components/Progress/ProgressCircle.stories.tsx +0 -28
  171. package/src/components/Progress/ProgressCircle.tsx +0 -104
  172. package/src/components/Progress/constants.ts +0 -23
  173. package/src/components/Progress/helpers.ts +0 -23
  174. package/src/components/PromoBanner/PromoBanner.module.scss +0 -121
  175. package/src/components/PromoBanner/PromoBanner.spec.tsx +0 -119
  176. package/src/components/PromoBanner/PromoBanner.stories.tsx +0 -125
  177. package/src/components/PromoBanner/PromoBanner.tsx +0 -99
  178. package/src/components/RadioButton/RadioButton.module.scss +0 -100
  179. package/src/components/RadioButton/RadioButton.spec.tsx +0 -70
  180. package/src/components/RadioButton/RadioButton.stories.tsx +0 -34
  181. package/src/components/RadioButton/RadioButton.tsx +0 -54
  182. package/src/components/Switch/Switch.module.scss +0 -126
  183. package/src/components/Switch/Switch.spec.tsx +0 -40
  184. package/src/components/Switch/Switch.stories.tsx +0 -23
  185. package/src/components/Switch/Switch.tsx +0 -100
  186. package/src/components/Tab/Tab.module.scss +0 -56
  187. package/src/components/Tab/Tab.spec.tsx +0 -34
  188. package/src/components/Tab/Tab.stories.tsx +0 -20
  189. package/src/components/Tab/Tab.tsx +0 -49
  190. package/src/components/Tab/TabsWrapper.module.scss +0 -11
  191. package/src/components/Tab/TabsWrapper.spec.tsx +0 -19
  192. package/src/components/Tab/TabsWrapper.stories.tsx +0 -46
  193. package/src/components/Tab/TabsWrapper.tsx +0 -24
  194. package/src/components/Tag/Tag.module.scss +0 -131
  195. package/src/components/Tag/Tag.spec.tsx +0 -93
  196. package/src/components/Tag/Tag.stories.tsx +0 -151
  197. package/src/components/Tag/Tag.tsx +0 -129
  198. package/src/components/TagInput/EditableTag.tsx +0 -54
  199. package/src/components/TagInput/EditableTagContent.tsx +0 -81
  200. package/src/components/TagInput/EmailTagInput.tsx +0 -31
  201. package/src/components/TagInput/TagInput.module.scss +0 -81
  202. package/src/components/TagInput/TagInput.spec.tsx +0 -58
  203. package/src/components/TagInput/TagInput.stories.tsx +0 -49
  204. package/src/components/TagInput/TagInput.tsx +0 -133
  205. package/src/components/TextField/TextField.module.scss +0 -90
  206. package/src/components/TextField/TextField.spec.tsx +0 -40
  207. package/src/components/TextField/TextField.stories.tsx +0 -60
  208. package/src/components/TextField/TextField.tsx +0 -100
  209. package/src/components/Toast/Toast.module.scss +0 -218
  210. package/src/components/Toast/Toast.spec.tsx +0 -96
  211. package/src/components/Toast/Toast.stories.tsx +0 -64
  212. package/src/components/Toast/Toast.tsx +0 -121
  213. package/src/components/Toast/ToastWrapper.spec.tsx +0 -13
  214. package/src/components/Toast/ToastWrapper.stories.tsx +0 -55
  215. package/src/components/Toast/ToastWrapper.tsx +0 -87
  216. package/src/components/Typography/Heading.tsx +0 -36
  217. package/src/components/Typography/Text.tsx +0 -49
  218. package/src/components/Typography/Typography.module.scss +0 -132
  219. package/src/index.scss +0 -9
  220. package/src/stories/ColorTokens.stories.mdx +0 -10
  221. package/src/stories/Icons.stories.mdx +0 -12
  222. package/src/stories/Typography.stories.mdx +0 -65
  223. package/src/stories/components/ColorTokens.tsx +0 -99
  224. package/src/stories/components/IconsShowcase.tsx +0 -25
  225. package/src/stories/components/iconsShowcase.css +0 -13
  226. package/src/test/setup.ts +0 -1
  227. package/src/test/utils.ts +0 -3
  228. package/src/themes/designTokens.ts +0 -126
  229. package/src/utils/keyCodes.ts +0 -12
  230. package/src/utils/noop.ts +0 -2
  231. package/tsconfig.json +0 -25
  232. package/tsconfig.node.json +0 -8
  233. package/vite.config.ts +0 -44
@@ -1,218 +0,0 @@
1
- $toast-appear-animation-timeout: 200ms;
2
- $toast-exit-animation-timeout: 200ms;
3
-
4
- .toast {
5
- align-items: center;
6
- background: #fff;
7
- border-radius: 4px;
8
- box-shadow: 0 6px 30px -10px rgba(0, 0, 0, 0.3);
9
- box-sizing: border-box;
10
- display: inline-flex;
11
- flex: 0 1 auto;
12
- font-size: 15px;
13
- font-stretch: normal;
14
- font-style: normal;
15
- font-weight: 600;
16
- justify-content: flex-start;
17
- letter-spacing: normal;
18
- line-height: 20px;
19
- max-width: 500px;
20
- min-width: 300px;
21
- padding: 10px 12px;
22
-
23
- &__content {
24
- color: var(--content-default);
25
- width: 100%;
26
- }
27
-
28
- &__icon,
29
- &__close {
30
- align-self: baseline;
31
- height: 20px;
32
- padding-right: 12px;
33
- }
34
-
35
- &__icon svg {
36
- display: flex;
37
- fill: var(--color-action-default);
38
- height: 20px;
39
- width: 20px;
40
- }
41
-
42
- &__actions {
43
- align-items: center;
44
- align-self: flex-start;
45
- display: inline-flex;
46
- flex: 1 0 auto;
47
- flex-wrap: nowrap;
48
- height: 20px;
49
- margin-bottom: auto;
50
- margin-left: auto;
51
-
52
- &-close {
53
- align-items: center;
54
- display: flex;
55
- flex: 0 1 auto;
56
- height: 100%;
57
- margin-left: 16px;
58
- width: 100%;
59
-
60
- svg {
61
- cursor: pointer;
62
- display: flex;
63
- fill: var(--content-subtle);
64
- height: 16px;
65
- width: 16px;
66
- }
67
- }
68
-
69
- &-custom {
70
- background-color: transparent;
71
- border: 0;
72
- color: var(--content-default);
73
- cursor: pointer;
74
- font-weight: 600;
75
- line-height: 20px;
76
- margin-left: 16px;
77
- outline: 0;
78
- padding: 0;
79
- text-decoration: underline;
80
- white-space: nowrap;
81
- }
82
- }
83
-
84
- &--notification {
85
- background: #fff;
86
- }
87
-
88
- &--success {
89
- background: var(--color-positive-default);
90
- }
91
-
92
- &--warning {
93
- background: var(--color-warning-default);
94
-
95
- .toast__content {
96
- color: #424d57;
97
- }
98
- }
99
-
100
- &--error {
101
- background: var(--color-negative-default);
102
- }
103
-
104
- &--info {
105
- background: var(--color-action-default);
106
- }
107
-
108
- &--success,
109
- &--error,
110
- &--info {
111
- .toast__content,
112
- .toast__actions-custom {
113
- color: #fff;
114
- }
115
- }
116
-
117
- &-wrapper {
118
- align-items: center;
119
- display: flex;
120
- flex-direction: column;
121
- position: absolute;
122
- z-index: 120;
123
-
124
- &--fixed {
125
- position: fixed;
126
- }
127
-
128
- &--block {
129
- position: static;
130
- }
131
-
132
- &--horizontal-center {
133
- left: calc(50%);
134
- transform: translateX(-50%);
135
- }
136
-
137
- &--horizontal-left {
138
- left: 5px;
139
- }
140
-
141
- &--horizontal-right {
142
- right: 5px;
143
- }
144
-
145
- &--vertical-top {
146
- top: 5px;
147
-
148
- .toast {
149
- margin-bottom: 10px;
150
- }
151
-
152
- .toast-appear--slide {
153
- transform: translateY(-100%) !important;
154
-
155
- &.toast-appear-active--slide {
156
- transform: translateY(0) !important;
157
- transition: transform $toast-appear-animation-timeout ease-in;
158
- }
159
- }
160
-
161
- .toast-exit--slide {
162
- transform: translateY(0) !important;
163
-
164
- &.toast-exit-active--slide {
165
- transform: translateY(-100%) !important;
166
- transition: transform $toast-exit-animation-timeout ease-in;
167
- }
168
- }
169
- }
170
-
171
- &--vertical-bottom {
172
- bottom: 5px;
173
-
174
- .toast {
175
- margin-top: 10px;
176
- }
177
-
178
- .toast-appear--slide {
179
- transform: translateY(100%) !important;
180
-
181
- &.toast-appear-active--slide {
182
- transform: translateY(0) !important;
183
- transition: transform $toast-appear-animation-timeout ease-in;
184
- }
185
- }
186
-
187
- .toast-exit--slide {
188
- transform: translateY(0) !important;
189
-
190
- &.toast-exit-active--slide {
191
- transform: translateY(100%) !important;
192
- transition: transform $toast-exit-animation-timeout ease-in;
193
- }
194
- }
195
- }
196
-
197
- &--vertical-top,
198
- &--vertical-bottom {
199
- .toast-appear--fade {
200
- opacity: 0;
201
-
202
- &.toast-appear-active--fade {
203
- opacity: 1;
204
- transition: opacity $toast-appear-animation-timeout ease-in;
205
- }
206
- }
207
-
208
- .toast-exit--fade {
209
- opacity: 1;
210
- transition: opacity $toast-appear-animation-timeout ease-in;
211
-
212
- &.toast-exit-active--fade {
213
- opacity: 0;
214
- }
215
- }
216
- }
217
- }
218
- }
@@ -1,96 +0,0 @@
1
- import * as React from 'react';
2
- import { render, fireEvent, vi } from 'test-utils';
3
- import { ToastProps, Toast, Variants } from './Toast';
4
-
5
- import styles from './Toast.module.scss';
6
-
7
- const renderComponent = (props: ToastProps) => {
8
- return render(
9
- <Toast {...props} className="my-css-class">
10
- This example content
11
- </Toast>
12
- );
13
- };
14
-
15
- describe('<Toast> component', () => {
16
- it('should allow for custom class', () => {
17
- const { container } = renderComponent({});
18
-
19
- expect(container.firstChild).toHaveClass('my-css-class');
20
- });
21
-
22
- it('should render as info by default', () => {
23
- const { container } = renderComponent({});
24
-
25
- expect(container.firstChild).toHaveClass(styles['toast--info']);
26
- });
27
-
28
- it('should render as success', () => {
29
- const { container } = renderComponent({ variant: Variants.Success });
30
-
31
- expect(container.firstChild).toHaveClass(styles['toast--success']);
32
- });
33
-
34
- it('should render as warning', () => {
35
- const { container } = renderComponent({ variant: Variants.Warning });
36
-
37
- expect(container.firstChild).toHaveClass(styles['toast--warning']);
38
- });
39
-
40
- it('should render as error', () => {
41
- const { container } = renderComponent({ variant: Variants.Error });
42
-
43
- expect(container.firstChild).toHaveClass(styles['toast--error']);
44
- });
45
-
46
- it('should render as notification', () => {
47
- const { container } = renderComponent({
48
- variant: Variants.Notification,
49
- });
50
-
51
- expect(container.firstChild).toHaveClass(styles['toast--notification']);
52
- });
53
-
54
- it('should render with action button and call action function', () => {
55
- const handler = vi.fn();
56
- const { getByText } = renderComponent({
57
- action: {
58
- label: 'Example action',
59
- handler,
60
- },
61
- });
62
-
63
- expect(getByText('Example action')).toBeVisible();
64
- fireEvent.click(getByText('Example action'));
65
- expect(handler).toHaveBeenCalled();
66
- });
67
-
68
- it('should call action function with onClose function', () => {
69
- const handler = vi.fn();
70
- const onClose = vi.fn();
71
- const { getByText } = renderComponent({
72
- action: {
73
- label: 'Example action',
74
- handler,
75
- closeOnClick: true,
76
- },
77
- onClose,
78
- });
79
-
80
- fireEvent.click(getByText('Example action'));
81
- expect(handler).toHaveBeenCalled();
82
- expect(onClose).toHaveBeenCalled();
83
- });
84
-
85
- it('should render with close button and call onClose function', () => {
86
- const onClose = vi.fn();
87
- const { getByLabelText } = renderComponent({
88
- removable: true,
89
- onClose,
90
- });
91
-
92
- expect(getByLabelText('Close toast')).toBeVisible();
93
- fireEvent.click(getByLabelText('Close toast'));
94
- expect(onClose).toHaveBeenCalled();
95
- });
96
- });
@@ -1,64 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentMeta, Story } from '@storybook/react';
3
-
4
- import { ToastProps, Toast as ToastComponent, Variants } from './Toast';
5
-
6
- export default {
7
- title: 'Components/Toast',
8
- component: ToastComponent,
9
- parameters: {
10
- componentSubtitle: `
11
- Toast is a small message that by default shows up in the top middle of the screen.
12
- It disappears on its own after a few seconds. It provides a feedback about an operation
13
- for user.
14
- `,
15
- },
16
- } as ComponentMeta<typeof ToastComponent>;
17
-
18
- interface IToastArgs extends ToastProps {
19
- label: string;
20
- }
21
-
22
- const StoryTemplate: Story<IToastArgs> = (args: IToastArgs) => (
23
- <div>
24
- <ToastComponent {...args}>Example text</ToastComponent>
25
- </div>
26
- );
27
-
28
- export const Toast = StoryTemplate.bind({});
29
- Toast.args = {};
30
-
31
- export const SuccessToast = StoryTemplate.bind({});
32
- SuccessToast.args = {
33
- variant: Variants.Success,
34
- };
35
-
36
- export const WarningToast = StoryTemplate.bind({});
37
- WarningToast.args = {
38
- variant: Variants.Warning,
39
- };
40
-
41
- export const ErrorToast = StoryTemplate.bind({});
42
- ErrorToast.args = {
43
- variant: Variants.Error,
44
- };
45
-
46
- export const InfoToast = StoryTemplate.bind({});
47
- InfoToast.args = {
48
- variant: Variants.Info,
49
- };
50
-
51
- export const NotificationToast = StoryTemplate.bind({});
52
- NotificationToast.args = {
53
- variant: Variants.Notification,
54
- };
55
-
56
- export const ToastWithActionAndRemovable = StoryTemplate.bind({});
57
- ToastWithActionAndRemovable.args = {
58
- action: {
59
- label: 'Action',
60
- handler: () => alert('onAction click'),
61
- },
62
- removable: true,
63
- onClose: () => alert('onClose click'),
64
- };
@@ -1,121 +0,0 @@
1
- import * as React from 'react';
2
- import cx from 'clsx';
3
-
4
- import {
5
- Close,
6
- Info,
7
- Warning,
8
- CheckCircleSolid,
9
- Error,
10
- } from '@livechat/design-system-icons/react/material';
11
- import { Icon, IconSizeName, IconTypeName } from '../Icon';
12
-
13
- import styles from './Toast.module.scss';
14
-
15
- const baseClass = 'toast';
16
-
17
- export const enum Variants {
18
- Success = 'success',
19
- Warning = 'warning',
20
- Error = 'error',
21
- Info = 'info',
22
- Notification = 'notification',
23
- }
24
-
25
- interface ToastAction {
26
- handler: () => void;
27
- label: string;
28
- closeOnClick?: boolean;
29
- }
30
-
31
- export interface ToastProps {
32
- action?: ToastAction;
33
- className?: string;
34
- removable?: boolean;
35
- variant?: Variants;
36
- onClose?: () => void;
37
- }
38
-
39
- const IconConfig = {
40
- [Variants.Success]: {
41
- source: CheckCircleSolid,
42
- iconType: IconTypeName.Inverted,
43
- },
44
- [Variants.Warning]: {
45
- source: Warning,
46
- },
47
- [Variants.Error]: {
48
- source: Error,
49
- iconType: IconTypeName.Inverted,
50
- },
51
- [Variants.Info]: {
52
- source: Info,
53
- iconType: IconTypeName.Inverted,
54
- },
55
- [Variants.Notification]: {
56
- source: Info,
57
- iconType: IconTypeName.Link,
58
- },
59
- };
60
-
61
- export const Toast: React.FC<ToastProps> = ({
62
- action,
63
- className,
64
- children,
65
- removable,
66
- variant = Variants.Info,
67
- onClose,
68
- }) => {
69
- const mergedClassNames = cx(
70
- styles[baseClass],
71
- styles[`${baseClass}--${variant}`],
72
- className
73
- );
74
-
75
- const onActionClick = (action: ToastAction) => {
76
- if (action && action.closeOnClick && onClose) {
77
- action.handler();
78
- return onClose();
79
- }
80
-
81
- return action.handler();
82
- };
83
-
84
- return (
85
- <div className={mergedClassNames}>
86
- <div className={styles[`${baseClass}__icon`]}>
87
- <Icon {...IconConfig[variant]} />
88
- </div>
89
- <div className={styles[`${baseClass}__content`]}>{children}</div>
90
- {(action || removable) && (
91
- <div className={styles[`${baseClass}__actions`]}>
92
- {action && (
93
- <button
94
- className={styles[`${baseClass}__actions-custom`]}
95
- onClick={() => onActionClick(action)}
96
- >
97
- {action.label}
98
- </button>
99
- )}
100
- {removable && (
101
- <div
102
- className={styles[`${baseClass}__actions-close`]}
103
- aria-label="Close toast"
104
- onClick={onClose}
105
- >
106
- <Icon
107
- source={Close}
108
- size={IconSizeName.Small}
109
- iconType={
110
- [Variants.Warning, Variants.Notification].includes(variant)
111
- ? IconTypeName.Primary
112
- : IconTypeName.Inverted
113
- }
114
- />
115
- </div>
116
- )}
117
- </div>
118
- )}
119
- </div>
120
- );
121
- };
@@ -1,13 +0,0 @@
1
- import * as React from 'react';
2
- import { render } from 'test-utils';
3
- import { ToastWrapper } from './ToastWrapper';
4
-
5
- describe('<ToastWrapper> component', () => {
6
- it('should allow for custom class', () => {
7
- const { container } = render(
8
- <ToastWrapper toasts={[]} className="my-css-class" />
9
- );
10
-
11
- expect(container.firstChild).toHaveClass('my-css-class');
12
- });
13
- });
@@ -1,55 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentMeta } from '@storybook/react';
3
-
4
- import {
5
- ToastWrapperProps,
6
- ToastWrapper as ToastWrapperComponent,
7
- } from './ToastWrapper';
8
- import { Variants } from './Toast';
9
-
10
- export default {
11
- title: 'Components/Toast Wrapper',
12
- component: ToastWrapperComponent,
13
- parameters: {
14
- componentSubtitle: `
15
- You can use ToastWrapper component to position your toasts.
16
- `,
17
- },
18
- } as ComponentMeta<typeof ToastWrapperComponent>;
19
-
20
- export const ToastWrapper = (args: ToastWrapperProps): React.ReactElement => (
21
- <div style={{ width: '100%', height: 700, position: 'relative' }}>
22
- <ToastWrapperComponent {...args} />
23
- </div>
24
- );
25
-
26
- ToastWrapper.args = {
27
- fixed: false,
28
- toasts: [
29
- {
30
- id: '1',
31
- variant: Variants.Success,
32
- content: <div>First toast with DOM element as content</div>,
33
- },
34
- {
35
- id: '2',
36
- variant: Variants.Info,
37
- content: 'Second toast with string as content and with removable prop',
38
- removable: true,
39
- },
40
- {
41
- id: '3',
42
- variant: Variants.Warning,
43
- content: 'Third toast with action',
44
- action: {
45
- label: 'Action',
46
- handler: () => alert('Third toast action click'),
47
- },
48
- },
49
- {
50
- id: '4',
51
- variant: Variants.Error,
52
- content: 'Fourth toast',
53
- },
54
- ],
55
- };
@@ -1,87 +0,0 @@
1
- import * as React from 'react';
2
- import cx from 'clsx';
3
- import { TransitionGroup, CSSTransition } from 'react-transition-group';
4
-
5
- import { ToastProps, Toast } from './Toast';
6
-
7
- import styles from './Toast.module.scss';
8
-
9
- export enum HorizontalPosition {
10
- Left = 'left',
11
- Center = 'center',
12
- Right = 'right',
13
- }
14
-
15
- export enum VerticalPosition {
16
- Top = 'top',
17
- Bottom = 'bottom',
18
- }
19
-
20
- export const ANIMATION_TIME = 200;
21
-
22
- const baseClass = 'toast-wrapper';
23
-
24
- interface Toast extends ToastProps {
25
- id: string;
26
- content: React.ReactElement | string;
27
- }
28
-
29
- export interface ToastWrapperProps {
30
- className?: string;
31
- toasts: Toast[];
32
- fixed?: boolean;
33
- block?: boolean;
34
- animationType?: string;
35
- verticalPosition?: VerticalPosition;
36
- horizontalPosition?: HorizontalPosition;
37
- }
38
-
39
- export const ToastWrapper: React.FC<ToastWrapperProps> = ({
40
- className,
41
- toasts = [],
42
- fixed = true,
43
- block = false,
44
- animationType = 'slide',
45
- verticalPosition = 'top',
46
- horizontalPosition = 'center',
47
- }) => {
48
- const mergedClassNames = cx(
49
- styles[baseClass],
50
- {
51
- [styles[`${baseClass}--fixed`]]: fixed,
52
- [styles[`${baseClass}--block`]]: !fixed && block,
53
- [styles[`${baseClass}--horizontal-${horizontalPosition}`]]:
54
- horizontalPosition,
55
- [styles[`${baseClass}--vertical-${verticalPosition}`]]: verticalPosition,
56
- },
57
- className
58
- );
59
-
60
- return (
61
- <div className={mergedClassNames}>
62
- <TransitionGroup component={null}>
63
- {toasts.map(({ id, variant, content, removable, action, onClose }) => (
64
- <CSSTransition
65
- key={id}
66
- classNames={{
67
- enter: styles[`toast-appear--${animationType}`],
68
- enterActive: styles[`toast-appear-active--${animationType}`],
69
- exit: styles[`toast-exit--${animationType}`],
70
- exitActive: styles[`toast-exit-active--${animationType}`],
71
- }}
72
- timeout={ANIMATION_TIME}
73
- >
74
- <Toast
75
- variant={variant}
76
- onClose={onClose}
77
- removable={removable}
78
- action={action}
79
- >
80
- {content}
81
- </Toast>
82
- </CSSTransition>
83
- ))}
84
- </TransitionGroup>
85
- </div>
86
- );
87
- };
@@ -1,36 +0,0 @@
1
- import * as React from 'react';
2
- import cx from 'clsx';
3
-
4
- import styles from './Typography.module.scss';
5
-
6
- enum sizeToElement {
7
- xl = 'h1',
8
- lg = 'h2',
9
- md = 'h3',
10
- sm = 'h4',
11
- xs = 'h5',
12
- }
13
-
14
- type TSize = 'xl' | 'lg' | 'md' | 'sm' | 'xs';
15
-
16
- interface IProps {
17
- size?: TSize;
18
- /** DOM element name that will be rendered */
19
- as?: string;
20
- /** Optional custom className */
21
- className?: string;
22
- }
23
-
24
- export const Heading: React.FC<IProps> = ({
25
- as,
26
- size = 'md',
27
- children,
28
- className,
29
- ...props
30
- }) => {
31
- return React.createElement(
32
- as || sizeToElement[size],
33
- { className: cx(styles[`heading-${size}`], className), ...props },
34
- children
35
- );
36
- };