/** * Styles */ import './style.scss'; /** * WordPress dependencies */ const { Component, } = wp.element; const { TextControl, Button, } = wp.components; const allRadius = [ 'topLeft', 'topRight', 'bottomLeft', 'bottomRight']; /** * Component */ export default class ComponentRadius extends Component { constructor() { super( ...arguments ); this.updateRadius = this.updateRadius.bind( this ); } /** * Update number value. * * @param {String} name - number name. * @param {String} prefix - type prefix. * @param {String} suffix - responsive suffix. * @param {String} val - new value. */ updateRadius( name, prefix = '', suffix = '', val ) { const { onChange, } = this.props; // TextControl return string value, we need to convert to int manually. val = parseInt( val, 10 ); if ( Number.isNaN( val ) ) { val = undefined; } const updateAttrs = { [ prefix + name.charAt(0).toUpperCase() + name.slice(1) + suffix ]: val, }; // Change all linked values. if ( this.props.link ) { allRadius.forEach( ( radius ) => { updateAttrs[ prefix + radius.charAt(0).toUpperCase() + radius.slice(1) + suffix ] = val; } ) } onChange( updateAttrs ); } render() { const { prefix = '', suffix = '', units = [ 'px', 'em' ], onChange, } = this.props; return (