Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: font picker #210

Merged
merged 16 commits into from
Jun 5, 2020
Merged

feat: font picker #210

merged 16 commits into from
Jun 5, 2020

Conversation

jeffersonrabb
Copy link
Contributor

@jeffersonrabb jeffersonrabb commented May 18, 2020

All Submissions:

Changes proposed in this Pull Request:

Add font selection to the Newsletters plugin. Adds a Typography sidebar panel with SelectControls for choosing body and header fonts. The options are all web-safe fonts, described in screenshots in #198. Selected fonts will immediately be used in the editor and in rendered emails.

Note: the editor font switching uses CSS variables, which are not supported in IE11: https://caniuse.com/#feat=css-variables.

Closes #198

Screen Shot 2020-05-26 at 8 45 54 AM

How to test the changes in this Pull Request:

  1. Create a Newsletter.
  2. Experiment with different changes to the Header and Body fonts in the Typography sidebar panel.
  3. Observe the typography in the editor changes to reflect the selections.
  4. Send yourself a test email, observe the correct fonts are used.
  5. View test emails in a variety of email clients. Verify the correct fonts are seen everywhere.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@jeffersonrabb
Copy link
Contributor Author

@laurelfulford could you take a look at this PR with two particular questions in mind?

  1. Is our list of fonts correct? It's a very safe list, although reading https://templates.mailchimp.com/design/typography/ seems to suggest that there might be opportunities to stretch out a bit more.
  2. What is the best strategy for applying the selected fonts to the Gutenberg editor? In the current state of the PR the fonts will be applied to the actual email, but there is no change in the editor.

@jeffersonrabb
Copy link
Contributor Author

@adekbadek before I get too far along on this PR I wanted to check if the approach runs afoul of #132? This PR creates a new sidebar panel for typography—should this be override-able in other ESP implementations, or should it be universal?

@laurelfulford
Copy link
Contributor

Is our list of fonts correct? It's a very safe list, although reading https://templates.mailchimp.com/design/typography/ seems to suggest that there might be opportunities to stretch out a bit more.

The only potential issue with stretching the font list has more to do with the experience editing the newsletter than those receiving it. If we're relying strictly on system fonts, it means someone will have to have a font installed to see it -- and though this is fine for the emails (we'll have font stacks to make sure there are a few similar options to fall back on if they don't have the first font), if someone creating a newsletter doesn't have the font installed, it won't preview the right one for them.

We could get around this with some education/expectation settings, though, maybe even wrangle some links to download the fonts if we do hear from any publishers. The benefits of stretching the list a bit -- and providing some more variety! -- could be worth the possible bit of friction.

We could also just start with the short "guaranteed" list for now, and build on it after the feature is launched :)

What is the best strategy for applying the selected fonts to the Gutenberg editor? In the current state of the PR the fonts will be applied to the actual email, but there is no change in the editor.

Since we're just looking at applying these styles to the editor (vs the front-end of the site), I think it could be a good opportunity to experiment with CSS variables, to follow what's being used in Global Styles in Gutenberg.

We'd just need a change whatever the variable values are, both on editor load (if they're editing an existing newsletter), and on the fly via JavaScript if they mess with the font picker.

We're currently not using CSS Variables in the theme because they aren't supported by IE11. It seems unlikely that any publishers would be using IE11 to edit their site, but if it happens it would just mean that they would not see a change in the preview when they changed the fonts.

@adekbadek
Copy link
Member

adekbadek commented May 20, 2020

This PR creates a new sidebar panel for typography—should this be override-able in other ESP implementations, or should it be universal?

In the end the font rendering depends on the email client, so I think this feature is universal.

We should add a note though that it's not guaranteed that the font will be rendered as intended in some email clients.

@laurelfulford
Copy link
Contributor

I pushed an update to switch the editor to use CSS variables for the header and body fonts.

With those updates, you can switch the fonts by adding the following JavaScript to the console:

document.documentElement.style.setProperty('--body-font', 'chalkboard');

or

document.documentElement.style.setProperty('--header-font', 'georgia');

The defaults for the variables are both set to an Helvetica/Arial font stack, but when the fonts aren't set to the default, something like the above would need to fire on page load (for editing existing newsletters), and when a new font is selected.

