mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 16:33:51 +00:00
5600235ba1
refactor: migrate react components
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { ButtonHTMLAttributes, forwardRef } from 'react';
|
|
import { IoEllipseOutline } from 'react-icons/io5';
|
|
|
|
import { cx } from '../../utils/styleUtils';
|
|
|
|
import style from './Button.module.scss';
|
|
|
|
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?:
|
|
| 'primary'
|
|
| 'subtle'
|
|
| 'subtle-white'
|
|
| 'destructive'
|
|
| 'subtle-destructive'
|
|
| 'ghosted'
|
|
| 'ghosted-white'
|
|
| 'ghosted-destructive';
|
|
size?: 'small' | 'medium' | 'large' | 'xlarge';
|
|
fluid?: boolean;
|
|
loading?: boolean;
|
|
}
|
|
|
|
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
|
({ className, children, variant = 'subtle', size = 'medium', fluid, loading, ...buttonProps }, ref) => {
|
|
return (
|
|
<button
|
|
ref={ref}
|
|
className={cx([
|
|
style.baseButton,
|
|
style[variant],
|
|
style[size],
|
|
fluid && style.fluid,
|
|
loading && style.loading,
|
|
className,
|
|
])}
|
|
type='button'
|
|
disabled={loading || buttonProps.disabled}
|
|
{...buttonProps}
|
|
>
|
|
<span className={style.content}>{children}</span>
|
|
{loading && (
|
|
<div className={style.loadingOverlay}>
|
|
<IoEllipseOutline className={style.spinner} />
|
|
</div>
|
|
)}
|
|
</button>
|
|
);
|
|
},
|
|
);
|
|
|
|
Button.displayName = 'Button';
|
|
|
|
export default Button;
|