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

style: Layout for inactive list card with map #3637

Merged
merged 2 commits into from
Sep 6, 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
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
Loading