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

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-07-25 20:27:29 +03:00
import { type MouseEventHandler } from 'react';
2023-07-20 17:11:03 +03:00
2023-07-15 17:46:19 +03:00
interface ButtonProps {
2023-07-20 17:11:03 +03:00
id?: string
2023-07-15 17:46:19 +03:00
text?: string
icon?: React.ReactNode
tooltip?: string
disabled?: boolean
dense?: boolean
loading?: boolean
2023-07-22 12:24:14 +03:00
widthClass?: string
2023-07-20 17:11:03 +03:00
borderClass?: string
2023-07-22 12:24:14 +03:00
colorClass?: string
2023-07-20 17:11:03 +03:00
onClick?: MouseEventHandler<HTMLButtonElement> | undefined
2023-07-15 17:46:19 +03:00
}
2023-07-25 20:27:29 +03:00
function Button({
id, text, icon, tooltip,
2023-07-20 17:11:03 +03:00
dense, disabled,
2023-07-25 20:27:29 +03:00
borderClass = 'border rounded', colorClass = 'clr-btn-default', widthClass = 'w-fit h-fit',
loading, onClick,
...props
2023-07-20 17:11:03 +03:00
}: ButtonProps) {
2023-07-25 20:27:29 +03:00
const padding = dense ? 'px-1' : 'px-3 py-2';
const cursor = 'disabled:cursor-not-allowed ' + (loading ? 'cursor-progress ' : 'cursor-pointer ');
2023-07-15 17:46:19 +03:00
return (
2023-07-20 17:11:03 +03:00
<button id={id}
2023-07-15 17:46:19 +03:00
type='button'
disabled={disabled}
onClick={onClick}
title={tooltip}
2023-07-22 12:24:14 +03:00
className={`inline-flex items-center gap-2 align-middle justify-center ${padding} ${borderClass} ${colorClass} ${widthClass} ${cursor}`}
{...props}
2023-07-15 17:46:19 +03:00
>
2023-07-20 17:11:03 +03:00
{icon && <span>{icon}</span>}
{text && <span className={'font-semibold'}>{text}</span>}
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;