diff --git a/web/app/themes/badegg/app/Admin/DisablePost.php b/web/app/themes/badegg/app/Admin/DisablePost.php index 3738ad0..a35f07b 100644 --- a/web/app/themes/badegg/app/Admin/DisablePost.php +++ b/web/app/themes/badegg/app/Admin/DisablePost.php @@ -6,8 +6,8 @@ class DisablePost { public function __construct() { - add_filter('register_post_type_args', [$this, 'args'], 0, 2); - add_filter('register_taxonomy_args', [$this, 'args'], 0, 2); + // add_filter('register_post_type_args', [$this, 'args'], 0, 2); + // add_filter('register_taxonomy_args', [$this, 'args'], 0, 2); } public function args($args, $type) diff --git a/web/app/themes/badegg/app/Admin/Theme.php b/web/app/themes/badegg/app/Admin/Theme.php new file mode 100644 index 0000000..8d06739 --- /dev/null +++ b/web/app/themes/badegg/app/Admin/Theme.php @@ -0,0 +1,48 @@ +values(); + + foreach($colours as $slug => $hex) { + $palette[] = [ + 'name' => esc_html__(@$NameThatColour->name($hex)['name'], 'badegg'), + 'slug' => $slug, + 'color' => $hex, + ]; + } + + if(!empty($colours)) { + add_theme_support('editor-color-palette', $palette); + } + } + + public function BackgroundTints() + { + register_block_style( + 'badegg/article', + [ + 'name' => 'badegg-colour-tint', + 'label' => __('Tint', 'badegg'), + // 'inline_style' =>'.wp-block-image.is-style-badegg-colour-tint { }', + ] + ); + } +} diff --git a/web/app/themes/badegg/app/Utilities/RestAPI.php b/web/app/themes/badegg/app/Utilities/RestAPI.php index 406538c..05144f5 100644 --- a/web/app/themes/badegg/app/Utilities/RestAPI.php +++ b/web/app/themes/badegg/app/Utilities/RestAPI.php @@ -1,6 +1,7 @@ 'GET', - 'callback' => [ $this, 'containerWidths'], + 'callback' => [ $this, 'config'], 'permission_callback' => function(){ return true; }, ]); } + public function config() + { + return rest_ensure_response([ + 'container' => $this->containerWidths(), + 'colours' => $this->colours(), + 'tints' => $this->tints(), + ]); + } + public function containerWidths() { - $containerWidths = [ + return [ [ 'label' => __('Auto', 'badegg'), 'value' => 0 ], [ 'label' => __('Narrow', 'badegg'), 'value' => 'narrow' ], [ 'label' => __('Small', 'badegg'), 'value' => 'small' ], @@ -32,7 +42,39 @@ class RestAPI [ 'label' => __('Large', 'badegg'), 'value' => 'large' ], [ 'label' => __('Edge to edge', 'badegg'), 'value' => 'full' ], ]; - - return rest_ensure_response($containerWidths); } + + public function colours() + { + $colour = new Colour; + $NameThatColour = new NameThatColor; + + $palette = []; + + $colours = $colour->values(); + + foreach($colours as $slug => $hex) { + $palette[] = [ + 'name' => esc_html__(@$NameThatColour->name($hex)['name'], 'badegg'), + 'slug' => $slug, + 'color' => $hex, + ]; + } + + return $palette; + } + + public function tints() + { + return [ + ['label' => __('Lightest', 'badegg'), 'value' => 'lightest'], + ['label' => __('Lighter', 'badegg'), 'value' => 'lighter' ], + ['label' => __('Light', 'badegg'), 'value' => 'light' ], + ['label' => __('None', 'badegg'), 'value' => 0 ], + ['label' => __('Dark', 'badegg'), 'value' => 'dark' ], + ['label' => __('Darker', 'badegg'), 'value' => 'darker' ], + ['label' => __('Darkest', 'badegg'), 'value' => 'darkest' ], + ]; + } + } diff --git a/web/app/themes/badegg/resources/js/lib/blocks/classNames.js b/web/app/themes/badegg/resources/js/lib/blocks/classNames.js index bf0e541..2f07a8d 100644 --- a/web/app/themes/badegg/resources/js/lib/blocks/classNames.js +++ b/web/app/themes/badegg/resources/js/lib/blocks/classNames.js @@ -28,6 +28,19 @@ export function sectionClassNames(attributes, defaultClasses, extraClasses = []) if('padding_bottom'in attributes && !attributes.padding_bottom) classNames.push('section-zero-bottom'); + if('background_colour' in attributes && attributes.background_colour) { + let bg = `bg-${ attributes.background_colour }`; + + if( + 'background_tint' in attributes && + attributes.background_tint != 0 && + !['white', 'black'].includes(attributes.background_colour) + ) { + bg += `-${ attributes.background_tint }`; + } + + classNames.push(bg); + } // combine arrays classNames = classNames.concat(defaultClasses).concat(extraClasses); diff --git a/web/app/themes/badegg/resources/views/blocks/article/block.json b/web/app/themes/badegg/resources/views/blocks/article/block.json index d61a997..30c1840 100644 --- a/web/app/themes/badegg/resources/views/blocks/article/block.json +++ b/web/app/themes/badegg/resources/views/blocks/article/block.json @@ -11,7 +11,7 @@ "attributes": { "container_width": { "type": "string", - "default": 0 + "default": "" }, "alignment": { "type": "string" @@ -23,12 +23,24 @@ "padding_bottom": { "type": "boolean", "default": true + }, + "background_colour": { + "type": "string", + "default": "" + }, + "background_hex": { + "type": "string", + "default": "" + }, + "background_tint": { + "type": "string", + "default": "0" } }, "supports": { "html": true, "color": { - "background": true, + "background": false, "text": false } } diff --git a/web/app/themes/badegg/resources/views/blocks/article/index.jsx b/web/app/themes/badegg/resources/views/blocks/article/index.jsx index 8757304..4b9a1d6 100644 --- a/web/app/themes/badegg/resources/views/blocks/article/index.jsx +++ b/web/app/themes/badegg/resources/views/blocks/article/index.jsx @@ -17,6 +17,8 @@ import { PanelRow, SelectControl, ToggleControl, + ColorIndicator, + ColorPalette, } from '@wordpress/components'; import { useState, useEffect } from '@wordpress/element'; @@ -35,20 +37,23 @@ registerBlockType(metadata.name, { alignment, padding_top, padding_bottom, + background_colour, + background_hex, + background_tint, } = attributes; const [ - containerWidthOptions, setContainerWidthOptions, + configOptions, setConfigOptions, ] = useState( [] ); useEffect( () => { - apiFetch( { path: '/badegg/v1/blocks/container-widths' } ) + apiFetch( { path: '/badegg/v1/blocks/config' } ) .then( ( data ) => { - setContainerWidthOptions( data ); + setConfigOptions( data ); setIsLoading( false ); } ) .catch( () => { - setContainerWidthOptions( [] ); + setConfigOptions( [] ); setIsLoading( false ); } ); }, [] ); @@ -60,7 +65,7 @@ registerBlockType(metadata.name, { 'wysiwyg' ]).join(' '); - console.log(blockProps.className); + // console.log(attributes); return (
@@ -76,7 +81,7 @@ registerBlockType(metadata.name, { setAttributes({ container_width: value }) } __next40pxDefaultSize={ true } __nextHasNoMarginBottom={ true } @@ -94,6 +99,46 @@ registerBlockType(metadata.name, { __nextHasNoMarginBottom /> + + { + let slug, hex, selected = ''; + + if(value) { + selected = configOptions.colours.find( + ( c ) => c.color === value + ); + + hex = value; + } + + if(selected) { + slug = selected.slug; + } + + setAttributes( { + background_colour: slug, + background_hex: hex, + }); + + } } + /> + + { 'background_colour' in attributes && attributes.background_colour ? ( + setAttributes({ background_tint: value }) } + __next40pxDefaultSize={ true } + __nextHasNoMarginBottom={ true } + /> + ) : null } + +