Skip to content

Commit

Permalink
feat: Use shared Switch component instead of MUISwitch directly (#3929
Browse files Browse the repository at this point in the history
)
  • Loading branch information
DafyddLlyr authored Nov 11, 2024
1 parent 5bbec23 commit 304490d
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 219 deletions.
4 changes: 4 additions & 0 deletions editor.planx.uk/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
"styled"
],
"message": "Please import styled from '@mui/material/styles'. Reason: https://mui.com/system/styled/#what-problems-does-it-solve"
},
{
"name": "@mui/material/Switch",
"message": "Please import shared Switch component from 'ui/shared/Switch' instead of the MUI Switch component directly"
}
],
"patterns": [
Expand Down
27 changes: 11 additions & 16 deletions editor.planx.uk/src/@planx/components/Calculate/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import FormControlLabel from "@mui/material/FormControlLabel";
import { styled } from "@mui/material/styles";
import Switch from "@mui/material/Switch";
import Typography from "@mui/material/Typography";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps } from "@planx/components/shared/types";
Expand All @@ -12,6 +10,7 @@ import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import { Switch } from "ui/shared/Switch";

import { ICONS } from "../shared/icons";
import type { Calculate } from "./model";
Expand Down Expand Up @@ -135,20 +134,16 @@ export default function Component(props: Props) {
/>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.formatOutputForAutomations}
onChange={() =>
formik.setFieldValue(
"formatOutputForAutomations",
!formik.values.formatOutputForAutomations,
)
}
/>
}
label="Format the output to automate a future Question or Checklist only"
/>
<Switch
checked={formik.values.formatOutputForAutomations}
onChange={() =>
formik.setFieldValue(
"formatOutputForAutomations",
!formik.values.formatOutputForAutomations
)
}
label="Format the output to automate a future Question or Checklist only"
/>
</InputRow>
</ModalSectionContent>
<ModalSectionContent title="Formula">
Expand Down
72 changes: 30 additions & 42 deletions editor.planx.uk/src/@planx/components/Checklist/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import FormControlLabel from "@mui/material/FormControlLabel";
import IconButton from "@mui/material/IconButton";
import Switch from "@mui/material/Switch";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { FormikErrors, FormikValues, useFormik } from "formik";
import adjust from "ramda/src/adjust";
Expand All @@ -22,6 +21,7 @@ import SimpleMenu from "ui/editor/SimpleMenu";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";
import { Switch } from "ui/shared/Switch";

import { Option, parseBaseNodeData } from "../shared";
import { FlagsSelect } from "../shared/FlagsSelect";
Expand Down Expand Up @@ -377,52 +377,40 @@ export const ChecklistComponent: React.FC<ChecklistProps> = (props) => {
/>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={!!formik.values.groupedOptions}
onChange={() =>
formik.setValues({
...formik.values,
...toggleExpandableChecklist({
options: formik.values.options,
groupedOptions: formik.values.groupedOptions,
}),
})
}
/>
}
label="Expandable"
/>
<Switch
checked={!!formik.values.groupedOptions}
onChange={() =>
formik.setValues({
...formik.values,
...toggleExpandableChecklist({
options: formik.values.options,
groupedOptions: formik.values.groupedOptions,
}),
})
}
label="Expandable"
/>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.allRequired}
onChange={() =>
formik.setFieldValue(
"allRequired",
!formik.values.allRequired,
)
}
/>
<Switch
checked={formik.values.allRequired}
onChange={() =>
formik.setFieldValue(
"allRequired",
!formik.values.allRequired,
)
}
label="All required"
/>
label="All required"
/>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.neverAutoAnswer}
onChange={() =>
formik.setFieldValue(
"neverAutoAnswer",
!formik.values.neverAutoAnswer,
)
}
/>
<Switch
checked={formik.values.neverAutoAnswer}
onChange={() =>
formik.setFieldValue(
"neverAutoAnswer",
!formik.values.neverAutoAnswer
)
}
label="Always put to user (forgo automation)"
/>
Expand Down
21 changes: 8 additions & 13 deletions editor.planx.uk/src/@planx/components/DrawBoundary/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
Expand All @@ -11,6 +9,7 @@ import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import { Switch } from "ui/shared/Switch";

import { ICONS } from "../shared/icons";
import type { DrawBoundary } from "./model";
Expand Down Expand Up @@ -99,17 +98,13 @@ function DrawBoundaryComponent(props: Props) {
/>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.hideFileUpload}
onChange={() =>
formik.setFieldValue(
"hideFileUpload",
!formik.values.hideFileUpload,
)
}
/>
<Switch
checked={formik.values.hideFileUpload}
onChange={() =>
formik.setFieldValue(
"hideFileUpload",
!formik.values.hideFileUpload,
)
}
label="Hide file upload and allow user to continue without data"
/>
Expand Down
21 changes: 8 additions & 13 deletions editor.planx.uk/src/@planx/components/Feedback/Editor/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { ICONS } from "@planx/components/shared/icons";
import { EditorProps } from "@planx/components/shared/types";
Expand All @@ -13,6 +11,7 @@ import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import { Switch } from "ui/shared/Switch";

