Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile: Add simple layout grid controls #187

Merged
merged 53 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
260fc32
Add variatioation picker for when block is first added.
enejb Sep 4, 2020
1e3141d
Minor code cleanup
enejb Sep 4, 2020
987be10
Add Gutter Settings
enejb Sep 4, 2020
4f60830
Add Example controls that
enejb Mar 26, 2021
b8e942a
Update all the controls
enejb Apr 2, 2021
ff76727
Fix the InnerBlocks Appender logic
enejb Apr 2, 2021
810ea7d
Add background Colour settings.
enejb Apr 23, 2021
4b6a12c
Stash
enejb Apr 28, 2021
c11ebf1
Remove the background colour
enejb Apr 29, 2021
77c8557
Remove the column title
enejb Apr 29, 2021
6af5124
Add New variation control component.
enejb Apr 29, 2021
14b0f2c
Remove bottom sheet controls
enejb Apr 29, 2021
c972434
Convert grid column to functional component
enejb Apr 29, 2021
cbfb7c8
Removed un used import from grid column
enejb Apr 29, 2021
872491d
Convert to edit columns to functional component
enejb Apr 30, 2021
2698020
Refactor Variation Control so that we don't end up with a nested Bott…
enejb Apr 30, 2021
3368ba1
Use the new VariationControl
enejb Apr 30, 2021
22742d2
Add Placeholder Styles to Grid Column
enejb Apr 30, 2021
a3dee8c
Add padding settings
enejb Apr 30, 2021
949f23a
Fix bottom padding between the inserter and settings cog
enejb May 3, 2021
6188f5e
Fix the styles so that they don't produce an extra bottom space when …
enejb May 3, 2021
98d682d
Add comments about translations
enejb May 3, 2021
b579c3b
Fix comment strings
enejb May 3, 2021
0179a6d
Fix: Styling of the controls
enejb May 5, 2021
f37bdf3
Fixes for variation control, fix typo, fix memo
enejb May 5, 2021
b56a9af
Remove edit.native.scss file not needed
enejb May 5, 2021
b934d40
Refactor to use HOC
enejb May 5, 2021
a26c456
Add iPad columns
enejb May 7, 2021
77f9503
Update the size on grid column
enejb May 10, 2021
cf985cb
Fix typo
enejb May 10, 2021
bf0ac0a
Improve the appender styles
enejb May 10, 2021
b14290d
Remove not neede minus margin.
enejb May 10, 2021
9128940
Clarify the variable name
enejb May 10, 2021
b22e86b
Fine tune the spacing between settings and inserter
enejb May 10, 2021
e13809b
Fix styles when not in full width alignment
enejb May 10, 2021
99fc7f7
Minor fixes, remove unused dependencies
enejb May 10, 2021
fea7ca5
Minor fixes.
enejb May 12, 2021
a0bb417
Add Selected State to the Input Button
enejb May 12, 2021
cde6157
Use constants for getColmnStyles
enejb May 12, 2021
e5671d7
Code clean up
enejb May 12, 2021
2a19368
Minor refactor
enejb May 12, 2021
2261831
Code fixes.
enejb May 13, 2021
476b18c
Update checkmark icon.
enejb May 13, 2021
83897ad
Fix the iPhone Pro Landscape more.
enejb May 13, 2021
3ef4a45
Remove the circle checkmark
enejb May 14, 2021
831f521
Add notice
enejb May 14, 2021
d1fb1c5
Update the buttons so that 3.2 buttons show up now
enejb May 14, 2021
67f08f3
remove the side spacing.
enejb May 14, 2021
5e6919c
Icon: Add support for the size prop
enejb May 14, 2021
317aeac
Rename higher-order to hooks/with-update-alignment
enejb May 14, 2021
7af39b0
Remove package-lock.json
enejb May 14, 2021
34945d8
Fixes Android selected button.
enejb May 14, 2021
9244271
Fix 3 column layout grid on Desktop (Mobile App iPad horizontal)
enejb May 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions blocks/layout-grid/src/grid-column/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/

