@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,133 @@
1
+ import * as React from 'react';
2
+ import cx from 'clsx';
3
+ import { EditableTag } from './EditableTag';
4
+ import { KeyCodes } from '../../utils/keyCodes';
5
+ import { FieldError } from '../FieldError';
6
+
7
+ import styles from './TagInput.module.scss';
8
+
9
+ const baseClass = 'tag-input';
10
+
11
+ const tagSeparatorKeys = [
12
+ KeyCodes.enter,
13
+ KeyCodes.spacebar,
14
+ KeyCodes.tab,
15
+ KeyCodes.semicolon,
16
+ KeyCodes.comma,
17
+ ];
18
+ const tagRemoveKeys = [KeyCodes.backspace, KeyCodes.delete];
19
+
20
+ type Tags = string[];
21
+
22
+ export interface TagInputProps {
23
+ error?: string;
24
+ tags?: Tags;
25
+ onChange: (tags: Tags) => void;
26
+ placeholder?: string;
27
+ validator?: (val: string) => boolean;
28
+ size?: 'medium' | 'large';
29
+ }
30
+
31
+ export const TagInput: React.FC<TagInputProps> = ({
32
+ tags,
33
+ onChange,
34
+ validator,
35
+ error,
36
+ placeholder,
37
+ size = 'medium',
38
+ }) => {
39
+ const mergedClassNames = cx(styles[baseClass], {
40
+ [styles[`${baseClass}--error`]]: error,
41
+ });
42
+ const inputClassNames = cx(
43
+ styles[`${baseClass}__input`],
44
+ styles[`${baseClass}__input--${size}`]
45
+ );
46
+
47
+ const [inputValue, setInputValue] = React.useState('');
48
+ const inputRef = React.useRef<HTMLInputElement>(null);
49
+
50
+ const addTag = (value: string) => {
51
+ onChange([...(tags || []), value]);
52
+ setInputValue('');
53
+ };
54
+
55
+ const removeTag = (idx: number) => {
56
+ const newTags = [...(tags || [])];
57
+ newTags.splice(idx, 1);
58
+ onChange(newTags);
59
+ };
60
+
61
+ const onInputChange = (e: React.ChangeEvent<HTMLInputElement>) =>
62
+ setInputValue(e.target.value);
63
+
64
+ const onInputKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
65
+ if (tagSeparatorKeys.includes(e.key)) {
66
+ e.preventDefault();
67
+
68
+ if (inputValue === '') {
69
+ return;
70
+ }
71
+
72
+ addTag(inputValue);
73
+ } else if (tagRemoveKeys.includes(e.key)) {
74
+ if (inputValue !== '' || !tags?.length) {
75
+ return;
76
+ }
77
+
78
+ removeTag(tags.length - 1);
79
+ }
80
+ };
81
+
82
+ const updateTag = (i: number, value: string) => {
83
+ const newTags = [...(tags || [])];
84
+ const numOccurrencesOfValue = newTags.reduce(
85
+ (prev, currentValue, index) =>
86
+ prev + (currentValue === value && index !== i ? 1 : 0),
87
+ 0
88
+ );
89
+ if (numOccurrencesOfValue > 0) {
90
+ newTags.splice(i, 1);
91
+ } else {
92
+ newTags[i] = value;
93
+ }
94
+ onChange(newTags);
95
+ };
96
+
97
+ const onPaste = (e: React.ClipboardEvent<HTMLInputElement>) => {
98
+ e.preventDefault();
99
+ const text = e.clipboardData.getData('text/plain');
100
+ const newTags = text.split(/[\s,;\n]+/);
101
+ onChange([...(tags || []), ...newTags]);
102
+ };
103
+
104
+ return (
105
+ <>
106
+ <div className={mergedClassNames}>
107
+ {tags?.map((tag, index) => (
108
+ <EditableTag
109
+ index={index}
110
+ key={`${index}${tag}`}
111
+ update={updateTag}
112
+ remove={removeTag}
113
+ inputRef={inputRef}
114
+ validator={validator}
115
+ size={size}
116
+ >
117
+ {tag}
118
+ </EditableTag>
119
+ ))}
120
+ <input
121
+ ref={inputRef}
122
+ className={inputClassNames}
123
+ placeholder={placeholder}
124
+ value={inputValue}
125
+ onChange={onInputChange}
126
+ onKeyDown={onInputKeyDown}
127
+ onPaste={onPaste}
128
+ />
129
+ </div>
130
+ {error && <FieldError>{error}</FieldError>}
131
+ </>
132
+ );
133
+ };
@@ -0,0 +1,4 @@
1
+ export { TagInput } from './TagInput';
2
+ export type { TagInputProps } from './TagInput';
3
+ export { EmailTagInput } from './EmailTagInput';
4
+ export type { EmailTagInputProps } from './EmailTagInput';
@@ -0,0 +1,90 @@
1
+ .text-field {
2
+ margin-bottom: 20px;
3
+
4
+ &--inline {
5
+ display: flex;
6
+ flex-direction: column;
7
+ }
8
+
9
+ &__wrapper--inline {
10
+ display: flex;
11
+ flex-direction: row;
12
+ flex-wrap: nowrap;
13
+ }
14
+
15
+ &__label {
16
+ align-items: center;
17
+ display: flex;
18
+ flex-direction: row;
19
+ justify-content: flex-start;
20
+ margin-bottom: 4px;
21
+
22
+ label {
23
+ margin-bottom: 0;
24
+ }
25
+
26
+ &--inline {
27
+ align-items: center;
28
+ height: 32px;
29
+ justify-content: center;
30
+ margin-bottom: 0;
31
+ margin-right: 10px;
32
+ }
33
+
34
+ &--no-text {
35
+ justify-content: flex-end;
36
+ margin-right: 0;
37
+ }
38
+ }
39
+
40
+ &__label-wrapper {
41
+ display: flex;
42
+ flex-grow: 1;
43
+ }
44
+
45
+ &__label-adornment {
46
+ align-items: center;
47
+ align-self: flex-end;
48
+ display: flex;
49
+ flex-shrink: 0;
50
+ height: 20px;
51
+ justify-content: flex-end;
52
+ line-height: 20px;
53
+ margin-left: 4px;
54
+ overflow: hidden;
55
+ width: 20px;
56
+ }
57
+
58
+ &__label-right-node {
59
+ align-self: flex-end;
60
+ color: var(--content-default);
61
+ display: flex;
62
+ flex-shrink: 0;
63
+ font-size: 14px;
64
+ justify-content: flex-end;
65
+ line-height: 20px;
66
+ margin-left: 5px;
67
+
68
+ &--inline {
69
+ flex-grow: 1;
70
+ margin-bottom: 4px;
71
+ }
72
+ }
73
+
74
+ &__row-break {
75
+ flex-basis: 100%;
76
+ height: 0;
77
+ }
78
+
79
+ &__content {
80
+ flex-grow: 1;
81
+ }
82
+ }
83
+
84
+ .field-label {
85
+ color: var(--content-default);
86
+ display: block;
87
+ font-size: 14px;
88
+ line-height: 20px;
89
+ margin-bottom: 4px;
90
+ }
@@ -0,0 +1,40 @@
1
+ import * as React from 'react';
2
+ import { render } from 'test-utils';
3
+ import { TextFieldProps, TextField } from './TextField';
4
+
5
+ const renderComponent = (props: TextFieldProps) => {
6
+ return render(
7
+ <TextField {...props} className="my-css-class">
8
+ <input id="input-field-example" />
9
+ </TextField>
10
+ );
11
+ };
12
+
13
+ describe('<TextField> component', () => {
14
+ it('should allow for custom class', () => {
15
+ const { container } = renderComponent({});
16
+
17
+ expect(container.firstChild).toHaveClass('my-css-class');
18
+ });
19
+
20
+ it('should render field elements', () => {
21
+ const label = 'Example label text';
22
+ const error = 'Error text';
23
+ const description = <div>Description text</div>;
24
+ const adornment = <div>Decoration element</div>;
25
+ const labelRight = <div>Label right</div>;
26
+ const { getByText } = renderComponent({
27
+ labelText: label,
28
+ error: error,
29
+ description: description,
30
+ labelAdornment: adornment,
31
+ labelRightNode: labelRight,
32
+ });
33
+
34
+ expect(getByText(label)).toBeVisible();
35
+ expect(getByText(error)).toBeVisible();
36
+ expect(getByText('Description text')).toBeVisible();
37
+ expect(getByText('Decoration element')).toBeVisible();
38
+ expect(getByText('Label right')).toBeVisible();
39
+ });
40
+ });
@@ -0,0 +1,60 @@
1
+ import * as React from 'react';
2
+ import { ComponentMeta, Story } from '@storybook/react';
3
+
4
+ import { TextFieldProps, TextField as TextFieldComponent } from './TextField';
5
+
6
+ export default {
7
+ title: 'Forms (WIP)/TextField',
8
+ component: TextFieldComponent,
9
+ parameters: {
10
+ componentSubtitle: `
11
+ TextField is useful if you need to develop custom input field,
12
+ but want to reuse the logic behind labels, descriptions and errors
13
+ present in other form components like InputField, TextAreaField etc.
14
+ `,
15
+ },
16
+ } as ComponentMeta<typeof TextFieldComponent>;
17
+
18
+ const StoryTemplate: Story<TextFieldProps> = (args: TextFieldProps) => (
19
+ <div>
20
+ <TextFieldComponent {...args}>
21
+ <input style={{ height: 26 }} id="text-field-example" />
22
+ </TextFieldComponent>
23
+ </div>
24
+ );
25
+
26
+ export const TextField = StoryTemplate.bind({});
27
+ TextField.args = {};
28
+
29
+ export const TextFieldWithLabel = StoryTemplate.bind({});
30
+ TextFieldWithLabel.args = {
31
+ labelText: 'Example label text',
32
+ };
33
+
34
+ export const TextFieldWithLabelInline = StoryTemplate.bind({});
35
+ TextFieldWithLabelInline.args = {
36
+ labelText: 'Example label text',
37
+ inline: true,
38
+ };
39
+
40
+ export const TextFieldWithLabelAndLabelRightNode = StoryTemplate.bind({});
41
+ TextFieldWithLabelAndLabelRightNode.args = {
42
+ labelText: 'Example label text',
43
+ labelRightNode: <img src="https://via.placeholder.com/100" />,
44
+ };
45
+
46
+ export const TextFieldWithLabelAdornment = StoryTemplate.bind({});
47
+ TextFieldWithLabelAdornment.args = {
48
+ labelText: 'Example label text',
49
+ labelAdornment: <img src="https://via.placeholder.com/100" />,
50
+ };
51
+
52
+ export const TextFieldWithError = StoryTemplate.bind({});
53
+ TextFieldWithError.args = {
54
+ error: 'Error text',
55
+ };
56
+
57
+ export const TextFieldWithDescription = StoryTemplate.bind({});
58
+ TextFieldWithDescription.args = {
59
+ description: <div>Description text</div>,
60
+ };
@@ -0,0 +1,100 @@
1
+ import * as React from 'react';
2
+ import cx from 'clsx';
3
+ import { Text } from '../Typography';
4
+ import { FieldError } from '../FieldError';
5
+ import { FieldDescription } from '../FieldDescription';
6
+
7
+ import styles from './TextField.module.scss';
8
+
9
+ const baseClass = 'text-field';
10
+
11
+ export interface TextFieldProps {
12
+ labelText?: string;
13
+ labelAdornment?: React.ReactNode;
14
+ labelFor?: string;
15
+ className?: string;
16
+ inline?: boolean;
17
+ error?: string;
18
+ description?: React.ReactNode;
19
+ children?: React.ReactNode;
20
+ labelRightNode?: React.ReactNode;
21
+ }
22
+
23
+ export const TextField: React.FC<TextFieldProps> = ({
24
+ inline,
25
+ error,
26
+ description,
27
+ labelText,
28
+ labelAdornment,
29
+ className,
30
+ labelFor,
31
+ children,
32
+ labelRightNode,
33
+ }) => {
34
+ const mergedClassNames = cx(
35
+ styles[baseClass],
36
+ {
37
+ [styles[`${baseClass}--inline`]]: inline,
38
+ },
39
+ className
40
+ );
41
+
42
+ return (
43
+ <div className={mergedClassNames}>
44
+ {labelRightNode && inline && (
45
+ <React.Fragment>
46
+ <div
47
+ className={cx(
48
+ styles[`${baseClass}__label-right-node`],
49
+ styles[`${baseClass}__label-right-node--inline`]
50
+ )}
51
+ >
52
+ {labelRightNode}
53
+ </div>
54
+ <div className={styles[`${baseClass}__row-break`]} />
55
+ </React.Fragment>
56
+ )}
57
+ <div
58
+ className={cx(
59
+ styles[`${baseClass}__wrapper`],
60
+ inline && styles[`${baseClass}__wrapper--inline`]
61
+ )}
62
+ >
63
+ {(labelText || labelRightNode) && (
64
+ <div
65
+ className={cx(
66
+ styles[`${baseClass}__label`],
67
+ inline && styles[`${baseClass}__label--inline`],
68
+ !labelText && styles[`${baseClass}__label--no-text`]
69
+ )}
70
+ >
71
+ {labelText && (
72
+ <div className={cx(styles[`${baseClass}__label-wrapper`])}>
73
+ <label className="lc-field-label" htmlFor={labelFor}>
74
+ <Text as="span" size="sm">
75
+ {labelText}
76
+ </Text>
77
+ </label>
78
+ {labelAdornment && (
79
+ <div className={cx(styles[`${baseClass}__label-adornment`])}>
80
+ {labelAdornment}
81
+ </div>
82
+ )}
83
+ </div>
84
+ )}
85
+ {labelRightNode && !inline && (
86
+ <div className={cx(styles[`${baseClass}__label-right-node`])}>
87
+ {labelRightNode}
88
+ </div>
89
+ )}
90
+ </div>
91
+ )}
92
+ <div className={cx(styles[`${baseClass}__content`])}>
93
+ {children}
94
+ {error && <FieldError>{error}</FieldError>}
95
+ {description && <FieldDescription>{description}</FieldDescription>}
96
+ </div>
97
+ </div>
98
+ </div>
99
+ );
100
+ };
@@ -0,0 +1 @@
1
+ export { TextField } from './TextField';
@@ -0,0 +1,218 @@
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
+ }