@pie-lib/config-ui 13.0.3-next.3 → 13.0.4-next.0

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 (188) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/alert-dialog.d.ts +44 -0
  3. package/dist/alert-dialog.js +47 -0
  4. package/dist/checkbox.d.ts +34 -0
  5. package/dist/checkbox.js +57 -0
  6. package/dist/choice-configuration/feedback-menu.d.ts +32 -0
  7. package/dist/choice-configuration/feedback-menu.js +85 -0
  8. package/dist/choice-configuration/index.d.ts +62 -0
  9. package/dist/choice-configuration/index.js +240 -0
  10. package/dist/choice-utils.d.ts +21 -0
  11. package/dist/choice-utils.js +15 -0
  12. package/dist/feedback-config/feedback-selector.d.ts +33 -0
  13. package/dist/feedback-config/feedback-selector.js +92 -0
  14. package/dist/feedback-config/group.d.ts +21 -0
  15. package/dist/feedback-config/group.js +33 -0
  16. package/dist/feedback-config/index.d.ts +48 -0
  17. package/dist/feedback-config/index.js +96 -0
  18. package/dist/form-section.d.ts +25 -0
  19. package/dist/form-section.js +25 -0
  20. package/dist/help.d.ts +41 -0
  21. package/dist/help.js +61 -0
  22. package/dist/index.d.ts +31 -0
  23. package/dist/index.js +34 -0
  24. package/dist/input.d.ts +29 -0
  25. package/dist/input.js +65 -0
  26. package/dist/inputs.d.ts +63 -0
  27. package/dist/inputs.js +70 -0
  28. package/dist/langs.d.ts +41 -0
  29. package/dist/langs.js +76 -0
  30. package/dist/layout/config-layout.d.ts +10 -0
  31. package/dist/layout/config-layout.js +75 -0
  32. package/dist/layout/index.d.ts +11 -0
  33. package/dist/layout/index.js +10 -0
  34. package/dist/layout/layout-contents.d.ts +21 -0
  35. package/dist/layout/layout-contents.js +70 -0
  36. package/dist/layout/settings-box.d.ts +19 -0
  37. package/dist/layout/settings-box.js +31 -0
  38. package/dist/mui-box/index.d.ts +21 -0
  39. package/dist/mui-box/index.js +47 -0
  40. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
  41. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +7 -0
  42. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
  43. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +8 -0
  44. package/dist/node_modules/.bun/react-measure@2.5.2_6dbf9a050bc9aadb/node_modules/react-measure/dist/index.esm.js +122 -0
  45. package/dist/node_modules/.bun/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +276 -0
  46. package/dist/number-text-field-custom.d.ts +51 -0
  47. package/dist/number-text-field-custom.js +192 -0
  48. package/dist/number-text-field.d.ts +47 -0
  49. package/dist/number-text-field.js +122 -0
  50. package/dist/radio-with-label.d.ts +25 -0
  51. package/dist/radio-with-label.js +27 -0
  52. package/dist/settings/display-size.d.ts +26 -0
  53. package/dist/settings/display-size.js +45 -0
  54. package/dist/settings/index.d.ts +45 -0
  55. package/dist/settings/index.js +63 -0
  56. package/dist/settings/panel.d.ts +27 -0
  57. package/dist/settings/panel.js +201 -0
  58. package/dist/settings/settings-radio-label.d.ts +25 -0
  59. package/dist/settings/settings-radio-label.js +29 -0
  60. package/dist/settings/toggle.d.ts +25 -0
  61. package/dist/settings/toggle.js +33 -0
  62. package/dist/tabs/index.d.ts +22 -0
  63. package/dist/tabs/index.js +39 -0
  64. package/dist/tags-input/index.d.ts +21 -0
  65. package/dist/tags-input/index.js +83 -0
  66. package/dist/two-choice.d.ts +43 -0
  67. package/dist/two-choice.js +79 -0
  68. package/dist/with-stateful-model.d.ts +42 -0
  69. package/dist/with-stateful-model.js +32 -0
  70. package/package.json +30 -18
  71. package/CHANGELOG.json +0 -32
  72. package/CHANGELOG.md +0 -2415
  73. package/LICENSE.md +0 -5
  74. package/lib/alert-dialog.js +0 -68
  75. package/lib/alert-dialog.js.map +0 -1
  76. package/lib/checkbox.js +0 -84
  77. package/lib/checkbox.js.map +0 -1
  78. package/lib/choice-configuration/feedback-menu.js +0 -129
  79. package/lib/choice-configuration/feedback-menu.js.map +0 -1
  80. package/lib/choice-configuration/index.js +0 -381
  81. package/lib/choice-configuration/index.js.map +0 -1
  82. package/lib/choice-utils.js +0 -42
  83. package/lib/choice-utils.js.map +0 -1
  84. package/lib/feedback-config/feedback-selector.js +0 -155
  85. package/lib/feedback-config/feedback-selector.js.map +0 -1
  86. package/lib/feedback-config/group.js +0 -61
  87. package/lib/feedback-config/group.js.map +0 -1
  88. package/lib/feedback-config/index.js +0 -146
  89. package/lib/feedback-config/index.js.map +0 -1
  90. package/lib/form-section.js +0 -44
  91. package/lib/form-section.js.map +0 -1
  92. package/lib/help.js +0 -106
  93. package/lib/help.js.map +0 -1
  94. package/lib/index.js +0 -186
  95. package/lib/index.js.map +0 -1
  96. package/lib/input.js +0 -106
  97. package/lib/input.js.map +0 -1
  98. package/lib/inputs.js +0 -105
  99. package/lib/inputs.js.map +0 -1
  100. package/lib/langs.js +0 -136
  101. package/lib/langs.js.map +0 -1
  102. package/lib/layout/config-layout.js +0 -137
  103. package/lib/layout/config-layout.js.map +0 -1
  104. package/lib/layout/index.js +0 -21
  105. package/lib/layout/index.js.map +0 -1
  106. package/lib/layout/layout-contents.js +0 -160
  107. package/lib/layout/layout-contents.js.map +0 -1
  108. package/lib/layout/settings-box.js +0 -57
  109. package/lib/layout/settings-box.js.map +0 -1
  110. package/lib/mui-box/index.js +0 -63
  111. package/lib/mui-box/index.js.map +0 -1
  112. package/lib/number-text-field-custom.js +0 -376
  113. package/lib/number-text-field-custom.js.map +0 -1
  114. package/lib/number-text-field.js +0 -229
  115. package/lib/number-text-field.js.map +0 -1
  116. package/lib/radio-with-label.js +0 -48
  117. package/lib/radio-with-label.js.map +0 -1
  118. package/lib/settings/display-size.js +0 -61
  119. package/lib/settings/display-size.js.map +0 -1
  120. package/lib/settings/index.js +0 -110
  121. package/lib/settings/index.js.map +0 -1
  122. package/lib/settings/panel.js +0 -392
  123. package/lib/settings/panel.js.map +0 -1
  124. package/lib/settings/settings-radio-label.js +0 -51
  125. package/lib/settings/settings-radio-label.js.map +0 -1
  126. package/lib/settings/toggle.js +0 -63
  127. package/lib/settings/toggle.js.map +0 -1
  128. package/lib/tabs/index.js +0 -75
  129. package/lib/tabs/index.js.map +0 -1
  130. package/lib/tags-input/index.js +0 -149
  131. package/lib/tags-input/index.js.map +0 -1
  132. package/lib/two-choice.js +0 -136
  133. package/lib/two-choice.js.map +0 -1
  134. package/lib/with-stateful-model.js +0 -61
  135. package/lib/with-stateful-model.js.map +0 -1
  136. package/src/__tests__/alert-dialog.test.jsx +0 -183
  137. package/src/__tests__/checkbox.test.jsx +0 -152
  138. package/src/__tests__/choice-utils.test.js +0 -12
  139. package/src/__tests__/form-section.test.jsx +0 -328
  140. package/src/__tests__/help.test.jsx +0 -184
  141. package/src/__tests__/input.test.jsx +0 -156
  142. package/src/__tests__/langs.test.jsx +0 -376
  143. package/src/__tests__/number-text-field-custom.test.jsx +0 -255
  144. package/src/__tests__/number-text-field.test.jsx +0 -263
  145. package/src/__tests__/radio-with-label.test.jsx +0 -155
  146. package/src/__tests__/settings-panel.test.js +0 -187
  147. package/src/__tests__/settings.test.jsx +0 -452
  148. package/src/__tests__/tabs.test.jsx +0 -188
  149. package/src/__tests__/two-choice.test.js +0 -110
  150. package/src/__tests__/with-stateful-model.test.jsx +0 -139
  151. package/src/alert-dialog.jsx +0 -75
  152. package/src/checkbox.jsx +0 -61
  153. package/src/choice-configuration/__tests__/feedback-menu.test.jsx +0 -151
  154. package/src/choice-configuration/__tests__/index.test.jsx +0 -234
  155. package/src/choice-configuration/feedback-menu.jsx +0 -96
  156. package/src/choice-configuration/index.jsx +0 -357
  157. package/src/choice-utils.js +0 -30
  158. package/src/feedback-config/__tests__/feedback-config.test.jsx +0 -141
  159. package/src/feedback-config/__tests__/feedback-selector.test.jsx +0 -97
  160. package/src/feedback-config/feedback-selector.jsx +0 -112
  161. package/src/feedback-config/group.jsx +0 -51
  162. package/src/feedback-config/index.jsx +0 -111
  163. package/src/form-section.jsx +0 -31
  164. package/src/help.jsx +0 -79
  165. package/src/index.js +0 -55
  166. package/src/input.jsx +0 -72
  167. package/src/inputs.jsx +0 -69
  168. package/src/langs.jsx +0 -111
  169. package/src/layout/__tests__/config.layout.test.jsx +0 -59
  170. package/src/layout/__tests__/layout-content.test.jsx +0 -3
  171. package/src/layout/config-layout.jsx +0 -103
  172. package/src/layout/index.js +0 -4
  173. package/src/layout/layout-contents.jsx +0 -117
  174. package/src/layout/settings-box.jsx +0 -32
  175. package/src/mui-box/index.jsx +0 -56
  176. package/src/number-text-field-custom.jsx +0 -333
  177. package/src/number-text-field.jsx +0 -215
  178. package/src/radio-with-label.jsx +0 -30
  179. package/src/settings/display-size.jsx +0 -53
  180. package/src/settings/index.js +0 -83
  181. package/src/settings/panel.jsx +0 -333
  182. package/src/settings/settings-radio-label.jsx +0 -32
  183. package/src/settings/toggle.jsx +0 -46
  184. package/src/tabs/index.jsx +0 -47
  185. package/src/tags-input/__tests__/index.test.jsx +0 -113
  186. package/src/tags-input/index.jsx +0 -116
  187. package/src/two-choice.jsx +0 -90
  188. package/src/with-stateful-model.jsx +0 -36
