Skip to content

Commit

Permalink
[RNMobile][Tech debt] Remove separatorType prop from TextControl, Ran…
Browse files Browse the repository at this point in the history
…geControl... (#21365)

* move separatorType to the panelBody

* fix rest of components

* fix gallery

* use Childrem.toArray

* revert one separatorType

* remove not needed separator type and use PanelBody instead

* revert some changes to prepare for the new approach

* revert panel body

* remove rest of separatorTypes and add view that covers the last separator

The exception here are BottomSheet.Cell that are used directly

* fix video settings

* remove top margin from PanelActions

* fix separatorType when icon is not set
  • Loading branch information
dratwas authored May 11, 2020
1 parent af44574 commit f6a401b
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ export default function PanelColorGradientSettings( { settings, title } ) {
<BottomSheetConsumer>
{ ( { onReplaceSubsheet } ) =>
settings.map(
(
{
onColorChange,
colorValue,
onGradientChange,
gradientValue,
label,
},
index
) => (
( {
onColorChange,
colorValue,
onGradientChange,
gradientValue,
label,
} ) => (
<ColorControl
onPress={ () => {
onReplaceSubsheet( 'Color', {
Expand All @@ -36,11 +33,6 @@ export default function PanelColorGradientSettings( { settings, title } ) {
key={ `color-setting-${ label }` }
label={ label }
color={ gradientValue || colorValue }
separatorType={
index !== settings.length - 1
? 'fullWidth'
: 'none'
}
/>
)
)
Expand Down
29 changes: 12 additions & 17 deletions packages/block-library/src/button/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
TextControl,
ToggleControl,
PanelBody,
PanelActions,
RangeControl,
ToolbarGroup,
ToolbarButton,
Expand Down Expand Up @@ -325,19 +326,13 @@ class ButtonEdit extends Component {
autoFocus={
! isCompatibleWithSettings && Platform.OS === 'ios'
}
separatorType={
isCompatibleWithSettings ? 'fullWidth' : 'leftMargin'
}
keyboardType="url"
/>
<ToggleControl
icon={ ! isCompatibleWithSettings && external }
label={ __( 'Open in new tab' ) }
checked={ linkTarget === '_blank' }
onChange={ this.onChangeOpenInNewTab }
separatorType={
isCompatibleWithSettings ? 'fullWidth' : 'leftMargin'
}
/>
<TextControl
icon={ ! isCompatibleWithSettings && LinkRelIcon }
Expand All @@ -348,9 +343,6 @@ class ButtonEdit extends Component {
onSubmit={ this.dismissSheet }
autoCapitalize="none"
autoCorrect={ false }
separatorType={
isCompatibleWithSettings ? 'none' : 'fullWidth'
}
keyboardType="url"
/>
</>
Expand Down Expand Up @@ -441,6 +433,13 @@ class ButtonEdit extends Component {
const backgroundColor = this.getBackgroundColor();
const textColor = this.getTextColor();

const actions = [
{
label: __( 'Remove link' ),
onPress: this.onClearSettings,
},
];

return (
<View onLayout={ this.onLayout }>
{ this.getPlaceholderWidth( placeholderText ) }
Expand Down Expand Up @@ -514,13 +513,10 @@ class ButtonEdit extends Component {
onClose={ this.onHideLinkSettings }
hideHeader
>
{ this.getLinkSettings( url, rel, linkTarget ) }
<BottomSheet.Cell
label={ __( 'Remove link' ) }
labelStyle={ styles.clearLinkButton }
separatorType={ 'none' }
onPress={ this.onClearSettings }
/>
<PanelBody style={ styles.linkSettingsPanel }>
{ this.getLinkSettings( url, rel, linkTarget ) }
</PanelBody>
<PanelActions actions={ actions } />
</BottomSheet>

<ColorEdit { ...this.props } />
Expand All @@ -532,7 +528,6 @@ class ButtonEdit extends Component {
maximumValue={ MAX_BORDER_RADIUS_VALUE }
value={ borderRadiusValue }
onChange={ this.onChangeBorderRadius }
separatorType="none"
/>
</PanelBody>
<PanelBody title={ __( 'Link Settings' ) }>
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/columns/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ function ColumnsEditContainer( {
}
min={ MIN_COLUMNS_NUMBER }
max={ columnCount + 1 }
separatorType={ 'none' }
type="stepper"
/>
</PanelBody>
Expand Down
2 changes: 0 additions & 2 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ const Cover = ( {
label={ __( 'Minimum height in pixels' ) }
minimumValue={ COVER_MIN_HEIGHT }
maximumValue={ COVER_MAX_HEIGHT }
separatorType={ 'none' }
value={ CONTAINER_HEIGHT }
onChange={ onHeightChange }
style={ styles.rangeCellContainer }
Expand All @@ -214,7 +213,6 @@ const Cover = ( {
label={ __( 'Background Opacity' ) }
minimumValue={ 0 }
maximumValue={ 100 }
separatorType={ 'none' }
value={ dimRatio }
onChange={ onOpactiyChange }
style={ styles.rangeCellContainer }
Expand Down
19 changes: 0 additions & 19 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ const PLACEHOLDER_TEXT = Platform.select( {
native: __( 'ADD MEDIA' ),
} );

// currently this is needed for consistent controls UI on mobile
// this can be removed after control components settle on consistent defaults
const MOBILE_CONTROL_PROPS = Platform.select( {
web: {},
native: { separatorType: 'fullWidth' },
} );
const MOBILE_CONTROL_PROPS_SEPARATOR_NONE = Platform.select( {
web: {},
native: { separatorType: 'none' },
} );

const MOBILE_CONTROL_PROPS_RANGE_CONTROL = Platform.select( {
web: {},
native: { type: 'stepper' },
Expand Down Expand Up @@ -385,10 +374,6 @@ class GalleryEdit extends Component {
const imageSizeOptions = this.getImagesSizeOptions();
const shouldShowSizeOptions =
hasImages && ! isEmpty( imageSizeOptions );
// This is needed to fix a separator fence-post issue on mobile.
const mobileLinkToProps = shouldShowSizeOptions
? MOBILE_CONTROL_PROPS
: MOBILE_CONTROL_PROPS_SEPARATOR_NONE;

return (
<>
Expand All @@ -401,30 +386,26 @@ class GalleryEdit extends Component {
onChange={ this.setColumnsNumber }
min={ 1 }
max={ Math.min( MAX_COLUMNS, images.length ) }
{ ...MOBILE_CONTROL_PROPS }
{ ...MOBILE_CONTROL_PROPS_RANGE_CONTROL }
required
/>
) }

<ToggleControl
label={ __( 'Crop images' ) }
{ ...MOBILE_CONTROL_PROPS }
checked={ !! imageCrop }
onChange={ this.toggleImageCrop }
help={ this.getImageCropHelp }
/>
<SelectControl
label={ __( 'Link to' ) }
{ ...mobileLinkToProps }
value={ linkTo }
onChange={ this.setLinkTo }
options={ linkOptions }
/>
{ shouldShowSizeOptions && (
<SelectControl
label={ __( 'Images size' ) }
{ ...MOBILE_CONTROL_PROPS_SEPARATOR_NONE }
value={ sizeSlug }
options={ imageSizeOptions }
onChange={ this.updateImagesSize }
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,6 @@ export class ImageEdit extends React.Component {
label={ __( 'Alt Text' ) }
value={ alt || '' }
valuePlaceholder={ __( 'None' ) }
separatorType={ 'none' }
onChangeValue={ this.updateAlt }
/>
</PanelBody>
Expand Down
9 changes: 0 additions & 9 deletions packages/block-library/src/latest-posts/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,12 @@ class LatestPostsEdit extends Component {
label={ __( 'Show post content' ) }
checked={ displayPostContent }
onChange={ this.onSetDisplayPostContent }
separatorType={
displayPostContent ? 'fullWidth' : 'none'
}
/>
{ displayPostContent && (
<ToggleControl
label={ __( 'Only show excerpt' ) }
checked={ displayExcerptPostContent }
onChange={ this.onSetDisplayPostContentRadio }
separatorType={
displayExcerptPostContent ? 'fullWidth' : 'none'
}
/>
) }
{ displayPostContent && displayExcerptPostContent && (
Expand All @@ -161,7 +155,6 @@ class LatestPostsEdit extends Component {
onChange={ this.onSetExcerptLength }
min={ MIN_EXCERPT_LENGTH }
max={ MAX_EXCERPT_LENGTH }
separatorType="none"
/>
) }
</PanelBody>
Expand All @@ -171,10 +164,8 @@ class LatestPostsEdit extends Component {
label={ __( 'Display post date' ) }
checked={ displayPostDate }
onChange={ this.onSetDisplayPostDate }
separatorType="none"
/>
</PanelBody>

<PanelBody title={ __( 'Sorting and filtering' ) }>
<QueryControls
{ ...{ order, orderBy } }
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/spacer/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const SpacerEdit = ( {
label={ __( 'Height in pixels' ) }
min={ MIN_SPACER_HEIGHT }
max={ Math.max( MAX_SPACER_HEIGHT, height ) }
separatorType={ 'none' }
value={ height }
onChange={ updateHeight }
step={ Platform.OS === 'web' ? 10 : 1 }
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/video/edit-common-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const VideoSettings = ( { setAttributes, attributes } ) => {
{ value: 'metadata', label: __( 'Metadata' ) },
{ value: 'none', label: __( 'None' ) },
] }
separatorType={ 'none' }
/>
</>
);
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/dropdown-menu/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ function DropdownMenu( {
leftAlign={ true }
isSelected={ control.isActive }
separatorType={
indexOfControl ===
controlSet.length - 1 ||
Platform.OS === 'android'
? 'none'
: 'leftMargin'
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/mobile/bottom-sheet/cell.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class BottomSheetCell extends Component {
case 'none':
return undefined;
case undefined:
if ( showValue && icon !== undefined ) {
if ( showValue && icon ) {
return leftMarginStyle;
}
return defaultSeparatorStyle;
Expand Down
15 changes: 11 additions & 4 deletions packages/components/src/panel/actions.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,35 @@ import { View } from 'react-native';
* WordPress dependencies
*/
import { TextControl } from '@wordpress/components';
import { withPreferredColorScheme } from '@wordpress/compose';

/**
* Internal dependencies
*/
import styles from './actions.scss';
import BottomSeparatorCover from './bottom-separator-cover';

function PanelActions( { actions } ) {
function PanelActions( { actions, getStylesFromColorScheme } ) {
return (
<View style={ styles.panelActionsContainer }>
<View
style={ getStylesFromColorScheme(
styles.panelActionsContainer,
styles.panelActionsContainerDark
) }
>
{ actions.map( ( { label, onPress } ) => {
return (
<TextControl
label={ label }
separatorType="topFullWidth"
onPress={ onPress }
labelStyle={ styles.defaultLabelStyle }
key={ label }
/>
);
} ) }
<BottomSeparatorCover />
</View>
);
}

export default PanelActions;
export default withPreferredColorScheme( PanelActions );
7 changes: 6 additions & 1 deletion packages/components/src/panel/actions.native.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.panelActionsContainer {
padding-top: 24;
border-top-color: $light-gray-400;
border-top-width: 1px;
}

.panelActionsContainerDark {
border-top-color: $gray-70;
}

.defaultLabelStyle {
Expand Down
33 changes: 11 additions & 22 deletions packages/components/src/panel/body.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,22 @@
*/
import { Text, View } from 'react-native';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import styles from './body.scss';
import BottomSeparatorCover from './bottom-separator-cover';

export class PanelBody extends Component {
constructor() {
super( ...arguments );
this.state = {};
}

render() {
const { children, title, style = {} } = this.props;

return (
<View style={ [ styles.panelContainer, style ] }>
{ title && (
<Text style={ styles.sectionHeaderText }>{ title }</Text>
) }
{ children }
</View>
);
}
export function PanelBody( { children, title, style = {} } ) {
return (
<View style={ [ styles.panelContainer, style ] }>
{ title && (
<Text style={ styles.sectionHeaderText }>{ title }</Text>
) }
{ children }
<BottomSeparatorCover />
</View>
);
}

export default PanelBody;
Loading

0 comments on commit f6a401b

Please sign in to comment.