import React, { useRef, FC } from 'react'; import H1 from '../button/H1'; import H2 from '../button/H2'; import H3 from '../button/H3'; import H4 from '../button/H4'; import Blockquote from '../button/Blockquote'; import CodeBlock from '../button/CodeBlock'; import Bold from '../button/Bold'; import Italic from '../button/Italic'; import StrikeThrough from '../button/StrikeThrough'; import Underline from '../button/Underline'; import InlineCode from '../button/InlineCode'; import Link from '../button/Link'; import NumberedList from '../button/NumberedList'; import BulletedList from '../button/BulletedList'; import { createLinkSpanAtSelection } from '../../utils/createEntity'; import Divider from './Divider'; import { GetEditor, StyleControlsButtonProps, LinkControlsProps, StyleControlsProps, } from '../../types'; const buildBlockTypeHandler = (getEditor: GetEditor, type: string) => () => { const { hooks, editorState } = getEditor(); hooks.toggleBlockType.call(editorState, type); }; const buildInlineTypeHandler = ( getEditor: GetEditor, inlineStyle: string ) => () => { const { hooks } = getEditor(); hooks.toggleInlineStyleV2.call(inlineStyle); }; const H1Button: FC = ({ active, getEditor }) => { const handleClick = useRef(buildBlockTypeHandler(getEditor, 'header-one')); return

; }; const H2Button: FC = ({ active, getEditor }) => { const handleClick = useRef(buildBlockTypeHandler(getEditor, 'header-two')); return

; }; const H3Button: FC = ({ active, getEditor }) => { const handleClick = useRef(buildBlockTypeHandler(getEditor, 'header-three')); return

; }; const H4Button: FC = ({ active, getEditor }) => { const handleClick = useRef(buildBlockTypeHandler(getEditor, 'header-four')); return

; }; const BlockquoteButton: FC = ({ active, getEditor, }) => { const handleClick = useRef(buildBlockTypeHandler(getEditor, 'blockquote')); return
; }; const CodeBlockButton: FC = ({ active, getEditor, }) => { const handleClick = useRef(buildBlockTypeHandler(getEditor, 'code-block')); return ; }; const BoldButton: FC = ({ active, getEditor }) => { const handleClick = useRef(buildInlineTypeHandler(getEditor, 'BOLD')); return ; }; const ItalicButton: FC = ({ active, getEditor }) => { const handleClick = useRef(buildInlineTypeHandler(getEditor, 'ITALIC')); return ; }; const StrikeThroughButton: FC = ({ active, getEditor, }) => { const handleClick = useRef( buildInlineTypeHandler(getEditor, 'STRIKE-THROUGH') ); return ; }; const UnderlineButton: FC = ({ active, getEditor, }) => { const handleClick = useRef(buildInlineTypeHandler(getEditor, 'UNDERLINE')); return ; }; const InlineCodeButton: FC = ({ active, getEditor, }) => { const handleClick = useRef(buildInlineTypeHandler(getEditor, 'CODE')); return ; }; const LinkButton: FC = ({ handleClick, getEditor, active, }) => { const onClickHandler = () => { const { editorState, hooks } = getEditor(); hooks.afterClickLinkButton.call(editorState); const nextState = createLinkSpanAtSelection(editorState); hooks.setState.call(nextState); handleClick(); }; return ; }; const NumberedListButton: FC = ({ active, getEditor, }) => { const handleClick = useRef( buildBlockTypeHandler(getEditor, 'ordered-list-item') ); return ; }; const BulletedListButton: FC = ({ active, getEditor, }) => { const handleClick = useRef( buildBlockTypeHandler(getEditor, 'unordered-list-item') ); return ; }; const onlyContains = (arr: string[] = [], item: string) => { if (arr.length > 1) return false; return arr[0] === item; }; const StyleControls: FC = ({ blockTypes, styles, getEditor, toggleDisplayMode, hasLink, }) => { return (
); }; export default StyleControls;