2024-03-06 06:31:25 -05:00
|
|
|
import { Button as B5Button, Spinner } from 'react-bootstrap-5'
|
2024-02-14 10:04:08 -05:00
|
|
|
import type { ButtonProps } from '@/features/ui/components/types/button-props'
|
2024-03-06 06:31:25 -05:00
|
|
|
import classNames from 'classnames'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-02-14 10:04:08 -05:00
|
|
|
|
|
|
|
const sizeClasses = new Map<ButtonProps['size'], string>([
|
|
|
|
['small', 'btn-sm'],
|
|
|
|
['default', ''],
|
|
|
|
['large', 'btn-lg'],
|
|
|
|
])
|
|
|
|
|
2024-03-06 06:31:25 -05:00
|
|
|
export default function Button({
|
2024-02-14 10:04:08 -05:00
|
|
|
children,
|
2024-02-23 06:23:32 -05:00
|
|
|
className,
|
2024-03-06 06:31:25 -05:00
|
|
|
isLoading = false,
|
|
|
|
size = 'default',
|
|
|
|
...props
|
2024-02-14 10:04:08 -05:00
|
|
|
}: ButtonProps) {
|
2024-03-06 06:31:25 -05:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2024-02-14 10:04:08 -05:00
|
|
|
const sizeClass = sizeClasses.get(size)
|
2024-03-06 06:31:25 -05:00
|
|
|
const buttonClassName = classNames('d-inline-grid', sizeClass, className, {
|
|
|
|
'button-loading': isLoading,
|
|
|
|
})
|
|
|
|
const loadingSpinnerClassName =
|
|
|
|
size === 'large' ? 'loading-spinner-large' : 'loading-spinner-small'
|
2024-02-14 10:04:08 -05:00
|
|
|
|
|
|
|
return (
|
2024-03-06 06:31:25 -05:00
|
|
|
<B5Button className={buttonClassName} {...props}>
|
|
|
|
{isLoading && (
|
|
|
|
<span className="spinner-container">
|
|
|
|
<Spinner
|
|
|
|
animation="border"
|
|
|
|
aria-hidden="true"
|
|
|
|
as="span"
|
|
|
|
className={loadingSpinnerClassName}
|
|
|
|
role="status"
|
|
|
|
/>
|
|
|
|
<span className="sr-only">{t('loading')}</span>
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
<span className="button-content" aria-hidden={isLoading}>
|
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
</B5Button>
|
2024-02-14 10:04:08 -05:00
|
|
|
)
|
|
|
|
}
|