diff --git a/src/blocks.js b/src/blocks.js index 60325ee..db862b1 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -24,6 +24,6 @@ import "./blocks/features-list"; import "./blocks/team-member"; import "./blocks/section"; import "./blocks/before-and-after"; -//import "./blocks/two-columns"; +import "./blocks/pdf-download"; //import "./blocks/fancy-heading"; diff --git a/src/blocks/before-and-after/index.js b/src/blocks/before-and-after/index.js index 83d8158..4cabef1 100644 --- a/src/blocks/before-and-after/index.js +++ b/src/blocks/before-and-after/index.js @@ -39,7 +39,7 @@ const { */ registerBlockType("cgb/block-before-and-after", { - title: __("Before & After", "CGB"), // Block title. + 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")], diff --git a/src/blocks/editor.scss b/src/blocks/editor.scss index 21496b8..5c3e9ce 100644 --- a/src/blocks/editor.scss +++ b/src/blocks/editor.scss @@ -7,9 +7,26 @@ // override the default gutenberg editor width .edit-post-visual-editor .editor-block-list__block { - max-width: 1102px; + max-width: 940px; } +// .editor-block-list__layout .editor-block-list__block { +// padding-left: 32px; +// padding-right: 32px; +// &:before { +// left: 28px; +// right: 28px; +// } +// } + +// .editor-block-list__layout .editor-block-list__block > .editor-block-mover { +// left: -10px; +// } + +// .editor-block-list__layout .editor-block-list__block > .editor-block-settings-menu { +// right: -12px; +// } + .image--circle { border-radius: 100%; } diff --git a/src/blocks/fancy-heading/index.js b/src/blocks/fancy-heading/index.js index 8cb22c5..1a3c945 100644 --- a/src/blocks/fancy-heading/index.js +++ b/src/blocks/fancy-heading/index.js @@ -25,7 +25,7 @@ const { Heading } = wp.components; */ registerBlockType("cgb/block-fancy-heading", { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. - title: __("fancy-heading", "CGB"), // Block title. + title: __("fancy-heading"), // Block title. icon: "heart", // 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: [__("Fancy heading")], diff --git a/src/blocks/features-list/blockControls.js b/src/blocks/features-list/blockControls.js new file mode 100644 index 0000000..e69de29 diff --git a/src/blocks/features-list/index.js b/src/blocks/features-list/index.js index 937e230..4d770d7 100644 --- a/src/blocks/features-list/index.js +++ b/src/blocks/features-list/index.js @@ -3,6 +3,7 @@ * * A simple block to show a feature */ +import classnames from "classnames"; import icons from "../icons"; import Inspector from './inspector'; /** @@ -12,11 +13,12 @@ import Inspector from './inspector'; const { __ } = wp.i18n; // Import __() from wp.i18n const { registerBlockType, - Editable, + RichText, MediaUpload, BlockControls, InnerBlocks, -} = wp.blocks; // Import registerBlockType() from wp.blocks as well as Editable so we can use TinyMCE + BlockAlignmentToolbar +} = wp.blocks; const { Button, Toolbar, @@ -37,7 +39,7 @@ const { */ registerBlockType("cgb/block-feature", { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. - title: __("Feature", "CGB"), // Block title. + title: __("Feature"), // Block title. icon: "heart", // 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: [__("feature"), __("Feature List")], @@ -67,6 +69,10 @@ registerBlockType("cgb/block-feature", { attribute: "alt", selector: "img" }, + circularImg: { + type: "boolean", + default: "false", + }, link: { type: "string", default: "/contact" @@ -74,11 +80,23 @@ registerBlockType("cgb/block-feature", { buttonText: { type: "string", default: "Find out more" + }, + blockAlignment: { + type: 'string', + default: 'center' + }, + }, + + getEditWrapperProps( attributes ) { + const { blockAlignment } = attributes; + if ( 'left' === blockAlignment || 'right' === blockAlignment || 'full' === blockAlignment ) { + return { 'data-align': blockAlignment } } }, // The "edit" property must be a valid function. edit: props => { + const { attributes: { blockAlignment, imgURL, imgAlt, buttonText, link, circularImg }, className } = props; // This control which editable will be focused and falls back to the title editable const focusedEditable = props.focus ? props.focus.editable || "title" @@ -100,17 +118,11 @@ registerBlockType("cgb/block-feature", { }; const onSelectImage = img => { - // fetch the thumb details - const image = new wp.api.models.Media({ id: img.id }) - .fetch() - .done(res => { - const thumb = res.media_details.sizes["square-thumb-small"]; - props.setAttributes({ - imgID: img.id, - imgURL: thumb.source_url, - imgAlt: img.alt - }); - }); + props.setAttributes({ + imgID: img.id, + imgURL: img.url, + imgAlt: img.alt + }); }; const onRemoveImage = () => { props.setAttributes({ @@ -128,16 +140,42 @@ registerBlockType("cgb/block-feature", { props.setAttributes({ buttonText: value }); }; + const updateAlignment = nextAlign => { + props.setAttributes({ + blockAlignment: nextAlign + }); + }; + + const onChangeImgType = value => { + props.setAttributes({ circularImg: value }); + }; + + const imgClasses = classnames( + 'center-block', + circularImg ? `image--circle` : null + ); + return [ !!props.focus && ( ), -
+ !!props.focus && ( + + + + ), +
{!attributes.imgID ? ( {attributes.imgAlt} {props.focus ? ( - ) : null} @@ -169,7 +207,7 @@ registerBlockType("cgb/block-feature", { )}
-
@@ -200,22 +238,33 @@ registerBlockType("cgb/block-feature", { // The "save" property must be specified and must be a valid function. save: function(props) { + + const { attributes: { blockAlignment, imgURL, imgAlt, title, description, buttonText, link }, classNames } = props; + + const classes = classnames( + classNames, + blockAlignment ? `flex--align${blockAlignment}` : null + ); + return ( -
- {props.attributes.imgAlt} +
+
+ { +
-

{props.attributes.title}

+

{ title }

- {props.attributes.description} + { description }
- - {props.attributes.buttonText} + + { buttonText }
diff --git a/src/blocks/features-list/inspector.js b/src/blocks/features-list/inspector.js index e8f5470..7a24bbc 100644 --- a/src/blocks/features-list/inspector.js +++ b/src/blocks/features-list/inspector.js @@ -4,47 +4,53 @@ const { __ } = wp.i18n; const { Component } = wp.element; const { - InspectorControls, - BlockDescription, + InspectorControls, } = wp.blocks; const { - Toolbar, - Button, - PanelBody, - PanelRow, - TextControl + PanelBody, + PanelRow, + TextControl, + ToggleControl, } = wp.components; /** * Create an Inspector Controls wrapper Component */ export default class Inspector extends Component { + constructor( props ) { + super( ...arguments ); + } - constructor( props ) { - super( ...arguments ); - } - - render() { - return ( - - - - - - - - - - - ); - } - -} \ No newline at end of file + render() { + const { attributes: { link, buttonText, circularImg }, onChangeLink, onChangeButtonText, onChangeImgType } = this.props; + return ( + + + + + + + + + + + + + + + + ); + } +} diff --git a/src/blocks/pdf-download/index.js b/src/blocks/pdf-download/index.js new file mode 100644 index 0000000..ffd8981 --- /dev/null +++ b/src/blocks/pdf-download/index.js @@ -0,0 +1,156 @@ +/** + * BLOCK: PDF Download + * + * A simple block to show a pdf download link + */ +import icons from "../icons"; +import Inspector from './inspector'; +/** + * Internal block libraries + */ + +const { __ } = wp.i18n; // Import __() from wp.i18n +const { + registerBlockType, + RichText, + BlockControls, +} = wp.blocks; +const { + Button, + Toolbar, + Tooltip, + Dashicon, + TextControl +} = wp.components; +/** + * Register: aa Gutenberg Block. + * + * Registers a new block provided a unique name and an object defining its + * behavior. Once registered, the block is made editor as an option to any + * editor interface where blocks are implemented. + * + * @param {string} name Block name. + * @param {Object} settings Block settings. + * @return {?WPBlock} The block, if it has been successfully + * registered; otherwise `undefined`. + */ +registerBlockType("cgb/block-pdf-download", { + // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. + title: __("PDF Download"), // Block title. + icon: "nametag", // 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: [__("pdf"), __("PDF Download")], + attributes: { + title: { + type: "string", + source: "children", + selector: "h3" + }, + description: { + type: "array", + source: "children", + selector: ".pdf-download__description" + }, + // imgURL: { + // type: "string", + // }, + // imgID: { + // type: "number", + // }, + // imgAlt: { + // type: "string", + // }, + url: { + type: "string" + } + }, + + // The "edit" property must be a valid function. + edit: props => { + // This control which editable will be focused and falls back to the title editable + const focusedEditable = props.focus + ? props.focus.editable || "title" + : null; + + const attributes = props.attributes; + + const onChangeTitle = value => { + props.setAttributes({ title: value }); + }; + const onFocusTitle = focus => { + props.setFocus(_.extend({}, focus, { editable: "title" })); + }; + + const onChangeDescription = value => { + props.setAttributes({ description: value }); + }; + const onFocusDescription = focus => { + props.setFocus(_.extend({}, focus, { editable: "description" })); + }; + + const onChangeUrl = value => { + props.setAttributes({ url: value }) + } + + // const onSelectImage = img => { + // props.setAttributes({ + // imgID: img.id, + // imgURL: img.url, + // imgAlt: img.alt, + // }); + // }; + // const onRemoveImage = () => { + // props.setAttributes({ + // imgID: null, + // imgURL: null, + // imgAlt: null + // }); + // }; + + return [ + !!props.focus && ( + + ), +
+
+ + +
+ +
+
+
+ ]; + }, + + // The "save" property must be specified and must be a valid function. + save: function(props) { + return ( + +
+

{props.attributes.title}

+
+ {props.attributes.description} +
+
+
+ ); + } +}); diff --git a/src/blocks/pdf-download/inspector.js b/src/blocks/pdf-download/inspector.js new file mode 100644 index 0000000..4855816 --- /dev/null +++ b/src/blocks/pdf-download/inspector.js @@ -0,0 +1,76 @@ +/** + * Internal block libraries + */ +const { __ } = wp.i18n; +const { Component } = wp.element; +const { + InspectorControls, + MediaUpload, + UrlInput, +} = wp.blocks; +const { + Toolbar, + Button, + PanelBody, + PanelRow, +} = wp.components; + +import icons from '../icons'; + +/** + * Create an Inspector Controls wrapper Component + */ +export default class Inspector extends Component { + constructor( props ) { + super( ...arguments ); + } + + render() { + const { attributes: { url }, onChangeUrl } = this.props; + return ( + + + + + + + + { /* {!this.props.attributes.imgID ? ( + ( + + )} + /> + ) : ( +
+ {this.props.attributes.imgAlt} + {this.props.focus ? ( + + ) : null} +
+ )} */ } + +
+
+
+ ); + } +} diff --git a/src/blocks/section/index.js b/src/blocks/section/index.js index e5c2eaa..0da6c80 100644 --- a/src/blocks/section/index.js +++ b/src/blocks/section/index.js @@ -39,7 +39,7 @@ const validAlignments = ["wide", "full"]; */ registerBlockType("cgb/block-section", { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. - title: __("Section", "CGB"), // Block title. + title: __("Section"), // Block title. icon: "editor-table", // 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: [__("team"), __("Section")], diff --git a/src/blocks/section/inspector.js b/src/blocks/section/inspector.js index 435a3b4..9aa906c 100644 --- a/src/blocks/section/inspector.js +++ b/src/blocks/section/inspector.js @@ -4,70 +4,67 @@ const { __ } = wp.i18n; const { Component } = wp.element; const { - InspectorControls, - BlockDescription, - ColorPalette, + InspectorControls, + ColorPalette, } = wp.blocks; const { - PanelBody, - PanelRow, - PanelColor, - TextControl, + PanelBody, + PanelRow, + PanelColor, + TextControl, } = wp.components; /** * Create an Inspector Controls wrapper Component */ export default class Inspector extends Component { + constructor( props ) { + super( ...arguments ); + } - constructor( props ) { - super( ...arguments ); - } + render() { + return ( + + + + + + + + + - render() { - return ( - - - - - - - - - + + + - - - - - - - - - - ); - } - -} \ No newline at end of file + + + + + + ); + } +} diff --git a/src/blocks/team-member/index.js b/src/blocks/team-member/index.js index f8f38b7..f7778db 100644 --- a/src/blocks/team-member/index.js +++ b/src/blocks/team-member/index.js @@ -39,7 +39,7 @@ const { */ registerBlockType("cgb/block-team-member", { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. - title: __("Team Member", "CGB"), // Block title. + title: __("Team Member"), // Block title. icon: "nametag", // 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: [__("team"), __("Team Member")], diff --git a/src/blocks/text-and-image/index.js b/src/blocks/text-and-image/index.js index 6e7add5..141ed80 100644 --- a/src/blocks/text-and-image/index.js +++ b/src/blocks/text-and-image/index.js @@ -7,7 +7,7 @@ /** * Block Dependencies */ -import icons from "../icons"; +import icons from '../icons'; import Inspector from './inspector'; /** * Internal block libraries @@ -16,20 +16,15 @@ import Inspector from './inspector'; const { __ } = wp.i18n; // Import __() from wp.i18n const { registerBlockType, - Editable, MediaUpload, BlockControls, InnerBlocks, - InspectorControls } = wp.blocks; // Import registerBlockType() from wp.blocks as well as Editable so we can use TinyMCE const { Button, Toolbar, Tooltip, Dashicon, - PanelBody, - PanelRow, - TextControl } = wp.components; /** * Register: aa Gutenberg Block. @@ -43,163 +38,160 @@ const { * @return {?WPBlock} The block, if it has been successfully * registered; otherwise `undefined`. */ -registerBlockType("cgb/block-text-and-image", { +registerBlockType( 'cgb/block-text-and-image', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. - title: __("Text & Image", "CGB"), // 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: [__("text-and-image — CGB Block"), __("Text and Image")], + title: __( 'Text & Image' ), // 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: [ __( 'text-and-image — CGB Block' ), __( 'Text and Image' ) ], attributes: { message: { - type: "array", - source: "children", - selector: ".message-body" + type: 'array', + source: 'children', + selector: '.message-body', }, imgURL: { - type: "string", - source: "attribute", - attribute: "src", - selector: "img" + type: 'string', + source: 'attribute', + attribute: 'src', + selector: 'img', }, imgID: { - type: "number" + type: 'number', }, imgAlt: { - type: "string", - source: "attribute", - attribute: "alt", - selector: "img" + type: 'string', + source: 'attribute', + attribute: 'alt', + selector: 'img', }, textFirstAlignment: { - type: "boolean", - default: false + type: 'boolean', + default: false, }, columnWidth: { - type: "number", + type: 'number', default: 50, - } + }, }, // The "edit" property must be a valid function. edit: props => { - const onChangeMessage = value => { - props.setAttributes({ message: value }); - }; const onSelectImage = img => { - props.setAttributes({ + props.setAttributes( { imgID: img.id, imgURL: img.url, - imgAlt: img.alt - }); + imgAlt: img.alt, + } ); }; const onRemoveImage = () => { - props.setAttributes({ + props.setAttributes( { imgID: null, imgURL: null, - imgAlt: null - }); + imgAlt: null, + } ); }; const toggleTextFirstAlignment = () => { - props.setAttributes({ - textFirstAlignment: !props.attributes.textFirstAlignment - }); + props.setAttributes( { + textFirstAlignment: ! props.attributes.textFirstAlignment, + } ); }; const onChangeColumnWidth = value => { - props.setAttributes({ - columnWidth: value - }) + props.setAttributes( { + columnWidth: value, + } ); }; return [ !! props.focus && ( - ), -
- {!!props.focus && ( + ), +
+ { !! props.focus && ( - + - )} + ) }
-
+
-
- {!props.attributes.imgID ? ( +
+ { ! props.attributes.imgID ? ( ( + value={ props.attributes.imgID } + render={ ( { open } ) => ( - )} + ) } /> ) : (
{props.attributes.imgAlt} - {props.focus ? ( - - ) : null} + ) : null }
- )} + ) }
-
+
, ]; }, // The "save" property must be specified and must be a valid function. - save: function(props) { - const colOrder = props.attributes.textFirstAlignment - ? "row-reverse" - : "row"; + save: function( props ) { + const colOrder = props.attributes.textFirstAlignment ? + 'row-reverse' : + 'row'; return ( -
-
-
+
+
+
-
- {props.attributes.imgAlt} +
+ {
); - } -}); + }, +} ); diff --git a/src/blocks/text-and-image/inspector.js b/src/blocks/text-and-image/inspector.js index 54c2e18..e4526ff 100644 --- a/src/blocks/text-and-image/inspector.js +++ b/src/blocks/text-and-image/inspector.js @@ -4,52 +4,40 @@ const { __ } = wp.i18n; const { Component } = wp.element; const { - InspectorControls, - BlockDescription, + InspectorControls, } = wp.blocks; const { - Toolbar, - Button, - PanelBody, - PanelRow, - RangeControl + PanelBody, + PanelRow, + RangeControl, } = wp.components; /** * Create an Inspector Controls wrapper Component */ export default class Inspector extends Component { - - constructor( props ) { - super( ...arguments ); - } - - render() { - return ( - - - -

{ __( 'Block settings' ) }

-
- - - - - - - - -
- ); - } - -} \ No newline at end of file + render() { + const { attributes: { columnWidth }, onChangeColumnWidth } = this.props; + + return ( + + + + + + + + + + ); + } +} diff --git a/src/blocks/two-columns/index.js b/src/blocks/two-columns/index.js deleted file mode 100644 index 819d09c..0000000 --- a/src/blocks/two-columns/index.js +++ /dev/null @@ -1,163 +0,0 @@ -/** - * BLOCK: Two Columns - * - * A temporary block to show 2 columns until the native columns block improves - */ - -/** - * Block Dependencies - */ -import icons from "../icons"; -import Inspector from './inspector'; -import { times } from 'lodash'; -import memoize from 'memize'; -/** - * Internal block libraries - */ - -const { __, sprintf } = wp.i18n; // Import __() from wp.i18n -const { - registerBlockType, - BlockControls, - InnerBlocks, - InspectorControls -} = wp.blocks; // Import registerBlockType() from wp.blocks as well as Editable so we can use TinyMCE -const { - Button, - Toolbar, - Tooltip, - Dashicon, - PanelBody, - PanelRow, - TextControl -} = wp.components; - -/** - * Returns the layouts configuration for a given number of columns. - * - * @param {number} columns Number of columns. - * - * @return {Object[]} Columns layout configuration. - */ -const getColumnLayouts = memoize( ( columns ) => { - return times( columns, ( n ) => ( { - name: `column-${ n + 1 }`, - label: sprintf( __( 'Column %d' ), n + 1 ), - icon: 'columns', - } ) ); -} ); - -/** - * Register: aa Gutenberg Block. - * - * Registers a new block provided a unique name and an object defining its - * behavior. Once registered, the block is made editor as an option to any - * editor interface where blocks are implemented. - * - * @param {string} name Block name. - * @param {Object} settings Block settings. - * @return {?WPBlock} The block, if it has been successfully - * registered; otherwise `undefined`. - */ -registerBlockType("cgb/block-two-columns", { - // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. - title: __("Two Columns", "CGB"), // Block title. - icon: "dashicons-screenoptions", // Block icon from Dashicons - category: "layout", // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. - keywords: [__("two-columns — CGB Block"), __("Two Columns")], - attributes: { - columns: { - type: 'number', - default: 2, - }, - textFirstAlignment: { - type: "boolean", - default: false - }, - columnWidth: { - type: "number", - default: 50, - } - }, - - // The "edit" property must be a valid function. - edit: props => { - - const toggleTextFirstAlignment = () => { - props.setAttributes({ - textFirstAlignment: !props.attributes.textFirstAlignment - }); - }; - const onChangeColumnWidth = value => { - props.setAttributes({ - columnWidth: value - }) - }; - return [ - !! props.focus && ( - - ), -
- {!!props.focus && ( - - - - - - - - )} - -
-
- -
-
- -
-
-
- ]; - }, - - // The "save" property must be specified and must be a valid function. - save: function(props) { - const colOrder = props.attributes.textFirstAlignment - ? "row-reverse" - : "row"; - return ( -
-
-
- -
-
- -
-
-
- ); - } -}); diff --git a/src/blocks/two-columns/inspector.js b/src/blocks/two-columns/inspector.js deleted file mode 100644 index 54c2e18..0000000 --- a/src/blocks/two-columns/inspector.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Internal block libraries - */ -const { __ } = wp.i18n; -const { Component } = wp.element; -const { - InspectorControls, - BlockDescription, -} = wp.blocks; -const { - Toolbar, - Button, - PanelBody, - PanelRow, - RangeControl -} = wp.components; - -/** - * Create an Inspector Controls wrapper Component - */ -export default class Inspector extends Component { - - constructor( props ) { - super( ...arguments ); - } - - render() { - return ( - - - -

{ __( 'Block settings' ) }

-
- - - - - - - - -
- ); - } - -} \ No newline at end of file diff --git a/src/common.scss b/src/common.scss index deccc33..bb50aec 100644 --- a/src/common.scss +++ b/src/common.scss @@ -60,3 +60,14 @@ $team-member__img--width: 120px; padding: calc(1em + calc(#{$team-member__img--width} / 2)) 1em 1em; } } + +.wp-block-cgb-block-pdf-download { + padding: 1rem; + + margin: 1rem 0; + background-color: #3ab4d2; + border-left: 5px solid darken(#3ab4d2, 10%); + float: left; + width: 100%; + h3, p { margin-bottom: 0; margin-top: 0; color: #fff; } +}