Skip to content

Commit

Permalink
style: Layout for inactive list card with map (#3637)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianjon3s authored Sep 6, 2024
1 parent 60403cc commit 579e56a
Showing 1 changed file with 53 additions and 27 deletions.
80 changes: 53 additions & 27 deletions editor.planx.uk/src/@planx/components/List/Public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,30 @@ import { ListProvider, useListContext } from "./Context";
export type Props = PublicProps<List>;

const ListCard = styled(Box)(({ theme }) => ({
padding: theme.spacing(2),
padding: theme.spacing(2.5),
backgroundColor: theme.palette.background.paper,
border: "1px solid darkgray",
border: `1px solid ${theme.palette.border.main}`,
display: "flex",
flexDirection: "column",
gap: theme.spacing(2),
gap: theme.spacing(3),
marginBottom: theme.spacing(2),
"& label, & table": {
maxWidth: theme.breakpoints.values.formWrap,
},
}));

const CardButton = styled(Button)(({ theme }) => ({
fontWeight: FONT_WEIGHT_SEMI_BOLD,
gap: theme.spacing(1),
background: theme.palette.common.white,
}));

const InactiveListCardLayout = styled(Box)(({ theme }) => ({
display: "flex",
flexDirection: "column",
gap: theme.spacing(2),
[theme.breakpoints.up("md")]: {
flexDirection: "row",
},
}));

const ActiveListCard: React.FC<{
Expand Down Expand Up @@ -96,12 +105,12 @@ const ActiveListCard: React.FC<{
Save
</Button>
{!isPageComponent && !isInitialCard && (
<Button
<CardButton
data-testid="cancel-edit-item-button"
onClick={cancelEditItem}
>
Cancel
</Button>
</CardButton>
)}
</Box>
</ListCard>
Expand All @@ -115,39 +124,56 @@ const InactiveListCard: React.FC<{
const { schema, formik, removeItem, editItem, isPageComponent } =
useListContext();

const mapPreview = schema.fields.find((field) => field.type === "map");

return (
<ListCard data-testid={`list-card-${i}`}>
<Typography component="h2" variant="h3">
{schema.type}
{!isPageComponent && ` ${i + 1}`}
</Typography>
<Table>
<TableBody>
{schema.fields.map((field, j) => (
<TableRow key={`tableRow-${j}`} sx={{ verticalAlign: "top" }}>
<TableCell
sx={{ fontWeight: FONT_WEIGHT_SEMI_BOLD, maxWidth: "100px" }}
>
{field.data.title}
</TableCell>
<TableCell>
{formatSchemaDisplayValue(
formik.values.schemaData[i][field.data.fn],
schema.fields[j],
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<InactiveListCardLayout>
{mapPreview && (
<Box sx={{ flexBasis: "50%" }}>
{formatSchemaDisplayValue(
formik.values.schemaData[i][mapPreview.data.fn],
mapPreview,
)}
</Box>
)}
<Table>
<TableBody>
{schema.fields.map(
(field, j) =>
field.type !== "map" && (
<TableRow key={`tableRow-${j}`} sx={{ verticalAlign: "top" }}>
<TableCell
sx={{
fontWeight: FONT_WEIGHT_SEMI_BOLD,
maxWidth: "160px",
}}
>
{field.data.title}
</TableCell>
<TableCell>
{formatSchemaDisplayValue(
formik.values.schemaData[i][field.data.fn],
schema.fields[j],
)}
</TableCell>
</TableRow>
),
)}
</TableBody>
</Table>
</InactiveListCardLayout>
<Box display="flex" gap={2}>
<CardButton onClick={() => removeItem(i)}>
<DeleteIcon color="warning" fontSize="medium" />
Remove
</CardButton>
<CardButton onClick={() => editItem(i)}>
{/* TODO: Is primary colour really right here? */}
<EditIcon color="primary" fontSize="medium" />
<EditIcon fontSize="medium" />
Edit
</CardButton>
</Box>
Expand Down

0 comments on commit 579e56a

Please sign in to comment.