import React, { Component } from "react"; import PropTypes from "prop-types"; import "./style.scss"; class DimentionControl extends Component { state = { top: this.props.top || "0", right: this.props.right || "0", bottom: this.props.bottom || "0", left: this.props.bottom || "0", isLinked: false, }; onButtonClick = () => this.setState({ isLinked: !this.state.isLinked }); onInputChange = event => { let { top, right, bottom, left, isLinked } = this.state; let { name, value } = event.target; if (isLinked) { top = right = bottom = left = value; this.setState({ top, right, bottom, left }); } else { this.setState({ [name]: value }); } this.props.onChange({ top, right, bottom, left }); }; render() { const { top, right, bottom, left, isLinked } = this.state; return (
{this.props.label}
); } } DimentionControl.propTypes = { label: PropTypes.string, onChange: PropTypes.func.isRequired, }; export default DimentionControl;