Skip to content
This repository has been archived by the owner on Mar 18, 2020. It is now read-only.

Commit

Permalink
Updated for v3+ deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
gubbigubbi committed May 21, 2018
1 parent 7168791 commit b21e01e
Show file tree
Hide file tree
Showing 9 changed files with 607 additions and 463 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"eject": "cgb-scripts eject"
},
"dependencies": {
"cgb-scripts": "1.9.5",
"cgb-scripts": "1.9.6",
"classnames": "^2.2.5",
"lodash": "^4.17.10",
"memize": "^1.0.5",
Expand Down
148 changes: 71 additions & 77 deletions src/blocks/before-and-after/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,17 @@
/**
* Block Dependencies
*/
import icons from "../icons";
import icons from '../icons';
/**
* Internal block libraries
*/

const { __ } = wp.i18n; // Import __() from wp.i18n
const {
registerBlockType,
MediaUpload,
BlockControls,
InnerBlocks,
} = wp.blocks;
const {
Button,
Toolbar,
Tooltip,
Dashicon,
} = wp.components;
const { registerBlockType } = wp.blocks;

const { MediaUpload } = wp.editor;

const { Button } = wp.components;
/**
* Register: aa Gutenberg Block.
*
Expand All @@ -37,71 +30,65 @@ const {
* @return {?WPBlock} The block, if it has been successfully
* registered; otherwise `undefined`.
*/
registerBlockType("cgb/block-before-and-after", {

title: __("Before & After"), // Block title.
icon: "image-flip-horizontal", // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
category: "common", // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
keywords: [__("before-and-after — CGB Block"), __("Before & After")],
registerBlockType('cgb/block-before-and-after', {
title: __('Before & After'), // Block title.
icon: 'image-flip-horizontal', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
category: 'common', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
keywords: [__('before-and-after — CGB Block'), __('Before & After')],
attributes: {
beforeImgURL: {
type: "string",
type: 'string',
},
beforeImgID: {
type: "number"
type: 'number',
},

afterImgURL: {
type: "string",
type: 'string',
},
afterImgID: {
type: "number"
type: 'number',
},

},

// The "edit" property must be a valid function.
edit: props => {

const onSelectBeforeImage = img => {
props.setAttributes({
beforeImgID: img.id,
beforeImgURL: img.url,

});
};
const onRemoveBeforeImage = () => {
props.setAttributes({
beforeImgID: null,
beforeImgURL: null,

});
};
};

const onSelectAfterImage = img => {
props.setAttributes({
afterImgID: img.id,
afterImgURL: img.url,

});
};
const onRemoveAfterImage = () => {
props.setAttributes({
afterImgID: null,
afterImgURL: null,

});
};

return [

<div className={props.className}>
<div className="flex align--centre">
<div style={{
flex: 1,
display: 'flex',
justifyContent: 'center'
}}>
<div className="flex align--centre">
<div
style={{
flex: 1,
display: 'flex',
justifyContent: 'center',
}}
>
{!props.attributes.beforeImgID ? (
<MediaUpload
onSelect={onSelectBeforeImage}
Expand All @@ -118,23 +105,22 @@ registerBlockType("cgb/block-before-and-after", {
/>
) : (
<div className="position-relative">
<img
src={props.attributes.beforeImgURL}
/>

<Button className="remove-image" onClick={onRemoveBeforeImage}>
{icons.remove}
</Button>

<img src={props.attributes.beforeImgURL} />

<Button className="remove-image" onClick={onRemoveBeforeImage}>
{icons.remove}
</Button>
</div>
)}
</div>

<div style={{
flex: 1,
display: 'flex',
justifyContent: 'center'
}}>
<div
style={{
flex: 1,
display: 'flex',
justifyContent: 'center',
}}
>
{!props.attributes.afterImgID ? (
<MediaUpload
onSelect={onSelectAfterImage}
Expand All @@ -151,41 +137,49 @@ registerBlockType("cgb/block-before-and-after", {
/>
) : (
<div className="position-relative">
<img
src={props.attributes.afterImgURL}
/>

<Button className="remove-image" onClick={onRemoveAfterImage}>
{icons.remove}
</Button>

<img src={props.attributes.afterImgURL} />

<Button className="remove-image" onClick={onRemoveAfterImage}>
{icons.remove}
</Button>
</div>
)}
</div>
</div>
</div>
</div>
</div>,
];
},

// The "save" property must be specified and must be a valid function.
save: function(props) {

return (
<div className={props.className}>
<div className="be__container">
<div id="be__comparison">
<figure className="be__figure" style={{
backgroundImage: `url( ${props.attributes.beforeImgURL} )`
}}>
<div className="be__handle"></div>
<div className="be__divisor" style={{
backgroundImage: `url( ${props.attributes.afterImgURL} )`
}} ></div>
</figure>
<input type="range" min="0" max="100" value="50" className="be__slider" />
</div>
</div>
<div className="be__container">
<div id="be__comparison">
<figure
className="be__figure"
style={{
backgroundImage: `url( ${props.attributes.beforeImgURL} )`,
}}
>
<div className="be__handle" />
<div
className="be__divisor"
style={{
backgroundImage: `url( ${props.attributes.afterImgURL} )`,
}}
/>
</figure>
<input
type="range"
min="0"
max="100"
value="50"
className="be__slider"
/>
</div>
</div>
</div>
);
}
});
},
});
Loading

0 comments on commit b21e01e

Please sign in to comment.