-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathToggleButtonGroup.tsx
More file actions
61 lines (53 loc) · 1.5 KB
/
ToggleButtonGroup.tsx
File metadata and controls
61 lines (53 loc) · 1.5 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
import { Dispatch } from 'react';
import { ButtonSize, cn, Variant } from '@common';
import { Button } from '@components';
import { useTranslation } from 'react-i18next';
interface ToggleButtonGroupProps {
/**
* Specify an optional className to be added to the component
*/
className?: string;
/**
* Indicates if the button is active
*/
isActive: boolean;
/**
* Sets the state of the button
*/
setIsActive: Dispatch<boolean>;
/**
* Sets the state of the Filter
*/
setFilter: Dispatch<string[]>;
}
export const ToggleButtonGroup = ({ className, isActive, setIsActive, setFilter }: ToggleButtonGroupProps) => {
const { t } = useTranslation();
const classes = {
container: cn('max-sm:grid max-sm:gap-4 ', className)
};
const handleActive = (isActive: boolean) => {
setFilter([]);
setIsActive(isActive);
};
const handleButtonVariant = (isActive: boolean): Variant => (isActive ? Variant.primary : Variant.secondary);
return (
<div className={classes.container}>
<Button
size={ButtonSize.xl}
onClick={() => handleActive(true)}
variant={handleButtonVariant(isActive)}
className="sm:rounded-r-none max-sm:w-full"
>
{t('common_active')}
</Button>
<Button
size={ButtonSize.xl}
onClick={() => handleActive(false)}
className="sm:rounded-l-none max-sm:w-full"
variant={handleButtonVariant(!isActive)}
>
{t('common_closed')}
</Button>
</div>
);
};