Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Result component multiline inputs #3796

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 15 additions & 27 deletions editor.planx.uk/src/@planx/components/Result/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Box from "@mui/material/Box";
import Collapse from "@mui/material/Collapse";
import Typography from "@mui/material/Typography";
import { Flag, flatFlags } from "@opensystemslab/planx-core/types";
import { ComponentType as TYPES } from "@opensystemslab/planx-core/types";
import { useFormik } from "formik";
import groupBy from "lodash/groupBy";
import React, { useState } from "react";
import React from "react";
import ModalSection from "ui/editor/ModalSection";
import ModalSectionContent from "ui/editor/ModalSectionContent";
import InputLabel from "ui/public/InputLabel";
import Input from "ui/shared/Input";
import InputRow from "ui/shared/InputRow";

Expand All @@ -28,46 +28,34 @@ const FlagEditor: React.FC<{
}> = (props) => {
const { flag, existingOverrides } = props;

const [expanded, setExpanded] = useState(false);

const showEditedIndicator = Boolean(existingOverrides);

return (
<Box
sx={{ cursor: "pointer" }}
padding={1}
bgcolor={flag.bgColor}
color={flag.color}
mt={1}
>
<Box onClick={() => setExpanded((x) => !x)}>
<Typography variant="body2">
{flag.text}
{showEditedIndicator && "*"}
</Typography>
<Box px={1.5} py={2} bgcolor={flag.bgColor} color={flag.color} mt={1}>
<Box>
<Typography variant="h4">{flag.text}</Typography>
</Box>
<Collapse in={expanded}>
<Box display="flex" mt={1}>

<Box display="flex" flexDirection="column" gap={2} mt={2}>
<InputLabel label="Heading">
<Input
value={existingOverrides?.heading ?? ""}
placeholder={"Heading"}
onChange={(ev) =>
props.onChange({ ...existingOverrides, heading: ev.target.value })
}
/>
<Box width={10} />
</InputLabel>
<InputLabel label="Description">
<Input
multiline
value={existingOverrides?.description ?? ""}
placeholder={"Description"}
onChange={(ev) =>
props.onChange({
...existingOverrides,
description: ev.target.value,
})
}
/>
</Box>
</Collapse>
</InputLabel>
</Box>
</Box>
);
};
Expand All @@ -85,7 +73,7 @@ const ResultComponent: React.FC<Props> = (props) => {
props.handleSubmit({ type: TYPES.Result, data: newValues });
}
},
validate: () => { },
validate: () => {},
});

const allFlagsForSet = flags[formik.values.flagSet];
Expand Down Expand Up @@ -149,4 +137,4 @@ const ResultComponent: React.FC<Props> = (props) => {
);
};

export default ResultComponent;
export default ResultComponent;
Loading