Skip to content

Commit

Permalink
Media controler
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrillaz committed Oct 29, 2020
1 parent 86e2f33 commit 7560a3d
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 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.1
* Version: 1.1.2
* 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' => '4efdc7ca779cc18f45231013227c2066'), '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' => '436bdb2481a9e4dbe3e29c98d55f57bd'), '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.

15 changes: 11 additions & 4 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.1
Stable tag: 1.1.2
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 @@ -43,11 +43,18 @@ directory take precedence. For example, `/assets/screenshot-1.png` would win ove

1. added new block map-block to use google maps in editor

== 1.1.0 ==
= 1.1.0 =
1. Google map block fixed

== 1.1.1 ==
Added location icon to core/button
= 1.1.1 =

* Patch 1.1.1

1. Added location icon to core/button

* Patch 1.1.2

1. Added global block control for media query display

== Arbitrary section ==

Expand Down
69 changes: 69 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import * as googleMap from './blocks/google-map/index'

import { addFilter } from '@wordpress/hooks'

import { __ } from '@wordpress/i18n'
import { createHigherOrderComponent } from '@wordpress/compose'
import { Fragment } from '@wordpress/element'
import { InspectorControls } from '@wordpress/block-editor'
import { PanelBody, ToggleControl } from '@wordpress/components'

import {
addInlineIconAttribute,
withIcon
Expand Down Expand Up @@ -35,6 +41,69 @@ const registerNoorBlocks = () => [

registerNoorBlocks();

const mediaQueryControl = (settings, name) => {

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>
);
}, 'mediaControl');

const mediaExtraProps = ( props, blockType, attributes ) => {

if ( ! attributes.mediaControl ) {

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

return props;
}

// MEDIA DISPLAY SWITCH
addFilter(
'blocks.registerBlockType',
'noor/gutenberg-blocks/custom-attributes',
mediaQueryControl
);

addFilter(
'editor.BlockEdit',
'noor/gutenberg-blocks/custom-control',
mediaControl
);

addFilter(
'blocks.getSaveContent.extraProps',
'noor/gutenberg-blocks/extraProps',
mediaExtraProps
);

// CORE/BUTTON
addFilter(
'blocks.registerBlockType',
Expand Down

0 comments on commit 7560a3d

Please sign in to comment.