@pie-lib/config-ui 13.0.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 -2419
  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 PropTypes from 'prop-types';
2
- import React from 'react';
3
- import TextField from '@mui/material/TextField';
4
- import { styled } from '@mui/material/styles';
5
- import { isFinite } from 'lodash-es';
6
- import IconButton from '@mui/material/IconButton';
7
- import InputAdornment from '@mui/material/InputAdornment';
8
- import Remove from '@mui/icons-material/Remove';
9
- import Add from '@mui/icons-material/Add';
10
- import * as math from 'mathjs';
11
-
12
- const StyledTextField = styled(TextField)(() => ({
13
- '& input[type=number]': {
14
- MozAppearance: 'textfield',
15
- },
16
- '& input[type=number]::-webkit-outer-spin-button': {
17
- WebkitAppearance: 'none',
18
- margin: 0,
19
- },
20
- '& input[type=number]::-webkit-inner-spin-button': {
21
- WebkitAppearance: 'none',
22
- margin: 0,
23
- },
24
- }));
25
-
26
- const StyledIconButton = styled(IconButton)(() => ({
27
- padding: '2px',
28
- }));
29
-
30
- const fallbackNumber = (min, max) => {
31
- if (!isFinite(min) && !isFinite(max)) {
32
- return 0;
33
- }
34
-
35
- if (!isFinite(min) && isFinite(max)) {
36
- return max;
37
- }
38
-
39
- if (isFinite(min)) {
40
- return min;
41
- }
42
- };
43
-
44
- export class NumberTextFieldCustom extends React.Component {
45
- static propTypes = {
46
- className: PropTypes.string,
47
- customValues: PropTypes.array,
48
- disabled: PropTypes.bool,
49
- error: PropTypes.bool,
50
- inputClassName: PropTypes.string,
51
- helperText: PropTypes.string,
52
- onChange: PropTypes.func.isRequired,
53
- onlyIntegersAllowed: PropTypes.bool,
54
- value: PropTypes.any,
55
- min: PropTypes.number,
56
- max: PropTypes.number,
57
- step: PropTypes.number,
58
- label: PropTypes.string,
59
- disableUnderline: PropTypes.bool,
60
- textAlign: PropTypes.string,
61
- variant: PropTypes.string,
62
- type: PropTypes.string,
63
- };
64
-
65
- static defaultProps = {
66
- step: 1,
67
- customValues: [],
68
- textAlign: 'center',
69
- variant: 'standard',
70
- onlyIntegersAllowed: false,
71
- };
72
-
73
- constructor(props) {
74
- super(props);
75
-
76
- const { value, currentIndex } = this.normalizeValueAndIndex(props.customValues, props.value);
77
-
78
- this.state = {
79
- value,
80
- currentIndex,
81
- };
82
-
83
- if (value !== props.value) {
84
- this.props.onChange({}, value);
85
- }
86
-
87
- this.onChange = this.onChange.bind(this);
88
- }
89
-
90
- UNSAFE_componentWillReceiveProps(props) {
91
- const { value, currentIndex } = this.normalizeValueAndIndex(props.customValues, props.value, props.min, props.max);
92
-
93
- this.setState({ value, currentIndex });
94
- }
95
-
96
- clamp(value, min = this.props.min, max = this.props.max) {
97
- const { customValues } = this.props;
98
-
99
- if ((customValues || []).length > 0) {
100
- return value;
101
- }
102
-
103
- if (!isFinite(value)) {
104
- return fallbackNumber(min, max);
105
- }
106
-
107
- if (isFinite(max)) {
108
- value = Math.min(value, max);
109
- }
110
-
111
- if (isFinite(min)) {
112
- value = Math.max(value, min);
113
- }
114
-
115
- return value;
116
- }
117
-
118
- normalizeValueAndIndex = (customValues, number, min, max) => {
119
- const { type } = this.props;
120
- const value = this.clamp(number, min, max);
121
- const currentIndex = (customValues || []).findIndex((val) => val === value);
122
-
123
- if ((customValues || []).length > 0 && currentIndex === -1) {
124
- const closestValue =
125
- type === 'text' ? this.getClosestFractionValue(customValues, value) : this.getClosestValue(customValues, value);
126
-
127
- return { value: closestValue.value, currentIndex: closestValue.index };
128
- }
129
-
130
- return { value, currentIndex };
131
- };
132
-
133
- getClosestValue = (customValues, number) =>
134
- customValues.reduce(
135
- (closest, value, index) =>
136
- Math.abs(value - number) < Math.abs(closest.value - number) ? { value, index } : closest,
137
- { value: customValues[0], index: 0 },
138
- );
139
-
140
- getClosestFractionValue = (customValues, number) =>
141
- customValues.reduce(
142
- (closest, value, index) =>
143
- Math.abs(math.number(math.fraction(value)) - math.number(math.fraction(number))) <
144
- Math.abs(math.number(math.fraction(closest.value)) - math.number(math.fraction(number)))
145
- ? { value, index }
146
- : closest,
147
- { value: customValues[0], index: 0 },
148
- );
149
-
150
- getValidFraction = (value) => {
151
- if (this.isPositiveInteger(value.trim())) {
152
- return value.trim();
153
- }
154
- if (value.trim() === '' || value.trim().split('/').length !== 2) {
155
- return false;
156
- }
157
- let [numerator, denominator] = value.trim().split('/');
158
- if (isNaN(numerator) || isNaN(denominator)) {
159
- return false;
160
- }
161
- numerator = parseFloat(numerator);
162
- denominator = parseFloat(denominator);
163
- if (!Number.isInteger(numerator) || !Number.isInteger(denominator)) {
164
- return false;
165
- }
166
- if (numerator < 0 || denominator < 1) {
167
- return false;
168
- }
169
- return numerator + '/' + denominator;
170
- };
171
-
172
- isPositiveInteger = (n) => {
173
- return n >>> 0 === parseFloat(n);
174
- };
175
-
176
- onBlur = (event) => {
177
- const { customValues, onlyIntegersAllowed, type } = this.props;
178
- let { value } = event.target;
179
- if (type === 'text') {
180
- let tempValue = this.getValidFraction(value);
181
- if (tempValue) {
182
- value = tempValue;
183
- } else {
184
- value = this.props.value;
185
- }
186
- }
187
- let rawNumber = onlyIntegersAllowed ? Math.round(parseFloat(value)) : parseFloat(value);
188
- if (type === 'text') {
189
- rawNumber = value.trim();
190
- }
191
- const { value: number, currentIndex } = this.normalizeValueAndIndex(customValues, rawNumber);
192
- this.setState(
193
- {
194
- value: number.toString(),
195
- currentIndex,
196
- },
197
- () => this.props.onChange(event, number),
198
- );
199
- };
200
-
201
- onChange(event) {
202
- const { type } = this.props;
203
- const { value } = event.target;
204
- if (type !== 'text' && typeof value === 'string' && value.trim() === '') {
205
- return;
206
- }
207
- this.setState({ value });
208
- }
209
-
210
- changeValue(event, sign = 1, shouldUpdate = false) {
211
- event.preventDefault();
212
- const { customValues, step, onlyIntegersAllowed, onChange } = this.props;
213
- const { currentIndex, value } = this.state;
214
- const updatedIndex = currentIndex + sign * 1;
215
- let number;
216
- if (customValues.length > 0) {
217
- if (updatedIndex < 0 || updatedIndex >= customValues.length) {
218
- return;
219
- }
220
- number = customValues[updatedIndex];
221
- } else {
222
- const rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);
223
- const updatedValue = (rawNumber * 10000 + step * sign * 10000) / 10000;
224
- number = this.clamp(updatedValue);
225
- }
226
- this.setState(
227
- {
228
- value: number.toString(),
229
- currentIndex: updatedIndex,
230
- },
231
- () => {
232
- if (shouldUpdate) {
233
- onChange(event, number);
234
- }
235
- },
236
- );
237
- }
238
-
239
- render() {
240
- const {
241
- className,
242
- label,
243
- disabled,
244
- error,
245
- min,
246
- max,
247
- customValues,
248
- inputClassName,
249
- disableUnderline,
250
- helperText,
251
- variant,
252
- textAlign,
253
- type = 'number',
254
- } = this.props;
255
- const { value } = this.state;
256
- const names = className;
257
- //Logic to disable the increment and decrement buttons
258
- let disabledStart = false;
259
- let disabledEnd = false;
260
- if (customValues.length > 0) {
261
- disabledStart = value === customValues[0];
262
- disabledEnd = value === customValues[customValues.length - 1];
263
- } else if (isFinite(min) && isFinite(max)) {
264
- disabledStart = value === min;
265
- disabledEnd = value === max;
266
- }
267
-
268
- return (
269
- <StyledTextField
270
- variant={variant}
271
- inputRef={(ref) => (this.inputRef = ref)}
272
- disabled={disabled}
273
- label={label}
274
- value={value}
275
- error={error}
276
- helperText={helperText}
277
- onChange={this.onChange}
278
- onBlur={this.onBlur}
279
- onKeyPress={(e) => {
280
- // once the Enter key is pressed, we force input blur
281
- if (e.key === 'Enter' && this.inputRef) {
282
- this.inputRef.blur();
283
- }
284
- }}
285
- onKeyDown={(e) => {
286
- if (e.key === 'ArrowUp') {
287
- this.changeValue(e);
288
- }
289
-
290
- if (e.key === 'ArrowDown') {
291
- this.changeValue(e, -1);
292
- }
293
- }}
294
- title={''}
295
- type={type}
296
- className={names}
297
- InputProps={{
298
- className: inputClassName,
299
- disableUnderline: disableUnderline,
300
- startAdornment: (
301
- <InputAdornment position="start">
302
- <StyledIconButton
303
- disabled={disabled ? disabled : disabledStart}
304
- onClick={(e) => this.changeValue(e, -1, true)}
305
- size="large"
306
- >
307
- <Remove fontSize="small" />
308
- </StyledIconButton>
309
- </InputAdornment>
310
- ),
311
- endAdornment: (
312
- <InputAdornment position="end">
313
- <StyledIconButton
314
- disabled={disabled ? disabled : disabledEnd}
315
- onClick={(e) => this.changeValue(e, 1, true)}
316
- size="large"
317
- >
318
- <Add fontSize="small" />
319
- </StyledIconButton>
320
- </InputAdornment>
321
- ),
322
- }}
323
- inputProps={{
324
- style: { textAlign },
325
- min,
326
- max,
327
- }}
328
- />
329
- );
330
- }
331
- }
332
-
333
- export default NumberTextFieldCustom;
@@ -1,215 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import React from 'react';
3
- import TextField from '@mui/material/TextField';
4
- import { styled } from '@mui/material/styles';
5
- import debug from 'debug';
6
- import { isFinite } from 'lodash-es';
7
- import InputAdornment from '@mui/material/InputAdornment';
8
-
9
- const log = debug('@pie-lib:config-ui:number-text-field');
10
-
11
- const StyledTextField = styled(TextField)(({ theme }) => ({
12
- marginRight: theme.spacing(1),
13
- '& .MuiInputLabel-root': {
14
- width: 'auto',
15
- minWidth: 'max-content',
16
- maxWidth: 'none',
17
- whiteSpace: 'nowrap',
18
- overflow: 'visible',
19
- transform: 'translate(0, 8px) scale(0.75)',
20
- transformOrigin: 'top left',
21
- position: 'relative',
22
- },
23
- '& .MuiInputBase-root, & .MuiInput-root, & .MuiFilledInput-root, & .MuiOutlinedInput-root': {
24
- height: 'auto',
25
- minHeight: 'auto',
26
- marginTop: 0,
27
- },
28
- '& .MuiInputBase-input': {
29
- height: 'auto',
30
- minHeight: 'auto',
31
- padding: '6px 0 7px',
32
- },
33
- }));
34
-
35
- const fallbackNumber = (min, max) => {
36
- if (!isFinite(min) && !isFinite(max)) {
37
- return 0;
38
- }
39
- if (!isFinite(min) && isFinite(max)) {
40
- return max;
41
- }
42
-
43
- if (isFinite(min)) {
44
- return min;
45
- }
46
- };
47
-
48
- export class NumberTextField extends React.Component {
49
- static propTypes = {
50
- disabled: PropTypes.bool,
51
- className: PropTypes.string,
52
- inputClassName: PropTypes.string,
53
- onChange: PropTypes.func.isRequired,
54
- value: PropTypes.number,
55
- min: PropTypes.number,
56
- max: PropTypes.number,
57
- label: PropTypes.string,
58
- suffix: PropTypes.string,
59
- showErrorWhenOutsideRange: PropTypes.bool,
60
- disableUnderline: PropTypes.bool,
61
- variant: PropTypes.string,
62
- };
63
-
64
- static defaultProps = {
65
- showErrorWhenOutsideRange: false,
66
- };
67
-
68
- constructor(props) {
69
- super(props);
70
-
71
- const value = this.clamp(props.value);
72
-
73
- this.state = {
74
- value,
75
- };
76
-
77
- if (value !== props.value) {
78
- this.props.onChange({}, value);
79
- }
80
-
81
- this.onChange = this.onChange.bind(this);
82
- }
83
-
84
- UNSAFE_componentWillReceiveProps(props) {
85
- const value = this.clamp(props.value, props.min, props.max);
86
-
87
- this.setState({ value });
88
- }
89
-
90
- clamp(value, min = this.props.min, max = this.props.max) {
91
- if (!isFinite(value)) {
92
- return fallbackNumber(min, max);
93
- }
94
-
95
- if (isFinite(max)) {
96
- value = Math.min(value, max);
97
- }
98
-
99
- if (isFinite(min)) {
100
- value = Math.max(value, min);
101
- }
102
-
103
- return value;
104
- }
105
-
106
- /**
107
- * on Blur (this can be triggered by pressing Enter, see below)
108
- * we check the entered value and reset it if needed
109
- */
110
- onBlur = (event) => {
111
- const value = event.target.value;
112
-
113
- const rawNumber = parseFloat(value);
114
- log('rawNumber: ', rawNumber);
115
-
116
- const number = this.clamp(rawNumber);
117
- log('number: ', number);
118
-
119
- if (number !== this.state.value) {
120
- log('trigger update...');
121
- this.setState({ value: number.toString() }, () => {
122
- this.props.onChange(event, number);
123
- });
124
- }
125
- };
126
-
127
- onChange(event) {
128
- const value = event.target.value;
129
- this.setState({ value });
130
- }
131
-
132
- errorMessage = () => {
133
- const { min, max } = this.props;
134
- if (min && max) {
135
- return `The value must be between ${min} and ${max}`;
136
- }
137
- if (min) {
138
- return `The value must be greater than ${min}`;
139
- }
140
- if (max) {
141
- return `The value must be less than ${max}`;
142
- }
143
- };
144
-
145
- /**
146
- * if the input has to show error when outside range,
147
- * and the entered value is not matching the requirements
148
- * we display error message
149
- */
150
-
151
- getError = () => {
152
- const { value } = this.state;
153
- const float = parseFloat(value);
154
- const clamped = this.clamp(float);
155
- if (clamped !== float) {
156
- return this.errorMessage();
157
- }
158
- };
159
-
160
- render() {
161
- const {
162
- className,
163
- label,
164
- disabled,
165
- suffix,
166
- min,
167
- max,
168
- inputClassName,
169
- disableUnderline,
170
- showErrorWhenOutsideRange,
171
- variant,
172
- } = this.props;
173
-
174
- const error = showErrorWhenOutsideRange && this.getError();
175
- return (
176
- <StyledTextField
177
- variant={disableUnderline ? 'filled' : variant || 'standard'}
178
- inputRef={(ref) => {
179
- this.inputRef = ref;
180
- }}
181
- disabled={disabled}
182
- label={label}
183
- InputLabelProps={{
184
- shrink: true,
185
- }}
186
- value={this.state.value}
187
- error={!!error}
188
- helperText={error}
189
- onChange={this.onChange}
190
- onBlur={this.onBlur}
191
- onKeyDown={(e) => {
192
- // once the Enter key is pressed, we force input blur
193
- if (e.key === 'Enter' && this.inputRef) {
194
- this.inputRef.blur();
195
- }
196
- }}
197
- type="number"
198
- className={className}
199
- slotProps={{
200
- input: {
201
- endAdornment: suffix && <InputAdornment position="end">{suffix}</InputAdornment>,
202
- className: inputClassName,
203
- inputProps: {
204
- min,
205
- max,
206
- },
207
- },
208
- }}
209
- margin="normal"
210
- />
211
- );
212
- }
213
- }
214
-
215
- export default NumberTextField;
@@ -1,30 +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)(() => ({
9
- '& .MuiFormControlLabel-label': {
10
- left: '-5px',
11
- position: 'relative',
12
- },
13
- }));
14
-
15
- const StyledRadio = styled(Radio)(() => ({
16
- color: `${color.tertiary()} !important`,
17
- }));
18
-
19
- const RadioWithLabel = ({ label, value, checked, onChange }) => (
20
- <StyledFormControlLabel value={value} control={<StyledRadio checked={checked} onChange={onChange} />} label={label} />
21
- );
22
-
23
- RadioWithLabel.propTypes = {
24
- label: PropTypes.string,
25
- value: PropTypes.string,
26
- checked: PropTypes.bool,
27
- onChange: PropTypes.func,
28
- };
29
-
30
- export default RadioWithLabel;
@@ -1,53 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import Typography from '@mui/material/Typography';
4
- import { styled } from '@mui/material/styles';
5
- import NumberTextField from '../number-text-field';
6
-
7
- const StyledDisplaySize = styled('div')(({ theme }) => ({
8
- display: 'flex',
9
- paddingTop: theme.spacing(1),
10
- }));
11
-
12
- const DisplaySize = ({ size, label, onChange }) => {
13
- const updateSize = (key, v) => {
14
- onChange({ ...size, [key]: v });
15
- };
16
-
17
- return (
18
- <div>
19
- <Typography>{label}</Typography>
20
- <StyledDisplaySize>
21
- <NumberTextField
22
- label="Width"
23
- type="number"
24
- variant="outlined"
25
- value={size.width}
26
- min={150}
27
- max={1000}
28
- onChange={(e, v) => updateSize('width', v)}
29
- />
30
- <NumberTextField
31
- label="Height"
32
- type="number"
33
- variant="outlined"
34
- min={150}
35
- max={1000}
36
- value={size.height}
37
- onChange={(e, v) => updateSize('height', v)}
38
- />
39
- </StyledDisplaySize>
40
- </div>
41
- );
42
- };
43
-
44
- DisplaySize.propTypes = {
45
- size: PropTypes.shape({
46
- width: PropTypes.number.isRequired,
47
- height: PropTypes.number.isRequired,
48
- }).isRequired,
49
- label: PropTypes.string.isRequired,
50
- onChange: PropTypes.func,
51
- };
52
-
53
- export default DisplaySize;
@@ -1,83 +0,0 @@
1
- import Panel from './panel';
2
-
3
- export { Panel };
4
-
5
- export const textField = (label, isConfigProperty = true) => ({
6
- label,
7
- type: 'textField',
8
- isConfigProperty,
9
- });
10
-
11
- export const toggle = (label, isConfigProperty = false, disabled = false) => ({
12
- type: 'toggle',
13
- label,
14
- isConfigProperty,
15
- disabled,
16
- });
17
-
18
- const toChoice = (opt) => {
19
- if (typeof opt === 'string') {
20
- return { label: opt, value: opt };
21
- } else {
22
- return opt;
23
- }
24
- };
25
-
26
- export const radio = function () {
27
- const args = Array.prototype.slice.call(arguments);
28
- const [label, choices, isConfigProperty = false] = args;
29
-
30
- return {
31
- type: 'radio',
32
- label,
33
- choices: choices && choices.map((o) => toChoice(o)),
34
- isConfigProperty,
35
- };
36
- };
37
-
38
- export const dropdown = (label, choices, isConfigProperty = false) => {
39
- return {
40
- type: 'dropdown',
41
- label,
42
- choices,
43
- isConfigProperty,
44
- };
45
- };
46
-
47
- export const numberField = (label, options, isConfigProperty = false) => ({
48
- ...options,
49
- label,
50
- type: 'numberField',
51
- isConfigProperty,
52
- });
53
-
54
- export const numberFields = (label, fields, isConfigProperty = false) => {
55
- Object.keys(fields).map((key) => {
56
- fields[key] = numberField(fields[key].label, fields[key], isConfigProperty);
57
- });
58
-
59
- return {
60
- type: 'numberFields',
61
- label,
62
- fields,
63
- };
64
- };
65
-
66
- export const checkbox = (label, settings, isConfigProperty = false) => ({
67
- ...settings,
68
- label,
69
- type: 'checkbox',
70
- isConfigProperty,
71
- });
72
-
73
- export const checkboxes = (label, choices, isConfigProperty = false) => {
74
- Object.keys(choices).map((key) => {
75
- choices[key] = checkbox(choices[key].label, choices[key], isConfigProperty);
76
- });
77
-
78
- return {
79
- type: 'checkboxes',
80
- label,
81
- choices,
82
- };
83
- };