generated from alleyinteractive/create-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from alleyinteractive/feature/LEDE-2641/templ…
…ate-color-font-link LEDE-2641 Template-level Fonts & Background & Link Color
- Loading branch information
Showing
18 changed files
with
194 additions
and
18 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
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
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
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
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
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
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,8 @@ | ||
import { registerPlugin } from '@wordpress/plugins'; | ||
|
||
import NewsletterTemplateStylesPanel from './newsletterStylesPanel'; | ||
|
||
registerPlugin('newsletter-template-styles', { | ||
render: NewsletterTemplateStylesPanel, | ||
icon: 'dashicons-art', | ||
}); |
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,42 @@ | ||
<?php | ||
/** | ||
* Adds the sidebar script to the Post edit screen. | ||
* | ||
* This file will be copied to the assets build directory. | ||
* | ||
* @package wp-newsletter-builder-demo-plugin | ||
*/ | ||
|
||
namespace WP_Newsletter_Builder; | ||
|
||
add_action( | ||
'enqueue_block_editor_assets', | ||
__NAMESPACE__ . '\action_enqueue_style_sidebar_assets' | ||
); | ||
|
||
/** | ||
* Registers all slotfill assets so that they can be enqueued through Gutenberg in | ||
* the corresponding context. | ||
*/ | ||
function register_style_plugin_scripts(): void { | ||
wp_register_script( | ||
'plugin-newsletter-template-styles', | ||
get_entry_asset_url( 'newsletter-template-styles' ), | ||
get_asset_dependency_array( 'newsletter-template-styles' ), | ||
get_asset_version( 'newsletter-template-styles' ), | ||
true | ||
); | ||
wp_set_script_translations( 'plugin-newsletter-template-styles' ); | ||
} | ||
add_action( 'init', __NAMESPACE__ . '\register_style_plugin_scripts' ); | ||
|
||
/** | ||
* Enqueue block editor assets for this slotfill. | ||
*/ | ||
function action_enqueue_style_sidebar_assets(): void { | ||
$post_type = get_edit_post_type(); | ||
if ( 'nb_template' !== $post_type ) { | ||
return; | ||
} | ||
wp_enqueue_script( 'plugin-newsletter-template-styles' ); | ||
} |
71 changes: 71 additions & 0 deletions
71
plugins/newsletter-template-styles/newsletterStylesPanel.tsx
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,71 @@ | ||
import React, { useEffect } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; | ||
import { usePostMetaValue } from '@alleyinteractive/block-editor-tools'; | ||
import { ColorPicker, SelectControl } from '@wordpress/components'; | ||
|
||
// @ts-ignore | ||
export default function NewsletterTemplateStylesPanel() { | ||
const [bgColor, setBgColor] = usePostMetaValue('nb_template_bg_color'); | ||
const [fontStack, setFontStack] = usePostMetaValue('nb_template_font'); | ||
const [linkColor, setLinkColor] = usePostMetaValue('nb_template_link_color'); | ||
|
||
const defaultValues = { | ||
bgColor: '#fefefe', | ||
fontStack: 'Arial, sans-serif', | ||
linkColor: '#0073aa', | ||
}; | ||
|
||
// Set intial styles on load. | ||
useEffect(() => { | ||
document.documentElement.style.setProperty('--template-bg-color', bgColor || defaultValues.bgColor); | ||
document.documentElement.style.setProperty('--template-font-family', fontStack || defaultValues.fontStack); | ||
document.documentElement.style.setProperty('--template-link-color', linkColor || defaultValues.linkColor); | ||
}, []); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
const emailSafeFonts = [ | ||
{ label: 'Arial', value: 'Arial, sans-serif' }, | ||
{ label: 'Courier New', value: 'Courier New, monospace' }, | ||
{ label: 'Georgia', value: 'Georgia, serif' }, | ||
{ label: 'Helvetica', value: 'Helvetica, sans-serif' }, | ||
{ label: 'Lucida Sans Unicode', value: 'Lucida Sans Unicode, sans-serif' }, | ||
{ label: 'Tahoma', value: 'Tahoma, sans-serif' }, | ||
{ label: 'Times New Roman', value: 'Times New Roman, serif' }, | ||
{ label: 'Trebuchet MS', value: 'Trebuchet MS, sans-serif' }, | ||
{ label: 'Verdana', value: 'Verdana, sans-serif' }, | ||
]; | ||
|
||
return ( | ||
<PluginDocumentSettingPanel | ||
name="newsletter-template-styles" | ||
title="Template Styles" | ||
className="newsletter-template-styles-panel" | ||
> | ||
<h3>{__('Background color', 'wp-newsletter-builder')}</h3> | ||
<ColorPicker | ||
color={bgColor || defaultValues.bgColor} | ||
onChange={(color) => { | ||
setBgColor(color); | ||
document.documentElement.style.setProperty('--template-bg-color', color); | ||
}} | ||
/> | ||
<h3>{__('Link color', 'wp-newsletter-builder')}</h3> | ||
<ColorPicker | ||
color={linkColor || defaultValues.linkColor} | ||
onChange={(color) => { | ||
setLinkColor(color); | ||
document.documentElement.style.setProperty('--template-link-color', color); | ||
}} | ||
/> | ||
<h3>{__('Font family', 'wp-newsletter-builder')}</h3> | ||
<SelectControl | ||
value={fontStack || defaultValues.fontStack} | ||
options={emailSafeFonts} | ||
onChange={(font) => { | ||
setFontStack(font); | ||
document.documentElement.style.setProperty('--template-font-family', font); | ||
}} | ||
/> | ||
</PluginDocumentSettingPanel> | ||
); | ||
} |
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
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
ul, ol { | ||
font-family: Georgia, serif; | ||
font-family: var(--template-font-family); | ||
font-size: 16px; | ||
line-height: 1.3; | ||
margin: 0; | ||
|
||
span { | ||
font-family: Georgia, serif; | ||
div { | ||
font-family: var(--template-font-family); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
p { | ||
font-family: Georgia, serif; | ||
font-family: var(--template-font-family); | ||
font-size: 16px; | ||
line-height: 1.33; | ||
margin: 0; | ||
|
||
span { | ||
font-family: Georgia, serif; | ||
font-family: var(--template-font-family); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
a, em, s, strong, sup, sub { | ||
font-family: Georgia, serif; | ||
font-family: var(--template-font-family); | ||
} | ||
|
||
a { | ||
color: var(--template-link-color); | ||
} |
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
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
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
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