/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { clamp, isNaN } from 'lodash'; import { Fragment } from '@wordpress/element'; import PropTypes from 'prop-types'; import { RangeControl, ToggleControl } from '@wordpress/components'; import { MAX_COLUMNS, MIN_COLUMNS, MAX_ROWS, MIN_ROWS } from '@woocommerce/settings'; /** * A combination of range controls for product grid layout settings. */ const GridLayoutControl = ( { columns, rows, setAttributes, alignButtons } ) => { return ( { const newValue = clamp( value, MIN_COLUMNS, MAX_COLUMNS ); setAttributes( { columns: isNaN( newValue ) ? '' : newValue } ); } } min={ MIN_COLUMNS } max={ MAX_COLUMNS } /> { const newValue = clamp( value, MIN_ROWS, MAX_ROWS ); setAttributes( { rows: isNaN( newValue ) ? '' : newValue } ); } } min={ MIN_ROWS } max={ MAX_ROWS } /> setAttributes( { alignButtons: ! alignButtons } ) } /> ); }; GridLayoutControl.propTypes = { /** * The current columns count. */ columns: PropTypes.oneOfType( [ PropTypes.number, PropTypes.string ] ).isRequired, /** * The current rows count. */ rows: PropTypes.oneOfType( [ PropTypes.number, PropTypes.string ] ).isRequired, /** * Whether or not buttons are aligned horizontally across items. */ alignButtons: PropTypes.bool.isRequired, /** * Callback to update the layout settings. */ setAttributes: PropTypes.func.isRequired, }; export default GridLayoutControl;