import React, { Component, PropTypes } from 'react'; import { Icon } from '../../UI'; import styles from './Toolbar.css'; function button(label, icon, action) { return (
  • ); } export default class Toolbar extends Component { static propTypes = { isOpen: PropTypes.bool, selectionPosition: PropTypes.object, onH1: PropTypes.func.isRequired, onH2: PropTypes.func.isRequired, onBold: PropTypes.func.isRequired, onItalic: PropTypes.func.isRequired, onLink: PropTypes.func.isRequired, onToggleMode: PropTypes.func.isRequired, }; componentDidUpdate() { const { selectionPosition } = this.props; if (selectionPosition) { const rect = this.element.getBoundingClientRect(); const parentRect = this.element.parentElement.getBoundingClientRect(); const style = this.element.style; const pos = { top: selectionPosition.top - rect.height - 5, left: Math.min(selectionPosition.left, parentRect.width - rect.width), }; style.setProperty('top', `${ pos.top }px`); style.setProperty('left', `${ pos.left }px`); } } handleRef = (ref) => { this.element = ref; }; render() { const { isOpen, onH1, onH2, onBold, onItalic, onLink, onToggleMode } = this.props; const classNames = [styles.Toolbar]; if (isOpen) { classNames.push(styles.Visible); } return ( ); } }