Skip to content

Commit

Permalink
mobile view control patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrillaz committed Oct 29, 2020
1 parent 7560a3d commit 3918074
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 43 deletions.
2 changes: 1 addition & 1 deletion blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Noor Blocks
* Description: Collection of custom blocks.
* Version: 1.1.2
* Version: 1.1.3
* Author: Noor Digital Agency
* Author URI: https://noordigital.com
* Text Domain: blocks
Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('index.js' => array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-polyfill'), 'version' => '436bdb2481a9e4dbe3e29c98d55f57bd'), 'accordion.js' => array('dependencies' => array('wp-polyfill'), 'version' => '954a5ccf99e04153addabfadf70be9cd'));
<?php return array('index.js' => array('dependencies' => array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-polyfill'), 'version' => '5864c2db1ff2d5760679b23e22a3bfb6'), 'accordion.js' => array('dependencies' => array('wp-polyfill'), 'version' => '954a5ccf99e04153addabfadf70be9cd'));
2 changes: 1 addition & 1 deletion build/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors:
Tags: block
Requires at least: 5.3.2
Tested up to: 5.4.1
Stable tag: 1.1.2
Stable tag: 1.1.3
Requires PHP: 7.0.0
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -52,7 +52,7 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove

1. Added location icon to core/button

* Patch 1.1.2
* Patch 1.1.3

1. Added global block control for media query display

Expand Down
13 changes: 12 additions & 1 deletion src/blocks/accordion/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RadioGroup } from '../../components/radio-group'

export default function Edit( props ) {

const { titleColor, setTitleColor, titleBackground, setTitleBackground, contentBackground, setContentBackground, attributes, setAttributes } = props;
const { titleColor, setTitleColor, titleBackground, setTitleBackground, contentBackground, setContentBackground, attributes, setAttributes, mediaControl } = props;

const [expanded, setExpanded] = useState(false);

Expand Down Expand Up @@ -79,6 +79,17 @@ export default function Edit( props ) {
showIcons={true}
/>
</PanelBody>

<PanelBody
title={ __( 'Mobile View Control' ) }
initialOpen={ true }
>
<ToggleControl
label={__(`${props.attributes.mediaControl ? 'Display' : 'Hide'} on mobile`)}
checked={props.attributes.mediaControl}
onChange={mediaControl => props.setAttributes({ mediaControl })}
/>
</PanelBody>

<PanelColorSettings
title={__('Color settings')}
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/accordion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export const settings = {
iconAlignment: {
type: 'string',
default: 'right'
},
mediaControl: {
type: 'boolean',
default: true
}
},
edit: withColors({
Expand Down
6 changes: 4 additions & 2 deletions src/blocks/accordion/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { InnerBlocks, RichText, getColorClassName } from '@wordpress/block-edito

export default function save( { attributes } ) {

const { titleColor, titleBackground, contentBackground } = attributes;
const { titleColor, titleBackground, contentBackground, mediaControl } = attributes;

const titleColorClass = titleColor != undefined ? getColorClassName('color', titleColor) : '';

const titleBackgroundClass = titleBackground != undefined ? getColorClassName('background-color', titleBackground) : '';

const contentBackgroundClass = contentBackground != undefined ? getColorClassName('background-color', contentBackground) : '';

const hide = mediaControl ? '' : 'on-media-hide';

return (
<>
<div
id={`#${attributes.anchorContent}`}
className={`noor-block-accordion ${titleBackgroundClass}`} aria-expanded={attributes.initialState}
className={`noor-block-accordion ${titleBackgroundClass} ${hide}`} aria-expanded={attributes.initialState}
>
<RichText.Content
className={`noor-block-accordion__title ${titleColorClass}`}
Expand Down
17 changes: 14 additions & 3 deletions src/blocks/bulletpoint/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { PanelBody, Button, ResponsiveWrapper, __experimentalInputControl as Inp
import { Fragment } from '@wordpress/element'

export default function Edit( props ) {

const {color, setColor, backgroundColor, setBackgroundColor, attributes, setAttributes, className} = props;

const { align, mediaId } = attributes;
const { align, mediaId, mediaControl } = attributes;

const colorClass = color.class != undefined ? color.class : '';

Expand All @@ -29,7 +29,7 @@ export default function Edit( props ) {

const blockStyle = {
backgroundImage: attributes.mediaUrl != '' ? 'url("' + attributes.mediaUrl + '")' : 'none'
};
};

return (
<Fragment>
Expand Down Expand Up @@ -73,6 +73,17 @@ export default function Edit( props ) {
/>}
</PanelBody>

<PanelBody
title={ __( 'Mobile View Control' ) }
initialOpen={ true }
>
<ToggleControl
label={__(`${props.attributes.mediaControl ? 'Display' : 'Hide'} on mobile`)}
checked={props.attributes.mediaControl}
onChange={mediaControl => props.setAttributes({ mediaControl })}
/>
</PanelBody>

<PanelColorSettings
title={__( 'Colot settings' )}
initialOpen={true}
Expand Down
10 changes: 8 additions & 2 deletions src/blocks/bulletpoint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const settings = {
mediaUrl: {
type: 'string',
default: ''
},
mediaControl: {
type: 'boolean',
default: true
}
},
edit: compose(
Expand All @@ -50,14 +54,16 @@ export const settings = {
}))( Edit ),
save: ({ attributes }) => {

const {color, backgroundColor, align} = attributes;
const {color, backgroundColor, align, mediaControl} = attributes;

const colorClass = color != undefined ? getColorClassName( 'color', color ) : '';

const backgroundColorClass = backgroundColor != undefined ? getColorClassName('background-color', backgroundColor) : '';

const hide = mediaControl ? '' : 'on-media-hide';

return (
<div class={`noor-block-bullet-point has-align-${align}`}>
<div className={`noor-block-bullet-point has-align-${align} ${hide}`}>
<div className={`noor-block-bullet-point__point ${backgroundColorClass}`}>
{attributes.useMedia && attributes.mediaId != 0
? <img src={attributes.mediaUrl} />
Expand Down
13 changes: 12 additions & 1 deletion src/blocks/google-map/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Edit ( props ) {

const { attributes, setAttributes } = props;

const { width, height, zoom, address } = attributes;
const { width, height, zoom, address, mediaControl } = attributes;

const getaddress = Object.values(address).filter(line => line != '');

Expand Down Expand Up @@ -75,6 +75,17 @@ export default function Edit ( props ) {
onChange={country => setAttributes({ address: { ...address, country } })}
/>
</PanelBody>

<PanelBody
title={ __( 'Mobile View Control' ) }
initialOpen={ true }
>
<ToggleControl
label={__(`${props.attributes.mediaControl ? 'Display' : 'Hide'} on mobile`)}
checked={props.attributes.mediaControl}
onChange={mediaControl => props.setAttributes({ mediaControl })}
/>
</PanelBody>
</InspectorControls>

<div className="noor-block-google-map" style={styles}>
Expand Down
6 changes: 5 additions & 1 deletion src/blocks/google-map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ export const settings = {
},
src: {
type: 'string'
},
mediaControl: {
type: 'boolean',
default: true
}
},
edit: Edit,
save: ( props ) => {

const {width, height, src } = props.attributes;

props.className = 'noor-block-google-map';
props.className = `noor-block-google-map ${props.attributes.mediaControl ? '' : 'on-media-hide'}`;

return (
<div className={props.className} style={{width: `${width}%`, paddingBottom: `${height}%`}}>
Expand Down
64 changes: 36 additions & 28 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,49 @@ registerNoorBlocks();

const mediaQueryControl = (settings, name) => {

Object.assign(settings.attributes, {
mediaControl: {
type: 'boolean',
default: true
}
});
if ( ! name.includes( 'noor' ) ) {

Object.assign(settings.attributes, {
mediaControl: {
type: 'boolean',
default: true
}
});
}

return settings;
}

const mediaControl = createHigherOrderComponent( BlockEdit => props => {

return (
<Fragment>
<BlockEdit {...props} />

<InspectorControls>
<PanelBody
title={ __( 'Mobile View Control' ) }
initialOpen={ true }
>
<ToggleControl
label={__('Display on mobile')}
checked={props.attributes.mediaControl}
onChange={mediaControl => props.setAttributes({ mediaControl })}
/>
</PanelBody>
</InspectorControls>
</Fragment>
);
const mediaControl = createHigherOrderComponent( BlockEdit => props => {

if ( ! props.name.includes( 'noor' ) ) {

return (
<Fragment>
<BlockEdit {...props} />

<InspectorControls>
<PanelBody
title={ __( 'Mobile View Control' ) }
initialOpen={ true }
>
<ToggleControl
label={__(`${props.attributes.mediaControl ? 'Display' : 'Hide'} on mobile`)}
checked={props.attributes.mediaControl}
onChange={mediaControl => props.setAttributes({ mediaControl })}
/>
</PanelBody>
</InspectorControls>
</Fragment>
);
}

return <BlockEdit {...props} />
}, 'mediaControl');

const mediaExtraProps = ( props, blockType, attributes ) => {
if ( ! attributes.mediaControl ) {

if ( ! attributes.mediaControl && ! blockType.name.includes('noor') ) {

props.className = props.className + ' on-media-hide';
}
Expand Down

0 comments on commit 3918074

Please sign in to comment.