clean up SelectionEditor code

main
Mike Fix 5 years ago
parent 3ad106cd20
commit 9dc13f702e

@ -12,7 +12,7 @@ function ModifierButton(props) {
center center
margin="0 8px 0 0" margin="0 8px 0 0"
style={{ borderBottom: `1px solid ${props.selected ? 'white' : 'transparent'}` }} style={{ borderBottom: `1px solid ${props.selected ? 'white' : 'transparent'}` }}
onClick={() => props.onChange(s => !s)} onClick={props.onClick}
> >
{props.children} {props.children}
</Button> </Button>
@ -21,10 +21,13 @@ function ModifierButton(props) {
function SelectionEditor({ position, onChange }) { function SelectionEditor({ position, onChange }) {
const [open, setOpen] = React.useState(false) const [open, setOpen] = React.useState(false)
const [bold, setBold] = React.useState(false) const [bold, setBold] = React.useState(false)
const [italics, setItalics] = React.useState(false) const [italics, setItalics] = React.useState(false)
const [underline, setUnderline] = React.useState(false) const [underline, setUnderline] = React.useState(false)
const [color, setColor] = React.useState(null) const [color, setColor] = React.useState(null)
React.useEffect(() => { React.useEffect(() => {
onChange({ onChange({
bold, bold,
@ -33,6 +36,7 @@ function SelectionEditor({ position, onChange }) {
color color
}) })
}, [onChange, bold, color, italics, underline]) }, [onChange, bold, color, italics, underline])
return ( return (
<Popout <Popout
hidden={false} hidden={false}
@ -45,13 +49,13 @@ function SelectionEditor({ position, onChange }) {
> >
<div className="colorizer"> <div className="colorizer">
<div className="modifier"> <div className="modifier">
<ModifierButton selected={bold} onChange={setBold}> <ModifierButton selected={bold} onClick={() => setBold(v => !v)}>
<b>B</b> <b>B</b>
</ModifierButton> </ModifierButton>
<ModifierButton selected={italics} onChange={setItalics}> <ModifierButton selected={italics} onClick={() => setItalics(v => !v)}>
<i>I</i> <i>I</i>
</ModifierButton> </ModifierButton>
<ModifierButton selected={underline} onChange={setUnderline}> <ModifierButton selected={underline} onClick={() => setUnderline(v => !v)}>
<u>U</u> <u>U</u>
</ModifierButton> </ModifierButton>
<button className="color-square" onClick={() => setOpen(o => !o)} /> <button className="color-square" onClick={() => setOpen(o => !o)} />

Loading…
Cancel
Save