-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(group field): Allow to configure repeat property in the UI (#1269)
- Loading branch information
1 parent
4ef81d7
commit 924e86f
Showing
3 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/slice-machine/lib/models/common/widgets/Group/Form.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Checkbox, Label, Box } from "theme-ui"; | ||
|
||
import { Col, Flex as FlexGrid } from "@components/Flex"; | ||
import { DefaultFields } from "@lib/forms/defaults"; | ||
import WidgetFormField from "@lib/builders/common/EditModal/Field"; | ||
import { CheckBox } from "@lib/forms/fields"; | ||
import { createFieldNameFromKey } from "@lib/forms"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const FormFields = { | ||
...DefaultFields, | ||
repeat: CheckBox("Repeatable", false, true), | ||
}; | ||
|
||
const Form = (props) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const { initialValues, fields, values, setFieldValue } = props; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
const { | ||
config: { repeat }, | ||
} = values; | ||
|
||
return ( | ||
<FlexGrid> | ||
{ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
Object.entries(FormFields) | ||
.filter(([key]) => key !== "repeat") | ||
.map(([key, field]) => ( | ||
<Col key={key}> | ||
<WidgetFormField | ||
fieldName={createFieldNameFromKey(key)} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
formField={field} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
fields={fields} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
initialValues={initialValues} | ||
/> | ||
</Col> | ||
)) | ||
} | ||
|
||
<Col> | ||
<Box | ||
sx={{ | ||
mt: 2, | ||
alignItems: "center", | ||
display: "flex", | ||
height: "130%", | ||
}} | ||
> | ||
<Label variant="label.border" sx={{ mb: 0 }}> | ||
<Checkbox | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
checked={repeat} | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/strict-boolean-expressions | ||
onChange={() => setFieldValue("config.repeat", !repeat)} | ||
/> | ||
Repeatable | ||
</Label> | ||
</Box> | ||
</Col> | ||
</FlexGrid> | ||
); | ||
}; | ||
|
||
export { FormFields }; | ||
export default Form; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters