Skip to content

Commit

Permalink
RNMobile - Gallery - better use of Stepper component
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo Pacheco committed Jan 30, 2020
1 parent 1a011eb commit 7c0a10d
Showing 1 changed file with 10 additions and 28 deletions.
38 changes: 10 additions & 28 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { sharedIcon } from './shared-icon';
import { defaultColumnsNumber, pickRelevantMediaFiles } from './shared';
import Gallery from './gallery';

const ColumnsControl = Platform.OS === 'web' ? RangeControl : StepperControl;
const MAX_COLUMNS = 8;
const linkOptions = [
{ value: 'attachment', label: __( 'Attachment Page' ) },
Expand Down Expand Up @@ -300,33 +301,6 @@ class GalleryEdit extends Component {
}
}

renderColumnsSettings( columns ) {
const { attributes } = this.props;
const { images } = attributes;
const label = __( 'Columns' );
const minValue = 1;
const maxValue = Math.min( MAX_COLUMNS, images.length );

return images.length > 1 && (
Platform.OS === 'web' ?
<RangeControl
label={ label }
value={ columns }
onChange={ this.setColumnsNumber }
min={ minValue }
max={ maxValue }
required
/> :
<StepperControl
label={ label }
maxValue={ maxValue }
minValue={ minValue }
onChangeValue={ this.setColumnsNumber }
value={ columns }
/>
);
}

render() {
const {
attributes,
Expand Down Expand Up @@ -382,7 +356,15 @@ class GalleryEdit extends Component {
<>
<InspectorControls>
<PanelBody title={ __( 'Gallery settings' ) }>
{ this.renderColumnsSettings( columns ) }
{ images.length > 1 && <ColumnsControl
label={ __( 'Columns' ) }
{ ...MOBILE_CONTROL_PROPS }
value={ columns }
onChange={ this.setColumnsNumber }
min={ 1 }
max={ Math.min( MAX_COLUMNS, images.length ) }
required
/> }

<ToggleControl
label={ __( 'Crop Images' ) }
Expand Down

0 comments on commit 7c0a10d

Please sign in to comment.