@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.
Files changed (167) 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/fraction-to-number.d.ts +7 -0
  21. package/dist/fraction-to-number.js +9 -0
  22. package/dist/help.d.ts +41 -0
  23. package/dist/help.js +62 -0
  24. package/dist/index.d.ts +31 -0
  25. package/dist/index.js +34 -0
  26. package/dist/input.d.ts +29 -0
  27. package/dist/input.js +65 -0
  28. package/dist/inputs.d.ts +63 -0
  29. package/dist/inputs.js +70 -0
  30. package/dist/langs.d.ts +41 -0
  31. package/dist/langs.js +76 -0
  32. package/dist/layout/config-layout.d.ts +10 -0
  33. package/dist/layout/config-layout.js +75 -0
  34. package/dist/layout/index.d.ts +11 -0
  35. package/dist/layout/index.js +10 -0
  36. package/dist/layout/layout-contents.d.ts +21 -0
  37. package/dist/layout/layout-contents.js +70 -0
  38. package/dist/layout/settings-box.d.ts +19 -0
  39. package/dist/layout/settings-box.js +32 -0
  40. package/dist/mui-box/index.d.ts +21 -0
  41. package/dist/mui-box/index.js +47 -0
  42. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/extends.js +12 -0
  43. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js +7 -0
  44. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js +12 -0
  45. package/dist/node_modules/.bun/@babel_runtime@7.29.7/node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js +8 -0
  46. package/dist/node_modules/.bun/react-measure@2.5.2_6dbf9a050bc9aadb/node_modules/react-measure/dist/index.esm.js +122 -0
  47. package/dist/node_modules/.bun/resize-observer-polyfill@1.5.1/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +276 -0
  48. package/dist/number-text-field-custom.d.ts +51 -0
  49. package/dist/number-text-field-custom.js +192 -0
  50. package/dist/number-text-field.d.ts +47 -0
  51. package/dist/number-text-field.js +122 -0
  52. package/dist/radio-with-label.d.ts +25 -0
  53. package/dist/radio-with-label.js +27 -0
  54. package/dist/settings/display-size.d.ts +26 -0
  55. package/dist/settings/display-size.js +45 -0
  56. package/dist/settings/index.d.ts +45 -0
  57. package/dist/settings/index.js +63 -0
  58. package/dist/settings/panel.d.ts +27 -0
  59. package/dist/settings/panel.js +201 -0
  60. package/dist/settings/settings-radio-label.d.ts +25 -0
  61. package/dist/settings/settings-radio-label.js +29 -0
  62. package/dist/settings/toggle.d.ts +25 -0
  63. package/dist/settings/toggle.js +33 -0
  64. package/dist/tabs/index.d.ts +22 -0
  65. package/dist/tabs/index.js +39 -0
  66. package/dist/tags-input/index.d.ts +21 -0
  67. package/dist/tags-input/index.js +83 -0
  68. package/dist/two-choice.d.ts +43 -0
  69. package/dist/two-choice.js +79 -0
  70. package/dist/with-stateful-model.d.ts +42 -0
  71. package/dist/with-stateful-model.js +32 -0
  72. package/package.json +31 -19
  73. package/CHANGELOG.json +0 -32
  74. package/CHANGELOG.md +0 -2419
  75. package/lib/alert-dialog.js +0 -68
  76. package/lib/alert-dialog.js.map +0 -1
  77. package/lib/checkbox.js +0 -84
  78. package/lib/checkbox.js.map +0 -1
  79. package/lib/choice-configuration/feedback-menu.js +0 -129
  80. package/lib/choice-configuration/feedback-menu.js.map +0 -1
  81. package/lib/choice-configuration/index.js +0 -381
  82. package/lib/choice-configuration/index.js.map +0 -1
  83. package/lib/choice-utils.js +0 -42
  84. package/lib/choice-utils.js.map +0 -1
  85. package/lib/feedback-config/feedback-selector.js +0 -155
  86. package/lib/feedback-config/feedback-selector.js.map +0 -1
  87. package/lib/feedback-config/group.js +0 -61
  88. package/lib/feedback-config/group.js.map +0 -1
  89. package/lib/feedback-config/index.js +0 -146
  90. package/lib/feedback-config/index.js.map +0 -1
  91. package/lib/form-section.js +0 -44
  92. package/lib/form-section.js.map +0 -1
  93. package/lib/help.js +0 -106
  94. package/lib/help.js.map +0 -1
  95. package/lib/index.js +0 -186
  96. package/lib/index.js.map +0 -1
  97. package/lib/input.js +0 -106
  98. package/lib/input.js.map +0 -1
  99. package/lib/inputs.js +0 -105
  100. package/lib/inputs.js.map +0 -1
  101. package/lib/langs.js +0 -136
  102. package/lib/langs.js.map +0 -1
  103. package/lib/layout/config-layout.js +0 -137
  104. package/lib/layout/config-layout.js.map +0 -1
  105. package/lib/layout/index.js +0 -21
  106. package/lib/layout/index.js.map +0 -1
  107. package/lib/layout/layout-contents.js +0 -160
  108. package/lib/layout/layout-contents.js.map +0 -1
  109. package/lib/layout/settings-box.js +0 -57
  110. package/lib/layout/settings-box.js.map +0 -1
  111. package/lib/mui-box/index.js +0 -63
  112. package/lib/mui-box/index.js.map +0 -1
  113. package/lib/number-text-field-custom.js +0 -376
  114. package/lib/number-text-field-custom.js.map +0 -1
  115. package/lib/number-text-field.js +0 -229
  116. package/lib/number-text-field.js.map +0 -1
  117. package/lib/radio-with-label.js +0 -48
  118. package/lib/radio-with-label.js.map +0 -1
  119. package/lib/settings/display-size.js +0 -61
  120. package/lib/settings/display-size.js.map +0 -1
  121. package/lib/settings/index.js +0 -110
  122. package/lib/settings/index.js.map +0 -1
  123. package/lib/settings/panel.js +0 -392
  124. package/lib/settings/panel.js.map +0 -1
  125. package/lib/settings/settings-radio-label.js +0 -51
  126. package/lib/settings/settings-radio-label.js.map +0 -1
  127. package/lib/settings/toggle.js +0 -63
  128. package/lib/settings/toggle.js.map +0 -1
  129. package/lib/tabs/index.js +0 -75
  130. package/lib/tabs/index.js.map +0 -1
  131. package/lib/tags-input/index.js +0 -149
  132. package/lib/tags-input/index.js.map +0 -1
  133. package/lib/two-choice.js +0 -136
  134. package/lib/two-choice.js.map +0 -1
  135. package/lib/with-stateful-model.js +0 -61
  136. package/lib/with-stateful-model.js.map +0 -1
  137. package/src/alert-dialog.jsx +0 -75
  138. package/src/checkbox.jsx +0 -61
  139. package/src/choice-configuration/feedback-menu.jsx +0 -96
  140. package/src/choice-configuration/index.jsx +0 -357
  141. package/src/choice-utils.js +0 -30
  142. package/src/feedback-config/feedback-selector.jsx +0 -112
  143. package/src/feedback-config/group.jsx +0 -51
  144. package/src/feedback-config/index.jsx +0 -111
  145. package/src/form-section.jsx +0 -31
  146. package/src/help.jsx +0 -79
  147. package/src/index.js +0 -55
  148. package/src/input.jsx +0 -72
  149. package/src/inputs.jsx +0 -69
  150. package/src/langs.jsx +0 -111
  151. package/src/layout/config-layout.jsx +0 -103
  152. package/src/layout/index.js +0 -4
  153. package/src/layout/layout-contents.jsx +0 -117
  154. package/src/layout/settings-box.jsx +0 -32
  155. package/src/mui-box/index.jsx +0 -56
  156. package/src/number-text-field-custom.jsx +0 -333
  157. package/src/number-text-field.jsx +0 -215
  158. package/src/radio-with-label.jsx +0 -30
  159. package/src/settings/display-size.jsx +0 -53
  160. package/src/settings/index.js +0 -83
  161. package/src/settings/panel.jsx +0 -333
  162. package/src/settings/settings-radio-label.jsx +0 -32
  163. package/src/settings/toggle.jsx +0 -46
  164. package/src/tabs/index.jsx +0 -47
  165. package/src/tags-input/index.jsx +0 -116
  166. package/src/two-choice.jsx +0 -90
  167. package/src/with-stateful-model.jsx +0 -36
