Compare commits
3 Commits
a4d764b510
...
706f04d91d
| Author | SHA1 | Date | |
|---|---|---|---|
| 706f04d91d | |||
| 3d51f8f735 | |||
| 39444a6898 |
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\API;
|
||||
namespace App\Utilities;
|
||||
|
||||
class Admin
|
||||
class RestAPI
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
@@ -11,16 +11,18 @@ class Admin
|
||||
|
||||
public function blocks( )
|
||||
{
|
||||
register_rest_route('badegg/v1', '/blocks/container_width', [
|
||||
$restBase = 'badegg/v1';
|
||||
|
||||
register_rest_route($restBase, '/blocks/container-widths', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [ $this, 'container_width'],
|
||||
'callback' => [ $this, 'containerWidths'],
|
||||
'permission_callback' => function(){
|
||||
return true;
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
public function container_width()
|
||||
public function containerWidths()
|
||||
{
|
||||
$containerWidths = [
|
||||
[ 'label' => __('Auto', 'badegg'), 'value' => 0 ],
|
||||
@@ -57,7 +57,6 @@ autoload_psr4('PostTypes');
|
||||
autoload_psr4('ACF');
|
||||
autoload_psr4('Utilities');
|
||||
autoload_psr4('Admin');
|
||||
autoload_psr4('API');
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -20,20 +20,6 @@
|
||||
}
|
||||
|
||||
.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 {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
@@ -43,26 +29,41 @@
|
||||
background: white;
|
||||
box-shadow: 0 0.5rem 1rem rgba(black, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
.wp-block-post-title {
|
||||
position: relative;
|
||||
padding: 0.5rem;
|
||||
border: 1px solid rgba(black, 0.3);
|
||||
margin: 0;
|
||||
.editor-styles-wrapper {
|
||||
background: colours.$grey-lightest;
|
||||
|
||||
&::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;
|
||||
}
|
||||
.block-list-appender {
|
||||
width: 350px;
|
||||
max-width: 90%;
|
||||
margin: 1em auto;
|
||||
}
|
||||
}
|
||||
|
||||
.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,
|
||||
ToggleControl,
|
||||
} from '@wordpress/components';
|
||||
|
||||
import { useState, useEffect } from '@wordpress/element';
|
||||
import apiFetch from '@wordpress/api-fetch';
|
||||
import metadata from './block.json';
|
||||
import allowedBlocks from '../../../json/core-block-whitelist.json';
|
||||
import { containerClassNames, sectionClassNames } from '../../../js/lib/blocks/classNames';
|
||||
|
||||
registerBlockType(metadata.name, {
|
||||
edit({ attributes, setAttributes }) {
|
||||
@@ -40,18 +42,25 @@ registerBlockType(metadata.name, {
|
||||
] = useState( [] );
|
||||
|
||||
useEffect( () => {
|
||||
apiFetch( { path: '/badegg/v1/blocks/container_width' } )
|
||||
.then( ( data ) => {
|
||||
setContainerWidthOptions( data );
|
||||
setIsLoading( false );
|
||||
} )
|
||||
.catch( () => {
|
||||
setContainerWidthOptions( [] );
|
||||
setIsLoading( false );
|
||||
} );
|
||||
apiFetch( { path: '/badegg/v1/blocks/container-widths' } )
|
||||
.then( ( data ) => {
|
||||
setContainerWidthOptions( data );
|
||||
setIsLoading( false );
|
||||
} )
|
||||
.catch( () => {
|
||||
setContainerWidthOptions( [] );
|
||||
setIsLoading( false );
|
||||
} );
|
||||
}, [] );
|
||||
|
||||
console.log(attributes);
|
||||
blockProps.className = sectionClassNames(
|
||||
attributes,
|
||||
blockProps.className,
|
||||
[
|
||||
'wysiwyg'
|
||||
]).join(' ');
|
||||
|
||||
console.log(blockProps.className);
|
||||
|
||||
return (
|
||||
<div { ...blockProps }>
|
||||
@@ -87,7 +96,7 @@ registerBlockType(metadata.name, {
|
||||
</PanelBody>
|
||||
</Panel>
|
||||
</InspectorControls>
|
||||
<div className={`container container-${ attributes.container_width } align-${ attributes.alignment }`}>
|
||||
<div className={ containerClassNames(attributes).join(' ') }>
|
||||
<InnerBlocks
|
||||
allowedBlocks={ allowedBlocks }
|
||||
defaultBlock={
|
||||
@@ -106,7 +115,7 @@ registerBlockType(metadata.name, {
|
||||
save({ attributes }) {
|
||||
return (
|
||||
<div { ...useBlockProps.save() }>
|
||||
<div className={`container container-${attributes.container_width} align-${ attributes.alignment }`}>
|
||||
<div className={ containerClassNames(attributes).join() }>
|
||||
<InnerBlocks.Content />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user