ConceptPortal-public/rsconcept/frontend/src/pages/RSFormPage/elements/RSTokenButton.tsx

28 lines
809 B
TypeScript
Raw Normal View History

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
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);
const width = label.length > 3 ? 'w-[4rem]' : 'w-[2rem]';
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}
className={`px-1 cursor-pointer border rounded-none h-7 ${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-20 17:11:03 +03:00
}
2023-07-25 20:27:29 +03:00
export default RSTokenButton;