@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,110 +0,0 @@
1
- .numeric-input {
2
- display: inline-block;
3
- height: 36px;
4
- position: relative;
5
- width: 64px;
6
-
7
- &__increment,
8
- &__decrement {
9
- align-items: center;
10
- background: transparent;
11
- border: 0;
12
- border-left: 1px solid var(--border-default);
13
- box-sizing: border-box;
14
- cursor: pointer;
15
- display: flex;
16
- height: 50%;
17
- justify-content: center;
18
- padding: 0;
19
- position: absolute;
20
- right: 1px;
21
- top: 1px;
22
- width: 23px;
23
-
24
- &:hover,
25
- &:focus {
26
- outline: 0;
27
- }
28
- }
29
-
30
- & &__increment {
31
- &:disabled {
32
- border-color: var(--border-disabled);
33
- cursor: not-allowed;
34
- }
35
- }
36
-
37
- & &__decrement {
38
- border-top: 1px solid var(--border-default);
39
- bottom: 1px;
40
- top: auto;
41
-
42
- &:disabled {
43
- border-color: var(--border-disabled);
44
- cursor: not-allowed;
45
- }
46
- }
47
-
48
- input {
49
- appearance: textfield;
50
- background-clip: padding-box;
51
- border: 1px solid var(--border-default);
52
- border-radius: 4px;
53
- box-sizing: border-box;
54
- color: var(--content-default);
55
- height: 100%;
56
- line-height: 36px;
57
- padding: 0 28px 0 4px;
58
- text-align: right;
59
- transition: border 0.25s ease-in-out;
60
- width: 100%;
61
- will-change: border-color;
62
-
63
- &::-webkit-outer-spin-button,
64
- &::-webkit-inner-spin-button {
65
- appearance: none;
66
- margin: 0;
67
- }
68
-
69
- &:hover {
70
- border-color: var(--border-hover);
71
- outline: 0;
72
- }
73
-
74
- &:focus {
75
- border-color: var(--color-action-default);
76
- outline: 0;
77
- }
78
-
79
- &:disabled {
80
- color: var(--content-disabled);
81
- cursor: not-allowed;
82
-
83
- &:hover {
84
- border-color: var(--border-disabled);
85
- }
86
- }
87
- }
88
-
89
- &--disabled {
90
- background-color: var(--surface-basic-disabled);
91
- color: var(--content-default);
92
- cursor: not-allowed;
93
- }
94
-
95
- &.numeric-input--no-controls {
96
- input {
97
- padding: 0 4px;
98
- }
99
- }
100
-
101
- &.numeric-input--error {
102
- input {
103
- &,
104
- &:hover,
105
- &:focus {
106
- border-color: var(--color-negative-default);
107
- }
108
- }
109
- }
110
- }
@@ -1,129 +0,0 @@
1
- import * as React from 'react';
2
- import { render, fireEvent, vi } from 'test-utils';
3
- import noop from '../../utils/noop';
4
- import { NumericInputProps, NumericInput } from './NumericInput';
5
-
6
- const renderComponent = (props: Partial<NumericInputProps>) => {
7
- const finalProps = Object.assign(
8
- {},
9
- { onChange: noop },
10
- props
11
- ) as NumericInputProps;
12
- return render(<NumericInput {...finalProps} className="my-css-class" />);
13
- };
14
-
15
- describe('<NumericInput> component', () => {
16
- it('should allow for custom class', () => {
17
- const { container } = renderComponent({
18
- value: '0',
19
- });
20
-
21
- expect(container.firstChild).toHaveClass('my-css-class');
22
- });
23
-
24
- it('should display buttons by default', () => {
25
- const { queryByRole } = renderComponent({
26
- value: '0',
27
- });
28
-
29
- expect(
30
- queryByRole('button', {
31
- name: /Increment value/i,
32
- })
33
- ).toBeVisible();
34
-
35
- expect(
36
- queryByRole('button', {
37
- name: /Decrement value/i,
38
- })
39
- ).toBeVisible();
40
- });
41
-
42
- it('should not display buttons', () => {
43
- const { queryByRole } = renderComponent({
44
- value: '0',
45
- noControls: true,
46
- });
47
-
48
- expect(
49
- queryByRole('button', {
50
- name: /Increment value/i,
51
- })
52
- ).toBeFalsy();
53
-
54
- expect(
55
- queryByRole('button', {
56
- name: /Decrement value/i,
57
- })
58
- ).toBeFalsy();
59
- });
60
-
61
- it('all elements should be disabled', () => {
62
- const { queryByRole } = renderComponent({
63
- value: '0',
64
- disabled: true,
65
- });
66
-
67
- expect(queryByRole('textbox')).toBeDisabled();
68
-
69
- expect(
70
- queryByRole('button', {
71
- name: /Increment value/i,
72
- })
73
- ).toBeDisabled();
74
-
75
- expect(
76
- queryByRole('button', {
77
- name: /Decrement value/i,
78
- })
79
- ).toBeDisabled();
80
- });
81
-
82
- it('should call onChange when button click', () => {
83
- const onChange = vi.fn();
84
- const { getByRole } = renderComponent({
85
- value: '0',
86
- onChange,
87
- });
88
-
89
- fireEvent.click(
90
- getByRole('button', {
91
- name: /Increment value/i,
92
- })
93
- );
94
- expect(onChange).toHaveBeenCalledTimes(1);
95
-
96
- fireEvent.click(
97
- getByRole('button', {
98
- name: /Decrement value/i,
99
- })
100
- );
101
- expect(onChange).toHaveBeenCalledTimes(2);
102
- });
103
-
104
- it('should disable Increment button when limit reached', () => {
105
- const { getByRole } = renderComponent({
106
- value: '10',
107
- max: 10,
108
- });
109
-
110
- expect(
111
- getByRole('button', {
112
- name: /Increment value/i,
113
- })
114
- ).toBeDisabled();
115
- });
116
-
117
- it('should disable Decrement button when limit reached', () => {
118
- const { getByRole } = renderComponent({
119
- value: '-10',
120
- min: -10,
121
- });
122
-
123
- expect(
124
- getByRole('button', {
125
- name: /Decrement value/i,
126
- })
127
- ).toBeDisabled();
128
- });
129
- });
@@ -1,56 +0,0 @@
1
- import * as React from 'react';
2
- import { ComponentMeta, Story } from '@storybook/react';
3
-
4
- import {
5
- NumericInputProps,
6
- NumericInput as NumericInputComponent,
7
- } from './NumericInput';
8
-
9
- export default {
10
- title: 'Forms (WIP)/NumericInput',
11
- component: NumericInputComponent,
12
- argTypes: {
13
- value: {
14
- control: {
15
- disable: true,
16
- },
17
- },
18
- },
19
- } as ComponentMeta<typeof NumericInputComponent>;
20
-
21
- const StoryTemplate: Story<NumericInputProps> = (args: NumericInputProps) => {
22
- const [value, setValue] = React.useState('0');
23
- return (
24
- <div>
25
- <NumericInputComponent
26
- {...args}
27
- value={value}
28
- onChange={(v) => setValue(v as string)}
29
- />
30
- </div>
31
- );
32
- };
33
-
34
- export const NumericInput = StoryTemplate.bind({});
35
- NumericInput.args = {};
36
-
37
- export const NumericInputWithMinAndMaxValues = StoryTemplate.bind({});
38
- NumericInputWithMinAndMaxValues.args = {
39
- min: -10,
40
- max: 10,
41
- };
42
-
43
- export const NumericInputWithNoControls = StoryTemplate.bind({});
44
- NumericInputWithNoControls.args = {
45
- noControls: true,
46
- };
47
-
48
- export const NumericInputWithDisabled = StoryTemplate.bind({});
49
- NumericInputWithDisabled.args = {
50
- disabled: true,
51
- };
52
-
53
- export const NumericInputWithError = StoryTemplate.bind({});
54
- NumericInputWithError.args = {
55
- error: 'Error',
56
- };
@@ -1,161 +0,0 @@
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
- };
@@ -1,58 +0,0 @@
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
- };
@@ -1,57 +0,0 @@
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
- };
@@ -1,16 +0,0 @@
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
- }
@@ -1,39 +0,0 @@
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
- });
@@ -1,23 +0,0 @@
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
- }