Compare commits
3 Commits
a4d764b510
...
706f04d91d
| Author | SHA1 | Date | |
|---|---|---|---|
| 706f04d91d | |||
| 3d51f8f735 | |||
| 39444a6898 |
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\API;
|
namespace App\Utilities;
|
||||||
|
|
||||||
class Admin
|
class RestAPI
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -11,16 +11,18 @@ class Admin
|
|||||||
|
|
||||||
public function blocks( )
|
public function blocks( )
|
||||||
{
|
{
|
||||||
register_rest_route('badegg/v1', '/blocks/container_width', [
|
$restBase = 'badegg/v1';
|
||||||
|
|
||||||
|
register_rest_route($restBase, '/blocks/container-widths', [
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
'callback' => [ $this, 'container_width'],
|
'callback' => [ $this, 'containerWidths'],
|
||||||
'permission_callback' => function(){
|
'permission_callback' => function(){
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function container_width()
|
public function containerWidths()
|
||||||
{
|
{
|
||||||
$containerWidths = [
|
$containerWidths = [
|
||||||
[ 'label' => __('Auto', 'badegg'), 'value' => 0 ],
|
[ 'label' => __('Auto', 'badegg'), 'value' => 0 ],
|
||||||
@@ -57,7 +57,6 @@ autoload_psr4('PostTypes');
|
|||||||
autoload_psr4('ACF');
|
autoload_psr4('ACF');
|
||||||
autoload_psr4('Utilities');
|
autoload_psr4('Utilities');
|
||||||
autoload_psr4('Admin');
|
autoload_psr4('Admin');
|
||||||
autoload_psr4('API');
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -20,20 +20,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.editor-visual-editor {
|
.editor-visual-editor {
|
||||||
.wp-block {
|
|
||||||
max-width: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.is-root-container > .wp-block:not(.block-list-appender) {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.block-list-appender {
|
|
||||||
width: 350px;
|
|
||||||
max-width: 90%;
|
|
||||||
margin: 1em auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
&__post-title-wrapper {
|
&__post-title-wrapper {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -43,26 +29,41 @@
|
|||||||
background: white;
|
background: white;
|
||||||
box-shadow: 0 0.5rem 1rem rgba(black, 0.15);
|
box-shadow: 0 0.5rem 1rem rgba(black, 0.15);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.wp-block-post-title {
|
.editor-styles-wrapper {
|
||||||
position: relative;
|
background: colours.$grey-lightest;
|
||||||
padding: 0.5rem;
|
|
||||||
border: 1px solid rgba(black, 0.3);
|
|
||||||
margin: 0;
|
|
||||||
|
|
||||||
&::before {
|
.block-list-appender {
|
||||||
content: 'Page Title';
|
width: 350px;
|
||||||
position: absolute;
|
max-width: 90%;
|
||||||
top: -0.5rem;
|
margin: 1em auto;
|
||||||
left: 0.5rem;
|
|
||||||
color: rgba(black, 0.3);
|
|
||||||
font-size: 0.8rem;
|
|
||||||
display: block;
|
|
||||||
padding: 0 0.5rem;
|
|
||||||
margin: 0;
|
|
||||||
background: white;
|
|
||||||
line-height: 1;
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.wp-block-post-title {
|
||||||
|
position: relative;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border: 1px solid rgba(black, 0.3);
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: 'Page Title';
|
||||||
|
position: absolute;
|
||||||
|
top: -0.5rem;
|
||||||
|
left: 0.5rem;
|
||||||
|
color: rgba(black, 0.3);
|
||||||
|
font-size: 0.8rem;
|
||||||
|
display: block;
|
||||||
|
padding: 0 0.5rem;
|
||||||
|
margin: 0;
|
||||||
|
background: white;
|
||||||
|
line-height: 1;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-root-container > .wp-block:not(.block-list-appender) {
|
||||||
|
max-width: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|||||||
39
web/app/themes/badegg/resources/js/lib/blocks/classNames.js
Normal file
39
web/app/themes/badegg/resources/js/lib/blocks/classNames.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
export function containerClassNames(attributes, bgProps)
|
||||||
|
{
|
||||||
|
|
||||||
|
let classNames = [
|
||||||
|
'container',
|
||||||
|
];
|
||||||
|
|
||||||
|
if('container_width' in attributes)
|
||||||
|
classNames.push(`container-${attributes.container_width}`);
|
||||||
|
|
||||||
|
if('alignment' in attributes)
|
||||||
|
classNames.push(`align-${attributes.alignment}`);
|
||||||
|
|
||||||
|
return classNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function sectionClassNames(attributes, defaultClasses, extraClasses = [])
|
||||||
|
{
|
||||||
|
defaultClasses = defaultClasses.split(' ');
|
||||||
|
|
||||||
|
let classNames = [
|
||||||
|
'section',
|
||||||
|
];
|
||||||
|
|
||||||
|
if('padding_top'in attributes && !attributes.padding_top)
|
||||||
|
classNames.push('section-zero-top');
|
||||||
|
|
||||||
|
if('padding_bottom'in attributes && !attributes.padding_bottom)
|
||||||
|
classNames.push('section-zero-bottom');
|
||||||
|
|
||||||
|
|
||||||
|
// combine arrays
|
||||||
|
classNames = classNames.concat(defaultClasses).concat(extraClasses);
|
||||||
|
|
||||||
|
// remove duplicate items
|
||||||
|
classNames = [ ...new Set(classNames) ];
|
||||||
|
|
||||||
|
return classNames;
|
||||||
|
}
|
||||||
@@ -18,10 +18,12 @@ import {
|
|||||||
SelectControl,
|
SelectControl,
|
||||||
ToggleControl,
|
ToggleControl,
|
||||||
} from '@wordpress/components';
|
} from '@wordpress/components';
|
||||||
|
|
||||||
import { useState, useEffect } from '@wordpress/element';
|
import { useState, useEffect } from '@wordpress/element';
|
||||||
import apiFetch from '@wordpress/api-fetch';
|
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';
|
||||||
|
import { containerClassNames, sectionClassNames } from '../../../js/lib/blocks/classNames';
|
||||||
|
|
||||||
registerBlockType(metadata.name, {
|
registerBlockType(metadata.name, {
|
||||||
edit({ attributes, setAttributes }) {
|
edit({ attributes, setAttributes }) {
|
||||||
@@ -40,18 +42,25 @@ registerBlockType(metadata.name, {
|
|||||||
] = useState( [] );
|
] = useState( [] );
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
apiFetch( { path: '/badegg/v1/blocks/container_width' } )
|
apiFetch( { path: '/badegg/v1/blocks/container-widths' } )
|
||||||
.then( ( data ) => {
|
.then( ( data ) => {
|
||||||
setContainerWidthOptions( data );
|
setContainerWidthOptions( data );
|
||||||
setIsLoading( false );
|
setIsLoading( false );
|
||||||
} )
|
} )
|
||||||
.catch( () => {
|
.catch( () => {
|
||||||
setContainerWidthOptions( [] );
|
setContainerWidthOptions( [] );
|
||||||
setIsLoading( false );
|
setIsLoading( false );
|
||||||
} );
|
} );
|
||||||
}, [] );
|
}, [] );
|
||||||
|
|
||||||
console.log(attributes);
|
blockProps.className = sectionClassNames(
|
||||||
|
attributes,
|
||||||
|
blockProps.className,
|
||||||
|
[
|
||||||
|
'wysiwyg'
|
||||||
|
]).join(' ');
|
||||||
|
|
||||||
|
console.log(blockProps.className);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div { ...blockProps }>
|
<div { ...blockProps }>
|
||||||
@@ -87,7 +96,7 @@ registerBlockType(metadata.name, {
|
|||||||
</PanelBody>
|
</PanelBody>
|
||||||
</Panel>
|
</Panel>
|
||||||
</InspectorControls>
|
</InspectorControls>
|
||||||
<div className={`container container-${ attributes.container_width } align-${ attributes.alignment }`}>
|
<div className={ containerClassNames(attributes).join(' ') }>
|
||||||
<InnerBlocks
|
<InnerBlocks
|
||||||
allowedBlocks={ allowedBlocks }
|
allowedBlocks={ allowedBlocks }
|
||||||
defaultBlock={
|
defaultBlock={
|
||||||
@@ -106,7 +115,7 @@ registerBlockType(metadata.name, {
|
|||||||
save({ attributes }) {
|
save({ attributes }) {
|
||||||
return (
|
return (
|
||||||
<div { ...useBlockProps.save() }>
|
<div { ...useBlockProps.save() }>
|
||||||
<div className={`container container-${attributes.container_width} align-${ attributes.alignment }`}>
|
<div className={ containerClassNames(attributes).join() }>
|
||||||
<InnerBlocks.Content />
|
<InnerBlocks.Content />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user