@pie-lib/config-ui 12.0.0-beta.5 → 12.1.0-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.
- package/CHANGELOG.json +8 -1653
- package/CHANGELOG.md +345 -4
- package/LICENSE.md +5 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/__tests__/alert-dialog.test.js +262 -0
- package/lib/__tests__/checkbox.test.js +227 -0
- package/lib/__tests__/choice-utils.test.js +14 -0
- package/lib/__tests__/form-section.test.js +252 -0
- package/lib/__tests__/help.test.js +270 -0
- package/lib/__tests__/input.test.js +268 -0
- package/lib/__tests__/langs.test.js +541 -0
- package/lib/__tests__/number-text-field-custom.test.js +362 -0
- package/lib/__tests__/number-text-field.test.js +421 -0
- package/lib/__tests__/radio-with-label.test.js +233 -0
- package/lib/__tests__/settings-panel.test.js +184 -0
- package/lib/__tests__/settings.test.js +653 -0
- package/lib/__tests__/tabs.test.js +211 -0
- package/lib/__tests__/two-choice.test.js +124 -0
- package/lib/__tests__/with-stateful-model.test.js +221 -0
- package/lib/alert-dialog.js +41 -11
- package/lib/alert-dialog.js.map +1 -1
- package/lib/checkbox.js +59 -49
- package/lib/checkbox.js.map +1 -1
- package/lib/choice-configuration/__tests__/feedback-menu.test.js +287 -0
- package/lib/choice-configuration/__tests__/index.test.js +253 -0
- package/lib/choice-configuration/feedback-menu.js +25 -27
- package/lib/choice-configuration/feedback-menu.js.map +1 -1
- package/lib/choice-configuration/index.js +183 -186
- package/lib/choice-configuration/index.js.map +1 -1
- package/lib/choice-utils.js +6 -8
- package/lib/choice-utils.js.map +1 -1
- package/lib/feedback-config/__tests__/feedback-config.test.js +201 -0
- package/lib/feedback-config/__tests__/feedback-selector.test.js +177 -0
- package/lib/feedback-config/feedback-selector.js +70 -74
- package/lib/feedback-config/feedback-selector.js.map +1 -1
- package/lib/feedback-config/group.js +23 -26
- package/lib/feedback-config/group.js.map +1 -1
- package/lib/feedback-config/index.js +42 -45
- package/lib/feedback-config/index.js.map +1 -1
- package/lib/form-section.js +32 -26
- package/lib/form-section.js.map +1 -1
- package/lib/help.js +38 -48
- package/lib/help.js.map +1 -1
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/input.js +13 -18
- package/lib/input.js.map +1 -1
- package/lib/inputs.js +59 -68
- package/lib/inputs.js.map +1 -1
- package/lib/langs.js +57 -71
- package/lib/langs.js.map +1 -1
- package/lib/layout/__tests__/config.layout.test.js +70 -0
- package/lib/layout/__tests__/layout-content.test.js +6 -0
- package/lib/layout/config-layout.js +79 -48
- package/lib/layout/config-layout.js.map +1 -1
- package/lib/layout/index.js +1 -1
- package/lib/layout/index.js.map +1 -1
- package/lib/layout/layout-contents.js +59 -61
- package/lib/layout/layout-contents.js.map +1 -1
- package/lib/layout/settings-box.js +26 -34
- package/lib/layout/settings-box.js.map +1 -1
- package/lib/mui-box/index.js +42 -51
- package/lib/mui-box/index.js.map +1 -1
- package/lib/number-text-field-custom.js +152 -90
- package/lib/number-text-field-custom.js.map +1 -1
- package/lib/number-text-field.js +75 -64
- package/lib/number-text-field.js.map +1 -1
- package/lib/radio-with-label.js +31 -17
- package/lib/radio-with-label.js.map +1 -1
- package/lib/settings/display-size.js +17 -21
- package/lib/settings/display-size.js.map +1 -1
- package/lib/settings/index.js +14 -20
- package/lib/settings/index.js.map +1 -1
- package/lib/settings/panel.js +141 -142
- package/lib/settings/panel.js.map +1 -1
- package/lib/settings/settings-radio-label.js +30 -17
- package/lib/settings/settings-radio-label.js.map +1 -1
- package/lib/settings/toggle.js +40 -26
- package/lib/settings/toggle.js.map +1 -1
- package/lib/tabs/index.js +19 -31
- package/lib/tabs/index.js.map +1 -1
- package/lib/tags-input/__tests__/index.test.js +183 -0
- package/lib/tags-input/index.js +50 -62
- package/lib/tags-input/index.js.map +1 -1
- package/lib/two-choice.js +34 -44
- package/lib/two-choice.js.map +1 -1
- package/lib/with-stateful-model.js +9 -13
- package/lib/with-stateful-model.js.map +1 -1
- package/package.json +14 -11
- package/src/__tests__/alert-dialog.test.jsx +283 -0
- package/src/__tests__/checkbox.test.jsx +249 -0
- package/src/__tests__/choice-utils.test.js +12 -0
- package/src/__tests__/form-section.test.jsx +334 -0
- package/src/__tests__/help.test.jsx +184 -0
- package/src/__tests__/input.test.jsx +192 -0
- package/src/__tests__/langs.test.jsx +457 -0
- package/src/__tests__/number-text-field-custom.test.jsx +438 -0
- package/src/__tests__/number-text-field.test.jsx +341 -0
- package/src/__tests__/radio-with-label.test.jsx +259 -0
- package/src/__tests__/settings-panel.test.js +187 -0
- package/src/__tests__/settings.test.jsx +515 -0
- package/src/__tests__/tabs.test.jsx +193 -0
- package/src/__tests__/two-choice.test.js +110 -0
- package/src/__tests__/with-stateful-model.test.jsx +145 -0
- package/src/alert-dialog.jsx +30 -8
- package/src/checkbox.jsx +43 -37
- package/src/choice-configuration/__tests__/feedback-menu.test.jsx +163 -0
- package/src/choice-configuration/__tests__/index.test.jsx +234 -0
- package/src/choice-configuration/feedback-menu.jsx +6 -6
- package/src/choice-configuration/index.jsx +208 -199
- package/src/feedback-config/__tests__/feedback-config.test.jsx +141 -0
- package/src/feedback-config/__tests__/feedback-selector.test.jsx +97 -0
- package/src/feedback-config/feedback-selector.jsx +50 -55
- package/src/feedback-config/group.jsx +21 -22
- package/src/feedback-config/index.jsx +27 -29
- package/src/form-section.jsx +26 -18
- package/src/help.jsx +20 -28
- package/src/input.jsx +1 -1
- package/src/inputs.jsx +35 -44
- package/src/langs.jsx +41 -46
- package/src/layout/__tests__/config.layout.test.jsx +59 -0
- package/src/layout/__tests__/layout-content.test.jsx +3 -0
- package/src/layout/config-layout.jsx +53 -23
- package/src/layout/layout-contents.jsx +38 -40
- package/src/layout/settings-box.jsx +16 -19
- package/src/mui-box/index.jsx +35 -43
- package/src/number-text-field-custom.jsx +117 -65
- package/src/number-text-field.jsx +51 -34
- package/src/radio-with-label.jsx +26 -10
- package/src/settings/display-size.jsx +12 -11
- package/src/settings/index.js +2 -1
- package/src/settings/panel.jsx +101 -92
- package/src/settings/settings-radio-label.jsx +26 -10
- package/src/settings/toggle.jsx +37 -18
- package/src/tabs/index.jsx +8 -8
- package/src/tags-input/__tests__/index.test.jsx +113 -0
- package/src/tags-input/index.jsx +35 -38
- package/src/two-choice.jsx +15 -19
- package/README.md +0 -12
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import TextField from '@material
|
|
4
|
-
import
|
|
5
|
-
import { withStyles } from '@material-ui/core/styles';
|
|
3
|
+
import TextField from '@mui/material/TextField';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
6
5
|
import isFinite from 'lodash/isFinite';
|
|
7
|
-
import IconButton from '@material
|
|
8
|
-
import InputAdornment from '@material
|
|
9
|
-
import Remove from '@
|
|
10
|
-
import Add from '@
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
'& input[type=number]::-webkit-outer-spin-button': {
|
|
18
|
-
'-webkit-appearance': 'none',
|
|
19
|
-
margin: 0,
|
|
20
|
-
},
|
|
21
|
-
'& input[type=number]::-webkit-inner-spin-button': {
|
|
22
|
-
'-webkit-appearance': 'none',
|
|
23
|
-
margin: 0,
|
|
24
|
-
},
|
|
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',
|
|
25
15
|
},
|
|
26
|
-
|
|
27
|
-
|
|
16
|
+
'& input[type=number]::-webkit-outer-spin-button': {
|
|
17
|
+
WebkitAppearance: 'none',
|
|
18
|
+
margin: 0,
|
|
28
19
|
},
|
|
29
|
-
|
|
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
|
+
}));
|
|
30
29
|
|
|
31
30
|
const fallbackNumber = (min, max) => {
|
|
32
31
|
if (!isFinite(min) && !isFinite(max)) {
|
|
@@ -44,7 +43,6 @@ const fallbackNumber = (min, max) => {
|
|
|
44
43
|
|
|
45
44
|
export class NumberTextFieldCustom extends React.Component {
|
|
46
45
|
static propTypes = {
|
|
47
|
-
classes: PropTypes.object.isRequired,
|
|
48
46
|
className: PropTypes.string,
|
|
49
47
|
customValues: PropTypes.array,
|
|
50
48
|
disabled: PropTypes.bool,
|
|
@@ -53,7 +51,7 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
53
51
|
helperText: PropTypes.string,
|
|
54
52
|
onChange: PropTypes.func.isRequired,
|
|
55
53
|
onlyIntegersAllowed: PropTypes.bool,
|
|
56
|
-
value: PropTypes.
|
|
54
|
+
value: PropTypes.any,
|
|
57
55
|
min: PropTypes.number,
|
|
58
56
|
max: PropTypes.number,
|
|
59
57
|
step: PropTypes.number,
|
|
@@ -61,6 +59,7 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
61
59
|
disableUnderline: PropTypes.bool,
|
|
62
60
|
textAlign: PropTypes.string,
|
|
63
61
|
variant: PropTypes.string,
|
|
62
|
+
type: PropTypes.string,
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
static defaultProps = {
|
|
@@ -89,13 +88,13 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
89
88
|
}
|
|
90
89
|
|
|
91
90
|
UNSAFE_componentWillReceiveProps(props) {
|
|
92
|
-
const { value, currentIndex } = this.normalizeValueAndIndex(props.customValues, props.value);
|
|
91
|
+
const { value, currentIndex } = this.normalizeValueAndIndex(props.customValues, props.value, props.min, props.max);
|
|
93
92
|
|
|
94
93
|
this.setState({ value, currentIndex });
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
clamp(value) {
|
|
98
|
-
const {
|
|
96
|
+
clamp(value, min = this.props.min, max = this.props.max) {
|
|
97
|
+
const { customValues } = this.props;
|
|
99
98
|
|
|
100
99
|
if ((customValues || []).length > 0) {
|
|
101
100
|
return value;
|
|
@@ -116,12 +115,14 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
116
115
|
return value;
|
|
117
116
|
}
|
|
118
117
|
|
|
119
|
-
normalizeValueAndIndex = (customValues, number) => {
|
|
120
|
-
const
|
|
118
|
+
normalizeValueAndIndex = (customValues, number, min, max) => {
|
|
119
|
+
const { type } = this.props;
|
|
120
|
+
const value = this.clamp(number, min, max);
|
|
121
121
|
const currentIndex = (customValues || []).findIndex((val) => val === value);
|
|
122
122
|
|
|
123
123
|
if ((customValues || []).length > 0 && currentIndex === -1) {
|
|
124
|
-
const closestValue =
|
|
124
|
+
const closestValue =
|
|
125
|
+
type === 'text' ? this.getClosestFractionValue(customValues, value) : this.getClosestValue(customValues, value);
|
|
125
126
|
|
|
126
127
|
return { value: closestValue.value, currentIndex: closestValue.index };
|
|
127
128
|
}
|
|
@@ -136,50 +137,92 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
136
137
|
{ value: customValues[0], index: 0 },
|
|
137
138
|
);
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
+
);
|
|
143
149
|
|
|
144
|
-
|
|
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
|
+
};
|
|
145
175
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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();
|
|
154
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
|
+
);
|
|
155
199
|
};
|
|
156
200
|
|
|
157
201
|
onChange(event) {
|
|
202
|
+
const { type } = this.props;
|
|
158
203
|
const { value } = event.target;
|
|
159
|
-
|
|
204
|
+
if (type !== 'text' && typeof value === 'string' && value.trim() === '') {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
160
207
|
this.setState({ value });
|
|
161
208
|
}
|
|
162
209
|
|
|
163
210
|
changeValue(event, sign = 1, shouldUpdate = false) {
|
|
164
211
|
event.preventDefault();
|
|
165
|
-
|
|
166
212
|
const { customValues, step, onlyIntegersAllowed, onChange } = this.props;
|
|
167
213
|
const { currentIndex, value } = this.state;
|
|
168
214
|
const updatedIndex = currentIndex + sign * 1;
|
|
169
215
|
let number;
|
|
170
|
-
|
|
171
216
|
if (customValues.length > 0) {
|
|
172
217
|
if (updatedIndex < 0 || updatedIndex >= customValues.length) {
|
|
173
218
|
return;
|
|
174
219
|
}
|
|
175
|
-
|
|
176
220
|
number = customValues[updatedIndex];
|
|
177
221
|
} else {
|
|
178
222
|
const rawNumber = onlyIntegersAllowed ? parseInt(value) : parseFloat(value);
|
|
179
223
|
const updatedValue = (rawNumber * 10000 + step * sign * 10000) / 10000;
|
|
180
224
|
number = this.clamp(updatedValue);
|
|
181
225
|
}
|
|
182
|
-
|
|
183
226
|
this.setState(
|
|
184
227
|
{
|
|
185
228
|
value: number.toString(),
|
|
@@ -196,23 +239,34 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
196
239
|
render() {
|
|
197
240
|
const {
|
|
198
241
|
className,
|
|
199
|
-
classes,
|
|
200
242
|
label,
|
|
201
243
|
disabled,
|
|
202
244
|
error,
|
|
203
245
|
min,
|
|
204
246
|
max,
|
|
247
|
+
customValues,
|
|
205
248
|
inputClassName,
|
|
206
249
|
disableUnderline,
|
|
207
250
|
helperText,
|
|
208
251
|
variant,
|
|
209
252
|
textAlign,
|
|
253
|
+
type = 'number',
|
|
210
254
|
} = this.props;
|
|
211
255
|
const { value } = this.state;
|
|
212
|
-
const names =
|
|
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
|
+
}
|
|
213
267
|
|
|
214
268
|
return (
|
|
215
|
-
<
|
|
269
|
+
<StyledTextField
|
|
216
270
|
variant={variant}
|
|
217
271
|
inputRef={(ref) => (this.inputRef = ref)}
|
|
218
272
|
disabled={disabled}
|
|
@@ -238,31 +292,29 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
238
292
|
}
|
|
239
293
|
}}
|
|
240
294
|
title={''}
|
|
241
|
-
type=
|
|
295
|
+
type={type}
|
|
242
296
|
className={names}
|
|
243
297
|
InputProps={{
|
|
244
298
|
className: inputClassName,
|
|
245
299
|
disableUnderline: disableUnderline,
|
|
246
300
|
startAdornment: (
|
|
247
301
|
<InputAdornment position="start">
|
|
248
|
-
<
|
|
249
|
-
|
|
250
|
-
disabled={disabled}
|
|
302
|
+
<StyledIconButton
|
|
303
|
+
disabled={disabled ? disabled : disabledStart}
|
|
251
304
|
onClick={(e) => this.changeValue(e, -1, true)}
|
|
252
|
-
|
|
305
|
+
size="large">
|
|
253
306
|
<Remove fontSize="small" />
|
|
254
|
-
</
|
|
307
|
+
</StyledIconButton>
|
|
255
308
|
</InputAdornment>
|
|
256
309
|
),
|
|
257
310
|
endAdornment: (
|
|
258
311
|
<InputAdornment position="end">
|
|
259
|
-
<
|
|
260
|
-
|
|
261
|
-
disabled={disabled}
|
|
312
|
+
<StyledIconButton
|
|
313
|
+
disabled={disabled ? disabled : disabledEnd}
|
|
262
314
|
onClick={(e) => this.changeValue(e, 1, true)}
|
|
263
|
-
|
|
315
|
+
size="large">
|
|
264
316
|
<Add fontSize="small" />
|
|
265
|
-
</
|
|
317
|
+
</StyledIconButton>
|
|
266
318
|
</InputAdornment>
|
|
267
319
|
),
|
|
268
320
|
}}
|
|
@@ -276,4 +328,4 @@ export class NumberTextFieldCustom extends React.Component {
|
|
|
276
328
|
}
|
|
277
329
|
}
|
|
278
330
|
|
|
279
|
-
export default
|
|
331
|
+
export default NumberTextFieldCustom;
|
|
@@ -1,21 +1,39 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import TextField from '@material
|
|
4
|
-
import
|
|
5
|
-
import { withStyles } from '@material-ui/core/styles';
|
|
3
|
+
import TextField from '@mui/material/TextField';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
6
5
|
import debug from 'debug';
|
|
7
6
|
import isFinite from 'lodash/isFinite';
|
|
8
|
-
import InputAdornment from '@material
|
|
7
|
+
import InputAdornment from '@mui/material/InputAdornment';
|
|
9
8
|
const log = debug('@pie-lib:config-ui:number-text-field');
|
|
10
9
|
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const StyledTextField = styled(TextField)(({ theme }) => ({
|
|
11
|
+
marginRight: theme.spacing(1),
|
|
12
|
+
'& .MuiInputLabel-root': {
|
|
13
|
+
width: 'auto',
|
|
14
|
+
minWidth: 'max-content',
|
|
15
|
+
maxWidth: 'none',
|
|
16
|
+
whiteSpace: 'nowrap',
|
|
17
|
+
overflow: 'visible',
|
|
18
|
+
transform: 'translate(0, 8px) scale(0.75)',
|
|
19
|
+
transformOrigin: 'top left',
|
|
20
|
+
position: 'relative',
|
|
21
|
+
},
|
|
22
|
+
'& .MuiInputBase-root, & .MuiInput-root, & .MuiFilledInput-root, & .MuiOutlinedInput-root': {
|
|
23
|
+
height: 'auto',
|
|
24
|
+
minHeight: 'auto',
|
|
25
|
+
},
|
|
26
|
+
'& .MuiInputBase-input': {
|
|
27
|
+
height: 'auto',
|
|
28
|
+
minHeight: 'auto',
|
|
29
|
+
padding: '8px 12px',
|
|
30
|
+
},
|
|
31
|
+
'& .MuiInput-root, & .MuiFilledInput-root': {
|
|
32
|
+
'&:before, &:after, &:hover:not(.Mui-disabled):before': {
|
|
33
|
+
display: 'none',
|
|
16
34
|
},
|
|
17
35
|
},
|
|
18
|
-
});
|
|
36
|
+
}));
|
|
19
37
|
|
|
20
38
|
const fallbackNumber = (min, max) => {
|
|
21
39
|
if (!isFinite(min) && !isFinite(max)) {
|
|
@@ -33,7 +51,6 @@ const fallbackNumber = (min, max) => {
|
|
|
33
51
|
export class NumberTextField extends React.Component {
|
|
34
52
|
static propTypes = {
|
|
35
53
|
disabled: PropTypes.bool,
|
|
36
|
-
classes: PropTypes.object.isRequired,
|
|
37
54
|
className: PropTypes.string,
|
|
38
55
|
inputClassName: PropTypes.string,
|
|
39
56
|
onChange: PropTypes.func.isRequired,
|
|
@@ -68,23 +85,24 @@ export class NumberTextField extends React.Component {
|
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
UNSAFE_componentWillReceiveProps(props) {
|
|
71
|
-
const value = this.clamp(props.value);
|
|
88
|
+
const value = this.clamp(props.value, props.min, props.max);
|
|
89
|
+
|
|
72
90
|
this.setState({ value });
|
|
73
91
|
}
|
|
74
92
|
|
|
75
|
-
clamp(value) {
|
|
93
|
+
clamp(value, min = this.props.min, max = this.props.max) {
|
|
76
94
|
if (!isFinite(value)) {
|
|
77
|
-
return fallbackNumber(
|
|
95
|
+
return fallbackNumber(min, max);
|
|
78
96
|
}
|
|
79
97
|
|
|
80
|
-
const { min, max } = this.props;
|
|
81
|
-
|
|
82
98
|
if (isFinite(max)) {
|
|
83
99
|
value = Math.min(value, max);
|
|
84
100
|
}
|
|
101
|
+
|
|
85
102
|
if (isFinite(min)) {
|
|
86
103
|
value = Math.max(value, min);
|
|
87
104
|
}
|
|
105
|
+
|
|
88
106
|
return value;
|
|
89
107
|
}
|
|
90
108
|
|
|
@@ -145,7 +163,6 @@ export class NumberTextField extends React.Component {
|
|
|
145
163
|
render() {
|
|
146
164
|
const {
|
|
147
165
|
className,
|
|
148
|
-
classes,
|
|
149
166
|
label,
|
|
150
167
|
disabled,
|
|
151
168
|
suffix,
|
|
@@ -156,41 +173,41 @@ export class NumberTextField extends React.Component {
|
|
|
156
173
|
showErrorWhenOutsideRange,
|
|
157
174
|
variant,
|
|
158
175
|
} = this.props;
|
|
159
|
-
const names = classNames(classes.root, className);
|
|
160
176
|
|
|
161
177
|
const error = showErrorWhenOutsideRange && this.getError();
|
|
162
178
|
return (
|
|
163
|
-
<
|
|
164
|
-
variant={variant || 'standard'}
|
|
179
|
+
<StyledTextField
|
|
180
|
+
variant={disableUnderline ? 'filled' : (variant || 'standard')}
|
|
165
181
|
inputRef={(ref) => {
|
|
166
182
|
this.inputRef = ref;
|
|
167
183
|
}}
|
|
168
184
|
disabled={disabled}
|
|
169
185
|
label={label}
|
|
186
|
+
InputLabelProps={{
|
|
187
|
+
shrink: true,
|
|
188
|
+
}}
|
|
170
189
|
value={this.state.value}
|
|
171
190
|
error={!!error}
|
|
172
191
|
helperText={error}
|
|
173
192
|
onChange={this.onChange}
|
|
174
193
|
onBlur={this.onBlur}
|
|
175
|
-
|
|
194
|
+
onKeyDown={(e) => {
|
|
176
195
|
// once the Enter key is pressed, we force input blur
|
|
177
196
|
if (e.key === 'Enter' && this.inputRef) {
|
|
178
197
|
this.inputRef.blur();
|
|
179
198
|
}
|
|
180
199
|
}}
|
|
181
200
|
type="number"
|
|
182
|
-
className={
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
min,
|
|
193
|
-
max,
|
|
201
|
+
className={className}
|
|
202
|
+
slotProps={{
|
|
203
|
+
input: {
|
|
204
|
+
endAdornment: suffix && <InputAdornment position="end">{suffix}</InputAdornment>,
|
|
205
|
+
className: inputClassName,
|
|
206
|
+
inputProps: {
|
|
207
|
+
min,
|
|
208
|
+
max,
|
|
209
|
+
},
|
|
210
|
+
},
|
|
194
211
|
}}
|
|
195
212
|
margin="normal"
|
|
196
213
|
/>
|
|
@@ -198,4 +215,4 @@ export class NumberTextField extends React.Component {
|
|
|
198
215
|
}
|
|
199
216
|
}
|
|
200
217
|
|
|
201
|
-
export default
|
|
218
|
+
export default NumberTextField;
|
package/src/radio-with-label.jsx
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
import FormControlLabel from '@material
|
|
2
|
-
import Radio from '@material
|
|
1
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
2
|
+
import Radio from '@mui/material/Radio';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import { color } from '@pie-lib/render-ui';
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
label: {
|
|
8
|
+
const StyledFormControlLabel = styled(FormControlLabel)(() => ({
|
|
9
|
+
'& .MuiFormControlLabel-label': {
|
|
8
10
|
left: '-5px',
|
|
9
11
|
position: 'relative',
|
|
10
12
|
},
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const StyledRadio = styled(Radio)(() => ({
|
|
16
|
+
color: `${color.tertiary()} !important`,
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const RadioWithLabel = ({ label, value, checked, onChange }) => (
|
|
20
|
+
<StyledFormControlLabel
|
|
13
21
|
value={value}
|
|
14
|
-
|
|
15
|
-
control={<Radio checked={checked} onChange={onChange} />}
|
|
22
|
+
control={<StyledRadio checked={checked} onChange={onChange} />}
|
|
16
23
|
label={label}
|
|
17
24
|
/>
|
|
18
|
-
)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
RadioWithLabel.propTypes = {
|
|
28
|
+
label: PropTypes.string,
|
|
29
|
+
value: PropTypes.string,
|
|
30
|
+
checked: PropTypes.bool,
|
|
31
|
+
onChange: PropTypes.func,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default RadioWithLabel;
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import Typography from '@material
|
|
4
|
-
import {
|
|
3
|
+
import Typography from '@mui/material/Typography';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
5
|
import NumberTextField from '../number-text-field';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const StyledDisplaySize = styled('div')(({ theme }) => ({
|
|
8
|
+
display: 'flex',
|
|
9
|
+
paddingTop: theme.spacing(1),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const DisplaySize = ({ size, label, onChange }) => {
|
|
13
13
|
const updateSize = (key, v) => {
|
|
14
14
|
onChange({ ...size, [key]: v });
|
|
15
15
|
};
|
|
16
|
+
|
|
16
17
|
return (
|
|
17
18
|
<div>
|
|
18
19
|
<Typography>{label}</Typography>
|
|
19
|
-
<
|
|
20
|
+
<StyledDisplaySize>
|
|
20
21
|
<NumberTextField
|
|
21
22
|
label="Width"
|
|
22
23
|
type="number"
|
|
@@ -35,10 +36,10 @@ const DisplaySize = withStyles((theme) => ({
|
|
|
35
36
|
value={size.height}
|
|
36
37
|
onChange={(e, v) => updateSize('height', v)}
|
|
37
38
|
/>
|
|
38
|
-
</
|
|
39
|
+
</StyledDisplaySize>
|
|
39
40
|
</div>
|
|
40
41
|
);
|
|
41
|
-
}
|
|
42
|
+
};
|
|
42
43
|
|
|
43
44
|
DisplaySize.propTypes = {
|
|
44
45
|
size: PropTypes.shape({
|
package/src/settings/index.js
CHANGED
|
@@ -8,10 +8,11 @@ export const textField = (label, isConfigProperty = true) => ({
|
|
|
8
8
|
isConfigProperty,
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
export const toggle = (label, isConfigProperty = false) => ({
|
|
11
|
+
export const toggle = (label, isConfigProperty = false, disabled = false) => ({
|
|
12
12
|
type: 'toggle',
|
|
13
13
|
label,
|
|
14
14
|
isConfigProperty,
|
|
15
|
+
disabled,
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
const toChoice = (opt) => {
|