import {
descriptionPlaceholder,
Expand Down Expand Up @@ -96,17 +95,13 @@ export const FeedbackEditor = (props: FeedbackEditorProps) => {
</InputLabel>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.feedbackRequired}
onChange={() =>
formik.setFieldValue(
"feedbackRequired",
!formik.values.feedbackRequired,
)
}
/>
<Switch
checked={formik.values.feedbackRequired}
onChange={() =>
formik.setFieldValue(
"feedbackRequired",
!formik.values.feedbackRequired,
)
}
label="Feedback required"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import RuleIcon from "@mui/icons-material/Rule";
import Box from "@mui/material/Box";
import Divider from "@mui/material/Divider";
import FormControlLabel from "@mui/material/FormControlLabel";
import MenuItem from "@mui/material/MenuItem";
import { styled } from "@mui/material/styles";
import Switch from "@mui/material/Switch";
import Typography from "@mui/material/Typography";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps } from "@planx/components/shared/types";
Expand All @@ -24,6 +22,7 @@ import SelectInput from "ui/editor/SelectInput/SelectInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";
import { Switch } from "ui/shared/Switch";

import { ICONS } from "../shared/icons";
import {
Expand Down Expand Up @@ -90,17 +89,13 @@ function FileUploadAndLabelComponent(props: Props) {
/>
</InputRow>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.hideDropZone}
onChange={() =>
formik.setFieldValue(
"hideDropZone",
!formik.values.hideDropZone,
)
}
/>
<Switch
checked={formik.values.hideDropZone}
onChange={() =>
formik.setFieldValue(
"hideDropZone",
!formik.values.hideDropZone,
)
}
label="Hide the drop zone and show files list for information only"
/>
Expand Down
21 changes: 8 additions & 13 deletions editor.planx.uk/src/@planx/components/FindProperty/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { EditorProps } from "@planx/components/shared/types";
import { useFormik } from "formik";
Expand All @@ -12,6 +10,7 @@ import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import InputRowItem from "ui/shared/InputRowItem";
import { Switch } from "ui/shared/Switch";

import { ICONS } from "../shared/icons";
import type { FindProperty } from "./model";
Expand Down Expand Up @@ -58,17 +57,13 @@ function FindPropertyComponent(props: Props) {
</ModalSectionContent>
<ModalSectionContent>
<InputRow>
<FormControlLabel
control={
<Switch
checked={formik.values.allowNewAddresses}
onChange={() =>
formik.setFieldValue(
"allowNewAddresses",
!formik.values.allowNewAddresses,
)
}
/>
<Switch
checked={formik.values.allowNewAddresses}
onChange={() =>
formik.setFieldValue(
"allowNewAddresses",
!formik.values.allowNewAddresses,
)
}
label="Allow users to plot new addresses without a UPRN"
/>
Expand Down
21 changes: 8 additions & 13 deletions editor.planx.uk/src/@planx/components/Notice/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import FormControlLabel from "@mui/material/FormControlLabel";
import Switch from "@mui/material/Switch";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import type { Notice } from "@planx/components/Notice/model";
import { parseNotice } from "@planx/components/Notice/model";
Expand All @@ -12,6 +10,7 @@ import ModalSectionContent from "ui/editor/ModalSectionContent";
import RichTextInput from "ui/editor/RichTextInput/RichTextInput";
import Input from "ui/shared/Input/Input";
import InputRow from "ui/shared/InputRow";
import { Switch } from "ui/shared/Switch";

import { InternalNotes } from "../../../ui/editor/InternalNotes";
import { MoreInformation } from "../../../ui/editor/MoreInformation/MoreInformation";
Expand Down Expand Up @@ -70,17 +69,13 @@ const NoticeEditor: React.FC<NoticeEditorProps> = (props) => {
}}
/>
<InputRow>
<FormControlLabel
control={
<Switch
checked={Boolean(props.value.resetButton)}
onChange={() =>
props.onChange({
...props.value,
resetButton: !props.value.resetButton,
})
}
/>
<Switch
checked={Boolean(props.value.resetButton)}
onChange={() =>
props.onChange({
...props.value,
resetButton: !props.value.resetButton,
})
}
label="Reset to start of service"
/>
Expand Down
Loading

0 comments on commit 304490d

Please sign in to comment.