Skip to content

Commit

Permalink
PLANET-7302 Move Cookies block into master theme (#2167)
Browse files Browse the repository at this point in the history
This commit also includes a few other things:
- style updates for the new identity
- script renaming for the enqueuing
- creation of a blocks scss file to remove some code duplication
- reflection of some variables from PHP to JS
  • Loading branch information
mleray authored Dec 22, 2023
1 parent 99b9ae4 commit a4e1928
Show file tree
Hide file tree
Showing 17 changed files with 704 additions and 9 deletions.
48 changes: 48 additions & 0 deletions assets/src/blocks/Cookies/CookiesBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {CookiesEditor} from './CookiesEditor.js';

export const BLOCK_NAME = 'planet4-blocks/cookies';

export const registerCookiesBlock = () => {
const {registerBlockType} = wp.blocks;

registerBlockType(BLOCK_NAME, {
title: 'Cookies',
icon: 'welcome-view-site',
category: 'planet4-blocks',
supports: {
multiple: false, // Use the block just once per post.
},
attributes: {
title: {
type: 'string',
default: '',
},
description: {
type: 'string',
default: '',
},
necessary_cookies_name: {
type: 'string',
},
necessary_cookies_description: {
type: 'string',
},
all_cookies_name: {
type: 'string',
},
all_cookies_description: {
type: 'string',
},
analytical_cookies_name: {
type: 'string',
},
analytical_cookies_description: {
type: 'string',
},
},
edit: CookiesEditor,
save() {
return null;
},
});
};
18 changes: 18 additions & 0 deletions assets/src/blocks/Cookies/CookiesEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {CookiesFrontend} from './CookiesFrontend';

export const CookiesEditor = ({attributes, isSelected, setAttributes}) => {
const toAttribute = attributeName => value => {
if (isSelected) {
setAttributes({[attributeName]: value});
}
};

return (
<CookiesFrontend
{...attributes}
isEditing
toAttribute={toAttribute}
isSelected={isSelected}
/>
);
};
3 changes: 3 additions & 0 deletions assets/src/blocks/Cookies/CookiesEditorScript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {registerCookiesBlock} from './CookiesBlock';

registerCookiesBlock();
28 changes: 28 additions & 0 deletions assets/src/blocks/Cookies/CookiesFieldResetButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const {__} = wp.i18n;

import {Tooltip} from '@wordpress/components';

const COOKIES_DEFAULT_COPY = window.p4_vars.cookies_default_copy || {};

export const CookiesFieldResetButton = ({fieldName, toAttribute, currentValue}) => {
const defaultValue = COOKIES_DEFAULT_COPY[fieldName] || '';

if (!currentValue || !defaultValue || currentValue === defaultValue) {
return null;
}

return (
<div className="field-reset-button">
<Tooltip text={__('This value is defined in the settings, in Planet 4 > Cookies', 'planet4-blocks-backend')}>
<span className="info">i</span>
</Tooltip>
<span
className="cta"
onClick={() => toAttribute(fieldName)(undefined)}
role="presentation"
>
{__('Use default value', 'planet4-blocks-backend')}
</span>
</div>
);
};
Loading

0 comments on commit a4e1928

Please sign in to comment.