@@ -1,333 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { get, set } from 'lodash-es';
4
- import { styled } from '@mui/material/styles';
5
- import Select from '@mui/material/Select';
6
- import Input from '@mui/material/Input';
7
- import MenuItem from '@mui/material/MenuItem';
8
- import Typography from '@mui/material/Typography';
9
- import debug from 'debug';
10
-
11
- import Toggle from './toggle';
12
- import { NChoice } from '../two-choice';
13
- import SettingsRadioLabel from './settings-radio-label';
14
- import NumberTextField from '../number-text-field';
15
- import Checkbox from '../checkbox';
16
-
17
- const log = debug('pie-lib:config-ui:settings:panel');
18
-
19
- const labelValue = {
20
- label: PropTypes.string,
21
- value: PropTypes.string,
22
- };
23
-
24
- const baseTypes = {
25
- label: PropTypes.string,
26
- value: PropTypes.string,
27
- onChange: PropTypes.func,
28
- };
29
-
30
- const CheckboxChoice = ({ label, value, onChange }) => {
31
- return (
32
- <Checkbox
33
- checked={value}
34
- label={label}
35
- onChange={(event) => {
36
- onChange(event.target.checked);
37
- }}
38
- />
39
- );
40
- };
41
-
42
- CheckboxChoice.propTypes = {
43
- label: PropTypes.string,
44
- value: PropTypes.bool,
45
- onChange: PropTypes.func,
46
- };
47
-
48
- const StyledNChoice = styled(NChoice)(({ theme }) => ({
49
- marginTop: theme.spacing(0.5),
50
- paddingBottom: theme.spacing(0.5),
51
- width: '100%',
52
- '& > label': {
53
- color: 'rgba(0, 0, 0, 0.89)',
54
- transform: 'translate(0, 10px) scale(1)',
55
- fontSize: '18px',
56
- marginTop: theme.spacing(2.5),
57
- },
58
- '& > div': {
59
- marginTop: theme.spacing(2.5),
60
- },
61
- }));
62
-
63
- const Radio = ({ label, value, onChange, choices }) => {
64
- return (
65
- <StyledNChoice
66
- direction="horizontal"
67
- customLabel={SettingsRadioLabel}
68
- value={value}
69
- header={label}
70
- opts={choices}
71
- onChange={onChange}
72
- />
73
- );
74
- };
75
-
76
- Radio.propTypes = { ...baseTypes, choices: PropTypes.arrayOf(PropTypes.shape(labelValue)) };
77
-
78
- const StyledRadio = Radio;
79
-
80
- const StyledLabel = styled('p')(({ theme }) => ({
81
- margin: 0,
82
- fontSize: theme.typography.fontSize,
83
- }));
84
-
85
- const StyledSelect = styled(Select)(({ theme }) => ({
86
- marginTop: theme.spacing(0.5),
87
- border: '2px solid lightgrey',
88
- padding: `0 ${theme.spacing(1)}`,
89
- borderRadius: '4px',
90
- }));
91
-
92
- const Dropdown = ({ label, value, onChange, choices = [] }) => {
93
- const getItemLabel = (l) => (typeof l === 'string' ? l : l.label);
94
- const getItemValue = (l) => (typeof l === 'string' ? l : l.value);
95
- return (
96
- <div>
97
- {label && <StyledLabel>{label}</StyledLabel>}
98
- <StyledSelect
99
- value={value || (choices && choices[0])}
100
- onChange={({ target }) => onChange(target.value)}
101
- input={<Input id={`dropdown-${label}`} />}
102
- disableUnderline
103
- MenuProps={{ transitionDuration: { enter: 225, exit: 195 } }}
104
- >
105
- {choices.map((l, index) => (
106
- <MenuItem key={index} value={getItemValue(l)}>
107
- {getItemLabel(l)}
108
- </MenuItem>
109
- ))}
110
- </StyledSelect>
111
- </div>
112
- );
113
- };
114
-
115
- Dropdown.propTypes = { ...baseTypes, choices: PropTypes.arrayOf(PropTypes.string) };
116
-
117
- const StyledTypography = styled(Typography)(({ theme }) => ({
118
- marginRight: theme.spacing(3),
119
- marginTop: theme.spacing(1),
120
- }));
121
-
122
- const TextField = ({ label }) => {
123
- return <StyledTypography>{label}</StyledTypography>;
124
- };
125
-
126
- const StyledNumberTextField = styled(NumberTextField)(({ theme }) => ({
127
- width: '35%',
128
- marginRight: theme.spacing(3),
129
- marginTop: theme.spacing(1),
130
- '& .MuiInputBase-root': {
131
- marginTop: theme.spacing(0.5),
132
- border: '2px solid lightgrey',
133
- borderRadius: '4px',
134
- padding: `0 ${theme.spacing(1)}`,
135
- backgroundColor: 'transparent',
136
- },
137
- }));
138
-
139
- const NumberField = ({ label, value, onChange = () => {}, suffix, min, max }) => {
140
- return (
141
- <StyledNumberTextField
142
- variant={'standard'}
143
- label={label || 'Label'}
144
- value={value}
145
- max={max}
146
- min={min}
147
- onChange={(ev, value) => onChange(value)}
148
- suffix={suffix}
149
- showErrorWhenOutsideRange
150
- disableUnderline
151
- />
152
- );
153
- };
154
-
155
- NumberField.propTypes = {
156
- ...baseTypes,
157
- suffix: PropTypes.string,
158
- min: PropTypes.number,
159
- max: PropTypes.number,
160
- value: PropTypes.number,
161
- };
162
-
163
- TextField.propTypes = {
164
- ...baseTypes,
165
- };
166
-
167
- const ToggleWrapper = ({ disabled, label, value, onChange }) => (
168
- <Toggle label={label} checked={!!value} disabled={!!disabled} toggle={onChange} />
169
- );
170
-
171
- ToggleWrapper.propTypes = { ...baseTypes, value: PropTypes.bool };
172
-
173
- const tagMap = {
174
- toggle: ToggleWrapper,
175
- radio: StyledRadio,
176
- dropdown: Dropdown,
177
- numberField: NumberField,
178
- checkbox: CheckboxChoice,
179
- textField: TextField,
180
- };
181
-
182
- const StyledGroup = styled('div')(({ theme }) => ({
183
- margin: `0 0 ${theme.spacing(2)} 0`,
184
- }));
185
-
186
- const StyledGroupHeader = styled('div')(({ theme }) => ({
187
- color: '#495B8F',
188
- fontSize: theme.typography.fontSize + 2,
189
- fontWeight: 600,
190
- marginBottom: theme.spacing(1),
191
- }));
192
-
193
- const StyledNumberFields = styled('p')(({ theme }) => ({
194
- fontSize: theme.typography.fontSize,
195
- marginBottom: 0,
196
- }));
197
-
198
- const Group = (props) => {
199
- const { model, label, group, configuration, onChange } = props;
200
-
201
- /**
202
- * @param group - the group of settings
203
- * @param key - the key(or path) to be used to set or get from model or configuration
204
- * @param innerKey - the key(or path) to be used to get from the group (used only for numberField type)
205
- * @returns tag that corresponds to element type */
206
- const getTag = (group, key, innerKey) => {
207
- const { isConfigProperty, ...properties } = get(group, innerKey || key);
208
- const value = isConfigProperty ? get(configuration, key) : get(model, key);
209
- const tagProps = { ...properties, key, value };
210
- const Tag = tagMap[tagProps.type];
211
-
212
- return <Tag key={key} {...tagProps} onChange={(v) => onChange(key, v, isConfigProperty)} />;
213
- };
214
-
215
- const content = (group, key) => {
216
- const currentGroup = group[key];
217
-
218
- if (!currentGroup) {
219
- return null;
220
- }
221
-
222
- const { type, label, fields, choices } = currentGroup;
223
-
224
- if (type === 'numberFields') {
225
- return (
226
- <div key={`numberField-${label}`}>
227
- <StyledNumberFields>{label}</StyledNumberFields>
228
- {Object.keys(fields).map((fieldKey) => {
229
- return getTag(group, `${key}.${fieldKey}`, `${key}.fields.${fieldKey}`);
230
- })}
231
- </div>
232
- );
233
- }
234
-
235
- if (type === 'checkboxes') {
236
- return (
237
- <div key={`checkbox-${label}`}>
238
- <p>{label}</p>
239
- {Object.keys(choices).map((choiceKey) => {
240
- return getTag(group, `${key}.${choiceKey}`, `${key}.choices.${choiceKey}`);
241
- })}
242
- </div>
243
- );
244
- }
245
-
246
- // if type is toggle, radio, dropdown, numberField or numberText
247
- return getTag(group, key);
248
- };
249
-
250
- return (
251
- <StyledGroup>
252
- <StyledGroupHeader>{label}</StyledGroupHeader>
253
-
254
- {Object.keys(group).map((key) => {
255
- return content(group, key);
256
- })}
257
- </StyledGroup>
258
- );
259
- };
260
-
261
- Group.propTypes = {
262
- model: PropTypes.object,
263
- label: PropTypes.string,
264
- group: PropTypes.object,
265
- configuration: PropTypes.object,
266
- onChange: PropTypes.func,
267
- };
268
-
269
- export class Panel extends React.Component {
270
- static propTypes = {
271
- model: PropTypes.object,
272
- configuration: PropTypes.object,
273
- groups: PropTypes.object,
274
- onChangeModel: PropTypes.func,
275
- onChangeConfiguration: PropTypes.func,
276
- modal: PropTypes.object,
277
- };
278
-
279
- static defaultProps = {
280
- onChangeModel: () => {},
281
- onChangeConfiguration: () => {},
282
- };
283
-
284
- change = (key, value, isConfigProperty = false) => {
285
- log('[changeModel]', key, value);
286
-
287
- const { onChangeModel, onChangeConfiguration } = this.props;
288
- const model = { ...this.props.model };
289
- const configuration = { ...this.props.configuration };
290
-
291
- if (isConfigProperty) {
292
- set(configuration, key, value);
293
- onChangeConfiguration(configuration, key);
294
- } else {
295
- set(model, key, value);
296
- onChangeModel(model, key);
297
- }
298
- };
299
-
300
- render() {
301
- const { groups, model, configuration, modal } = this.props;
302
-
303
- log('render:', model);
304
-
305
- const renderedGroups = Object.keys(groups || {}).map((group) => {
306
- const showGroup = Object.entries(groups[group]).some(([, propVal]) => !!propVal);
307
-
308
- if (showGroup) {
309
- return (
310
- <Group
311
- label={group}
312
- key={group}
313
- model={model}
314
- configuration={configuration}
315
- group={groups[group]}
316
- onChange={this.change}
317
- />
318
- );
319
- }
320
-
321
- return null;
322
- });
323
-
324
- return (
325
- <div>
326
- {renderedGroups}
327
- {modal}
328
- </div>
329
- );
330
- }
331
- }
332
-
333
- export default Panel;
@@ -1,32 +0,0 @@
1
- import FormControlLabel from '@mui/material/FormControlLabel';
2
- import Radio from '@mui/material/Radio';
3
- import React from 'react';
4
- import PropTypes from 'prop-types';
5
- import { styled } from '@mui/material/styles';
6
- import { color } from '@pie-lib/render-ui';
7
-
8
- const StyledFormControlLabel = styled(FormControlLabel)(({ theme }) => ({
9
- '& .MuiFormControlLabel-label': {
10
- color: 'rgba(0, 0, 0, 0.89)',
11
- fontSize: theme.typography.fontSize - 2,
12
- left: '-5px',
13
- position: 'relative',
14
- },
15
- }));
16
-
17
- const StyledRadio = styled(Radio)(() => ({
18
- color: `${color.tertiary()} !important`,
19
- }));
20
-
21
- const SettingsRadioLabel = ({ label, value, checked, onChange }) => (
22
- <StyledFormControlLabel value={value} control={<StyledRadio checked={checked} onChange={onChange} />} label={label} />
23
- );
24
-
25
- SettingsRadioLabel.propTypes = {
26
- label: PropTypes.string,
27
- value: PropTypes.string,
28
- checked: PropTypes.bool,
29
- onChange: PropTypes.func,
30
- };
31
-
32
- export default SettingsRadioLabel;
@@ -1,46 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import InputLabel from '@mui/material/InputLabel';
4
- import { styled } from '@mui/material/styles';
5
- import Switch from '@mui/material/Switch';
6
- import { color } from '@pie-lib/render-ui';
7
-
8
- const StyledToggle = styled('div')(() => ({
9
- display: 'flex',
10
- width: '100%',
11
- justifyContent: 'space-between',
12
- }));
13
-
14
- const StyledInputLabel = styled(InputLabel)(({ theme }) => ({
15
- color: 'rgba(0, 0, 0, 0.89)',
16
- fontSize: theme.typography.fontSize,
17
- paddingTop: theme.spacing(2),
18
- }));
19
-
20
- const StyledSwitch = styled(Switch)(({ checked }) => ({
21
- '&.Mui-checked .MuiSwitch-thumb': {
22
- color: `${color.tertiary()} !important`,
23
- },
24
- '&.Mui-checked .MuiSwitch-track': {
25
- backgroundColor: `${color.tertiaryLight()} !important`,
26
- },
27
- '& .MuiSwitch-track': {
28
- backgroundColor: checked ? `${color.tertiaryLight()} !important` : undefined,
29
- },
30
- }));
31
-
32
- const Toggle = ({ checked, disabled, label, toggle }) => (
33
- <StyledToggle>
34
- <StyledInputLabel>{label}</StyledInputLabel>
35
- <StyledSwitch checked={checked} disabled={disabled} onChange={(e) => toggle(e.target.checked)} />
36
- </StyledToggle>
37
- );
38
-
39
- Toggle.propTypes = {
40
- checked: PropTypes.bool,
41
- disabled: PropTypes.bool,
42
- label: PropTypes.string.isRequired,
43
- toggle: PropTypes.func.isRequired,
44
- };
45
-
46
- export default Toggle;
@@ -1,47 +0,0 @@
1
- import React from 'react';
2
-
3
- import MuiTabs from '@mui/material/Tabs';
4
- import MuiTab from '@mui/material/Tab';
5
- import PropTypes from 'prop-types';
6
- import { styled } from '@mui/material/styles';
7
-
8
- const StyledMuiTab = styled(MuiTab)(() => ({}));
9
-
10
- export class Tabs extends React.Component {
11
- static propTypes = {
12
- className: PropTypes.string,
13
- contentClassName: PropTypes.string,
14
- contentStyle: PropTypes.object,
15
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
16
- };
17
-
18
- constructor(props) {
19
- super(props);
20
- this.state = { value: 0 };
21
- }
22
-
23
- handleChange = (event, value) => {
24
- this.setState({ value });
25
- };
26
-
27
- render() {
28
- const { value } = this.state;
29
- const { children, className, contentClassName, contentStyle = {} } = this.props;
30
-
31
- return (
32
- <div className={className}>
33
- <MuiTabs indicatorColor="primary" value={value} onChange={this.handleChange}>
34
- {React.Children.map(children, (c, index) =>
35
- c && c.props.title ? <StyledMuiTab key={index} label={c.props.title} /> : null,
36
- )}
37
- </MuiTabs>
38
-
39
- <div className={contentClassName} style={contentStyle}>
40
- {children[value]}
41
- </div>
42
- </div>
43
- );
44
- }
45
- }
46
-
47
- export default Tabs;
@@ -1,113 +0,0 @@
1
- import { TagsInput } from '../index';
2
- import { Keys, pressKey, render, screen, userEvent } from '@pie-lib/test-utils';
3
- import React from 'react';
4
-
5
- describe('TagsInput', () => {
6
- describe('rendering', () => {
7
- it('renders existing tags as chips', () => {
8
- render(<TagsInput tags={['foo', 'bar']} onChange={jest.fn()} />);
9
-
10
- expect(screen.getByText('foo')).toBeInTheDocument();
11
- expect(screen.getByText('bar')).toBeInTheDocument();
12
- });
13
-
14
- it('renders input field', () => {
15
- render(<TagsInput tags={['foo']} onChange={jest.fn()} />);
16
-
17
- const input = screen.getByRole('textbox');
18
- expect(input).toBeInTheDocument();
19
- });
20
- });
21
-
22
- describe('user interactions', () => {
23
- let onChange;
24
- const renderComponent = (tags = ['foo']) => {
25
- onChange = jest.fn();
26
- return render(<TagsInput onChange={onChange} tags={tags} />);
27
- };
28
-
29
- describe('focus behavior', () => {
30
- it('allows user to focus the input', async () => {
31
- const user = userEvent.setup();
32
- renderComponent();
33
-
34
- const input = screen.getByRole('textbox');
35
- await user.click(input);
36
-
37
- expect(input).toHaveFocus();
38
- });
39
-
40
- it('allows user to blur the input', async () => {
41
- const user = userEvent.setup();
42
- renderComponent();
43
-
44
- const input = screen.getByRole('textbox');
45
- await user.click(input);
46
- expect(input).toHaveFocus();
47
-
48
- await user.tab();
49
- expect(input).not.toHaveFocus();
50
- });
51
- });
52
-
53
- describe('typing in input', () => {
54
- it('updates input value when user types', async () => {
55
- const user = userEvent.setup();
56
- renderComponent();
57
-
58
- const input = screen.getByRole('textbox');
59
- await user.type(input, 'boo');
60
-
61
- expect(input).toHaveValue('boo');
62
- });
63
- });
64
-
65
- describe('adding tags', () => {
66
- it('adds new tag when user presses Enter', async () => {
67
- const user = userEvent.setup();
68
- renderComponent();
69
-
70
- const input = screen.getByRole('textbox');
71
- await user.type(input, 'banana');
72
- pressKey(input, Keys.ENTER);
73
-
74
- expect(onChange).toHaveBeenCalledWith(['foo', 'banana']);
75
- });
76
-
77
- it('does not add duplicate tags', async () => {
78
- const user = userEvent.setup();
79
- renderComponent();
80
-
81
- const input = screen.getByRole('textbox');
82
- await user.type(input, 'foo');
83
- pressKey(input, Keys.ENTER);
84
-
85
- expect(onChange).not.toHaveBeenCalled();
86
- });
87
-
88
- it('clears input after adding tag', async () => {
89
- const user = userEvent.setup();
90
- renderComponent();
91
-
92
- const input = screen.getByRole('textbox');
93
- await user.type(input, 'banana');
94
- pressKey(input, Keys.ENTER);
95
-
96
- expect(input).toHaveValue('');
97
- });
98
- });
99
-
100
- describe('deleting tags', () => {
101
- it('removes tag when user clicks delete button', async () => {
102
- const user = userEvent.setup();
103
- renderComponent(['foo', 'bar']);
104
-
105
- // Find the delete button for 'foo' tag
106
- const deleteButtons = screen.getAllByTestId('CancelIcon');
107
- await user.click(deleteButtons[0]);
108
-
109
- expect(onChange).toHaveBeenCalledWith(['bar']);
110
- });
111
- });
112
- });
113
- });
@@ -1,116 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { styled } from '@mui/material/styles';
4
- import { uniq } from 'lodash-es';
5
- import Chip from '@mui/material/Chip';
6
- import MuiBox from '../mui-box';
7
-
8
- const ENTER = 13;
9
-
10
- const StyledChip = styled(Chip)(() => ({
11
- padding: '0px',
12
- margin: '1px',
13
- }));
14
-
15
- const Tag = ({ label, onDelete }) => <StyledChip label={label} onDelete={onDelete} />;
16
-
17
- Tag.propTypes = {
18
- label: PropTypes.string.isRequired,
19
- onDelete: PropTypes.func.isRequired,
20
- };
21
-
22
- const StyledTagsInput = styled('div')(({ theme }) => ({
23
- border: `0px solid ${theme.palette.background.paper}`,
24
- display: 'flex',
25
- flexWrap: 'wrap',
26
- }));
27
-
28
- const StyledInput = styled('input')(({ theme }) => ({
29
- padding: '2px',
30
- margin: '1px',
31
- minWidth: '30px',
32
- width: '100%',
33
- flex: '1',
34
- border: `0px solid ${theme.palette.background.paper}`,
35
- height: '28px',
36
- fontSize: theme.typography.fontSize,
37
- fontFamily: theme.typography.fontFamily,
38
- outline: 'none',
39
- '&:focus': {
40
- outline: 'none',
41
- },
42
- }));
43
-
44
- export class TagsInput extends React.Component {
45
- static propTypes = {
46
- tags: PropTypes.arrayOf(PropTypes.string).isRequired,
47
- onChange: PropTypes.func.isRequired,
48
- };
49
-
50
- constructor(props) {
51
- super(props);
52
- this.state = {
53
- value: '',
54
- focused: false,
55
- };
56
-
57
- this.onKeyDown = (event) => {
58
- if (event.keyCode === ENTER && this.state.value !== '') {
59
- const tag = this.state.value.trim();
60
- const newTags = uniq(this.props.tags.concat([tag]));
61
-
62
- if (newTags.length !== this.props.tags.length) {
63
- this.props.onChange(newTags);
64
- this.setState({ value: '' });
65
- }
66
- }
67
- };
68
-
69
- this.onChange = (event) => {
70
- this.setState({ value: event.target.value });
71
- };
72
-
73
- this.deleteTag = (tag) => {
74
- const { tags } = this.props;
75
-
76
- const tagIndex = tags.indexOf(tag);
77
- if (tagIndex !== -1) {
78
- tags.splice(tagIndex, 1);
79
- this.props.onChange(tags);
80
- this.input.focus();
81
- }
82
- };
83
- }
84
-
85
- onFocus = () => {
86
- this.setState({ focused: true });
87
- };
88
-
89
- onBlur = () => {
90
- this.setState({ focused: false });
91
- };
92
-
93
- render() {
94
- const { tags } = this.props;
95
- return (
96
- <MuiBox focused={this.state.focused}>
97
- <StyledTagsInput>
98
- {(tags || []).map((t, index) => (
99
- <Tag key={index} label={t} onDelete={() => this.deleteTag(t)} />
100
- ))}
101
- <StyledInput
102
- ref={(r) => (this.input = r)}
103
- onKeyDown={this.onKeyDown}
104
- onChange={this.onChange}
105
- value={this.state.value}
106
- onFocus={this.onFocus}
107
- onBlur={this.onBlur}
108
- type="text"
109
- />
110
- </StyledTagsInput>
111
- </MuiBox>
112
- );
113
- }
114
- }
115
-
116
- export default TagsInput;