import type { FC } from '../../../lib/teact/teact'; import React, { memo, useEffect, useRef } from '../../../lib/teact/teact'; import buildClassName from '../../../util/buildClassName'; import renderText from '../../common/helpers/renderText'; import Icon from '../../common/icons/Icon'; import Button from '../../ui/Button'; type OwnProps = { isOpen?: boolean; onClick: VoidFunction; text: string; isDisabled?: boolean; }; const BotMenuButton: FC = ({ isOpen, onClick, text, isDisabled, }) => { // eslint-disable-next-line no-null/no-null const textRef = useRef(null); useEffect(() => { const textEl = textRef.current; if (!textEl) return; const width = textEl.scrollWidth + 1; // Make width slightly bigger prevent ellipsis in some cases const composerEl = textEl.closest('.Composer') as HTMLElement; composerEl.style.setProperty('--bot-menu-text-width', `${width}px`); }, [isOpen, text]); useEffect(() => { const textEl = textRef.current; if (!textEl) return undefined; const composerEl = textEl.closest('.Composer') as HTMLElement; return () => { composerEl.style.removeProperty('--bot-menu-text-width'); }; }, []); return ( ); }; export default memo(BotMenuButton);