ConceptPortal-public/rsconcept/frontend/src/components/Common/Button.tsx

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-11-05 16:31:49 +03:00
import { IColorsProps, IControlProps } from '../commonInterfaces'
2023-07-25 22:29:33 +03:00
interface ButtonProps
2023-11-05 16:31:49 +03:00
extends IControlProps, IColorsProps, Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'className' | 'children' | 'title'| 'type'> {
2023-07-15 17:46:19 +03:00
text?: string
icon?: React.ReactNode
2023-11-05 16:31:49 +03:00
2023-07-15 17:46:19 +03:00
dense?: boolean
loading?: boolean
}
2023-07-25 20:27:29 +03:00
function Button({
2023-10-06 14:39:32 +03:00
text, icon, tooltip,
2023-11-05 16:31:49 +03:00
dense, disabled, noBorder, noOutline,
colors = 'clr-btn-default',
dimensions = 'w-fit h-fit',
2023-10-06 14:39:32 +03:00
loading,
...props
2023-07-20 17:11:03 +03:00
}: ButtonProps) {
2023-11-05 16:31:49 +03:00
const borderClass = noBorder ? '' : 'border rounded';
2023-07-25 20:27:29 +03:00
const padding = dense ? 'px-1' : 'px-3 py-2';
2023-11-05 16:31:49 +03:00
const outlineClass = noOutline ? 'outline-none': 'clr-outline';
2023-07-25 20:27:29 +03:00
const cursor = 'disabled:cursor-not-allowed ' + (loading ? 'cursor-progress ' : 'cursor-pointer ');
2023-07-15 17:46:19 +03:00
return (
2023-10-06 14:39:32 +03:00
<button type='button'
2023-07-25 22:29:33 +03:00
disabled={disabled ?? loading}
2023-07-15 17:46:19 +03:00
title={tooltip}
2023-11-05 16:31:49 +03:00
className={`inline-flex items-center gap-2 align-middle justify-center select-none ${padding} ${colors} ${outlineClass} ${borderClass} ${dimensions} ${cursor}`}
{...props}
2023-07-15 17:46:19 +03:00
>
{icon ? icon : null}
{text ? <span className='font-semibold'>{text}</span> : null}
2023-07-15 17:46:19 +03:00
</button>
2023-07-25 20:27:29 +03:00
);
2023-07-15 17:46:19 +03:00
}
2023-07-25 20:27:29 +03:00
export default Button;