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