// @flow import React, { Component } from "react"; import "../style/Tip.css"; type State = { compact: boolean, text: string, emoji: string }; type Props = { onConfirm: (comment: { text: string, emoji: string }) => void, onOpen: () => void, onUpdate?: () => void }; class Tip extends Component { state: State = { compact: true, text: "", emoji: "" }; // for TipContainer componentDidUpdate(nextProps: Props, nextState: State) { const { onUpdate } = this.props; if (onUpdate && this.state.compact !== nextState.compact) { onUpdate(); } } render() { const { onConfirm, onOpen } = this.props; const { compact, text, emoji } = this.state; return (
{compact ? (
{ onOpen(); this.setState({ compact: false }); }} > Add highlight
) : (
{ event.preventDefault(); onConfirm({ text, emoji }); }} >