1 | // @mui
|
---|
2 | import Box from '@mui/material/Box';
|
---|
3 | import Chip from '@mui/material/Chip';
|
---|
4 | import Paper from '@mui/material/Paper';
|
---|
5 | import Button from '@mui/material/Button';
|
---|
6 | import Stack, { StackProps } from '@mui/material/Stack';
|
---|
7 | // types
|
---|
8 | import { EmployeeTableFilters } from 'src/schemas';
|
---|
9 | // components
|
---|
10 | import Iconify from 'src/components/iconify';
|
---|
11 |
|
---|
12 | // ----------------------------------------------------------------------
|
---|
13 |
|
---|
14 | interface Props extends StackProps {
|
---|
15 | filters: EmployeeTableFilters;
|
---|
16 | onFilters: (name: string, value: string | string[]) => void;
|
---|
17 | onResetFilters: VoidFunction;
|
---|
18 | results: number;
|
---|
19 | }
|
---|
20 |
|
---|
21 | export default function EmployeeTableFiltersResult({
|
---|
22 | filters,
|
---|
23 | onFilters,
|
---|
24 | onResetFilters,
|
---|
25 | results,
|
---|
26 | ...other
|
---|
27 | }: Props) {
|
---|
28 | const handleRemoveStatus = () => {
|
---|
29 | onFilters('status', 'all');
|
---|
30 | };
|
---|
31 |
|
---|
32 | const handleRemoveName = () => {
|
---|
33 | onFilters('name', '');
|
---|
34 | };
|
---|
35 |
|
---|
36 | return (
|
---|
37 | <Stack spacing={1.5} {...other}>
|
---|
38 | <Box sx={{ typography: 'body2' }}>
|
---|
39 | <strong>{results}</strong>
|
---|
40 | <Box component="span" sx={{ color: 'text.secondary', ml: 0.25 }}>
|
---|
41 | results found
|
---|
42 | </Box>
|
---|
43 | </Box>
|
---|
44 |
|
---|
45 | <Stack flexGrow={1} spacing={1} direction="row" flexWrap="wrap" alignItems="center">
|
---|
46 | {filters.status !== 'all' && (
|
---|
47 | <Block label="Status:">
|
---|
48 | <Chip size="small" label={filters.status} onDelete={handleRemoveStatus} />
|
---|
49 | </Block>
|
---|
50 | )}
|
---|
51 |
|
---|
52 | {filters.name && (
|
---|
53 | <Block label="Name:">
|
---|
54 | <Chip size="small" label={filters.name} onDelete={handleRemoveName} />
|
---|
55 | </Block>
|
---|
56 | )}
|
---|
57 |
|
---|
58 | <Button
|
---|
59 | color="error"
|
---|
60 | onClick={onResetFilters}
|
---|
61 | startIcon={<Iconify icon="solar:trash-bin-trash-bold" />}
|
---|
62 | >
|
---|
63 | Clear
|
---|
64 | </Button>
|
---|
65 | </Stack>
|
---|
66 | </Stack>
|
---|
67 | );
|
---|
68 | }
|
---|
69 |
|
---|
70 | // ----------------------------------------------------------------------
|
---|
71 |
|
---|
72 | type BlockProps = {
|
---|
73 | label: string;
|
---|
74 | children: React.ReactNode;
|
---|
75 | };
|
---|
76 |
|
---|
77 | function Block({ label, children }: BlockProps) {
|
---|
78 | return (
|
---|
79 | <Stack direction="row" alignItems="center" sx={{ typography: 'body2' }}>
|
---|
80 | <Box component="span" sx={{ color: 'text.secondary' }}>
|
---|
81 | {label}
|
---|
82 | </Box>
|
---|
83 | {children}
|
---|
84 | </Stack>
|
---|
85 | );
|
---|
86 | }
|
---|