import {
InnerBlocks,
InspectorControls,
Expand All @@ -18,14 +17,15 @@ import {
} from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { withSelect } from '@wordpress/data';
import { PanelBody, SelectControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { getPaddingValues } from '../constants';
import { withUpdateAlignment } from './hooks/with-update-alignment';

class Edit extends Component {
constructor( props ) {
Expand Down Expand Up @@ -151,26 +151,5 @@ export default compose(
hasChildBlocks: getBlockOrder( clientId ).length > 0,
};
} ),
withDispatch( ( dispatch, ownProps, registry ) => {
return {
updateAlignment( verticalAlignment ) {
const { clientId, setAttributes } = ownProps;
const { updateBlockAttributes } = dispatch(
'core/block-editor'
);
const { getBlockRootClientId } = registry.select(
'core/block-editor'
);

// Update own alignment.
setAttributes( { verticalAlignment } );

// Reset Parent Columns Block
const rootClientId = getBlockRootClientId( clientId );
updateBlockAttributes( rootClientId, {
verticalAlignment: null,
} );
},
};
} )
withUpdateAlignment(),
)( Edit );
227 changes: 214 additions & 13 deletions blocks/layout-grid/src/grid-column/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,228 @@ import { View } from 'react-native';
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { Component } from '@wordpress/element';
import {
PanelBody,
BottomSheetSelectControl,
alignmentHelpers,
} from '@wordpress/components';
import { withViewportMatch } from '@wordpress/viewport';
import {
InnerBlocks,
InspectorControls,
BlockControls,
BlockVerticalAlignmentToolbar,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';
import { withSelect } from '@wordpress/data';
import { compose, usePreferredColorSchemeStyle } from '@wordpress/compose';

class Edit extends Component {
constructor( props ) {
super( props );
/**
* Internal dependencies
*/
import { getPaddingValues } from '../constants';
import { withUpdateAlignment } from './hooks/with-update-alignment';
import styles from './edit.native.scss';

/**
* Calculate the column styles.
*
* @param {int} columns
* @param {int} index
* @param {int} fullWidth
* @param {string} viewport
* @return {object}
*/
function getColumnStyles( columns, index, fullWidth, viewport ) {
// Default widths for 1 column layout.
let widths = {
mobile: fullWidth,
tablet: fullWidth,
desktop: fullWidth,
};
const TWO_COLUMN_MARGIN = 16;
const THREE_COLUMN_MARGIN = 22;
const FOUR_COLUMN_MARGIN = 24;

switch ( columns ) {
case 2:
widths = {
mobile: fullWidth,
tablet: Math.floor( fullWidth / 2 ) - TWO_COLUMN_MARGIN,
desktop: Math.floor( fullWidth / 2 ) - TWO_COLUMN_MARGIN,
};
break;
case 3:
widths = {
mobile: fullWidth,
tablet: Math.floor( fullWidth / 2 ) - TWO_COLUMN_MARGIN,
desktop: Math.floor( fullWidth / 3 ) - THREE_COLUMN_MARGIN,
};
if ( index === 2 ) {
widths.tablet = fullWidth;
}
break;
case 4:
widths = {
mobile: fullWidth,
tablet: Math.floor( fullWidth / 2 ) - TWO_COLUMN_MARGIN,
desktop: Math.floor( fullWidth / 4 ) - FOUR_COLUMN_MARGIN,
};
break;
}

render() {
return { width: widths[ viewport ] };
}

function ColumnsEdit( {
hasChildren,
attributes,
isSelected,
setAttributes,
updateAlignment,
isParentSelected,
selectedColumnIndex,
contentStyle,
isMobile,
isTablet,
parentAlign,
parentColumnCount,
} ) {
const { padding, verticalAlignment } = attributes;

const { isFullWidth } = alignmentHelpers;

let viewportSize = 'desktop';
if ( isTablet ) {
viewportSize = 'tablet';
}
if ( isMobile ) {
viewportSize = 'mobile';
}

const stylePlaceholder = usePreferredColorSchemeStyle(
styles.column__placeholder,
styles[ 'column__placeholder-dark' ]
);

const calculatedColumnStyles = getColumnStyles(
parentColumnCount,
selectedColumnIndex,
contentStyle.width,
viewportSize
);

if ( ! isSelected && ! hasChildren ) {
return (
<View>
<View
style={ [
! isParentSelected && stylePlaceholder,
styles[ 'column__placeholder-not-selected' ],
calculatedColumnStyles,
] }
/>
);
}

const columnPadding =
isSelected && 'none' === padding
? styles[ 'column__padding-none-is-selected' ]
: styles[ 'column__padding-' + padding ];

const appenderStyle = hasChildren
? styles[ 'column__appender-has-children' ]
: styles.column__appender;

return (
<>
<View style={ [ columnPadding, calculatedColumnStyles ] }>
<InnerBlocks
templateLock={ false }
renderAppender={ this.props.hasChildBlocks
? undefined
: () => <InnerBlocks.ButtonBlockAppender />
renderAppender={
! hasChildren || isSelected
? () => (
<View
style={
isFullWidth( parentAlign )
? appenderStyle
: [
appenderStyle,
styles[
'column__appender-not-full-width'
],
]
}
>
<InnerBlocks.ButtonBlockAppender />
</View>
)
: undefined
}
parentWidth={ calculatedColumnStyles.width }
blockWidth={ calculatedColumnStyles.width }
/>
</View>
);
}
<InspectorControls>
<PanelBody title={ __( 'Column Settings', 'layout-grid' ) }>
<BottomSheetSelectControl
label={ __( 'Padding', 'layout-grid' ) }
value={ padding }
onChange={ ( newValue ) =>
setAttributes( { padding: newValue } )
}
options={ getPaddingValues() }
/>
</PanelBody>
</InspectorControls>

<BlockControls>
<BlockVerticalAlignmentToolbar
onChange={ updateAlignment }
value={ verticalAlignment }
/>
</BlockControls>
</>
);
}

export default Edit;
export default compose(
withSelect( ( select, { clientId } ) => {
const {
getBlockCount,
getBlockRootClientId,
getSelectedBlockClientId,
getBlocks,
getBlockOrder,
getBlockAttributes,
} = select( blockEditorStore );

const selectedBlockClientId = getSelectedBlockClientId();
const isSelected = selectedBlockClientId === clientId;

const parentId = getBlockRootClientId( clientId );
const hasChildren = !! getBlockCount( clientId );
const isParentSelected =
selectedBlockClientId && selectedBlockClientId === parentId;

const blockOrder = getBlockOrder( parentId );

const selectedColumnIndex = blockOrder.indexOf( clientId );
const columns = getBlocks( parentId );

const parentAlign = getBlockAttributes( parentId )?.align;
const parentColumnCount = getBlockCount( parentId );

return {
hasChildren,
isParentSelected,
isSelected,
selectedColumnIndex,
columns,
parentAlign,
parentColumnCount,
};
} ),
withUpdateAlignment(),
withViewportMatch( { isMobile: '< small', isTablet: '< large' } )
)( ColumnsEdit );
54 changes: 54 additions & 0 deletions blocks/layout-grid/src/grid-column/edit.native.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.column__placeholder {
flex: 1;
padding: $block-selected-to-content;
background-color: $white;
border: $border-width dashed $gray;
border-radius: 4px;
}

.column__placeholder-dark {
background-color: $black;
border: $border-width dashed $gray-70;
}

.column__placeholder-not-selected {
padding-top: $block-selected-to-content;
}

.column__appender {
margin-left: 8px;
margin-right: 8px;
margin-bottom: -10px;
}

.column__appender-has-children {
margin-left: 16px;
margin-right: 16px;
margin-bottom: 6px;
}

.column__appender-not-full-width {
margin-left: 0;
margin-right: 0;
}

.column__padding-none {
padding: 0;
}
/* Add extra space to the bottom of the column block make sure that the there is enough space between column block and the settings cog. */
.column__padding-none-is-selected {
padding: 0 0 10px;
}

.column__padding-small {
padding: 10px 8px 10px;
}
.column__padding-medium {
padding: 16px;
}
.column__padding-large {
padding: 24px;
}
.column__padding-huge {
padding: 48px;
}
29 changes: 29 additions & 0 deletions blocks/layout-grid/src/grid-column/hooks/with-update-alignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* WordPress dependencies
*/
import { withDispatch } from '@wordpress/data';

export function withUpdateAlignment() {
return withDispatch( ( dispatch, ownProps, registry ) => {
return {
updateAlignment( verticalAlignment ) {
const { clientId, setAttributes } = ownProps;
const { updateBlockAttributes } = dispatch(
'core/block-editor'
);
const { getBlockRootClientId } = registry.select(
'core/block-editor'
);

// Update own alignment.
setAttributes( { verticalAlignment } );

// Reset Parent Columns Block
const rootClientId = getBlockRootClientId( clientId );
updateBlockAttributes( rootClientId, {
verticalAlignment: null,
} );
},
};
} );
}
Loading