Skip to content

Commit

Permalink
Introduce support for custom gutter controls (godaddy-wordpress#1619)
Browse files Browse the repository at this point in the history
* Add animation transition between gallery collage items

* [wip] Add Settings icon to gutter

* [tiny] Add vertical-align on option-selector-group

* WIP implement gutter custom control on collage block

* [tiny] update snapshop

* [WIP] Add filter to add support for gutters in block declaration

* 🐛 fix missing classname on save

* ✨ cleaning up scss related to gutters and running style lint

* 🎉 Added support for features

* [skip-ci] ✨ Added support for gallery-offset

* [skip-ci] ✨ Added support for post block

* ✨ Add custom gutter for rows, services and refactor save for posts

* [fix] Php Unit test

* Fix failing e2e tests

* 🧹 Remove yarn start:dev

* 🐛 Make sure we save a string and not a number

* Remove invalid isLarge prop from Button

* Update style.scss

* Minor tweaks

Co-authored-by: Jason Lemay <[email protected]>
Co-authored-by: Jonathan Bardo <[email protected]>
Co-authored-by: JR Tashjian <[email protected]>
Co-authored-by: Rich Tabor <[email protected]>
  • Loading branch information
5 people authored Aug 24, 2020
1 parent 76987f8 commit e688df8
Show file tree
Hide file tree
Showing 82 changed files with 2,524 additions and 1,210 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
"@wordpress/babel-preset-default"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
12 changes: 6 additions & 6 deletions .dev/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const postcssConfig = require( './postcss.config' );

const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const RtlCssPlugin = require( 'rtlcss-webpack-plugin' );
const FixStyleOnlyEntriesPlugin = require( "webpack-fix-style-only-entries" );
const FixStyleOnlyEntriesPlugin = require( 'webpack-fix-style-only-entries' );
const nodeSassGlobImporter = require( 'node-sass-glob-importer' );

const isProduction = process.env.NODE_ENV === 'production';
Expand Down Expand Up @@ -67,9 +67,9 @@ module.exports = {
sourceMap: ! isProduction,
sassOptions: {
importer: nodeSassGlobImporter(),
}
}
}
},
},
},
],
},
],
Expand All @@ -88,8 +88,8 @@ module.exports = {
new MiniCssExtractPlugin( {
filename: '[name].css',
} ),
new RtlCssPlugin( {
filename: '[name]-rtl.css'
new RtlCssPlugin( {
filename: '[name]-rtl.css',
} ),
],
};
1 change: 1 addition & 0 deletions .dev/tests/jest/empty-class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
3 changes: 3 additions & 0 deletions .dev/tests/jest/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ module.exports = {
testMatch: [ '<rootDir>/src/**/test/*.spec.js' ],
setupFilesAfterEnv: [ '<rootDir>/.dev/tests/jest/setup-globals.js' ],
reporters: [ 'default' ],
moduleNameMapper: {
'@godaddy-wordpress/coblocks-icons': '<rootDir>/.dev/tests/jest/empty-class.js',
},
};
2 changes: 1 addition & 1 deletion .dev/tests/phpunit/src/blocks/posts/test-index.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function test_coblocks_render_posts_block() {
global $post;
$post = get_post( $post_id );

$this->assertEquals( '<div class="wp-block-coblocks-posts test-class-name"><div class="wp-block-coblocks-posts__inner"></div></div>', coblocks_render_posts_block( $attributes ) );
$this->assertEquals( '<div class="wp-block-coblocks-posts test-class-name"><div class="wp-block-coblocks-posts__inner" style=""></div></div>', coblocks_render_posts_block( $attributes ) );
}

/**
Expand Down
3 changes: 3 additions & 0 deletions class-coblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ private function includes() {
$gutenberg_plugin_file = 'gutenberg/gutenberg.php';
$gutenberg_plugin_version = empty( $installed_plugins[ $gutenberg_plugin_file ] ) ? null : $installed_plugins[ $gutenberg_plugin_file ]['Version'];

// Require CoBlocks custom filters
require_once COBLOCKS_PLUGIN_DIR . 'src/components/gutter-control/gutter-wrapper.php';

if ( is_admin() && is_plugin_active( $gutenberg_plugin_file ) && version_compare( $gutenberg_plugin_version, '8.0.0', '>=' ) ) {
require_once COBLOCKS_PLUGIN_DIR . 'src/extensions/layout-selector/index.php';
}
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@
"zh_CN": "简体中文",
"zh_TW": "繁體中文"
},
"dependencies": {
"@godaddy-wordpress/coblocks-icons": "1.0.1"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "7.10.4",
"@testing-library/jest-dom": "^4.2.4",
"@wordpress/block-editor": "3.1.0",
"@wordpress/block-library": "2.8.0",
Expand Down
3 changes: 3 additions & 0 deletions src/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import './extensions/image-crop';
import './extensions/coblocks-settings/';
import './extensions/layout-selector';

// Internal Extensions / Components
import './components/gutter-control';

// Formats
import './formats';

Expand Down
7 changes: 5 additions & 2 deletions src/blocks/accordion/styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
padding: 0 12px;
}

_:-ms-fullscreen, :root .wp-block-coblocks-accordion summary {
_:-ms-fullscreen,
:root .wp-block-coblocks-accordion summary {
display: block;
}

_:-ms-lang(x), _:-webkit-full-screen, .wp-block-coblocks-accordion summary {
_:-ms-lang(x),
_:-webkit-full-screen,
.wp-block-coblocks-accordion summary {
display: block;
}
1 change: 1 addition & 0 deletions src/blocks/buttons/styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ $gutter: 1.35em;
}

.is-stacked-on-mobile {

@media (max-width: #{ ($break-small) }) {
display: block;

Expand Down
4 changes: 0 additions & 4 deletions src/blocks/features/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
"type": "integer",
"default": 4
},
"gutter": {
"type": "string",
"default": "medium"
},
"columns": {
"type": "number",
"default": 2
Expand Down
24 changes: 13 additions & 11 deletions src/blocks/features/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { BackgroundStyles, BackgroundClasses, BackgroundVideo, BackgroundDropZon
import applyWithColors from './colors';
import Inspector from './inspector';
import Controls from './controls';
import GutterWrapper from '../../components/gutter-control/gutter-wrapper';

/**
* WordPress dependencies
Expand Down Expand Up @@ -121,7 +122,6 @@ class Edit extends Component {
'has-columns': columns > 1,
[ `has-${ columns }-columns` ]: columns,
'has-responsive-columns': columns > 1,
[ `has-${ gutter }-gutter` ]: gutter,
'has-padding': paddingSize && paddingSize !== 'no',
[ `has-${ paddingSize }-padding` ]: paddingSize && ( paddingSize !== 'no' && paddingSize !== 'advanced' ),
'has-margin': marginSize && marginSize !== 'no',
Expand Down Expand Up @@ -159,16 +159,18 @@ class Edit extends Component {
<div
className={ classes }
>
<div className={ innerClasses } style={ innerStyles }>
{ isBlobURL( backgroundImg ) && <Spinner /> }
{ BackgroundVideo( attributes ) }
<InnerBlocks
template={ getCount( columns ) }
allowedBlocks={ ALLOWED_BLOCKS }
templateLock="all"
templateInsertUpdatesSelection={ false }
renderAppender={ () => ( null ) } />
</div>
<GutterWrapper { ...attributes }>
<div className={ innerClasses } style={ innerStyles }>
{ isBlobURL( backgroundImg ) && <Spinner /> }
{ BackgroundVideo( attributes ) }
<InnerBlocks
template={ getCount( columns ) }
allowedBlocks={ ALLOWED_BLOCKS }
templateLock="all"
templateInsertUpdatesSelection={ false }
renderAppender={ () => ( null ) } />
</div>
</GutterWrapper>
</div>
</Fragment>
);
Expand Down
3 changes: 3 additions & 0 deletions src/blocks/features/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const settings = {
supports: {
align: [ 'wide', 'full' ],
coBlocksSpacing: true,
gutter: {
default: 'medium',
},
},
example: {
attributes: {
Expand Down
10 changes: 2 additions & 8 deletions src/blocks/features/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import applyWithColors from './colors';
import { BackgroundPanel } from '../../components/background';
import DimensionsControl from '../../components/dimensions-control/';
import OptionSelectorControl from '../../components/option-selector-control';
import gutterOptions from '../../utils/gutter-options';

/**
* WordPress dependencies
Expand All @@ -15,6 +13,7 @@ import { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { InspectorControls, PanelColorSettings } from '@wordpress/block-editor';
import { PanelBody, RangeControl, withFallbackStyles } from '@wordpress/components';
import GutterControl from '../../components/gutter-control/gutter-control';

/**
* Fallback styles
Expand Down Expand Up @@ -111,12 +110,7 @@ class Inspector extends Component {
min={ 1 }
max={ 4 }
/>
{ columns >= 2 && <OptionSelectorControl
label={ __( 'Gutter', 'coblocks' ) }
currentOption={ gutter }
options={ gutterOptions }
onChange={ ( newGutter ) => setAttributes( { gutter: newGutter } ) }
/> }
{ columns >= 2 && <GutterControl { ...this.props } /> }
<DimensionsControl { ...this.props }
type={ 'padding' }
label={ __( 'Padding', 'coblocks' ) }
Expand Down
13 changes: 7 additions & 6 deletions src/blocks/features/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import classnames from 'classnames';
* Internal dependencies
*/
import { BackgroundStyles, BackgroundClasses, BackgroundVideo } from '../../components/background';
import GutterWrapper from '../../components/gutter-control/gutter-wrapper';

/**
* WordPress dependencies
Expand All @@ -20,7 +21,6 @@ const save = ( { attributes, className } ) => {
contentAlign,
customTextColor,
textColor,
gutter,
marginSize,
paddingSize,
} = attributes;
Expand All @@ -40,7 +40,6 @@ const save = ( { attributes, className } ) => {
'has-columns': columns > 1,
[ `has-${ columns }-columns` ]: columns,
'has-responsive-columns': columns > 1,
[ `has-${ gutter }-gutter` ]: gutter,
'has-text-color': textColor || customTextColor,
[ textClass ]: textClass,
'has-padding': paddingSize && paddingSize !== 'no',
Expand All @@ -57,10 +56,12 @@ const save = ( { attributes, className } ) => {

return (
<div className={ classes }>
<div className={ innerClasses } style={ innerStyles }>
{ BackgroundVideo( attributes ) }
<InnerBlocks.Content />
</div>
<GutterWrapper { ...attributes }>
<div className={ innerClasses } style={ innerStyles }>
{ BackgroundVideo( attributes ) }
<InnerBlocks.Content />
</div>
</GutterWrapper>
</div>
);
};
Expand Down
Loading

0 comments on commit e688df8

Please sign in to comment.