I've also updated the styles so the font changes shouldn't affect the placeholder text (like the "Posts Inserter" header, or blocks like the Image block before you've uploaded anything).

Copy link
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In testing, the fonts change as expected, and when I edit a newsletter, save it, and return to the editor, the font selections are saved.

A couple things I noticed:

'System' as is isn't a font -- when I pick it, the preview switches the font to a serif font in the editor. I've normally seen that referring to a specific 'system font stack' that includes similar fonts for OSX, Windows, and Linux -- like -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; from here. (This is what the theme uses as the default header font). I'm not sure if it'd be better to update the option to load that stack, or remove it (and/or use it as the fallback list for the sans-serif fonts) since it kind of overlaps the other options that are there.

Also, a couple of the blocks -- buttons, image captions -- are picking up the body font in the editor, but not picking up any font in the actual email (there, they're using the original Ubuntu, Helvetica, Arial, sans-serif default). I'm not sure which is actually correct -- it might just be that I have it wrong in the editor -- but wanted to confirm before I make any changes:

Editor:
image

Email:
image

Lastly, something I know I have to fix: the links nested in h1-h6 (like the post titles) are picking up the body font in the editor, rather than the header font. They're displaying correctly in the email; I can push up a change for this shortly, but wanted to record the "why".

image

@laurelfulford
Copy link
Contributor

Also, a couple of the blocks -- buttons, image captions -- are picking up the body font in the editor, but not picking up any font in the actual email

Jeff and I chatted about this and decided the email should be considered correct here, so I'll be following up shortly with an update to the editor to fix it there.

@jeffersonrabb
Copy link
Contributor Author

'System' as is isn't a font -- when I pick it, the preview switches the font to a serif font in the editor.

Opted to simply remove System in 6564dad.

@jeffersonrabb
Copy link
Contributor Author

Also, a couple of the blocks -- buttons, image captions -- are picking up the body font in the editor, but not picking up any font in the actual email (there, they're using the original Ubuntu, Helvetica, Arial, sans-serif default). I'm not sure which is actually correct -- it might just be that I have it wrong in the editor -- but wanted to confirm before I make any changes:

Fixed in f212f98

@jeffersonrabb
Copy link
Contributor Author

We should add a note though that it's not guaranteed that the font will be rendered as intended in some email clients.

For now we're offering only email-safe fonts as described by Mailchimp, so I would think there's no need for a warning. @adekbadek have you seen cases where these don't render in email clients?

@jeffersonrabb
Copy link
Contributor Author

Resolved an issue where emails sent immediately after a font change do not reflect the change, in fe0e4b1.

Set the default fonts to Arial/Georgia in 3dc85bd

The PR should be ready for review again cc: @adekbadek @laurelfulford

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well, I just have two remarks.

{
value: null,
label: __( 'Monospace', 'newspack-newsletters' ),
disabled: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these three disabled option in the select? Also, two of them are not in the backend list of fonts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Serif, Sans Serif and Monotype are category groupings, not actual fonts. It's meant to match this screenshot, although without the indentation. Actually all three of these should be absent from the list of fonts—which was the one you did find?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category groupings

SelectControl does not support optgroup :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'Serif' is on the PHP list

Whoops: 7bb8e8b

includes/class-newspack-newsletters.php Show resolved Hide resolved
@github-actions github-actions bot added [Status] Approved Ready to merge and removed [Status] Needs Review labels Jun 4, 2020
@jeffersonrabb
Copy link
Contributor Author

jeffersonrabb commented Jun 4, 2020

@adekbadek pointed out that the mockups call for optgroups in the font SelectControls. The SelectControl component has no support for optgroups at the moment (feature request here), so I've added this in f487d7f

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

@github-actions github-actions bot added [Status] Approved Ready to merge and removed [Status] Needs Review labels Jun 4, 2020
Copy link
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM!

@jeffersonrabb jeffersonrabb merged commit 0234bf9 into master Jun 5, 2020
matticbot pushed a commit that referenced this pull request Jun 9, 2020
# [1.1.0](v1.0.1...v1.1.0) (2020-06-09)

### Bug Fixes

* prevent deduplication in layout picker preview ([4a5721e](4a5721e)), closes [#199](#199)
* **posts-inserter:** prevent empty featured image rendering ([56a97c4](56a97c4)), closes [#201](#201)
* resolve excerpt length issue ([d40f98a](d40f98a))
* situation that overwrote mc campaign id ([8ecf564](8ecf564))
* update editor block paddings ([#195](#195)) ([eb100b8](eb100b8))
* when trashing post allow mailchimp api call to fail silently ([7e2d9c4](7e2d9c4))
* when trashing post allow mailchimp api call to fail silently ([8257451](8257451))

### Features

* add layouts management ([#165](#165)) ([446674f](446674f)), closes [#31](#31) [#216](#216)
* font picker ([#210](#210)) ([0234bf9](0234bf9))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@adekbadek adekbadek deleted the add/font-picker branch August 5, 2021 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a fonts setting
4 participants