-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectButton.tsx
More file actions
62 lines (58 loc) · 1.34 KB
/
SelectButton.tsx
File metadata and controls
62 lines (58 loc) · 1.34 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
62
import { cn } from '@/shared/lib/core';
import { Flex } from '../Flex';
import { Icon } from '../Icon';
type Props = {
/**
* The currently selected option.
*/
selected: string;
/**
* Callback function to be called when the button is clicked.
* @returns void
*/
onClick: () => void;
/**
* Whether the dropdown is open or closed.
*/
isOpen: boolean;
/**
* The size of the button.
*/
size?: 'md' | 'lg';
};
const sizeVariants = {
md: 'px-3 py-1 text-sm min-w-24',
lg: 'px-4 py-3.5 min-w-64 text-lg',
} as const;
export function SelectButton({ selected, onClick, isOpen, size = 'lg' }: Props) {
return (
<Flex
alignItems="center"
onClick={onClick}
className={cn(
sizeVariants[size],
'w-full rounded-lg border border-gray-200 bg-white font-semibold text-gray-400'
)}
>
<Flex
as="button"
alignItems="center"
justifyContent="between"
className={cn(
'w-full cursor-pointer rounded-lg align-middle',
isOpen && 'hover:rounded-b-none'
)}
>
{selected}
<Icon
name="arrowDown"
className={cn(
'transform transition-transform duration-300',
isOpen && 'rotate-180',
size === 'md' && 'w-5'
)}
/>
</Flex>
</Flex>
);
}