hide style editor on escape instead of removing selection

main
Mike Fix 5 years ago committed by repo-ranger[bot]
parent 5414683f85
commit 24b685ae72

@ -129,8 +129,6 @@ class Carbon extends React.PureComponent {
} }
} }
closeSelectionEditor = () => this.setState({ selectionAt: null })
render() { render() {
const config = { ...DEFAULT_SETTINGS, ...this.props.config } const config = { ...DEFAULT_SETTINGS, ...this.props.config }
@ -313,10 +311,7 @@ class Carbon extends React.PureComponent {
{!this.props.readOnly && {!this.props.readOnly &&
this.state.selectionAt && this.state.selectionAt &&
ReactDOM.createPortal( ReactDOM.createPortal(
<SelectionEditor <SelectionEditor onChange={this.onSelectionChange} />,
onChange={this.onSelectionChange}
onClose={this.closeSelectionEditor}
/>,
// TODO: don't use portal? // TODO: don't use portal?
document.getElementById('style-editor-button') document.getElementById('style-editor-button')
)} )}

@ -6,7 +6,7 @@ import ColorPicker from './ColorPicker'
import ThemeIcon from './svg/Theme' import ThemeIcon from './svg/Theme'
import { COLORS } from '../lib/constants' import { COLORS } from '../lib/constants'
const styleEditorButtonStyle = { width: 32, maxWidth: 32, height: 32, borderRadius: '50%' } const styleEditorButtonStyle = { width: 28, maxWidth: 28, height: 28, borderRadius: '50%' }
function ModifierButton(props) { function ModifierButton(props) {
return ( return (
@ -53,11 +53,12 @@ function reducer(state, action) {
throw new Error('Invalid action') throw new Error('Invalid action')
} }
function SelectionEditor({ onChange, onClose }) { function SelectionEditor({ onChange }) {
useKeyboardListener('Escape', onClose)
const [visible, setVisible] = React.useState(false) const [visible, setVisible] = React.useState(false)
const [open, setOpen] = React.useState(true) const [open, setOpen] = React.useState(true)
useKeyboardListener('Escape', () => setVisible(false))
const [state, dispatch] = React.useReducer(reducer, { const [state, dispatch] = React.useReducer(reducer, {
bold: false, bold: false,
italics: false, italics: false,
@ -77,7 +78,7 @@ function SelectionEditor({ onChange, onClose }) {
center center
selected={visible} selected={visible}
style={styleEditorButtonStyle} style={styleEditorButtonStyle}
margin="4px 0 0" margin="6px 0 0"
onClick={() => setVisible(v => !v)} onClick={() => setVisible(v => !v)}
> >
<ThemeIcon /> <ThemeIcon />

Loading…
Cancel
Save