41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import type { ElementType, ReactNode } from 'react';
|
|
import { Box, Stack } from '@mui/material';
|
|
import { alpha } from '@mui/material/styles';
|
|
import { SectionPaper } from './SectionPaper';
|
|
import { SectionTitle } from './SectionTitle';
|
|
|
|
/**
|
|
* A framed card for the small data-entry screens (assign destination, manual input, close a permit, truck inquiry...):
|
|
* icon + title, the fields, and a footer strip with the buttons. Same frame as every record section.
|
|
*/
|
|
export function FormCard({ icon, title, children, actions, maxWidth = 760 }: {
|
|
icon: ElementType;
|
|
title: string;
|
|
children: ReactNode;
|
|
/** Buttons shown in a tinted footer strip. */
|
|
actions?: ReactNode;
|
|
maxWidth?: number | string;
|
|
}) {
|
|
return (
|
|
<SectionPaper sx={{ maxWidth, overflow: 'hidden' }}>
|
|
<Box sx={{ p: { xs: 2, sm: 2.5 }, pb: actions ? { xs: 2, sm: 2.5 } : undefined }}>
|
|
<SectionTitle icon={icon} title={title} />
|
|
{children}
|
|
</Box>
|
|
{actions && (
|
|
<Stack
|
|
direction="row" spacing={1} useFlexGap
|
|
sx={(t) => ({ flexWrap: 'wrap', px: { xs: 2, sm: 2.5 }, py: 1.5, borderTop: 1, borderColor: 'divider', bgcolor: alpha(t.palette.primary.main, t.palette.mode === 'dark' ? 0.08 : 0.04) })}
|
|
>
|
|
{actions}
|
|
</Stack>
|
|
)}
|
|
</SectionPaper>
|
|
);
|
|
}
|
|
|
|
/** Two columns of fields on wide screens, one on phones. */
|
|
export function FormGrid({ children }: { children: ReactNode }) {
|
|
return <Box sx={{ display: 'grid', gap: 2, gridTemplateColumns: { xs: '1fr', md: 'repeat(2, minmax(0, 1fr))' } }}>{children}</Box>;
|
|
}
|