@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,161 @@
1
+ import * as React from 'react';
2
+ import cx from 'clsx';
3
+ import {
4
+ ChevronUp,
5
+ ChevronDown,
6
+ } from '@livechat/design-system-icons/react/material';
7
+ import { Icon, IconTypeName } from '../Icon';
8
+ import { KeyCodes } from '../../utils/keyCodes';
9
+
10
+ import styles from './NumericInput.module.scss';
11
+
12
+ const baseClass = 'numeric-input';
13
+
14
+ interface Props {
15
+ className?: string;
16
+ error?: string;
17
+ value: string;
18
+ max?: number;
19
+ min?: number;
20
+ disabled?: boolean;
21
+ noControls?: boolean;
22
+ onChange: (value: string) => void;
23
+ }
24
+
25
+ export type NumericInputProps = React.InputHTMLAttributes<HTMLInputElement> &
26
+ Props;
27
+
28
+ export const NumericInput: React.FC<NumericInputProps> = ({
29
+ className,
30
+ error,
31
+ value,
32
+ max,
33
+ min,
34
+ disabled,
35
+ noControls,
36
+ style,
37
+ onChange,
38
+ ...restProps
39
+ }) => {
40
+ const inputRef = React.useRef<null | HTMLInputElement>(null);
41
+
42
+ const mergedClassNames = cx(
43
+ styles[baseClass],
44
+ {
45
+ [styles[`${baseClass}--error`]]: error,
46
+ [styles[`${baseClass}--no-controls`]]: noControls,
47
+ [styles[`${baseClass}--disabled`]]: disabled,
48
+ },
49
+ className
50
+ );
51
+
52
+ const callOnChange = (val: number | string) => onChange(String(val));
53
+
54
+ const calcValue = (val: number) => {
55
+ if (max !== undefined && val > max) {
56
+ return max;
57
+ }
58
+
59
+ if (min !== undefined && val < min) {
60
+ return min;
61
+ }
62
+
63
+ return val;
64
+ };
65
+
66
+ const updateValue = (val: number) => {
67
+ const newValue = parseInt(value, 10) + val;
68
+
69
+ return callOnChange(calcValue(newValue));
70
+ };
71
+
72
+ const onKeyDown: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
73
+ if (e.key === KeyCodes.arrowDown) {
74
+ e.preventDefault();
75
+ updateValue(-1);
76
+ }
77
+
78
+ if (e.key === KeyCodes.arrowUp) {
79
+ e.preventDefault();
80
+ updateValue(1);
81
+ }
82
+ };
83
+
84
+ const hasReachedTheLimit = (value: string, margin?: number) =>
85
+ margin !== undefined && parseInt(value, 10) === margin;
86
+
87
+ const handleOnChange = (e: React.FormEvent<HTMLInputElement>) => {
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ const inputVal = e.currentTarget.value.replace(
91
+ /((?!([-]|([-]?\d+))).)/,
92
+ ''
93
+ );
94
+
95
+ if (inputVal === '' || inputVal === '-') {
96
+ return callOnChange(inputVal);
97
+ }
98
+
99
+ const newValue = parseInt(inputVal, 10);
100
+
101
+ return callOnChange(calcValue(newValue));
102
+ };
103
+
104
+ const handleIncrementClick = () => {
105
+ inputRef.current?.focus();
106
+ return updateValue(1);
107
+ };
108
+
109
+ const handleDecrementClick = () => {
110
+ inputRef.current?.focus();
111
+ return updateValue(-1);
112
+ };
113
+
114
+ return (
115
+ <div className={mergedClassNames} style={style}>
116
+ <input
117
+ type="text"
118
+ ref={inputRef}
119
+ {...restProps}
120
+ value={value}
121
+ disabled={disabled}
122
+ onChange={handleOnChange}
123
+ onKeyDown={onKeyDown}
124
+ min={min}
125
+ max={max}
126
+ />
127
+ {!noControls && (
128
+ <>
129
+ <button
130
+ tabIndex={-1}
131
+ disabled={disabled || hasReachedTheLimit(value, max)}
132
+ onClick={handleIncrementClick}
133
+ aria-label="Increment value"
134
+ className={styles[`${baseClass}__increment`]}
135
+ type="button"
136
+ >
137
+ <Icon
138
+ source={ChevronUp}
139
+ disabled={disabled || hasReachedTheLimit(value, max)}
140
+ iconType={IconTypeName.Primary}
141
+ />
142
+ </button>
143
+ <button
144
+ tabIndex={-1}
145
+ disabled={disabled || hasReachedTheLimit(value, min)}
146
+ aria-label="Decrement value"
147
+ className={styles[`${baseClass}__decrement`]}
148
+ onClick={handleDecrementClick}
149
+ type="button"
150
+ >
151
+ <Icon
152
+ source={ChevronDown}
153
+ iconType={IconTypeName.Primary}
154
+ disabled={disabled || hasReachedTheLimit(value, min)}
155
+ />
156
+ </button>
157
+ </>
158
+ )}
159
+ </div>
160
+ );
161
+ };
@@ -0,0 +1,58 @@
1
+ import * as React from 'react';
2
+ import { ComponentMeta, Story } from '@storybook/react';
3
+
4
+ import {
5
+ NumericInputFieldProps,
6
+ NumericInputField as NumericInputFieldComponent,
7
+ } from './NumericInputField';
8
+
9
+ export default {
10
+ title: 'Forms (WIP)/NumericInputField',
11
+ component: NumericInputFieldComponent,
12
+ argTypes: {
13
+ value: {
14
+ control: {
15
+ disable: true,
16
+ },
17
+ },
18
+ },
19
+ } as ComponentMeta<typeof NumericInputFieldComponent>;
20
+
21
+ const StoryTemplate: Story<NumericInputFieldProps> = (
22
+ args: NumericInputFieldProps
23
+ ) => {
24
+ const [value, setValue] = React.useState('0');
25
+
26
+ return (
27
+ <div>
28
+ <NumericInputFieldComponent
29
+ {...args}
30
+ value={value}
31
+ onChange={(v) => setValue(v as string)}
32
+ />
33
+ </div>
34
+ );
35
+ };
36
+
37
+ export const NumericInputField = StoryTemplate.bind({});
38
+ NumericInputField.args = {};
39
+
40
+ export const NumericInputFieldWithProps = StoryTemplate.bind({});
41
+ NumericInputFieldWithProps.args = {
42
+ labelText: 'Number',
43
+ description: 'Value should be within range [-10, 20]',
44
+ min: -10,
45
+ max: 20,
46
+ };
47
+
48
+ export const NumericInputFieldWithDisabled = StoryTemplate.bind({});
49
+ NumericInputFieldWithDisabled.args = {
50
+ labelText: 'Number',
51
+ disabled: true,
52
+ };
53
+
54
+ export const NumericInputFieldWithError = StoryTemplate.bind({});
55
+ NumericInputFieldWithError.args = {
56
+ labelText: 'Number',
57
+ error: 'Error text',
58
+ };
@@ -0,0 +1,57 @@
1
+ import * as React from 'react';
2
+ import { TextField } from '../TextField';
3
+ import { NumericInput } from './NumericInput';
4
+
5
+ interface Props {
6
+ id: string;
7
+ labelText?: string;
8
+ labelAdornment?: React.ReactNode;
9
+ className?: string;
10
+ inline?: boolean;
11
+ error?: string;
12
+ description?: React.ReactNode;
13
+ labelRightNode?: React.ReactNode;
14
+ fieldClassName?: string;
15
+ value: string;
16
+ max?: number;
17
+ min?: number;
18
+ onChange: (value: string) => void;
19
+ }
20
+
21
+ export type NumericInputFieldProps = Props &
22
+ React.InputHTMLAttributes<HTMLInputElement>;
23
+
24
+ export const NumericInputField: React.FC<NumericInputFieldProps> = ({
25
+ id,
26
+ labelText,
27
+ labelAdornment,
28
+ className,
29
+ inline,
30
+ error,
31
+ description,
32
+ labelRightNode,
33
+ fieldClassName,
34
+ style,
35
+ ...restProps
36
+ }) => {
37
+ return (
38
+ <TextField
39
+ inline={inline}
40
+ error={error}
41
+ description={description}
42
+ labelText={labelText}
43
+ labelAdornment={labelAdornment}
44
+ className={className}
45
+ labelFor={id}
46
+ labelRightNode={labelRightNode}
47
+ >
48
+ <NumericInput
49
+ {...restProps}
50
+ id={id}
51
+ className={fieldClassName}
52
+ style={style}
53
+ error={error}
54
+ />
55
+ </TextField>
56
+ );
57
+ };
@@ -0,0 +1,2 @@
1
+ export { NumericInput } from './NumericInput';
2
+ export { NumericInputField } from './NumericInputField';
@@ -0,0 +1,16 @@
1
+ .popover {
2
+ background-color: var(--surface-basic-default);
3
+ border-radius: 4px;
4
+ box-shadow: 0 1px 10px 0 rgba(66, 77, 87, 0.3);
5
+ display: none;
6
+ max-width: 336px;
7
+ min-width: 168px;
8
+
9
+ &:focus {
10
+ outline: none;
11
+ }
12
+
13
+ &--visible {
14
+ display: block;
15
+ }
16
+ }
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ import { render, fireEvent } from 'test-utils';
3
+ import { Popover } from './Popover';
4
+
5
+ const PopperContent = () => {
6
+ return <div>Content</div>;
7
+ };
8
+
9
+ const PopperTrigger = () => {
10
+ return <button>Button</button>;
11
+ };
12
+
13
+ describe('<Popover> component', () => {
14
+ it('should show content if isVisible is set', () => {
15
+ const { container } = render(
16
+ <Popover isVisible={true} triggerRenderer={PopperTrigger}>
17
+ <PopperContent></PopperContent>
18
+ </Popover>
19
+ );
20
+
21
+ expect(container).toHaveTextContent('Content');
22
+ });
23
+
24
+ it('should show content if trigger has been clicked', () => {
25
+ const { container, getByRole } = render(
26
+ <Popover triggerRenderer={PopperTrigger}>
27
+ <PopperContent></PopperContent>
28
+ </Popover>
29
+ );
30
+
31
+ fireEvent.click(
32
+ getByRole('button', {
33
+ name: /Button/i,
34
+ })
35
+ );
36
+
37
+ expect(container).toHaveTextContent('Content');
38
+ });
39
+ });
@@ -0,0 +1,23 @@
1
+ .lc-listElement {
2
+ align-items: center;
3
+ color: var(--content-default);
4
+ cursor: pointer;
5
+ display: flex;
6
+ font-size: 14px;
7
+ line-height: 1.5;
8
+ list-style: none;
9
+ padding: 10px;
10
+ }
11
+
12
+ .lc-listElement:hover {
13
+ background-color: var(--surface-basic-hover);
14
+ }
15
+
16
+ .lc-divider {
17
+ border-bottom: 1px solid var(--border-default);
18
+ }
19
+
20
+ .lc-label {
21
+ line-height: 20px;
22
+ margin-left: 5px;
23
+ }
@@ -0,0 +1,164 @@
1
+ import * as React from 'react';
2
+ import { ComponentMeta } from '@storybook/react';
3
+ import { Button } from '../Button';
4
+ import { Popover as PopoverComponent } from './Popover';
5
+ import {
6
+ Block,
7
+ Chats,
8
+ DropDown,
9
+ Email,
10
+ Tickets,
11
+ } from '@livechat/design-system-icons/react/material';
12
+ import { Icon } from '../Icon';
13
+
14
+ import * as PopperCore from '@popperjs/core';
15
+ import './Popover.stories.css';
16
+
17
+ const OpenChat = () => {
18
+ return (
19
+ <div className="lc-listElement">
20
+ <Icon source={Chats} /> <span className="lc-label">Open chat</span>{' '}
21
+ </div>
22
+ );
23
+ };
24
+
25
+ const CreateTicket = () => {
26
+ return (
27
+ <div className="lc-listElement">
28
+ <Icon source={Tickets} />{' '}
29
+ <span className="lc-label">Create a ticket</span>{' '}
30
+ </div>
31
+ );
32
+ };
33
+
34
+ const SendTranscript = () => {
35
+ return (
36
+ <div className="lc-listElement lc-divider">
37
+ <Icon source={Email} /> <span className="lc-label">Send transcript</span>{' '}
38
+ </div>
39
+ );
40
+ };
41
+
42
+ const BanCustomer = () => {
43
+ return (
44
+ <div className="lc-listElement">
45
+ <Icon source={Block} />{' '}
46
+ <span className="lc-label">Ban this customer</span>{' '}
47
+ </div>
48
+ );
49
+ };
50
+
51
+ export const Popover = ({
52
+ placement,
53
+ isVisible,
54
+ }: {
55
+ placement: PopperCore.Placement;
56
+ isVisible: boolean;
57
+ }): React.ReactElement => (
58
+ <div style={{ minHeight: '400px' }}>
59
+ <PopoverComponent
60
+ placement={placement}
61
+ isVisible={isVisible}
62
+ triggerRenderer={() => (
63
+ <div>
64
+ <Button icon={<Icon source={DropDown}></Icon>} iconPosition={'right'}>
65
+ Open Popover
66
+ </Button>
67
+ </div>
68
+ )}
69
+ modifiers={{
70
+ preventOverflow: {
71
+ enabled: true,
72
+ },
73
+ }}
74
+ >
75
+ <div
76
+ style={{
77
+ display: 'flex',
78
+ justifyContent: 'center',
79
+ alignItems: 'center',
80
+ padding: '12px',
81
+ width: '308px',
82
+ height: '308px',
83
+ }}
84
+ >
85
+ <div
86
+ style={{
87
+ display: 'flex',
88
+ justifyContent: 'center',
89
+ alignItems: 'center',
90
+ border: '1px dashed var(--border-default)',
91
+ backgroundColor: 'var(--surface-basic-default)',
92
+ width: '100%',
93
+ height: '100%',
94
+ borderRadius: '4px',
95
+ }}
96
+ >
97
+ Popover content
98
+ </div>
99
+ </div>
100
+ </PopoverComponent>
101
+ </div>
102
+ );
103
+
104
+ Popover.args = {
105
+ placement: 'bottom-start',
106
+ isVisible: true,
107
+ };
108
+
109
+ export const Actions = ({
110
+ placement,
111
+ isVisible,
112
+ }: {
113
+ placement: PopperCore.Placement;
114
+ isVisible: boolean;
115
+ }): React.ReactElement => (
116
+ <div style={{ minHeight: '200px' }}>
117
+ <PopoverComponent
118
+ placement={placement}
119
+ isVisible={isVisible}
120
+ triggerRenderer={() => (
121
+ <div>
122
+ <Button icon={<Icon source={DropDown}></Icon>} iconPosition={'right'}>
123
+ Actions
124
+ </Button>
125
+ </div>
126
+ )}
127
+ modifiers={{
128
+ preventOverflow: {
129
+ enabled: true,
130
+ },
131
+ }}
132
+ >
133
+ <div
134
+ style={{
135
+ minWidth: '200px',
136
+ }}
137
+ >
138
+ <OpenChat />
139
+ <CreateTicket />
140
+ <SendTranscript />
141
+ <BanCustomer />
142
+ </div>
143
+ </PopoverComponent>
144
+ </div>
145
+ );
146
+
147
+ Actions.args = {
148
+ placement: 'bottom-start',
149
+ isVisible: true,
150
+ };
151
+
152
+ export default {
153
+ title: 'Components/Popover',
154
+ component: Popover,
155
+ argTypes: {
156
+ placement: {
157
+ options: PopperCore.placements,
158
+ control: {
159
+ type: 'select',
160
+ labels: PopperCore.placements,
161
+ },
162
+ },
163
+ },
164
+ } as ComponentMeta<typeof Popover>;
@@ -0,0 +1,124 @@
1
+ import * as React from 'react';
2
+ import { usePopper } from 'react-popper';
3
+ import * as PopperCore from '@popperjs/core';
4
+ import cx from 'clsx';
5
+
6
+ import cssStyles from './Popover.module.scss';
7
+
8
+ type PopoverModifiers = {
9
+ [key: string]: Partial<PopperCore.StrictModifiers>;
10
+ };
11
+ export interface IPopoverProps {
12
+ children?: React.ReactNode;
13
+ className?: string;
14
+ modifiers?: PopoverModifiers;
15
+ placement?: PopperCore.Placement;
16
+ isVisible?: boolean;
17
+ triggerRenderer: () => React.ReactNode;
18
+ }
19
+
20
+ const buildPopperModifiers = (modifiers: PopoverModifiers) => {
21
+ const { offset, flip, preventOverflow } = modifiers;
22
+
23
+ const calculatedOffset = [
24
+ {
25
+ name: 'offset',
26
+ options: {
27
+ offset: [0, 4],
28
+ ...(offset?.options || {}),
29
+ },
30
+ },
31
+ ];
32
+
33
+ const calculateFlip = [
34
+ {
35
+ name: 'flip',
36
+ options: {
37
+ ...(flip?.options || {}),
38
+ },
39
+ },
40
+ ];
41
+
42
+ const calculatePreventOverflow = [
43
+ {
44
+ name: 'preventOverlow',
45
+ options: {
46
+ rootBoundary: 'viewport',
47
+ ...(preventOverflow || {}),
48
+ },
49
+ },
50
+ ];
51
+
52
+ return [...calculatedOffset, ...calculateFlip, ...calculatePreventOverflow];
53
+ };
54
+
55
+ export const Popover: React.FC<IPopoverProps> = (props) => {
56
+ const {
57
+ triggerRenderer,
58
+ children,
59
+ className,
60
+ placement,
61
+ isVisible = false,
62
+ } = props;
63
+
64
+ const rendererRef = React.useRef<HTMLDivElement | null>(null);
65
+ const popperRef = React.useRef<HTMLDivElement | null>(null);
66
+
67
+ const [visible, setVisibility] = React.useState(false);
68
+
69
+ React.useEffect(() => {
70
+ setVisibility(isVisible);
71
+ }, [isVisible]);
72
+
73
+ function handleDocumentClick(event: MouseEvent) {
74
+ if (popperRef.current?.contains(event.target as Node)) {
75
+ return;
76
+ } else if (rendererRef.current?.contains(event.target as Node)) {
77
+ setVisibility((prevVisible) => !prevVisible);
78
+ } else {
79
+ setVisibility(false);
80
+ }
81
+ }
82
+
83
+ const handleHideOnEscape = (event: KeyboardEvent) => {
84
+ if (event.key === 'Escape') {
85
+ setVisibility(false);
86
+ }
87
+ };
88
+
89
+ React.useEffect(() => {
90
+ document.addEventListener('keydown', handleHideOnEscape);
91
+ document.addEventListener('mousedown', handleDocumentClick);
92
+ return () => {
93
+ document.removeEventListener('keydown', handleHideOnEscape);
94
+ document.removeEventListener('mousedown', handleDocumentClick);
95
+ };
96
+ }, []);
97
+
98
+ const { styles, attributes } = usePopper(
99
+ rendererRef.current,
100
+ popperRef.current,
101
+ {
102
+ modifiers: props.modifiers ? buildPopperModifiers(props.modifiers) : [],
103
+ placement: placement,
104
+ }
105
+ );
106
+
107
+ const mergedClassNames = cx(cssStyles['popover'], className, {
108
+ [cssStyles['popover--visible']]: visible,
109
+ });
110
+
111
+ return (
112
+ <>
113
+ <div ref={rendererRef}>{triggerRenderer()}</div>
114
+ <div
115
+ ref={popperRef}
116
+ className={mergedClassNames}
117
+ style={styles.popper}
118
+ {...attributes.popper}
119
+ >
120
+ {children}
121
+ </div>
122
+ </>
123
+ );
124
+ };
@@ -0,0 +1 @@
1
+ export * from './Popover';
@@ -0,0 +1,48 @@
1
+ .progress-bar {
2
+ background-color: var(--color-action-disabled);
3
+ border-radius: 100px;
4
+ display: inline-block;
5
+ height: 4px;
6
+ position: relative;
7
+ width: 100%;
8
+
9
+ &--small {
10
+ height: 3px;
11
+ }
12
+
13
+ &--medium {
14
+ height: 4px;
15
+ }
16
+
17
+ &--large {
18
+ height: 6px;
19
+ }
20
+
21
+ &--error {
22
+ background-color: var(--color-negative-disabled);
23
+ }
24
+
25
+ &--success {
26
+ background-color: var(--color-positive-disabled);
27
+ }
28
+
29
+ &--normal {
30
+ background-color: var(--color-action-disabled);
31
+ }
32
+
33
+ &__indicator--success {
34
+ background-color: var(--color-positive-default);
35
+ border-radius: 100px;
36
+ height: 100%;
37
+ position: relative;
38
+ transition: all 0.4s cubic-bezier(0.08, 0.82, 0.17, 1) 0s;
39
+ }
40
+
41
+ &__indicator--normal {
42
+ background-color: var(--color-action-default);
43
+ border-radius: 100px;
44
+ height: 100%;
45
+ position: relative;
46
+ transition: all 0.4s cubic-bezier(0.08, 0.82, 0.17, 1) 0s;
47
+ }
48
+ }