From 8c9f00a6aa45cc8bb2279d857b7a63a16c1dae33 Mon Sep 17 00:00:00 2001 From: Ian Jones Date: Tue, 24 Sep 2024 16:00:58 +0100 Subject: [PATCH 1/2] refactor: Simplify and improve description radio layout --- .../components/Question/Public/Question.tsx | 22 +++++------ .../components/shared/Radio/BasicRadio.tsx | 8 +++- .../shared/Radio/DescriptionRadio.tsx | 39 ++++++------------- 3 files changed, 30 insertions(+), 39 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/Question/Public/Question.tsx b/editor.planx.uk/src/@planx/components/Question/Public/Question.tsx index a17e5573ec..552df05c69 100644 --- a/editor.planx.uk/src/@planx/components/Question/Public/Question.tsx +++ b/editor.planx.uk/src/@planx/components/Question/Public/Question.tsx @@ -108,7 +108,7 @@ const Question: React.FC = (props) => { > {props.responses?.map((response) => { @@ -136,16 +136,16 @@ const Question: React.FC = (props) => { ); case QuestionLayout.Descriptions: return ( - - - + + + + + ); case QuestionLayout.Images: return ( diff --git a/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx b/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx index 55a9a7606b..d2e040fe01 100644 --- a/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx +++ b/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx @@ -23,7 +23,13 @@ const BasicRadio: React.FC = ({ onChange={onChange} control={} label={title} - sx={variant === "default" ? { pb: 1 } : {}} + sx={(theme) => ({ + mb: variant === "default" ? 1 : 0, + alignItems: "flex-start", + ".MuiFormControlLabel-label": { + paddingTop: theme.spacing(0.95), + }, + })} /> ); diff --git a/editor.planx.uk/src/@planx/components/shared/Radio/DescriptionRadio.tsx b/editor.planx.uk/src/@planx/components/shared/Radio/DescriptionRadio.tsx index 5798bd4ea0..f6ad7847bb 100644 --- a/editor.planx.uk/src/@planx/components/shared/Radio/DescriptionRadio.tsx +++ b/editor.planx.uk/src/@planx/components/shared/Radio/DescriptionRadio.tsx @@ -1,7 +1,6 @@ import Box from "@mui/material/Box"; import FormLabel from "@mui/material/FormLabel"; import Radio, { RadioProps } from "@mui/material/Radio"; -import { useRadioGroup } from "@mui/material/RadioGroup"; import { styled } from "@mui/material/styles"; import Typography from "@mui/material/Typography"; import React from "react"; @@ -13,25 +12,10 @@ export interface Props { onChange: RadioProps["onChange"]; } -interface StyledFormLabelProps { - isSelected: boolean; -} - -const StyledFormLabel = styled(FormLabel, { - shouldForwardProp: (prop) => prop !== "isSelected", -})(({ theme, isSelected }) => ({ - border: "2px solid", - borderColor: isSelected - ? theme.palette.primary.main - : theme.palette.border.main, - padding: theme.spacing(1.5), +const StyledFormLabel = styled(FormLabel)(({ theme }) => ({ + display: "flex", + marginBottom: theme.spacing(1), cursor: "pointer", - display: "block", - height: "100%", - color: theme.palette.text.primary, - "& > p": { - color: theme.palette.text.secondary, - }, })); const DescriptionRadio: React.FC = ({ @@ -40,16 +24,17 @@ const DescriptionRadio: React.FC = ({ onChange, id, }) => { - const radioGroupState = useRadioGroup(); - const isSelected = radioGroupState?.value === id; - return ( - - - - {title} + + + + + {title} + + + {description} + - {description} ); }; From 6109824cdf38a8c8b7a042c86008be297d77bd51 Mon Sep 17 00:00:00 2001 From: Ian Jones Date: Tue, 24 Sep 2024 18:08:07 +0100 Subject: [PATCH 2/2] css class import --- .../src/@planx/components/shared/Radio/BasicRadio.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx b/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx index d2e040fe01..42271ca227 100644 --- a/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx +++ b/editor.planx.uk/src/@planx/components/shared/Radio/BasicRadio.tsx @@ -1,6 +1,7 @@ import FormControlLabel, { FormControlLabelProps, } from "@mui/material/FormControlLabel"; +import { formControlLabelClasses } from "@mui/material/FormControlLabel"; import Radio from "@mui/material/Radio"; import React from "react"; @@ -26,7 +27,7 @@ const BasicRadio: React.FC = ({ sx={(theme) => ({ mb: variant === "default" ? 1 : 0, alignItems: "flex-start", - ".MuiFormControlLabel-label": { + [`& .${formControlLabelClasses.label}`]: { paddingTop: theme.spacing(0.95), }, })}