Compare commits
5 Commits
a53a0c2cc0
...
a4d764b510
| Author | SHA1 | Date | |
|---|---|---|---|
| a4d764b510 | |||
| beb4ca8e6c | |||
| e11cdede0b | |||
| 007bc6cbac | |||
| 5a3d5f148a |
36
web/app/themes/badegg/app/API/Admin.php
Normal file
36
web/app/themes/badegg/app/API/Admin.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\API;
|
||||||
|
|
||||||
|
class Admin
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
add_action( 'rest_api_init', [$this, 'blocks']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function blocks( )
|
||||||
|
{
|
||||||
|
register_rest_route('badegg/v1', '/blocks/container_width', [
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => [ $this, 'container_width'],
|
||||||
|
'permission_callback' => function(){
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function container_width()
|
||||||
|
{
|
||||||
|
$containerWidths = [
|
||||||
|
[ 'label' => __('Auto', 'badegg'), 'value' => 0 ],
|
||||||
|
[ 'label' => __('Narrow', 'badegg'), 'value' => 'narrow' ],
|
||||||
|
[ 'label' => __('Small', 'badegg'), 'value' => 'small' ],
|
||||||
|
[ 'label' => __('Medium', 'badegg'), 'value' => 'medium' ],
|
||||||
|
[ 'label' => __('Large', 'badegg'), 'value' => 'large' ],
|
||||||
|
[ 'label' => __('Edge to edge', 'badegg'), 'value' => 'full' ],
|
||||||
|
];
|
||||||
|
|
||||||
|
return rest_ensure_response($containerWidths);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,21 +57,8 @@ autoload_psr4('PostTypes');
|
|||||||
autoload_psr4('ACF');
|
autoload_psr4('ACF');
|
||||||
autoload_psr4('Utilities');
|
autoload_psr4('Utilities');
|
||||||
autoload_psr4('Admin');
|
autoload_psr4('Admin');
|
||||||
autoload_psr4('Ajax');
|
autoload_psr4('API');
|
||||||
|
|
||||||
function autoload_psr4_blocks() {
|
|
||||||
$path = __dir__ . '/resources/views/acf-blocks/*';
|
|
||||||
$namespace = 'Blocks\\';
|
|
||||||
|
|
||||||
foreach(glob($path, GLOB_ONLYDIR) as $directory) {
|
|
||||||
$name = basename($directory);
|
|
||||||
$class = $namespace . $name . '\\' . $name;
|
|
||||||
|
|
||||||
new $class();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
autoload_psr4_blocks();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -142,11 +142,7 @@ hr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.align {
|
.align {
|
||||||
&-centre {
|
&-left { text-align: left; }
|
||||||
text-align: center;
|
&-centre, &-center { text-align: center; }
|
||||||
}
|
&-right { text-align: right; }
|
||||||
|
|
||||||
&-right {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"apiVersion": 3,
|
||||||
"name": "badegg/acfdemo",
|
"name": "badegg/acfdemo",
|
||||||
"title": "ACF Demo",
|
"title": "ACF Demo",
|
||||||
"category": "badegg",
|
"category": "badegg",
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
// block.json's editorScript, loaded only in the block editor
|
// block.json's editorScript, loaded only in the block editor
|
||||||
console.log('loaded: resources/views/blocks/acfdemo/index.js')
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
// block.json's script, loaded in block editor and front end
|
// block.json's script, loaded in block editor and front end
|
||||||
console.log('loaded: resources/views/blocks/acf-demo/script.js')
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
// block.json's viewScript, applied on front end only
|
// block.json's viewScript, applied on front end only
|
||||||
console.log('loaded: resources/views/blocks/acf-demo/view.js')
|
|
||||||
|
|||||||
@@ -8,9 +8,25 @@
|
|||||||
"foreground": "#f58762"
|
"foreground": "#f58762"
|
||||||
},
|
},
|
||||||
"description": "A wrapper to contain core blocks",
|
"description": "A wrapper to contain core blocks",
|
||||||
|
"attributes": {
|
||||||
|
"container_width": {
|
||||||
|
"type": "string",
|
||||||
|
"default": 0
|
||||||
|
},
|
||||||
|
"alignment": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"padding_top": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
},
|
||||||
|
"padding_bottom": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true
|
||||||
|
}
|
||||||
|
},
|
||||||
"supports": {
|
"supports": {
|
||||||
"html": true,
|
"html": true,
|
||||||
"align": ["wide", "full"],
|
|
||||||
"color": {
|
"color": {
|
||||||
"background": true,
|
"background": true,
|
||||||
"text": false
|
"text": false
|
||||||
|
|||||||
@@ -1,17 +1,93 @@
|
|||||||
// block.json's editorScript, loaded only in the block editor
|
// block.json's editorScript, loaded only in the block editor
|
||||||
|
|
||||||
|
import { __ } from '@wordpress/i18n';
|
||||||
import { registerBlockType } from '@wordpress/blocks';
|
import { registerBlockType } from '@wordpress/blocks';
|
||||||
import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
|
|
||||||
|
import {
|
||||||
|
useBlockProps,
|
||||||
|
InnerBlocks,
|
||||||
|
InspectorControls,
|
||||||
|
BlockControls,
|
||||||
|
AlignmentToolbar,
|
||||||
|
} from '@wordpress/block-editor';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Panel,
|
||||||
|
PanelBody,
|
||||||
|
PanelRow,
|
||||||
|
SelectControl,
|
||||||
|
ToggleControl,
|
||||||
|
} from '@wordpress/components';
|
||||||
|
import { useState, useEffect } from '@wordpress/element';
|
||||||
|
import apiFetch from '@wordpress/api-fetch';
|
||||||
import metadata from './block.json';
|
import metadata from './block.json';
|
||||||
import allowedBlocks from '../../../json/core-block-whitelist.json';
|
import allowedBlocks from '../../../json/core-block-whitelist.json';
|
||||||
|
|
||||||
registerBlockType(metadata.name, {
|
registerBlockType(metadata.name, {
|
||||||
edit({ attributes, setAttributes }) {
|
edit({ attributes, setAttributes }) {
|
||||||
const blockProps = useBlockProps();
|
const blockProps = useBlockProps();
|
||||||
|
const [ isLoading, setIsLoading ] = useState( true );
|
||||||
|
|
||||||
|
const {
|
||||||
|
container_width,
|
||||||
|
alignment,
|
||||||
|
padding_top,
|
||||||
|
padding_bottom,
|
||||||
|
} = attributes;
|
||||||
|
|
||||||
|
const [
|
||||||
|
containerWidthOptions, setContainerWidthOptions,
|
||||||
|
] = useState( [] );
|
||||||
|
|
||||||
|
useEffect( () => {
|
||||||
|
apiFetch( { path: '/badegg/v1/blocks/container_width' } )
|
||||||
|
.then( ( data ) => {
|
||||||
|
setContainerWidthOptions( data );
|
||||||
|
setIsLoading( false );
|
||||||
|
} )
|
||||||
|
.catch( () => {
|
||||||
|
setContainerWidthOptions( [] );
|
||||||
|
setIsLoading( false );
|
||||||
|
} );
|
||||||
|
}, [] );
|
||||||
|
|
||||||
|
console.log(attributes);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
<div className="container">
|
<BlockControls>
|
||||||
|
<AlignmentToolbar
|
||||||
|
value={ alignment }
|
||||||
|
onChange={(value) => setAttributes({alignment: value})}
|
||||||
|
/>
|
||||||
|
</BlockControls>
|
||||||
|
<InspectorControls>
|
||||||
|
<Panel>
|
||||||
|
<PanelBody title={ __("Settings", "badegg") }>
|
||||||
|
<SelectControl
|
||||||
|
label={ __("Container Width", "badegg") }
|
||||||
|
value={ container_width }
|
||||||
|
options={ containerWidthOptions }
|
||||||
|
onChange={ (value) => setAttributes({ container_width: value }) }
|
||||||
|
__next40pxDefaultSize={ true }
|
||||||
|
__nextHasNoMarginBottom={ true }
|
||||||
|
/>
|
||||||
|
<ToggleControl
|
||||||
|
label={ __('Top Padding', 'badegg') }
|
||||||
|
checked={ padding_top }
|
||||||
|
onChange={(value) => setAttributes({ padding_top: value }) }
|
||||||
|
__nextHasNoMarginBottom
|
||||||
|
/>
|
||||||
|
<ToggleControl
|
||||||
|
label={ __('Bottom Padding', 'badegg') }
|
||||||
|
checked={ padding_bottom }
|
||||||
|
onChange={(value) => setAttributes({ padding_bottom: value }) }
|
||||||
|
__nextHasNoMarginBottom
|
||||||
|
/>
|
||||||
|
</PanelBody>
|
||||||
|
</Panel>
|
||||||
|
</InspectorControls>
|
||||||
|
<div className={`container container-${ attributes.container_width } align-${ attributes.alignment }`}>
|
||||||
<InnerBlocks
|
<InnerBlocks
|
||||||
allowedBlocks={ allowedBlocks }
|
allowedBlocks={ allowedBlocks }
|
||||||
defaultBlock={
|
defaultBlock={
|
||||||
@@ -27,10 +103,10 @@ registerBlockType(metadata.name, {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
save() {
|
save({ attributes }) {
|
||||||
return (
|
return (
|
||||||
<div { ...useBlockProps.save() }>
|
<div { ...useBlockProps.save() }>
|
||||||
<div className="container">
|
<div className={`container container-${attributes.container_width} align-${ attributes.alignment }`}>
|
||||||
<InnerBlocks.Content />
|
<InnerBlocks.Content />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
// block.json's script, loaded in block editor and front end
|
// block.json's script, loaded in block editor and front end
|
||||||
console.log('loaded: resources/views/blocks/article/script.js')
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
// block.json's viewScript, applied on front end only
|
// block.json's viewScript, applied on front end only
|
||||||
console.log('loaded: resources/views/blocks/article/view.js')
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
// block.json's script, loaded in block editor and front end
|
// block.json's script, loaded in block editor and front end
|
||||||
console.log('loaded: resources/views/blocks/example/script.js')
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
// block.json's viewScript, applied on front end only
|
// block.json's viewScript, applied on front end only
|
||||||
console.log('loaded: resources/views/blocks/example/view.js')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user