-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: split Checklist into sub-components and hooks (#4088)
- Loading branch information
Showing
12 changed files
with
385 additions
and
248 deletions.
There are no files selected for viewing
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
2 changes: 1 addition & 1 deletion
2
...hecklist/Public/AutoAnsweredChecklist.tsx → ...blic/components/AutoAnsweredChecklist.tsx
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
56 changes: 56 additions & 0 deletions
56
editor.planx.uk/src/@planx/components/Checklist/Public/components/ChecklistItems.tsx
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,56 @@ | ||
import Grid from "@mui/material/Grid"; | ||
import { Option } from "@planx/components/shared"; | ||
import ImageButton from "@planx/components/shared/Buttons/ImageButton"; | ||
import { FormikProps } from "formik"; | ||
import React from "react"; | ||
import FormWrapper from "ui/public/FormWrapper"; | ||
import ChecklistItem from "ui/shared/ChecklistItem/ChecklistItem"; | ||
|
||
import { ChecklistLayout } from "./VisibleChecklist"; | ||
|
||
interface Props { | ||
nonExclusiveOptions: Option[]; | ||
layout: ChecklistLayout; | ||
changeCheckbox: (id: string) => () => void; | ||
formik: FormikProps<{ checked: Array<string> }>; | ||
exclusiveOptionIsChecked: boolean; | ||
} | ||
|
||
export const ChecklistItems = ({ | ||
nonExclusiveOptions, | ||
layout, | ||
changeCheckbox, | ||
formik, | ||
exclusiveOptionIsChecked, | ||
}: Props) => ( | ||
<> | ||
{nonExclusiveOptions.map((option: Option) => | ||
layout === ChecklistLayout.Basic ? ( | ||
<FormWrapper key={option.id}> | ||
<Grid item xs={12} key={option.data.text}> | ||
<ChecklistItem | ||
onChange={changeCheckbox(option.id)} | ||
label={option.data.text} | ||
id={option.id} | ||
checked={ | ||
formik.values.checked.includes(option.id) && | ||
!exclusiveOptionIsChecked | ||
} | ||
/> | ||
</Grid> | ||
</FormWrapper> | ||
) : ( | ||
<Grid item xs={12} sm={6} contentWrap={4} key={option.data.text}> | ||
<ImageButton | ||
title={option.data.text} | ||
id={option.id} | ||
img={option.data.img} | ||
selected={formik.values.checked.includes(option.id)} | ||
onClick={changeCheckbox(option.id)} | ||
checkbox | ||
/> | ||
</Grid> | ||
) | ||
)} | ||
</> | ||
); |
32 changes: 32 additions & 0 deletions
32
editor.planx.uk/src/@planx/components/Checklist/Public/components/ExclusiveChecklistItem.tsx
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,32 @@ | ||
import Grid from "@mui/material/Grid"; | ||
import Typography from "@mui/material/Typography"; | ||
import { FormikProps } from "formik"; | ||
import React from "react"; | ||
import FormWrapper from "ui/public/FormWrapper"; | ||
import ChecklistItem from "ui/shared/ChecklistItem/ChecklistItem"; | ||
|
||
import { Option } from "../../../shared"; | ||
|
||
export const ExclusiveChecklistItem = ({ | ||
exclusiveOrOption, | ||
changeCheckbox, | ||
formik, | ||
}: { | ||
exclusiveOrOption: Option; | ||
changeCheckbox: (id: string) => () => void; | ||
formik: FormikProps<{ checked: Array<string> }>; | ||
}) => ( | ||
<FormWrapper key={exclusiveOrOption.id}> | ||
<Grid item xs={12} key={exclusiveOrOption.data.text}> | ||
<Typography width={36} display="flex" justifyContent="center"> | ||
or | ||
</Typography> | ||
<ChecklistItem | ||
onChange={changeCheckbox(exclusiveOrOption.id)} | ||
label={exclusiveOrOption.data.text} | ||
id={exclusiveOrOption.id} | ||
checked={formik.values.checked.includes(exclusiveOrOption.id)} | ||
/> | ||
</Grid> | ||
</FormWrapper> | ||
); |
Oops, something went wrong.