import type { Theme } from '@material-ui/core' import { makeStyles } from '@material-ui/core' import { Bold16, Italic16, ListOrdered16, ListUnordered16, } from '@toptal/picasso-icons' import { Container } from '@toptal/picasso-container' import { Select } from '@toptal/picasso-select' import { useMultipleForwardRefs } from '@toptal/picasso-utils' import cx from 'classnames' import React, { forwardRef } from 'react' import { useRTEPluginContext, useToolbarPortalRegister } from '../plugins/api' import TextEditorButton from '../RichTextEditorButton' import styles from './styles' import type { ButtonHandlerType, FormatType, SelectOnChangeHandler, } from './types' type Props = { id: string format?: FormatType testIds?: { headerSelect?: string boldButton?: string italicButton?: string unorderedListButton?: string orderedListButton?: string linkButton?: string emojiButton?: string } onBoldClick?: ButtonHandlerType onItalicClick?: ButtonHandlerType onHeaderChange?: SelectOnChangeHandler onUnorderedClick?: ButtonHandlerType onOrderedClick?: ButtonHandlerType } const useStyles = makeStyles(styles, { name: 'RichTextEditorToolbar', }) export const ALLOWED_HEADER_TYPE = '3' export const RichTextEditorToolbar = forwardRef( function RichTextEditorToolbar( { format = { bold: false, italic: false, list: false, header: '', }, onBoldClick = () => {}, onItalicClick = () => {}, onHeaderChange = () => {}, onUnorderedClick = () => {}, onOrderedClick = () => {}, testIds, id, }: Props, ref ) { const { setToolbarPortalEl } = useToolbarPortalRegister() const { disabledFormatting, disabled, focused } = useRTEPluginContext() const toolbarRef = useMultipleForwardRefs([ref, setToolbarPortalEl]) const classes = useStyles({ format, onBoldClick, onItalicClick, onHeaderChange, onUnorderedClick, onOrderedClick, testIds, id, }) const isInlineFormattingDisabled = disabled || disabledFormatting || !focused const isBlockFormattingDisabled = disabled || !focused return (