import React from "react"; import { StyledTextToolbar, ToolbarItemWrapper, MenuArea, ItemWrapper } from "./style"; import { UndoChangesIcon, RedoChangesIcon, IncreaseIndentIcon, DecreaseIndentIcon, TextStyleIcon, TextColorIcon, TextBoxIcon, TextBoxColorIcon, DrawIcon, ArrowDownIcon, SuccessArrowIcon } from "../../iconography"; import { Separator } from "../Separator"; import { BodyText, Spotlight, Legend3, Legend2 } from "../../typography"; import { TypographyCardItems } from "./TypographyCardItems"; import { Card } from "../Card"; import { ArrowUpIcon } from "../../iconography/ArrowUpIcon"; import { CirclePicker } from "react-color"; import { TextBoxStyleCardContent, StrokeType } from "./TextBoxStyleCardContent"; import { generateKey } from "../../utils/generateKey"; import { Column } from "../../base/Flex"; import { palette } from "../../utils/palette"; interface ScopeInterface { [key: string]: string; } export interface TextToolbarProps { bodyText?: { label: string; options: string[]; }; textStyle?: { menuTitle: string; scopes: ScopeInterface[]; options: { scope: keyof ScopeInterface; fontFamily: string; }[]; }; textColor?: { menuTitle: string; color: string; onChange: (color: string) => void; }; textBoxColor?: { menuTitle: string; color: string; onChange: (color: string) => void; }; textBoxStyle?: { menuTitle: string; }; withDrawOption?: { onClick: () => void; }; } export const TextToolbar: React.FC = ({ bodyText, textStyle, textColor, textBoxColor, textBoxStyle, withDrawOption }) => { const [ displayTypographySettings, setDisplayTypographySettings ] = React.useState(false); const [ currentTypographySetting, setCurrentTypographySetting ] = React.useState(3); const [ displayTextStyleSettings, setDisplayTextStyleSettings ] = React.useState(false); const [currentTextStyleSetting, setCurrentTextStyleSetting] = React.useState({ key: 3, fontFamily: "Domine", scope: "classics" }); const [ displayTextColorSettings, setDisplayTextColorSettings ] = React.useState(false); const [ displayTextBoxColorSettings, setDisplayTextBoxColorSettings ] = React.useState(false); const [ displayTextBoxStyleSettings, setDisplayTextBoxStyleSettings ] = React.useState(false); const [ currentTextBoxStyleSetting, setCurrentTextBoxStyleSetting ] = React.useState(StrokeType.default); const textColorToolbarItemRef = React.useRef(); const textStyleToolbarItemRef = React.useRef(); const textBoxStyleToolbarItemRef = React.useRef(); const textBoxColorToolbarItemRef = React.useRef(); const typographyToolbarItemRef = React.useRef(); const renderTextStyles = () => { const scopes: React.ReactNode[] = []; const stylesByScope: { fragments: React.ReactNode[]; scope: string }[] = []; textStyle.scopes.map(scope => { const scopeKey = Object.keys(scope)[0]; textStyle.options.map((option, optionIndex) => { if (option.scope === scopeKey) { stylesByScope.push({ scope: scopeKey, fragments: [ setCurrentTextStyleSetting({ key: optionIndex, scope: option.scope as string, fontFamily: option.fontFamily }) } isSelectedItem={ currentTextStyleSetting.key === optionIndex && currentTextStyleSetting.scope === option.scope && currentTextStyleSetting.fontFamily === option.fontFamily } > ABC abc 123 !?% {option.fontFamily} {currentTextStyleSetting.key === optionIndex && currentTextStyleSetting.scope === option.scope && currentTextStyleSetting.fontFamily === option.fontFamily && ( )} {optionIndex + 1 !== textStyle.options.length && ( )} ] }); } }); scopes.push( {Object.values(scope)[0]} {stylesByScope.map(styles => { if (styles.scope === scopeKey) { return styles.fragments; } })} ); }); return scopes; }; return ( <> {bodyText && ( <> { setDisplayTypographySettings(!displayTypographySettings); setDisplayTextStyleSettings(false); setDisplayTextBoxColorSettings(false); setDisplayTextBoxStyleSettings(false); setDisplayTextColorSettings(false); }} > {bodyText.label} {displayTypographySettings ? : } )} {textStyle && ( { setDisplayTextStyleSettings(!displayTextStyleSettings); setDisplayTypographySettings(false); setDisplayTextBoxColorSettings(false); setDisplayTextBoxStyleSettings(false); setDisplayTextColorSettings(false); }} > {displayTextStyleSettings ? : } )} {textColor && ( <> { setDisplayTextColorSettings(!displayTextColorSettings); setDisplayTextBoxColorSettings(false); setDisplayTextBoxStyleSettings(false); setDisplayTypographySettings(false); setDisplayTextStyleSettings(false); }} > {displayTextColorSettings ? : } {(textBoxStyle || textBoxColor) && } )} {textBoxStyle && ( <> { setDisplayTextBoxStyleSettings(!displayTextBoxStyleSettings); setDisplayTextBoxColorSettings(false); setDisplayTextColorSettings(false); setDisplayTypographySettings(false); setDisplayTextStyleSettings(false); }} > {displayTextBoxStyleSettings ? ( ) : ( )} )} {textBoxColor && ( <> { setDisplayTextBoxColorSettings(!displayTextBoxColorSettings); setDisplayTextColorSettings(false); setDisplayTextBoxStyleSettings(false); setDisplayTypographySettings(false); setDisplayTextStyleSettings(false); }} ref={textBoxColorToolbarItemRef} > {displayTextBoxColorSettings ? ( ) : ( )} )} {withDrawOption && ( <> )} {displayTypographySettings && ( setCurrentTypographySetting(currentItem) } labels={bodyText.options} /> )} {displayTextStyleSettings && ( {textStyle.menuTitle} {renderTextStyles()} )} {displayTextColorSettings && ( {textColor.menuTitle} { textColor.onChange(color.hex); }} /> )} {displayTextBoxColorSettings && ( {textBoxColor.menuTitle} { textBoxColor.onChange(color.hex); }} /> palette )} {displayTextBoxStyleSettings && ( {textBoxStyle.menuTitle} setCurrentTextBoxStyleSetting(selectedStroke) } /> )} ); };