2023-09-11 20:31:54 +03:00
|
|
|
import { TokenID } from '../../../models/rslang';
|
2023-09-21 14:58:01 +03:00
|
|
|
import { describeToken, labelToken } from '../../../utils/labels';
|
2023-07-20 17:11:03 +03:00
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
interface RSTokenButtonProps {
|
2023-09-21 14:58:01 +03:00
|
|
|
token: TokenID
|
2023-07-20 17:11:03 +03:00
|
|
|
disabled?: boolean
|
2023-07-22 03:18:48 +03:00
|
|
|
onInsert: (token: TokenID, key?: string) => void
|
2023-07-20 17:11:03 +03:00
|
|
|
}
|
|
|
|
|
2023-09-21 14:58:01 +03:00
|
|
|
function RSTokenButton({ token, disabled, onInsert }: RSTokenButtonProps) {
|
|
|
|
const label = labelToken(token);
|
2023-10-23 18:22:55 +03:00
|
|
|
const width = label.length > 3 ? 'w-[4.5rem]' : 'w-[2.25rem]';
|
2023-07-20 17:11:03 +03:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type='button'
|
|
|
|
disabled={disabled}
|
2023-09-21 14:58:01 +03:00
|
|
|
onClick={() => onInsert(token)}
|
|
|
|
title={describeToken(token)}
|
2023-07-20 17:11:03 +03:00
|
|
|
tabIndex={-1}
|
2023-10-23 18:22:55 +03:00
|
|
|
className={`px-1 cursor-pointer disabled:cursor-default border rounded-none h-6 ${width} clr-outline clr-hover clr-btn-clear`}
|
2023-07-20 17:11:03 +03:00
|
|
|
>
|
2023-09-21 14:58:01 +03:00
|
|
|
{label && <span className='whitespace-nowrap'>{label}</span>}
|
2023-07-20 17:11:03 +03:00
|
|
|
</button>
|
2023-07-22 03:18:48 +03:00
|
|
|
);
|
2023-07-20 17:11:03 +03:00
|
|
|
}
|
|
|
|
|
2023-07-25 20:27:29 +03:00
|
|
|
export default RSTokenButton;
|