-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLANET-7302 Move Cookies block into master theme (#2167)
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
Showing
17 changed files
with
704 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import {registerCookiesBlock} from './CookiesBlock'; | ||
|
||
registerCookiesBlock(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
Oops, something went wrong.