@@ -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
- };
@@ -1,333 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { get, set } from 'lodash-es';
4
- import { styled } from '@mui/material/styles';
5
- import Select from '@mui/material/Select';
6
- import Input from '@mui/material/Input';
7
- import MenuItem from '@mui/material/MenuItem';
8
- import Typography from '@mui/material/Typography';
9
- import debug from 'debug';
10
-
11
- import Toggle from './toggle';
12
- import { NChoice } from '../two-choice';
13
- import SettingsRadioLabel from './settings-radio-label';
14
- import NumberTextField from '../number-text-field';
15
- import Checkbox from '../checkbox';
16
-
17
- const log = debug('pie-lib:config-ui:settings:panel');
18
-
19
- const labelValue = {
20
- label: PropTypes.string,
21
- value: PropTypes.string,
22
- };
23
-
24
- const baseTypes = {
25
- label: PropTypes.string,
26
- value: PropTypes.string,
27
- onChange: PropTypes.func,
28
- };
29
-
30
- const CheckboxChoice = ({ label, value, onChange }) => {
31
- return (
32
- <Checkbox
33
- checked={value}
34
- label={label}
35
- onChange={(event) => {
36
- onChange(event.target.checked);
37
- }}
38
- />
39
- );
40
- };
41
-
42
- CheckboxChoice.propTypes = {
43
- label: PropTypes.string,
44
- value: PropTypes.bool,
45
- onChange: PropTypes.func,
46
- };
47
-
48
- const StyledNChoice = styled(NChoice)(({ theme }) => ({
49
- marginTop: theme.spacing(0.5),
50
- paddingBottom: theme.spacing(0.5),
51
- width: '100%',
52
- '& > label': {
53
- color: 'rgba(0, 0, 0, 0.89)',
54
- transform: 'translate(0, 10px) scale(1)',
55
- fontSize: '18px',
56
- marginTop: theme.spacing(2.5),
57
- },
58
- '& > div': {
59
- marginTop: theme.spacing(2.5),
60
- },
61
- }));
62
-
63
- const Radio = ({ label, value, onChange, choices }) => {
64
- return (
65
- <StyledNChoice
66
- direction="horizontal"
67
- customLabel={SettingsRadioLabel}
68
- value={value}
69
- header={label}
70
- opts={choices}
71
- onChange={onChange}
72
- />
73
- );
74
- };
75
-
76
- Radio.propTypes = { ...baseTypes, choices: PropTypes.arrayOf(PropTypes.shape(labelValue)) };
77
-
78
- const StyledRadio = Radio;
79
-
80
- const StyledLabel = styled('p')(({ theme }) => ({
81
- margin: 0,
82
- fontSize: theme.typography.fontSize,
83
- }));
84
-
85
- const StyledSelect = styled(Select)(({ theme }) => ({
86
- marginTop: theme.spacing(0.5),
87
- border: '2px solid lightgrey',
88
- padding: `0 ${theme.spacing(1)}`,
89
- borderRadius: '4px',
90
- }));
91
-
92
- const Dropdown = ({ label, value, onChange, choices = [] }) => {
93
- const getItemLabel = (l) => (typeof l === 'string' ? l : l.label);
94
- const getItemValue = (l) => (typeof l === 'string' ? l : l.value);
95
- return (
96
- <div>
97
- {label && <StyledLabel>{label}</StyledLabel>}
98
- <StyledSelect
99
- value={value || (choices && choices[0])}
100
- onChange={({ target }) => onChange(target.value)}
101
- input={<Input id={`dropdown-${label}`} />}
102
- disableUnderline
103
- MenuProps={{ transitionDuration: { enter: 225, exit: 195 } }}
104
- >
105
- {choices.map((l, index) => (
106
- <MenuItem key={index} value={getItemValue(l)}>
107
- {getItemLabel(l)}
108
- </MenuItem>
109
- ))}
110
- </StyledSelect>
111
- </div>
112
- );
113
- };
114
-
115
- Dropdown.propTypes = { ...baseTypes, choices: PropTypes.arrayOf(PropTypes.string) };
116
-
117
- const StyledTypography = styled(Typography)(({ theme }) => ({
118
- marginRight: theme.spacing(3),
119
- marginTop: theme.spacing(1),
120
- }));
121
-
122
- const TextField = ({ label }) => {
123
- return <StyledTypography>{label}</StyledTypography>;
124
- };
125
-
126
- const StyledNumberTextField = styled(NumberTextField)(({ theme }) => ({
127
- width: '35%',
128
- marginRight: theme.spacing(3),
129
- marginTop: theme.spacing(1),
130
- '& .MuiInputBase-root': {
131
- marginTop: theme.spacing(0.5),
132
- border: '2px solid lightgrey',
133
- borderRadius: '4px',
134
- padding: `0 ${theme.spacing(1)}`,
135
- backgroundColor: 'transparent',
136
- },
137
- }));
138
-
139
- const NumberField = ({ label, value, onChange = () => {}, suffix, min, max }) => {
140
- return (
141
- <StyledNumberTextField
142
- variant={'standard'}
143
- label={label || 'Label'}
144
- value={value}
145
- max={max}
146
- min={min}
147
- onChange={(ev, value) => onChange(value)}
148
- suffix={suffix}
149
- showErrorWhenOutsideRange
150
- disableUnderline
151
- />
152
- );
153
- };
154
-
155
- NumberField.propTypes = {
156
- ...baseTypes,
157
- suffix: PropTypes.string,
158
- min: PropTypes.number,
159
- max: PropTypes.number,
160
- value: PropTypes.number,
161
- };
162
-
163
- TextField.propTypes = {
164
- ...baseTypes,
165
- };
166
-
167
- const ToggleWrapper = ({ disabled, label, value, onChange }) => (
168
- <Toggle label={label} checked={!!value} disabled={!!disabled} toggle={onChange} />
169
- );
170
-
171
- ToggleWrapper.propTypes = { ...baseTypes, value: PropTypes.bool };
172
-
173
- const tagMap = {
174
- toggle: ToggleWrapper,
175
- radio: StyledRadio,
176
- dropdown: Dropdown,
177
- numberField: NumberField,
178
- checkbox: CheckboxChoice,
179
- textField: TextField,
180
- };
181
-
182
- const StyledGroup = styled('div')(({ theme }) => ({
183
- margin: `0 0 ${theme.spacing(2)} 0`,
184
- }));
185
-
186
- const StyledGroupHeader = styled('div')(({ theme }) => ({
187
- color: '#495B8F',
188
- fontSize: theme.typography.fontSize + 2,
189
- fontWeight: 600,
190
- marginBottom: theme.spacing(1),
191
- }));
192
-
193
- const StyledNumberFields = styled('p')(({ theme }) => ({
194
- fontSize: theme.typography.fontSize,
195
- marginBottom: 0,
196
- }));
197
-
198
- const Group = (props) => {
199
- const { model, label, group, configuration, onChange } = props;
200
-
201
- /**
202
- * @param group - the group of settings
203
- * @param key - the key(or path) to be used to set or get from model or configuration
204
- * @param innerKey - the key(or path) to be used to get from the group (used only for numberField type)
205
- * @returns tag that corresponds to element type */
206
- const getTag = (group, key, innerKey) => {
207
- const { isConfigProperty, ...properties } = get(group, innerKey || key);
208
- const value = isConfigProperty ? get(configuration, key) : get(model, key);
209
- const tagProps = { ...properties, key, value };
210
- const Tag = tagMap[tagProps.type];
211
-
212
- return <Tag key={key} {...tagProps} onChange={(v) => onChange(key, v, isConfigProperty)} />;
213
- };
214
-
215
- const content = (group, key) => {
216
- const currentGroup = group[key];
217
-
218
- if (!currentGroup) {
219
- return null;
220
- }
221
-
222
- const { type, label, fields, choices } = currentGroup;
223
-
224
- if (type === 'numberFields') {
225
- return (
226
- <div key={`numberField-${label}`}>
227
- <StyledNumberFields>{label}</StyledNumberFields>
228
- {Object.keys(fields).map((fieldKey) => {
229
- return getTag(group, `${key}.${fieldKey}`, `${key}.fields.${fieldKey}`);
230
- })}
231
- </div>
232
- );
233
- }
234
-
235
- if (type === 'checkboxes') {
236
- return (
237
- <div key={`checkbox-${label}`}>
238
- <p>{label}</p>
239
- {Object.keys(choices).map((choiceKey) => {
240
- return getTag(group, `${key}.${choiceKey}`, `${key}.choices.${choiceKey}`);
241
- })}
242
- </div>
243
- );
244
- }
245
-
246
- // if type is toggle, radio, dropdown, numberField or numberText
247
- return getTag(group, key);
248
- };
249
-
250
- return (
251
- <StyledGroup>
252
- <StyledGroupHeader>{label}</StyledGroupHeader>
253
-
254
- {Object.keys(group).map((key) => {
255
- return content(group, key);
256
- })}
257
- </StyledGroup>
258
- );
259
- };
260
-
261
- Group.propTypes = {
262
- model: PropTypes.object,
263
- label: PropTypes.string,
264
- group: PropTypes.object,
265
- configuration: PropTypes.object,
266
- onChange: PropTypes.func,
267
- };
268
-
269
- export class Panel extends React.Component {
270
- static propTypes = {
271
- model: PropTypes.object,
272
- configuration: PropTypes.object,
273
- groups: PropTypes.object,
274
- onChangeModel: PropTypes.func,
275
- onChangeConfiguration: PropTypes.func,
276
- modal: PropTypes.object,
277
- };
278
-
279
- static defaultProps = {
280
- onChangeModel: () => {},
281
- onChangeConfiguration: () => {},
282
- };
283
-
284
- change = (key, value, isConfigProperty = false) => {
285
- log('[changeModel]', key, value);
286
-
287
- const { onChangeModel, onChangeConfiguration } = this.props;
288
- const model = { ...this.props.model };
289
- const configuration = { ...this.props.configuration };
290
-
291
- if (isConfigProperty) {
292
- set(configuration, key, value);
293
- onChangeConfiguration(configuration, key);
294
- } else {
295
- set(model, key, value);
296
- onChangeModel(model, key);
297
- }
298
- };
299
-
300
- render() {
301
- const { groups, model, configuration, modal } = this.props;
302
-
303
- log('render:', model);
304
-
305
- const renderedGroups = Object.keys(groups || {}).map((group) => {
306
- const showGroup = Object.entries(groups[group]).some(([, propVal]) => !!propVal);
307
-
308
- if (showGroup) {
309
- return (
310
- <Group
311
- label={group}
312
- key={group}
313
- model={model}
314
- configuration={configuration}
315
- group={groups[group]}
316
- onChange={this.change}
317
- />
318
- );
319
- }
320
-
321
- return null;
322
- });
323
-
324
- return (
325
- <div>
326
- {renderedGroups}
327
- {modal}
328
- </div>
329
- );
330
- }
331
- }
332
-
333
- export default Panel;