blob: 458bf15b3ce6549a5ab2b20051ffcfeebccad1e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import React from 'react';
import Paper from '../components/Paper';
import Button from '../components/Button';
import { Action, Filter } from '../lib/ServiceContext';
import { SelectBase } from '../components/Select';
interface Props {
title?: string;
actions?: Action[];
filters?: Filter[];
applyFilter?: (key: string, value: string) => void;
className?: string;
}
const style = 'mb-2 flex justify-between md:flex-row md:items-center';
const Page: React.FC<Props> = ({ title, actions, filters, applyFilter, className, children }) => {
const handleFilterChange = (key: string) => (event: React.ChangeEvent<HTMLSelectElement>) => {
if (applyFilter) applyFilter(key, event.target.value);
};
return (
<Paper className="xl:m-5">
<div className={`${style} ${(actions?.length || 0) > 1 ? 'flex-col items-start' : 'flex-row items-center'}`}>
<span className="text-2xl font-bold">{title}</span>
<div className="flex">
<div className="mr-6 flex">
{filters?.map(filter => (
<SelectBase
key={filter.key}
options={filter.options || []}
value={filter.value}
onChange={handleFilterChange(filter.key)}
/>
))}
</div>
<div>
{actions?.map(action => (<Button {...action} key={action.name} size="sm">{action.name}</Button>))}
</div>
</div>
</div>
<div className={className}>
{children}
</div>
</Paper>
);
};
export default Page;
|