@aglyn/shared-ui-jsx-forms 1.0.0-beta.143
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/LICENSE +201 -0
- package/README.md +7 -0
- package/package.json +52 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +18 -0
- package/src/index.js.map +1 -0
- package/src/lib/components/color-picker-tokens.d.ts +135 -0
- package/src/lib/components/color-picker-tokens.js +431 -0
- package/src/lib/components/color-picker-tokens.js.map +1 -0
- package/src/lib/components/color-picker.component.d.ts +64 -0
- package/src/lib/components/color-picker.component.js +322 -0
- package/src/lib/components/color-picker.component.js.map +1 -0
- package/src/lib/components/create-artifact-drawer.component.d.ts +100 -0
- package/src/lib/components/create-artifact-drawer.component.js +184 -0
- package/src/lib/components/create-artifact-drawer.component.js.map +1 -0
- package/src/lib/components/grid-form-template.component.d.ts +21 -0
- package/src/lib/components/grid-form-template.component.js +81 -0
- package/src/lib/components/grid-form-template.component.js.map +1 -0
- package/src/lib/components/icon-select.component.d.ts +52 -0
- package/src/lib/components/icon-select.component.js +453 -0
- package/src/lib/components/icon-select.component.js.map +1 -0
- package/src/lib/components/select.component.d.ts +58 -0
- package/src/lib/components/select.component.js +107 -0
- package/src/lib/components/select.component.js.map +1 -0
- package/src/lib/components/switch.component.d.ts +38 -0
- package/src/lib/components/switch.component.js +76 -0
- package/src/lib/components/switch.component.js.map +1 -0
- package/src/lib/components/text-field.component.d.ts +45 -0
- package/src/lib/components/text-field.component.js +77 -0
- package/src/lib/components/text-field.component.js.map +1 -0
- package/src/lib/components/textarea.component.d.ts +45 -0
- package/src/lib/components/textarea.component.js +61 -0
- package/src/lib/components/textarea.component.js.map +1 -0
- package/src/lib/components/toggle-button.component.d.ts +27 -0
- package/src/lib/components/toggle-button.component.js +116 -0
- package/src/lib/components/toggle-button.component.js.map +1 -0
- package/src/lib/constants/component-mappers.d.ts +42 -0
- package/src/lib/constants/component-mappers.js +70 -0
- package/src/lib/constants/component-mappers.js.map +1 -0
- package/src/lib/constants/dynamic-fields.d.ts +45 -0
- package/src/lib/constants/dynamic-fields.js +65 -0
- package/src/lib/constants/dynamic-fields.js.map +1 -0
- package/src/lib/constants/field-configurations.d.ts +53 -0
- package/src/lib/constants/field-configurations.js +121 -0
- package/src/lib/constants/field-configurations.js.map +1 -0
- package/src/lib/constants/flags.d.ts +72 -0
- package/src/lib/constants/flags.js +69 -0
- package/src/lib/constants/flags.js.map +1 -0
- package/src/lib/hocs/with-grid-item.d.ts +25 -0
- package/src/lib/hocs/with-grid-item.js +48 -0
- package/src/lib/hocs/with-grid-item.js.map +1 -0
- package/src/lib/jsx-forms.d.ts +41 -0
- package/src/lib/jsx-forms.js +42 -0
- package/src/lib/jsx-forms.js.map +1 -0
- package/src/lib/mapper/breakpoint-span.d.ts +73 -0
- package/src/lib/mapper/breakpoint-span.js +346 -0
- package/src/lib/mapper/breakpoint-span.js.map +1 -0
- package/src/lib/mapper/checkbox.d.ts +43 -0
- package/src/lib/mapper/checkbox.js +111 -0
- package/src/lib/mapper/checkbox.js.map +1 -0
- package/src/lib/mapper/css-border.d.ts +113 -0
- package/src/lib/mapper/css-border.js +410 -0
- package/src/lib/mapper/css-border.js.map +1 -0
- package/src/lib/mapper/css-dimension.d.ts +89 -0
- package/src/lib/mapper/css-dimension.js +327 -0
- package/src/lib/mapper/css-dimension.js.map +1 -0
- package/src/lib/mapper/css-gradient.d.ts +110 -0
- package/src/lib/mapper/css-gradient.js +720 -0
- package/src/lib/mapper/css-gradient.js.map +1 -0
- package/src/lib/mapper/data-table.d.ts +23 -0
- package/src/lib/mapper/data-table.js +296 -0
- package/src/lib/mapper/data-table.js.map +1 -0
- package/src/lib/mapper/date-picker.d.ts +26 -0
- package/src/lib/mapper/date-picker.js +69 -0
- package/src/lib/mapper/date-picker.js.map +1 -0
- package/src/lib/mapper/dual-list-select.d.ts +115 -0
- package/src/lib/mapper/dual-list-select.js +353 -0
- package/src/lib/mapper/dual-list-select.js.map +1 -0
- package/src/lib/mapper/field-array.d.ts +71 -0
- package/src/lib/mapper/field-array.js +326 -0
- package/src/lib/mapper/field-array.js.map +1 -0
- package/src/lib/mapper/form-field-grid.d.ts +155 -0
- package/src/lib/mapper/form-field-grid.js +194 -0
- package/src/lib/mapper/form-field-grid.js.map +1 -0
- package/src/lib/mapper/index.d.ts +50 -0
- package/src/lib/mapper/index.js +49 -0
- package/src/lib/mapper/index.js.map +1 -0
- package/src/lib/mapper/multiple-choice-list.d.ts +32 -0
- package/src/lib/mapper/multiple-choice-list.js +105 -0
- package/src/lib/mapper/multiple-choice-list.js.map +1 -0
- package/src/lib/mapper/plain-text.d.ts +31 -0
- package/src/lib/mapper/plain-text.js +48 -0
- package/src/lib/mapper/plain-text.js.map +1 -0
- package/src/lib/mapper/preset-choice.d.ts +106 -0
- package/src/lib/mapper/preset-choice.js +267 -0
- package/src/lib/mapper/preset-choice.js.map +1 -0
- package/src/lib/mapper/radio.d.ts +40 -0
- package/src/lib/mapper/radio.js +122 -0
- package/src/lib/mapper/radio.js.map +1 -0
- package/src/lib/mapper/select.d.ts +60 -0
- package/src/lib/mapper/select.js +203 -0
- package/src/lib/mapper/select.js.map +1 -0
- package/src/lib/mapper/slider.d.ts +45 -0
- package/src/lib/mapper/slider.js +119 -0
- package/src/lib/mapper/slider.js.map +1 -0
- package/src/lib/mapper/stored-field-value.d.ts +23 -0
- package/src/lib/mapper/stored-field-value.js +29 -0
- package/src/lib/mapper/stored-field-value.js.map +1 -0
- package/src/lib/mapper/sub-form.d.ts +39 -0
- package/src/lib/mapper/sub-form.js +108 -0
- package/src/lib/mapper/sub-form.js.map +1 -0
- package/src/lib/mapper/switch.d.ts +47 -0
- package/src/lib/mapper/switch.js +93 -0
- package/src/lib/mapper/switch.js.map +1 -0
- package/src/lib/mapper/tabs.d.ts +34 -0
- package/src/lib/mapper/tabs.js +64 -0
- package/src/lib/mapper/tabs.js.map +1 -0
- package/src/lib/mapper/text-field.d.ts +33 -0
- package/src/lib/mapper/text-field.js +88 -0
- package/src/lib/mapper/text-field.js.map +1 -0
- package/src/lib/mapper/textarea.d.ts +31 -0
- package/src/lib/mapper/textarea.js +68 -0
- package/src/lib/mapper/textarea.js.map +1 -0
- package/src/lib/mapper/theme-scale.d.ts +79 -0
- package/src/lib/mapper/theme-scale.js +162 -0
- package/src/lib/mapper/theme-scale.js.map +1 -0
- package/src/lib/mapper/time-picker.d.ts +26 -0
- package/src/lib/mapper/time-picker.js +69 -0
- package/src/lib/mapper/time-picker.js.map +1 -0
- package/src/lib/mapper/types.d.ts +43 -0
- package/src/lib/mapper/types.js +22 -0
- package/src/lib/mapper/types.js.map +1 -0
- package/src/lib/mapper/validation-error.d.ts +24 -0
- package/src/lib/mapper/validation-error.js +24 -0
- package/src/lib/mapper/validation-error.js.map +1 -0
- package/src/lib/mapper/wizard.d.ts +21 -0
- package/src/lib/mapper/wizard.js +203 -0
- package/src/lib/mapper/wizard.js.map +1 -0
- package/src/lib/types.d.ts +19 -0
- package/src/lib/types.js +18 -0
- package/src/lib/types.js.map +1 -0
- package/src/lib/utils/option-is-equal-to-value.d.ts +20 -0
- package/src/lib/utils/option-is-equal-to-value.js +21 -0
- package/src/lib/utils/option-is-equal-to-value.js.map +1 -0
- package/src/lib/utils/validation-message.d.ts +22 -0
- package/src/lib/utils/validation-message.js +24 -0
- package/src/lib/utils/validation-message.js.map +1 -0
- package/src/lib/vendor/data-driven-forms.d.ts +33 -0
- package/src/lib/vendor/data-driven-forms.js +29 -0
- package/src/lib/vendor/data-driven-forms.js.map +1 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
+
import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
|
|
3
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
+
/**
|
|
5
|
+
* @license
|
|
6
|
+
* Copyright 2026 Aglyn LLC
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/ /**
|
|
20
|
+
* Ported from `@data-driven-forms/mui-component-mapper` (Apache-2.0) and
|
|
21
|
+
* updated for the current MUI Grid API.
|
|
22
|
+
*/ import { memo, useReducer } from "react";
|
|
23
|
+
import { Button, FormControl, FormHelperText, Grid, IconButton, Typography } from "@mui/material";
|
|
24
|
+
import { styled } from "@mui/material/styles";
|
|
25
|
+
import RedoIcon from "@mui/icons-material/Redo";
|
|
26
|
+
import UndoIcon from "@mui/icons-material/Undo";
|
|
27
|
+
import clsx from "clsx";
|
|
28
|
+
import { isEqual } from "lodash-es";
|
|
29
|
+
import { FieldArray, useFieldApi, useFormApi } from "../vendor/data-driven-forms.js";
|
|
30
|
+
import FormFieldGrid from "./form-field-grid.js";
|
|
31
|
+
const PREFIX = 'DynamicArray';
|
|
32
|
+
const classes = {
|
|
33
|
+
formControl: `${PREFIX}-formControl`,
|
|
34
|
+
centerText: `${PREFIX}-centerText`,
|
|
35
|
+
buttonsToEnd: `${PREFIX}-buttonsToEnd`,
|
|
36
|
+
header: `${PREFIX}-header`,
|
|
37
|
+
label: `${PREFIX}-label`,
|
|
38
|
+
fieldArrayGroup: `${PREFIX}-fieldArrayGroup`
|
|
39
|
+
};
|
|
40
|
+
const StyledFormFieldGrid = styled(FormFieldGrid)({
|
|
41
|
+
[`& .${classes.formControl}`]: {
|
|
42
|
+
width: '100%'
|
|
43
|
+
},
|
|
44
|
+
[`& .${classes.centerText}`]: {
|
|
45
|
+
display: 'flex',
|
|
46
|
+
justifyContent: 'center'
|
|
47
|
+
},
|
|
48
|
+
[`& .${classes.buttonsToEnd}`]: {
|
|
49
|
+
display: 'flex',
|
|
50
|
+
justifyContent: 'flex-end'
|
|
51
|
+
},
|
|
52
|
+
[`& .${classes.header}`]: {
|
|
53
|
+
display: 'flex'
|
|
54
|
+
},
|
|
55
|
+
[`& .${classes.label}`]: {
|
|
56
|
+
flexGrow: 1
|
|
57
|
+
},
|
|
58
|
+
[`&.${classes.fieldArrayGroup}`]: {
|
|
59
|
+
marginBottom: 32
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const ArrayItem = /*#__PURE__*/ memo(({ fields, fieldIndex, name, remove, length, minItems, removeLabel, FieldContainerProps = {}, FieldGroupGridProps = {}, RemoveButtonGridProps = {}, RemoveButtonProps = {} })=>{
|
|
63
|
+
const { renderForm } = useFormApi();
|
|
64
|
+
const editedFields = fields.map((field, index)=>{
|
|
65
|
+
const computedName = field.name ? `${name}.${field.name}` : name;
|
|
66
|
+
return _extends({}, field, {
|
|
67
|
+
name: computedName,
|
|
68
|
+
key: `${computedName}-${index}`
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
return /*#__PURE__*/ _jsxs(Grid, _extends({
|
|
72
|
+
container: true,
|
|
73
|
+
spacing: 3
|
|
74
|
+
}, FieldContainerProps, {
|
|
75
|
+
children: [
|
|
76
|
+
/*#__PURE__*/ _jsx(Grid, _extends({
|
|
77
|
+
size: {
|
|
78
|
+
xs: 12
|
|
79
|
+
}
|
|
80
|
+
}, FieldGroupGridProps, {
|
|
81
|
+
children: /*#__PURE__*/ _jsx(Grid, {
|
|
82
|
+
container: true,
|
|
83
|
+
spacing: 3,
|
|
84
|
+
children: renderForm(editedFields)
|
|
85
|
+
})
|
|
86
|
+
})),
|
|
87
|
+
/*#__PURE__*/ _jsx(Grid, _extends({
|
|
88
|
+
size: {
|
|
89
|
+
xs: 12
|
|
90
|
+
},
|
|
91
|
+
className: classes.buttonsToEnd
|
|
92
|
+
}, RemoveButtonGridProps, {
|
|
93
|
+
children: /*#__PURE__*/ _jsx(Button, _extends({
|
|
94
|
+
color: "primary",
|
|
95
|
+
onClick: ()=>remove(fieldIndex),
|
|
96
|
+
disabled: length <= minItems
|
|
97
|
+
}, RemoveButtonProps, {
|
|
98
|
+
children: removeLabel
|
|
99
|
+
}))
|
|
100
|
+
}))
|
|
101
|
+
]
|
|
102
|
+
}));
|
|
103
|
+
}, (_0, _1)=>{
|
|
104
|
+
let _ref = [
|
|
105
|
+
_0,
|
|
106
|
+
_1
|
|
107
|
+
], [_ref1, ..._rest] = _ref, { remove: _prevRemove } = _ref1, prev = _object_without_properties_loose(_ref1, [
|
|
108
|
+
"remove"
|
|
109
|
+
]), [_ref2] = _rest, { remove: _nextRemove } = _ref2, next = _object_without_properties_loose(_ref2, [
|
|
110
|
+
"remove"
|
|
111
|
+
]);
|
|
112
|
+
return isEqual(prev, next);
|
|
113
|
+
});
|
|
114
|
+
const defaultButtonLabels = {
|
|
115
|
+
add: 'ADD',
|
|
116
|
+
remove: 'REMOVE'
|
|
117
|
+
};
|
|
118
|
+
const initialState = {
|
|
119
|
+
index: 0,
|
|
120
|
+
history: []
|
|
121
|
+
};
|
|
122
|
+
export const reducer = (state, actionObj)=>{
|
|
123
|
+
switch(actionObj.type){
|
|
124
|
+
case 'redo':
|
|
125
|
+
return _extends({}, state, {
|
|
126
|
+
index: state.index + 1
|
|
127
|
+
});
|
|
128
|
+
case 'action':
|
|
129
|
+
return {
|
|
130
|
+
index: state.index + 1,
|
|
131
|
+
history: [
|
|
132
|
+
...state.history.slice(0, state.index),
|
|
133
|
+
actionObj.action
|
|
134
|
+
]
|
|
135
|
+
};
|
|
136
|
+
case 'undo':
|
|
137
|
+
return _extends({}, state, {
|
|
138
|
+
index: state.index - 1
|
|
139
|
+
});
|
|
140
|
+
case 'resetHistory':
|
|
141
|
+
return _extends({}, state, {
|
|
142
|
+
history: state.history.slice(0, state.index)
|
|
143
|
+
});
|
|
144
|
+
default:
|
|
145
|
+
return state;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
export const DynamicArray = (props)=>{
|
|
149
|
+
const _useFieldApi = useFieldApi(props), { arrayValidator, label, description, fields: formFields, defaultItem, meta, minItems = 0, maxItems = Infinity, noItemsMessage = 'No items added', help, FormFieldGridProps = {}, FormControlProps = {}, buttonLabels, GridContainerProps = {}, HeaderGridProps = {}, HeaderProps = {}, UndoButtonProps = {}, RedoButtonProps = {}, AddButtonProps = {}, DescriptionGridProps = {}, DescriptionProps = {}, BodyGridProps = {}, NoItemsProps = {}, FormHelperTextGridProps = {}, FormHelperTextProps = {}, FieldContainerProps = {}, FieldGroupGridProps = {}, RemoveButtonGridProps = {}, RemoveButtonProps = {} } = _useFieldApi, rest = _object_without_properties_loose(_useFieldApi, [
|
|
150
|
+
"arrayValidator",
|
|
151
|
+
"label",
|
|
152
|
+
"description",
|
|
153
|
+
"fields",
|
|
154
|
+
"defaultItem",
|
|
155
|
+
"meta",
|
|
156
|
+
"minItems",
|
|
157
|
+
"maxItems",
|
|
158
|
+
"noItemsMessage",
|
|
159
|
+
"help",
|
|
160
|
+
"FormFieldGridProps",
|
|
161
|
+
"FormControlProps",
|
|
162
|
+
"buttonLabels",
|
|
163
|
+
"GridContainerProps",
|
|
164
|
+
"HeaderGridProps",
|
|
165
|
+
"HeaderProps",
|
|
166
|
+
"UndoButtonProps",
|
|
167
|
+
"RedoButtonProps",
|
|
168
|
+
"AddButtonProps",
|
|
169
|
+
"DescriptionGridProps",
|
|
170
|
+
"DescriptionProps",
|
|
171
|
+
"BodyGridProps",
|
|
172
|
+
"NoItemsProps",
|
|
173
|
+
"FormHelperTextGridProps",
|
|
174
|
+
"FormHelperTextProps",
|
|
175
|
+
"FieldContainerProps",
|
|
176
|
+
"FieldGroupGridProps",
|
|
177
|
+
"RemoveButtonGridProps",
|
|
178
|
+
"RemoveButtonProps"
|
|
179
|
+
]);
|
|
180
|
+
const [state, dispatch] = useReducer(reducer, initialState);
|
|
181
|
+
const combinedButtonLabels = _extends({}, defaultButtonLabels, buttonLabels);
|
|
182
|
+
const { dirty, submitFailed, error, submitError } = meta;
|
|
183
|
+
const isError = (dirty || submitFailed) && error && typeof error === 'string';
|
|
184
|
+
return /*#__PURE__*/ _jsx(StyledFormFieldGrid, _extends({
|
|
185
|
+
help: help
|
|
186
|
+
}, FormFieldGridProps, {
|
|
187
|
+
className: clsx(classes.fieldArrayGroup, FormFieldGridProps.className),
|
|
188
|
+
children: /*#__PURE__*/ _jsx(FormControl, _extends({
|
|
189
|
+
component: "fieldset",
|
|
190
|
+
error: isError || submitError
|
|
191
|
+
}, FormControlProps, {
|
|
192
|
+
className: clsx(classes.formControl, FormControlProps.className),
|
|
193
|
+
children: /*#__PURE__*/ _jsx(FieldArray, {
|
|
194
|
+
name: rest.input.name,
|
|
195
|
+
validate: arrayValidator,
|
|
196
|
+
children: ({ fields: { map, value = [], push, remove } })=>{
|
|
197
|
+
const pushWrapper = ()=>{
|
|
198
|
+
dispatch({
|
|
199
|
+
type: 'resetHistory'
|
|
200
|
+
});
|
|
201
|
+
push(defaultItem);
|
|
202
|
+
};
|
|
203
|
+
const removeWrapper = (index)=>{
|
|
204
|
+
dispatch({
|
|
205
|
+
type: 'action',
|
|
206
|
+
action: {
|
|
207
|
+
action: 'remove',
|
|
208
|
+
value: value[index]
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
remove(index);
|
|
212
|
+
};
|
|
213
|
+
const undo = ()=>{
|
|
214
|
+
push(state.history[state.index - 1].value);
|
|
215
|
+
dispatch({
|
|
216
|
+
type: 'undo'
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
const redo = ()=>{
|
|
220
|
+
remove(value.length - 1);
|
|
221
|
+
dispatch({
|
|
222
|
+
type: 'redo'
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
return /*#__PURE__*/ _jsxs(Grid, _extends({
|
|
226
|
+
container: true,
|
|
227
|
+
spacing: 3
|
|
228
|
+
}, GridContainerProps, {
|
|
229
|
+
children: [
|
|
230
|
+
/*#__PURE__*/ _jsxs(Grid, _extends({
|
|
231
|
+
size: {
|
|
232
|
+
xs: 12
|
|
233
|
+
},
|
|
234
|
+
className: classes.header
|
|
235
|
+
}, HeaderGridProps, {
|
|
236
|
+
children: [
|
|
237
|
+
label && /*#__PURE__*/ _jsx(Typography, _extends({
|
|
238
|
+
variant: "h6",
|
|
239
|
+
className: classes.label
|
|
240
|
+
}, HeaderProps, {
|
|
241
|
+
children: label
|
|
242
|
+
})),
|
|
243
|
+
/*#__PURE__*/ _jsx(IconButton, _extends({
|
|
244
|
+
color: "primary",
|
|
245
|
+
"aria-label": "undo",
|
|
246
|
+
component: "span",
|
|
247
|
+
disabled: state.index === 0,
|
|
248
|
+
onClick: undo
|
|
249
|
+
}, UndoButtonProps, {
|
|
250
|
+
size: "large",
|
|
251
|
+
children: /*#__PURE__*/ _jsx(UndoIcon, {})
|
|
252
|
+
})),
|
|
253
|
+
/*#__PURE__*/ _jsx(IconButton, _extends({
|
|
254
|
+
color: "primary",
|
|
255
|
+
"aria-label": "redo",
|
|
256
|
+
component: "span",
|
|
257
|
+
disabled: state.index === state.history.length,
|
|
258
|
+
onClick: redo
|
|
259
|
+
}, RedoButtonProps, {
|
|
260
|
+
size: "large",
|
|
261
|
+
children: /*#__PURE__*/ _jsx(RedoIcon, {})
|
|
262
|
+
})),
|
|
263
|
+
/*#__PURE__*/ _jsx(Button, _extends({
|
|
264
|
+
color: "primary",
|
|
265
|
+
onClick: pushWrapper,
|
|
266
|
+
disabled: value.length >= maxItems
|
|
267
|
+
}, AddButtonProps, {
|
|
268
|
+
children: combinedButtonLabels.add
|
|
269
|
+
}))
|
|
270
|
+
]
|
|
271
|
+
})),
|
|
272
|
+
description && /*#__PURE__*/ _jsx(Grid, _extends({
|
|
273
|
+
size: {
|
|
274
|
+
xs: 12
|
|
275
|
+
}
|
|
276
|
+
}, DescriptionGridProps, {
|
|
277
|
+
children: /*#__PURE__*/ _jsx(Typography, _extends({
|
|
278
|
+
variant: "subtitle1"
|
|
279
|
+
}, DescriptionProps, {
|
|
280
|
+
children: description
|
|
281
|
+
}))
|
|
282
|
+
})),
|
|
283
|
+
/*#__PURE__*/ _jsx(Grid, _extends({
|
|
284
|
+
size: {
|
|
285
|
+
xs: 12
|
|
286
|
+
}
|
|
287
|
+
}, BodyGridProps, {
|
|
288
|
+
children: value.length <= 0 ? /*#__PURE__*/ _jsx(Typography, _extends({
|
|
289
|
+
variant: "body1",
|
|
290
|
+
gutterBottom: true,
|
|
291
|
+
className: classes.centerText
|
|
292
|
+
}, NoItemsProps, {
|
|
293
|
+
children: noItemsMessage
|
|
294
|
+
})) : map((name, index)=>/*#__PURE__*/ _jsx(ArrayItem, {
|
|
295
|
+
fields: formFields,
|
|
296
|
+
name: name,
|
|
297
|
+
fieldIndex: index,
|
|
298
|
+
remove: removeWrapper,
|
|
299
|
+
length: value.length,
|
|
300
|
+
minItems: minItems,
|
|
301
|
+
removeLabel: combinedButtonLabels.remove,
|
|
302
|
+
FieldContainerProps: FieldContainerProps,
|
|
303
|
+
FieldGroupGridProps: FieldGroupGridProps,
|
|
304
|
+
RemoveButtonGridProps: RemoveButtonGridProps,
|
|
305
|
+
RemoveButtonProps: RemoveButtonProps
|
|
306
|
+
}, name))
|
|
307
|
+
})),
|
|
308
|
+
(isError || submitError) && /*#__PURE__*/ _jsx(Grid, _extends({
|
|
309
|
+
size: {
|
|
310
|
+
xs: 12
|
|
311
|
+
}
|
|
312
|
+
}, FormHelperTextGridProps, {
|
|
313
|
+
children: /*#__PURE__*/ _jsx(FormHelperText, _extends({}, FormHelperTextProps, {
|
|
314
|
+
children: error || submitError
|
|
315
|
+
}))
|
|
316
|
+
}))
|
|
317
|
+
]
|
|
318
|
+
}));
|
|
319
|
+
}
|
|
320
|
+
}, rest.input.name)
|
|
321
|
+
}))
|
|
322
|
+
}));
|
|
323
|
+
};
|
|
324
|
+
export default DynamicArray;
|
|
325
|
+
|
|
326
|
+
//# sourceMappingURL=field-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../libs/shared/ui/jsx-forms/src/lib/mapper/field-array.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Ported from `@data-driven-forms/mui-component-mapper` (Apache-2.0) and\n * updated for the current MUI Grid API.\n */\n\nimport { memo, useReducer } from 'react'\n\nimport {\n Button,\n type ButtonProps,\n FormControl,\n type FormControlProps,\n FormHelperText,\n type FormHelperTextProps,\n Grid,\n type GridProps,\n IconButton,\n type IconButtonProps,\n Typography,\n type TypographyProps,\n} from '@mui/material'\nimport { styled } from '@mui/material/styles'\n\nimport RedoIcon from '@mui/icons-material/Redo'\nimport UndoIcon from '@mui/icons-material/Undo'\n\nimport clsx from 'clsx'\n\nimport { isEqual } from 'lodash-es'\n\nimport {\n FieldArray,\n useFieldApi,\n useFormApi,\n} from '../vendor/data-driven-forms'\nimport FormFieldGrid, { type FormFieldGridProps } from './form-field-grid'\nimport type { BaseFieldProps } from './types'\n\nconst PREFIX = 'DynamicArray'\n\nconst classes = {\n formControl: `${PREFIX}-formControl`,\n centerText: `${PREFIX}-centerText`,\n buttonsToEnd: `${PREFIX}-buttonsToEnd`,\n header: `${PREFIX}-header`,\n label: `${PREFIX}-label`,\n fieldArrayGroup: `${PREFIX}-fieldArrayGroup`,\n}\n\nconst StyledFormFieldGrid = styled(FormFieldGrid)({\n [`& .${classes.formControl}`]: {\n width: '100%',\n },\n [`& .${classes.centerText}`]: {\n display: 'flex',\n justifyContent: 'center',\n },\n [`& .${classes.buttonsToEnd}`]: {\n display: 'flex',\n justifyContent: 'flex-end',\n },\n [`& .${classes.header}`]: {\n display: 'flex',\n },\n [`& .${classes.label}`]: {\n flexGrow: 1,\n },\n [`&.${classes.fieldArrayGroup}`]: {\n marginBottom: 32,\n },\n})\n\ninterface ArrayItemProps {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields: (Record<string, any> & { name?: string; component: string })[]\n fieldIndex: number\n name: string\n remove: (index: number) => void\n length: number\n minItems: number\n removeLabel: string\n FieldContainerProps?: GridProps\n FieldGroupGridProps?: GridProps\n RemoveButtonGridProps?: GridProps\n RemoveButtonProps?: ButtonProps\n}\n\nconst ArrayItem = memo<ArrayItemProps>(\n ({\n fields,\n fieldIndex,\n name,\n remove,\n length,\n minItems,\n removeLabel,\n FieldContainerProps = {},\n FieldGroupGridProps = {},\n RemoveButtonGridProps = {},\n RemoveButtonProps = {},\n }) => {\n const { renderForm } = useFormApi()\n\n const editedFields = fields.map((field, index) => {\n const computedName = field.name ? `${name}.${field.name}` : name\n return { ...field, name: computedName, key: `${computedName}-${index}` }\n })\n\n return (\n <Grid container spacing={3} {...FieldContainerProps}>\n <Grid size={{ xs: 12 }} {...FieldGroupGridProps}>\n <Grid container spacing={3}>\n {renderForm(editedFields)}\n </Grid>\n </Grid>\n <Grid\n size={{ xs: 12 }}\n className={classes.buttonsToEnd}\n {...RemoveButtonGridProps}\n >\n <Button\n color=\"primary\"\n onClick={() => remove(fieldIndex)}\n disabled={length <= minItems}\n {...RemoveButtonProps}\n >\n {removeLabel}\n </Button>\n </Grid>\n </Grid>\n )\n },\n ({ remove: _prevRemove, ...prev }, { remove: _nextRemove, ...next }) =>\n isEqual(prev, next),\n)\n\ninterface ButtonLabels {\n add?: string\n remove?: string\n}\n\nconst defaultButtonLabels: Required<ButtonLabels> = {\n add: 'ADD',\n remove: 'REMOVE',\n}\n\ninterface HistoryAction {\n action: 'remove'\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: any\n}\n\ninterface HistoryState {\n index: number\n history: HistoryAction[]\n}\n\ntype ReducerAction =\n | { type: 'redo' }\n | { type: 'undo' }\n | { type: 'action'; action: HistoryAction }\n | { type: 'resetHistory' }\n\nconst initialState: HistoryState = {\n index: 0,\n history: [],\n}\n\nexport const reducer = (\n state: HistoryState,\n actionObj: ReducerAction,\n): HistoryState => {\n switch (actionObj.type) {\n case 'redo':\n return {\n ...state,\n index: state.index + 1,\n }\n case 'action':\n return {\n index: state.index + 1,\n history: [...state.history.slice(0, state.index), actionObj.action],\n }\n case 'undo':\n return {\n ...state,\n index: state.index - 1,\n }\n case 'resetHistory':\n return {\n ...state,\n history: state.history.slice(0, state.index),\n }\n default:\n return state\n }\n}\n\nexport interface FieldArrayProps extends BaseFieldProps {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n arrayValidator?: (value: any[]) => string | undefined\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields: Record<string, any>[]\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n defaultItem?: any\n minItems?: number\n maxItems?: number\n noItemsMessage?: string\n buttonLabels?: ButtonLabels\n FormFieldGridProps?: FormFieldGridProps\n FormControlProps?: FormControlProps\n GridContainerProps?: GridProps\n HeaderGridProps?: GridProps\n HeaderProps?: TypographyProps\n UndoButtonProps?: IconButtonProps\n RedoButtonProps?: IconButtonProps\n AddButtonProps?: ButtonProps\n DescriptionGridProps?: GridProps\n DescriptionProps?: TypographyProps\n BodyGridProps?: GridProps\n NoItemsProps?: TypographyProps\n FormHelperTextGridProps?: GridProps\n FormHelperTextProps?: FormHelperTextProps\n FieldContainerProps?: GridProps\n FieldGroupGridProps?: GridProps\n RemoveButtonGridProps?: GridProps\n RemoveButtonProps?: ButtonProps\n}\n\nexport const DynamicArray = (props: FieldArrayProps) => {\n const {\n arrayValidator,\n label,\n description,\n fields: formFields,\n defaultItem,\n meta,\n minItems = 0,\n maxItems = Infinity,\n noItemsMessage = 'No items added',\n help,\n FormFieldGridProps = {},\n FormControlProps = {},\n buttonLabels,\n GridContainerProps = {},\n HeaderGridProps = {},\n HeaderProps = {},\n UndoButtonProps = {},\n RedoButtonProps = {},\n AddButtonProps = {},\n DescriptionGridProps = {},\n DescriptionProps = {},\n BodyGridProps = {},\n NoItemsProps = {},\n FormHelperTextGridProps = {},\n FormHelperTextProps = {},\n FieldContainerProps = {},\n FieldGroupGridProps = {},\n RemoveButtonGridProps = {},\n RemoveButtonProps = {},\n ...rest\n } = useFieldApi(props)\n const [state, dispatch] = useReducer(reducer, initialState)\n\n const combinedButtonLabels = {\n ...defaultButtonLabels,\n ...buttonLabels,\n }\n\n const { dirty, submitFailed, error, submitError } = meta\n const isError = (dirty || submitFailed) && error && typeof error === 'string'\n\n return (\n <StyledFormFieldGrid\n help={help}\n {...FormFieldGridProps}\n className={clsx(classes.fieldArrayGroup, FormFieldGridProps.className)}\n >\n <FormControl\n component=\"fieldset\"\n error={isError || submitError}\n {...FormControlProps}\n className={clsx(classes.formControl, FormControlProps.className)}\n >\n <FieldArray\n key={rest.input.name}\n name={rest.input.name}\n validate={arrayValidator}\n >\n {({ fields: { map, value = [], push, remove } }) => {\n const pushWrapper = () => {\n dispatch({ type: 'resetHistory' })\n push(defaultItem)\n }\n\n const removeWrapper = (index: number) => {\n dispatch({\n type: 'action',\n action: { action: 'remove', value: value[index] },\n })\n remove(index)\n }\n\n const undo = () => {\n push(state.history[state.index - 1].value)\n dispatch({ type: 'undo' })\n }\n\n const redo = () => {\n remove(value.length - 1)\n dispatch({ type: 'redo' })\n }\n\n return (\n <Grid container spacing={3} {...GridContainerProps}>\n <Grid\n size={{ xs: 12 }}\n className={classes.header}\n {...HeaderGridProps}\n >\n {label && (\n <Typography\n variant=\"h6\"\n className={classes.label}\n {...HeaderProps}\n >\n {label}\n </Typography>\n )}\n <IconButton\n color=\"primary\"\n aria-label=\"undo\"\n component=\"span\"\n disabled={state.index === 0}\n onClick={undo}\n {...UndoButtonProps}\n size=\"large\"\n >\n <UndoIcon />\n </IconButton>\n <IconButton\n color=\"primary\"\n aria-label=\"redo\"\n component=\"span\"\n disabled={state.index === state.history.length}\n onClick={redo}\n {...RedoButtonProps}\n size=\"large\"\n >\n <RedoIcon />\n </IconButton>\n <Button\n color=\"primary\"\n onClick={pushWrapper}\n disabled={value.length >= maxItems}\n {...AddButtonProps}\n >\n {combinedButtonLabels.add}\n </Button>\n </Grid>\n {description && (\n <Grid size={{ xs: 12 }} {...DescriptionGridProps}>\n <Typography variant=\"subtitle1\" {...DescriptionProps}>\n {description}\n </Typography>\n </Grid>\n )}\n <Grid size={{ xs: 12 }} {...BodyGridProps}>\n {value.length <= 0 ? (\n <Typography\n variant=\"body1\"\n gutterBottom\n className={classes.centerText}\n {...NoItemsProps}\n >\n {noItemsMessage}\n </Typography>\n ) : (\n map((name, index) => (\n <ArrayItem\n key={name}\n fields={formFields}\n name={name}\n fieldIndex={index}\n remove={removeWrapper}\n length={value.length}\n minItems={minItems}\n removeLabel={combinedButtonLabels.remove}\n FieldContainerProps={FieldContainerProps}\n FieldGroupGridProps={FieldGroupGridProps}\n RemoveButtonGridProps={RemoveButtonGridProps}\n RemoveButtonProps={RemoveButtonProps}\n />\n ))\n )}\n </Grid>\n {(isError || submitError) && (\n <Grid size={{ xs: 12 }} {...FormHelperTextGridProps}>\n <FormHelperText {...FormHelperTextProps}>\n {error || submitError}\n </FormHelperText>\n </Grid>\n )}\n </Grid>\n )\n }}\n </FieldArray>\n </FormControl>\n </StyledFormFieldGrid>\n )\n}\n\nexport default DynamicArray\n"],"names":["memo","useReducer","Button","FormControl","FormHelperText","Grid","IconButton","Typography","styled","RedoIcon","UndoIcon","clsx","isEqual","FieldArray","useFieldApi","useFormApi","FormFieldGrid","PREFIX","classes","formControl","centerText","buttonsToEnd","header","label","fieldArrayGroup","StyledFormFieldGrid","width","display","justifyContent","flexGrow","marginBottom","ArrayItem","fields","fieldIndex","name","remove","length","minItems","removeLabel","FieldContainerProps","FieldGroupGridProps","RemoveButtonGridProps","RemoveButtonProps","renderForm","editedFields","map","field","index","computedName","key","container","spacing","size","xs","className","color","onClick","disabled","_prevRemove","prev","_nextRemove","next","defaultButtonLabels","add","initialState","history","reducer","state","actionObj","type","slice","action","DynamicArray","props","arrayValidator","description","formFields","defaultItem","meta","maxItems","Infinity","noItemsMessage","help","FormFieldGridProps","FormControlProps","buttonLabels","GridContainerProps","HeaderGridProps","HeaderProps","UndoButtonProps","RedoButtonProps","AddButtonProps","DescriptionGridProps","DescriptionProps","BodyGridProps","NoItemsProps","FormHelperTextGridProps","FormHelperTextProps","rest","dispatch","combinedButtonLabels","dirty","submitFailed","error","submitError","isError","component","input","validate","value","push","pushWrapper","removeWrapper","undo","redo","variant","aria-label","gutterBottom"],"mappings":";;;AAAA;;;;;;;;;;;;;;;CAeC,GAED;;;CAGC,GAED,SAASA,IAAI,EAAEC,UAAU,QAAQ,QAAO;AAExC,SACEC,MAAM,EAENC,WAAW,EAEXC,cAAc,EAEdC,IAAI,EAEJC,UAAU,EAEVC,UAAU,QAEL,gBAAe;AACtB,SAASC,MAAM,QAAQ,uBAAsB;AAE7C,OAAOC,cAAc,2BAA0B;AAC/C,OAAOC,cAAc,2BAA0B;AAE/C,OAAOC,UAAU,OAAM;AAEvB,SAASC,OAAO,QAAQ,YAAW;AAEnC,SACEC,UAAU,EACVC,WAAW,EACXC,UAAU,QACL,iCAA6B;AACpC,OAAOC,mBAAgD,uBAAmB;AAG1E,MAAMC,SAAS;AAEf,MAAMC,UAAU;IACdC,aAAa,GAAGF,OAAO,YAAY,CAAC;IACpCG,YAAY,GAAGH,OAAO,WAAW,CAAC;IAClCI,cAAc,GAAGJ,OAAO,aAAa,CAAC;IACtCK,QAAQ,GAAGL,OAAO,OAAO,CAAC;IAC1BM,OAAO,GAAGN,OAAO,MAAM,CAAC;IACxBO,iBAAiB,GAAGP,OAAO,gBAAgB,CAAC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AAK+C,MAAM;oCAAEC,IAAI;gCAAG;+BAAOuC;0CAC1B,cAAA,KAACrF;oCAAW4G,SAAQ;mCAAgBtB;8CACjClB;;;0CAIP,KAACtE;gCAAK+C,MAAM;oCAAEC,IAAI;gCAAG;+BAAOyC;0CACzBe,MAAMzE,MAAM,IAAI,kBACf,KAAC7B;oCACC4G,SAAQ;oCACRE,YAAY;oCACZ/D,WAAWpC,QAAQE,UAAU;mCACzB2E;8CAEHd;sCAGHpC,IAAI,CAACX,MAAMa,sBACT,KAAChB;wCAECC,QAAQ4C;wCACR1C,MAAMA;wCACND,YAAYc;wCACZZ,QAAQ6E;wCACR5E,QAAQyE,MAAMzE,MAAM;wCACpBC,UAAUA;wCACVC,aAAa8D,qBAAqBjE,MAAM;wCACxCI,qBAAqBA;wCACrBC,qBAAqBA;wCACrBC,uBAAuBA;wCACvBC,mBAAmBA;uCAXdR;;4BAgBXuE,CAAAA,WAAWD,WAAU,mBACrB,KAACnG;gCAAK+C,MAAM;oCAAEC,IAAI;gCAAG;+BAAO2C;0CAC1B,cAAA,KAAC5F,6BAAmB6F;8CACjBM,SAASC;;;;;gBAMtB;eAxHKN,KAAKS,KAAK,CAACzE,IAAI;;;AA6H9B,EAAC;AAED,eAAesC,aAAY"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Ported from `@data-driven-forms/mui-component-mapper` (Apache-2.0) and
|
|
19
|
+
* updated for the current MUI Grid API (`size` instead of `item`/`xs`).
|
|
20
|
+
*/
|
|
21
|
+
import type { ReactNode } from 'react';
|
|
22
|
+
import { type HelpTipContent } from '@aglyn/shared-ui-jsx';
|
|
23
|
+
import { type GridProps } from '@mui/material';
|
|
24
|
+
/**
|
|
25
|
+
* How a row whose declaration is switched off reads.
|
|
26
|
+
*
|
|
27
|
+
* It has to say "set, but not applying" and never "unset" — that distinction
|
|
28
|
+
* is the whole point of switching a declaration off rather than deleting it.
|
|
29
|
+
* So the VALUE is struck through and the control fades, while the corner
|
|
30
|
+
* buttons stay at full strength: they are the way back, and must not look
|
|
31
|
+
* disabled themselves.
|
|
32
|
+
*
|
|
33
|
+
* Exported as a plain sx object because a mute can sit on surfaces that are
|
|
34
|
+
* not grid-wrapped fields — the inline toggle rows, the box editor's sides,
|
|
35
|
+
* the custom-CSS builder — and all of them have to read the same.
|
|
36
|
+
*/
|
|
37
|
+
export declare const FIELD_MUTED_STYLES: {
|
|
38
|
+
[x: string]: {
|
|
39
|
+
opacity: number;
|
|
40
|
+
textDecoration?: undefined;
|
|
41
|
+
} | {
|
|
42
|
+
textDecoration: string;
|
|
43
|
+
opacity?: undefined;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The "put this field back to unset" affordance (AGL-2486).
|
|
48
|
+
*
|
|
49
|
+
* Every editor in the styles panel could SET a value and none of them
|
|
50
|
+
* could take one off again: a colour typed once stayed on the node
|
|
51
|
+
* forever, because "unset" is not a value any of these controls can be
|
|
52
|
+
* driven to — a colour picker has no empty swatch, a length box with a
|
|
53
|
+
* unit picked re-serializes `px` onto an emptied number, and a select's
|
|
54
|
+
* "Default" option only exists where someone remembered to author one.
|
|
55
|
+
* The way back has to be a control of its own.
|
|
56
|
+
*
|
|
57
|
+
* It lives on the shared wrapper rather than inside each editor so the
|
|
58
|
+
* affordance is one thing in one place — but each editor still supplies
|
|
59
|
+
* {@link onClear}, because what "clear" MEANS differs per editor (a
|
|
60
|
+
* gradient drops its stops, a length drops its unit) and a wrapper that
|
|
61
|
+
* only knew the form value would leave those drafts behind.
|
|
62
|
+
*/
|
|
63
|
+
export interface FieldClearAction {
|
|
64
|
+
/** Accessible name, e.g. `Clear Text Color`. */
|
|
65
|
+
label: string;
|
|
66
|
+
/** Nothing to clear — the button is not rendered at all. */
|
|
67
|
+
hidden?: boolean;
|
|
68
|
+
disabled?: boolean;
|
|
69
|
+
onClear: () => void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Builds a {@link FieldClearAction} for one editor.
|
|
73
|
+
*
|
|
74
|
+
* `hasValue` is passed in rather than derived from a form value because
|
|
75
|
+
* `0` and `'0'` are legitimate style values and this repo compiles with
|
|
76
|
+
* `strictNullChecks` off — a falsy test here would hide the clear button
|
|
77
|
+
* on exactly the values hardest to type back in.
|
|
78
|
+
*/
|
|
79
|
+
export declare const buildFieldClear: (options: {
|
|
80
|
+
/** Opt-in: only fields whose schema asks for it get the affordance. */
|
|
81
|
+
clearable?: boolean;
|
|
82
|
+
label?: ReactNode;
|
|
83
|
+
hasValue: boolean;
|
|
84
|
+
locked?: boolean;
|
|
85
|
+
onClear: () => void;
|
|
86
|
+
}) => FieldClearAction | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The "stop applying this one declaration, keep its value" affordance
|
|
89
|
+
* (AGL-2486) — the browser-devtools checkbox, in the styles panel.
|
|
90
|
+
*
|
|
91
|
+
* Distinct from {@link FieldClearAction} in the only way that matters: clear
|
|
92
|
+
* takes the value off the element, mute leaves it exactly where it is and
|
|
93
|
+
* stops it painting, so a layout can be looked at with one property switched
|
|
94
|
+
* off and the comparison value is still there to switch back on.
|
|
95
|
+
*
|
|
96
|
+
* Supplied by the panel through the field's `FormFieldGridProps`, not by each
|
|
97
|
+
* editor, because unlike clear it needs nothing from the editor: which
|
|
98
|
+
* declaration to mute is the field's own name, and where the mute lives is
|
|
99
|
+
* the panel's business.
|
|
100
|
+
*/
|
|
101
|
+
export interface FieldMuteAction {
|
|
102
|
+
/** Accessible name, e.g. `Stop applying Max Width`. */
|
|
103
|
+
label: string;
|
|
104
|
+
/** True while the declaration is switched off. */
|
|
105
|
+
muted?: boolean;
|
|
106
|
+
onToggle: () => void;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The eye itself, so every surface that can carry a mute renders the same
|
|
110
|
+
* control: the grid-wrapped fields, the inline toggle rows, the box editor's
|
|
111
|
+
* sides and the custom-CSS builder. `offset` places it in a corner where one
|
|
112
|
+
* is free.
|
|
113
|
+
*/
|
|
114
|
+
export declare const FieldMuteButton: {
|
|
115
|
+
({ mute, offset, sx, }: {
|
|
116
|
+
mute?: FieldMuteAction;
|
|
117
|
+
offset?: number;
|
|
118
|
+
sx?: object;
|
|
119
|
+
}): import("react").JSX.Element;
|
|
120
|
+
displayName: string;
|
|
121
|
+
};
|
|
122
|
+
/** Class marking a row whose declaration is switched off. */
|
|
123
|
+
export declare const FIELD_MUTED_CLASS: string;
|
|
124
|
+
/**
|
|
125
|
+
* The "let something else supply this value" affordance — the `{}` a
|
|
126
|
+
* free-text field carries inside its box, for a field that has no box to
|
|
127
|
+
* carry it in.
|
|
128
|
+
*
|
|
129
|
+
* A switch or a checkbox has no box to put an end adornment in, so the button
|
|
130
|
+
* joins the corner controls instead, where it sits the same way on any field.
|
|
131
|
+
* What it opens is the caller's business: the field's name is all a wrapper
|
|
132
|
+
* knows, and which values may stand in for it is a question only the surface
|
|
133
|
+
* that rendered the field can answer.
|
|
134
|
+
*/
|
|
135
|
+
export interface FieldBindAction {
|
|
136
|
+
/** Accessible name, e.g. `Bind Autoplay to a property`. */
|
|
137
|
+
label: string;
|
|
138
|
+
/** Opens the caller's picker, anchored on the button that was pressed. */
|
|
139
|
+
onOpen: (anchor: HTMLElement) => void;
|
|
140
|
+
}
|
|
141
|
+
export interface FormFieldGridProps extends Omit<GridProps, 'size'> {
|
|
142
|
+
children?: ReactNode;
|
|
143
|
+
className?: string;
|
|
144
|
+
size?: GridProps['size'];
|
|
145
|
+
/** Contextual help affordance at the field's top-right (AGL-601). */
|
|
146
|
+
help?: HelpTipContent;
|
|
147
|
+
/** Reset-to-unset affordance at the field's top-right (AGL-2486). */
|
|
148
|
+
clear?: FieldClearAction;
|
|
149
|
+
/** Switch this declaration off without losing it (AGL-2486). */
|
|
150
|
+
mute?: FieldMuteAction;
|
|
151
|
+
/** Supply this value from elsewhere, e.g. a component property. */
|
|
152
|
+
bind?: FieldBindAction;
|
|
153
|
+
}
|
|
154
|
+
export declare const FormFieldGrid: ({ children, className, help, clear, mute, bind, size, ...props }: FormFieldGridProps) => import("react").JSX.Element;
|
|
155
|
+
export default FormFieldGrid;
|