headplane/app/components/Button.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-12-31 10:31:50 +05:30
import type { Dispatch, SetStateAction } from 'react';
import React, { useRef } from 'react';
2025-01-24 08:17:12 -05:00
import { type AriaButtonOptions, useButton } from 'react-aria';
2024-12-31 10:30:14 +05:30
import { cn } from '~/utils/cn';
2024-03-29 15:58:22 -04:00
export interface ButtonProps extends AriaButtonOptions<'button'> {
2025-01-24 08:17:12 -05:00
variant?: 'heavy' | 'light' | 'danger';
className?: string;
children?: React.ReactNode;
}
export default function Button({ variant = 'light', ...props }: ButtonProps) {
const ref = useRef<HTMLButtonElement | null>(null);
const { buttonProps } = useButton(props, ref);
2024-03-29 15:58:22 -04:00
return (
<button
ref={ref}
{...buttonProps}
className={cn(
'w-fit text-sm rounded-xl px-3 py-2',
'focus:outline-none focus:ring',
props.isDisabled && 'opacity-60 cursor-not-allowed',
...(variant === 'heavy'
? [
2025-01-24 08:17:12 -05:00
'bg-headplane-900 dark:bg-headplane-50 font-semibold',
'hover:bg-headplane-900/90 dark:hover:bg-headplane-50/90',
'text-headplane-200 dark:text-headplane-800',
]
: variant === 'danger'
? ['bg-red-500 text-white font-semibold', 'hover:bg-red-500/90']
: [
'bg-headplane-100 dark:bg-headplane-700/30 font-medium',
'hover:bg-headplane-200/90 dark:hover:bg-headplane-800/30',
]),
2024-12-31 10:30:14 +05:30
props.className,
2024-03-29 15:58:22 -04:00
)}
>
{props.children}
</button>
2025-01-24 08:17:12 -05:00
);
2024-03-29 15:58:22 -04:00
}