es.func.isRequired, color: PropTypes.string.isRequired, flexContainer: PropTypes.shape(Types.flexContainer).isRequired, getSwatchColorPickerTooltip: PropTypes.func.isRequired, onSetFlexboxOverlayColor: PropTypes.func.isRequired, }; } constructor(props) { super(props); this.swatchEl = createRef(); this.setFlexboxColor = this.setFlexboxColor.bind(this); } componentDidMount() { const tooltip = this.props.getSwatchColorPickerTooltip(); let previousColor; tooltip.addSwatch(this.swatchEl.current, { onCommit: this.setFlexboxColor, onPreview: this.setFlexboxColor, onRevert: () => { this.props.onSetFlexboxOverlayColor(previousColor); }, onShow: () => { previousColor = this.props.color; }, }); } componentWillUnmount() { const tooltip = this.props.getSwatchColorPickerTooltip(); tooltip.removeSwatch(this.swatchEl.current); } setFlexboxColor() { const color = this.swatchEl.current.dataset.color; this.props.onSetFlexboxOverlayColor(color); } render() { const { color, flexContainer, dispatch } = this.props; const { nodeFront, properties } = flexContainer; return createElement( Fragment, null, dom.div( { className: "flex-header-container-label", }, getNodeRep(nodeFront, { onDOMNodeMouseOut: () => dispatch(unhighlightNode()), onDOMNodeMouseOver: () => dispatch(highlightNode(nodeFront)), }), dom.button({ className: "layout-color-swatch", "data-color": color, ref: this.swatchEl, style: { backgroundColor: color, }, title: getFormatStr("layout.colorSwatch.tooltip", color), }) ), dom.div( { className: "flex-header-container-properties" }, dom.div( { className: "inspector-badge", role: "figure", title: `flex-direction: ${properties["flex-direction"]}`, }, properties["flex-direction"] ), dom.div( { className: "inspector-badge", role: "figure", title: `flex-wrap: ${properties["flex-wrap"]}`, }, properties["flex-wrap"] ) ) ); } } module.exports = FlexContainer; PK