Files
dzone-admin/src/components/Button.tsx
T
hamid zarghami 6cb45848ce structure
2025-05-11 11:34:09 +03:30

32 lines
1001 B
TypeScript

import { ButtonHTMLAttributes, FC, memo, ReactNode } from 'react'
import MoonLoader from "react-spinners/MoonLoader"
import { XOR } from '../helpers/types'
import { clx } from '../helpers/utils'
type Props = {
className?: string;
isLoading?: boolean,
} & ButtonHTMLAttributes<HTMLButtonElement> &
XOR<{ children: ReactNode }, { label: string }>;
const Button: FC<Props> = memo((props: Props) => {
const buttonClass = clx(
'flex rounded-xl items-center justify-center text-center h-10 text-sm bg-primary text-white w-full',
props.disabled && 'cursor-not-allowed opacity-60',
props.className
);
return (
<button disabled={props.isLoading} {...props} className={`${buttonClass} ${props.className}`} >
{
props.isLoading ?
<MoonLoader color="white" size={16} />
:
props.label || props.children
}
</button>
)
})
export default Button