@pie-lib/config-ui 13.1.0-beta.9 → 14.0.0-next.36
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.js +47 -0
- package/dist/checkbox.d.ts +34 -0
- package/dist/checkbox.js +57 -0
- package/dist/choice-configuration/feedback-menu.d.ts +32 -0
- package/dist/choice-configuration/feedback-menu.js +85 -0
- package/dist/choice-configuration/index.d.ts +62 -0
- package/dist/choice-configuration/index.js +240 -0
- package/dist/choice-utils.d.ts +21 -0
- package/dist/choice-utils.js +15 -0
- package/dist/feedback-config/feedback-selector.d.ts +33 -0
- package/dist/feedback-config/feedback-selector.js +92 -0
- package/dist/feedback-config/group.d.ts +21 -0
- package/dist/feedback-config/group.js +33 -0
- package/dist/feedback-config/index.d.ts +48 -0
- package/dist/feedback-config/index.js +96 -0
- package/dist/form-section.d.ts +25 -0
- package/dist/form-section.js +25 -0
- package/dist/fraction-to-number.d.ts +7 -0
- package/dist/fraction-to-number.js +9 -0
- package/dist/help.d.ts +41 -0
- package/dist/help.js +62 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +34 -0
- package/dist/input.d.ts +29 -0
- package/dist/input.js +65 -0
- package/dist/inputs.d.ts +63 -0
- package/dist/inputs.js +70 -0
- package/dist/langs.d.ts +41 -0
- package/dist/langs.js +76 -0
- package/dist/layout/config-layout.d.ts +10 -0
- package/dist/layout/config-layout.js +75 -0
- package/dist/layout/index.d.ts +11 -0
- package/dist/layout/index.js +10 -0
- package/dist/layout/layout-contents.d.ts +21 -0
- package/dist/layout/layout-contents.js +70 -0
- package/dist/layout/settings-box.d.ts +19 -0
- package/dist/layout/settings-box.js +32 -0
- package/dist/mui-box/index.d.ts +21 -0
- package/dist/mui-box/index.js +47 -0
- package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
- package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +7 -0
- package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
- package/dist/node_modules/.bun/@babel_runtime@7.29.7/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 +51 -0
- package/dist/number-text-field-custom.js +192 -0
- package/dist/number-text-field.d.ts +47 -0
- package/dist/number-text-field.js +122 -0
- package/dist/radio-with-label.d.ts +25 -0
- package/dist/radio-with-label.js +27 -0
- package/dist/settings/display-size.d.ts +26 -0
- package/dist/settings/display-size.js +45 -0
- package/dist/settings/index.d.ts +45 -0
- package/dist/settings/index.js +63 -0
- package/dist/settings/panel.d.ts +27 -0
- package/dist/settings/panel.js +201 -0
- package/dist/settings/settings-radio-label.d.ts +25 -0
- package/dist/settings/settings-radio-label.js +29 -0
- package/dist/settings/toggle.d.ts +25 -0
- package/dist/settings/toggle.js +33 -0
- package/dist/tabs/index.d.ts +22 -0
- package/dist/tabs/index.js +39 -0
- package/dist/tags-input/index.d.ts +21 -0
- package/dist/tags-input/index.js +83 -0
- package/dist/two-choice.d.ts +43 -0
- package/dist/two-choice.js +79 -0
- package/dist/with-stateful-model.d.ts +42 -0
- package/dist/with-stateful-model.js +32 -0
- package/package.json +31 -19
- package/CHANGELOG.json +0 -32
- package/CHANGELOG.md +0 -2419
- package/lib/alert-dialog.js +0 -68
- package/lib/alert-dialog.js.map +0 -1
- package/lib/checkbox.js +0 -84
- package/lib/checkbox.js.map +0 -1
- package/lib/choice-configuration/feedback-menu.js +0 -129
- package/lib/choice-configuration/feedback-menu.js.map +0 -1
- package/lib/choice-configuration/index.js +0 -381
- package/lib/choice-configuration/index.js.map +0 -1
- package/lib/choice-utils.js +0 -42
- package/lib/choice-utils.js.map +0 -1
- package/lib/feedback-config/feedback-selector.js +0 -155
- package/lib/feedback-config/feedback-selector.js.map +0 -1
- package/lib/feedback-config/group.js +0 -61
- package/lib/feedback-config/group.js.map +0 -1
- package/lib/feedback-config/index.js +0 -146
- package/lib/feedback-config/index.js.map +0 -1
- package/lib/form-section.js +0 -44
- package/lib/form-section.js.map +0 -1
- package/lib/help.js +0 -106
- package/lib/help.js.map +0 -1
- package/lib/index.js +0 -186
- package/lib/index.js.map +0 -1
- package/lib/input.js +0 -106
- package/lib/input.js.map +0 -1
- package/lib/inputs.js +0 -105
- package/lib/inputs.js.map +0 -1
- package/lib/langs.js +0 -136
- package/lib/langs.js.map +0 -1
- package/lib/layout/config-layout.js +0 -137
- package/lib/layout/config-layout.js.map +0 -1
- package/lib/layout/index.js +0 -21
- package/lib/layout/index.js.map +0 -1
- package/lib/layout/layout-contents.js +0 -160
- package/lib/layout/layout-contents.js.map +0 -1
- package/lib/layout/settings-box.js +0 -57
- package/lib/layout/settings-box.js.map +0 -1
- package/lib/mui-box/index.js +0 -63
- package/lib/mui-box/index.js.map +0 -1
- package/lib/number-text-field-custom.js +0 -376
- package/lib/number-text-field-custom.js.map +0 -1
- package/lib/number-text-field.js +0 -229
- package/lib/number-text-field.js.map +0 -1
- package/lib/radio-with-label.js +0 -48
- package/lib/radio-with-label.js.map +0 -1
- package/lib/settings/display-size.js +0 -61
- package/lib/settings/display-size.js.map +0 -1
- package/lib/settings/index.js +0 -110
- package/lib/settings/index.js.map +0 -1
- package/lib/settings/panel.js +0 -392
- package/lib/settings/panel.js.map +0 -1
- package/lib/settings/settings-radio-label.js +0 -51
- package/lib/settings/settings-radio-label.js.map +0 -1
- package/lib/settings/toggle.js +0 -63
- package/lib/settings/toggle.js.map +0 -1
- package/lib/tabs/index.js +0 -75
- package/lib/tabs/index.js.map +0 -1
- package/lib/tags-input/index.js +0 -149
- package/lib/tags-input/index.js.map +0 -1
- package/lib/two-choice.js +0 -136
- package/lib/two-choice.js.map +0 -1
- package/lib/with-stateful-model.js +0 -61
- package/lib/with-stateful-model.js.map +0 -1
- package/src/alert-dialog.jsx +0 -75
- package/src/checkbox.jsx +0 -61
- package/src/choice-configuration/feedback-menu.jsx +0 -96
- package/src/choice-configuration/index.jsx +0 -357
- package/src/choice-utils.js +0 -30
- package/src/feedback-config/feedback-selector.jsx +0 -112
- package/src/feedback-config/group.jsx +0 -51
- package/src/feedback-config/index.jsx +0 -111
- package/src/form-section.jsx +0 -31
- package/src/help.jsx +0 -79
- package/src/index.js +0 -55
- package/src/input.jsx +0 -72
- package/src/inputs.jsx +0 -69
- package/src/langs.jsx +0 -111
- package/src/layout/config-layout.jsx +0 -103
- package/src/layout/index.js +0 -4
- package/src/layout/layout-contents.jsx +0 -117
- package/src/layout/settings-box.jsx +0 -32
- package/src/mui-box/index.jsx +0 -56
- package/src/number-text-field-custom.jsx +0 -333
- package/src/number-text-field.jsx +0 -215
- package/src/radio-with-label.jsx +0 -30
- package/src/settings/display-size.jsx +0 -53
- package/src/settings/index.js +0 -83
- package/src/settings/panel.jsx +0 -333
- package/src/settings/settings-radio-label.jsx +0 -32
- package/src/settings/toggle.jsx +0 -46
- package/src/tabs/index.jsx +0 -47
- package/src/tags-input/index.jsx +0 -116
- package/src/two-choice.jsx +0 -90
- package/src/with-stateful-model.jsx +0 -36
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { styled } from '@mui/material/styles';
|
|
4
|
-
import Tabs from '../tabs';
|
|
5
|
-
|
|
6
|
-
const StyledContainer = styled('div')(() => ({
|
|
7
|
-
display: 'flex',
|
|
8
|
-
flexDirection: 'column',
|
|
9
|
-
position: 'relative',
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
const StyledFlow = styled('div')(() => ({
|
|
13
|
-
display: 'flex',
|
|
14
|
-
justifyContent: 'space-between',
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
const StyledContentContainer = styled('div')(({ theme }) => ({
|
|
18
|
-
padding: `${theme.spacing(2)} 0`,
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
const StyledConfigContainer = styled('div')(() => ({
|
|
22
|
-
flex: '1',
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const StyledSettingsContainer = styled('div')(({ theme }) => ({
|
|
26
|
-
marginLeft: theme.spacing(2),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
class RawLayoutContents extends React.Component {
|
|
30
|
-
static propTypes = {
|
|
31
|
-
mode: PropTypes.oneOf(['tabbed', 'inline']),
|
|
32
|
-
secondary: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
33
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
34
|
-
dimensions: PropTypes.object,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
getConfiguration = () => {
|
|
38
|
-
const { secondary } = this.props;
|
|
39
|
-
// in config-layout, secondary can be: <SettingsBox>{settings}</SettingsBox>, settings, null
|
|
40
|
-
|
|
41
|
-
return secondary?.props?.configuration || secondary?.props?.children?.props?.configuration || undefined;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// // eslint-disable-next-line no-unused-vars
|
|
45
|
-
// componentDidUpdate(prevProps, prevState, snapshot) {
|
|
46
|
-
// const configuration = this.getConfiguration();
|
|
47
|
-
// const { mode } = this.props;
|
|
48
|
-
//
|
|
49
|
-
// // promptHolder class is used to wrap up inputs:
|
|
50
|
-
// // we don't want inputs to fill the entire scrollable container,
|
|
51
|
-
// // but instead we want inputs to fit in the first view,
|
|
52
|
-
// // so we calculate the maximum space inputs need
|
|
53
|
-
// try {
|
|
54
|
-
// if (
|
|
55
|
-
// configuration?.maxWidth &&
|
|
56
|
-
// getComputedStyle(document.documentElement).getPropertyValue('--pie-prompt-holder-max-width') !==
|
|
57
|
-
// configuration?.maxWidth
|
|
58
|
-
// ) {
|
|
59
|
-
// document.documentElement.style.setProperty(
|
|
60
|
-
// '--pie-prompt-holder-max-width',
|
|
61
|
-
// mode === 'inline' ? `calc(${configuration.maxWidth} - 340px)` : configuration.maxWidth,
|
|
62
|
-
// );
|
|
63
|
-
// }
|
|
64
|
-
// } catch (e) {
|
|
65
|
-
// console.log(e.toString());
|
|
66
|
-
// }
|
|
67
|
-
// }
|
|
68
|
-
|
|
69
|
-
render() {
|
|
70
|
-
const { mode, secondary, children, dimensions } = this.props;
|
|
71
|
-
const { minHeight, minWidth, maxHeight, maxWidth } = dimensions || {};
|
|
72
|
-
const configuration = this.getConfiguration();
|
|
73
|
-
|
|
74
|
-
let hasSettingsPanel = Object.entries(configuration || {}).some(([, obj]) => !!obj?.settings);
|
|
75
|
-
// ebsr has configuration.partA and configuration.partB
|
|
76
|
-
// because we might have nested configuration for other item types as well, let's add this simple regex to check values for settings
|
|
77
|
-
|
|
78
|
-
if (!hasSettingsPanel) {
|
|
79
|
-
try {
|
|
80
|
-
hasSettingsPanel = JSON.stringify(configuration)?.match(/settings":true/)?.length;
|
|
81
|
-
} catch (e) {
|
|
82
|
-
// eslint-disable-next-line no-console
|
|
83
|
-
console.log(e.toString());
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<StyledContainer style={{ minHeight, minWidth, maxHeight, maxWidth }}>
|
|
89
|
-
{mode === 'inline' && (
|
|
90
|
-
<StyledFlow>
|
|
91
|
-
<StyledConfigContainer className="design-container">{children}</StyledConfigContainer>
|
|
92
|
-
{hasSettingsPanel && (
|
|
93
|
-
<StyledSettingsContainer className="settings-container">{secondary}</StyledSettingsContainer>
|
|
94
|
-
)}
|
|
95
|
-
</StyledFlow>
|
|
96
|
-
)}
|
|
97
|
-
|
|
98
|
-
{mode === 'tabbed' && hasSettingsPanel && (
|
|
99
|
-
<Tabs onChange={this.onTabsChange} contentClassName="content-container" indicatorColor="primary">
|
|
100
|
-
<StyledContentContainer title="Design" className="design-container">
|
|
101
|
-
{children}
|
|
102
|
-
</StyledContentContainer>
|
|
103
|
-
<StyledContentContainer title="Settings" className="settings-container">
|
|
104
|
-
{secondary}
|
|
105
|
-
</StyledContentContainer>
|
|
106
|
-
</Tabs>
|
|
107
|
-
)}
|
|
108
|
-
|
|
109
|
-
{mode === 'tabbed' && !hasSettingsPanel && (
|
|
110
|
-
<StyledContentContainer className="design-container">{children}</StyledContentContainer>
|
|
111
|
-
)}
|
|
112
|
-
</StyledContainer>
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export default RawLayoutContents;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { styled } from '@mui/material/styles';
|
|
4
|
-
|
|
5
|
-
const StyledSettingsBox = styled('div')(({ theme }) => ({
|
|
6
|
-
backgroundColor: theme.palette.background.paper,
|
|
7
|
-
border: `2px solid ${theme.palette.grey[200]}`,
|
|
8
|
-
display: 'flex',
|
|
9
|
-
flexDirection: 'column',
|
|
10
|
-
justifyContent: 'flex-start',
|
|
11
|
-
minWidth: '275px',
|
|
12
|
-
maxWidth: '300px',
|
|
13
|
-
padding: '20px 4px 4px 20px',
|
|
14
|
-
zIndex: 99,
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
export class SettingsBox extends React.Component {
|
|
18
|
-
static propTypes = {
|
|
19
|
-
className: PropTypes.string,
|
|
20
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
static defaultProps = {};
|
|
24
|
-
|
|
25
|
-
render() {
|
|
26
|
-
const { className, children } = this.props;
|
|
27
|
-
|
|
28
|
-
return <StyledSettingsBox className={className}>{children}</StyledSettingsBox>;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default SettingsBox;
|
package/src/mui-box/index.jsx
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { styled } from '@mui/material/styles';
|
|
4
|
-
import debug from 'debug';
|
|
5
|
-
|
|
6
|
-
const log = debug('pie-elements:config-ui:mui-box');
|
|
7
|
-
|
|
8
|
-
const StyledMuiBox = styled('div')(({ theme, focused }) => {
|
|
9
|
-
const light = theme.palette.mode === 'light';
|
|
10
|
-
const bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
|
|
11
|
-
|
|
12
|
-
log(theme.palette.primary[theme.palette.mode || 'light']);
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
paddingTop: theme.spacing(1),
|
|
16
|
-
paddingBottom: theme.spacing(1),
|
|
17
|
-
position: 'relative',
|
|
18
|
-
'&:before': {
|
|
19
|
-
left: 0,
|
|
20
|
-
right: 0,
|
|
21
|
-
bottom: 0,
|
|
22
|
-
height: '1px',
|
|
23
|
-
content: '""',
|
|
24
|
-
position: 'absolute',
|
|
25
|
-
transition: 'background-color 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms',
|
|
26
|
-
pointerEvents: 'none',
|
|
27
|
-
backgroundColor: bottomLineColor,
|
|
28
|
-
},
|
|
29
|
-
'&:hover:before': {
|
|
30
|
-
height: '2px',
|
|
31
|
-
},
|
|
32
|
-
'&:after': {
|
|
33
|
-
left: 0,
|
|
34
|
-
right: 0,
|
|
35
|
-
bottom: 0,
|
|
36
|
-
height: '2px',
|
|
37
|
-
content: '""',
|
|
38
|
-
position: 'absolute',
|
|
39
|
-
transform: focused ? 'scaleX(1)' : 'scaleX(0)',
|
|
40
|
-
transition: 'transform 200ms cubic-bezier(0.0, 0, 0.2, 1) 0ms',
|
|
41
|
-
pointerEvents: 'none',
|
|
42
|
-
backgroundColor: theme.palette.primary[theme.palette.mode], //'#304ffe'
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const MuiBox = ({ children, focused }) => {
|
|
48
|
-
return <StyledMuiBox focused={focused}>{children}</StyledMuiBox>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
MuiBox.propTypes = {
|
|
52
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
53
|
-
focused: PropTypes.bool.isRequired,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export default MuiBox;
|
|
@@ -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;
|