import React from 'react' import Popout from './Popout' import Button from './Button' import ColorPicker from './ColorPicker' import { COLORS } from '../lib/constants' function ModifierButton(props) { return ( {props.children} ) } function reducer(state, action) { switch (action.type) { case 'BOLD': { return { ...state, bold: !state.bold } } case 'ITALICS': { return { ...state, italics: !state.italics } } case 'UNDERLINE': { return { ...state, underline: !state.underline } } case 'COLOR': { return { ...state, color: action.color } } } throw new Error('Invalid action') } function SelectionEditor({ position, onChange }) { const [open, setOpen] = React.useState(false) const [state, dispatch] = React.useReducer(reducer, { bold: false, italics: false, underline: false, color: null }) React.useEffect(() => { onChange(state) }, [onChange, state]) return ( dispatch({ type: 'BOLD' })}> B dispatch({ type: 'ITALICS' })}> I dispatch({ type: 'UNDERLINE' })} > U setOpen(o => !o)} /> {open && ( dispatch({ type: 'COLOR', color: d.hex })} /> )} ) } export default SelectionEditor