headplane/app/components/Button.tsx

39 lines
1 KiB
TypeScript
Raw Normal View History

2024-12-31 10:31:50 +05:30
import type { Dispatch, SetStateAction } from 'react';
2024-12-31 10:30:14 +05:30
import { Button as AriaButton } from 'react-aria-components';
import { cn } from '~/utils/cn';
2024-03-29 15:58:22 -04:00
2024-12-31 10:30:14 +05:30
type Props = Parameters<typeof AriaButton>[0] & {
readonly control?: [boolean, Dispatch<SetStateAction<boolean>>];
readonly variant?: 'heavy' | 'light';
};
2024-03-29 15:58:22 -04:00
2024-12-31 10:30:14 +05:30
export default function Button(props: Props) {
2024-03-29 15:58:22 -04:00
return (
<AriaButton
2024-12-31 10:30:14 +05:30
{...props}
className={cn(
'w-fit text-sm rounded-lg px-4 py-2',
2024-12-31 10:30:14 +05:30
props.variant === 'heavy'
? 'bg-main-700 dark:bg-main-800'
: 'bg-main-200 dark:bg-main-700/30',
2024-12-31 10:30:14 +05:30
props.variant === 'heavy'
? 'hover:bg-main-800 dark:hover:bg-main-700'
: 'hover:bg-main-300 dark:hover:bg-main-600/30',
2024-12-31 10:30:14 +05:30
props.variant === 'heavy'
? 'text-white'
: 'text-ui-700 dark:text-ui-300',
2024-12-31 10:30:14 +05:30
props.isDisabled && 'opacity-50 cursor-not-allowed',
props.className,
2024-03-29 15:58:22 -04:00
)}
// If control is passed, set the state value
2024-12-31 10:30:14 +05:30
onPress={
props.control
? () => {
props.control?.[1](true);
}
: props.onPress
}
/>
2024-12-31 10:30:14 +05:30
);
2024-03-29 15:58:22 -04:00
}