-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableButtons.tsx
48 lines (42 loc) · 1.26 KB
/
TableButtons.tsx
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
import { useFilterContext } from "@/context/filter.context";
import ChartRange from "@/types/chartRange.type";
import classNames from "@/utils/classNames";
import { Dispatch, SetStateAction } from "react";
const TableButtons = () => {
const { filter: currentFilter, setFilter } = useFilterContext();
const Button = ({
filter,
setFilter,
}: {
filter: ChartRange;
setFilter: Dispatch<SetStateAction<ChartRange>>;
}) => {
const buttonClassNames = [
"relative -ml-px inline-flex items-center px-3 py-2 text-sm font-semibold ring-1 ring-inset focus:z-10",
];
currentFilter === filter
? buttonClassNames.push("text-white bg-purple-900 ring-purple-300")
: buttonClassNames.push("text-gray-900 bg-gray-50 ring-gray-300");
return (
<button
type="button"
className={classNames(...buttonClassNames)}
onClick={() => setFilter(filter)}
>
{filter}
</button>
);
};
return (
<span className="isolate flex justify-end rounded-md shadow-sm">
{Object.keys(ChartRange).map((k) => (
<Button
key={k}
filter={ChartRange[k as keyof typeof ChartRange]}
setFilter={setFilter}
/>
))}
</span>
);
};
export default TableButtons;