diff --git a/components/Carbon.js b/components/Carbon.js index eade6b6..0d2f677 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -7,6 +7,10 @@ import { Controlled as CodeMirror } from 'react-codemirror2' import SpinnerWrapper from './SpinnerWrapper' import WindowControls from './WindowControls' +import Popout from './Popout' +import Button from './Button' +import ColorPicker from './ColorPicker' + import { COLORS, LANGUAGES, @@ -17,6 +21,93 @@ import { THEMES_HASH } from '../lib/constants' +function ModifierButton(props) { + const [selected, setOpen] = React.useState(props.selected) + + return ( + + ) +} + +function SeletionEditor(props) { + const [open, setOpen] = React.useState(false) + const [color, setColor] = React.useState(COLORS.PRIMARY) + + return ( + + ) +} + const Watermark = dynamic(() => import('./svg/Watermark'), { loading: () => null }) @@ -29,6 +120,7 @@ class Carbon extends React.PureComponent { static defaultProps = { onChange: () => {} } + state = {} handleLanguageChange = debounce( (newCode, language) => { @@ -94,8 +186,38 @@ class Carbon extends React.PureComponent { const light = themeConfig && themeConfig.light + /* eslint-disable jsx-a11y/no-static-element-interactions */ const content = ( -
+
{ + if (this.currentSelection) { + // let x = this.props.editorRef.current.editor.doc.markText( + // this.currentSelection.from, + // this.currentSelection.to, + // { + // css: 'font-weight: bold' + // } + // ) + const modifierOpenAt = this.props.editorRef.current.editor.charCoords( + this.currentSelection.from, + 'local' + ) + const modifierOpenAtEnd = this.props.editorRef.current.editor.charCoords( + this.currentSelection.to, + 'local' + ) + // TODO find a better more consistent way to measure + const top = modifierOpenAt.bottom + parseInt(config.paddingVertical) + 45 + const left = (modifierOpenAt.left + modifierOpenAtEnd.right) / 2 + + this.setState({ modifierOpenAt: { ...modifierOpenAt, top, left } }) + this.currentSelection = null + } else { + this.setState({ modifierOpenAt: null }) + } + }} + > {config.windowControls ? ( { + const selection = data.ranges[0] + + if ( + selection.head.line === selection.anchor.line && + selection.head.ch === selection.anchor.ch + ) { + return + } + + if ( + selection.head.line + selection.head.ch > + selection.anchor.line + selection.anchor.ch + ) { + this.currentSelection = { + from: selection.anchor, + to: selection.head + } + } else { + this.currentSelection = { + from: selection.head, + to: selection.anchor + } + } + }} /> {config.watermark && }
@@ -234,6 +381,7 @@ class Carbon extends React.PureComponent { {content}
+ {this.state.modifierOpenAt && }