Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Global styles #371

Merged
merged 5 commits into from Jul 23, 2019
Merged

Global styles #371

merged 5 commits into from Jul 23, 2019

Conversation

lukecarbis
Copy link
Member

@lukecarbis lukecarbis commented Jul 22, 2019

With this PR, Block Lab will try to enqueue a global stylesheet.

It will try to do this under one of two conditions:

  1. You are using Gutenberg
  2. Any custom block lab block is used on the page

Note: These styles won't load if you're not using any Block Lab blocks.

The global stylesheet will be loaded if it exists in one of these places:

  • {theme}/blocks/blocks.css
  • {theme}/blocks/css/blocks.css
  • {child theme}/blocks/blocks.css
  • {child theme}/blocks/css/blocks.css

If the global stylesheet exists in multiple places, it will only be loaded the first time it's found. So if you've got one in blocks/blocks.css and blocks/css/blocks.css, then second stylesheet will be ignored.

Note that once #370 is merged, the child theme will be preferenced over the parent theme.

Closes #351 .

@kienstra
Copy link
Collaborator

Approved

Hi @lukecarbis,
This looks good. The only code review points is very minor.

Like you mentioned, I also saw that the stylesheet is loaded if it's in any of these 4 locations:

{theme}/blocks/blocks.css
{theme}/blocks/css/blocks.css
{child theme}/blocks/blocks.css
{child theme}/blocks/css/blocks.css

blocks-css-present

It looks like it's always enqueued in the block editor, regardless of whether a Block Lab block was added. But maybe that's intentional, as one could be added.

kienstra
kienstra previously approved these changes Jul 23, 2019
@@ -351,6 +359,30 @@ public function enqueue_block_styles( $name, $type = 'block' ) {
);
}
}
/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a big deal, but this should probably have an empty line above it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 16befc7.

tests/php/blocks/test-class-loader.php Show resolved Hide resolved
tests/php/blocks/test-class-loader.php Show resolved Hide resolved
tests/php/blocks/test-class-loader.php Show resolved Hide resolved
@lukecarbis
Copy link
Member Author

@kienstra Yes, always enqueuing it in the editor is intentional, so it's there and ready in case a block is added. I'll sort out that extra line now.

@kienstra
Copy link
Collaborator

@kienstra Yes, always enqueuing it in the editor is intentional, so it's there and ready in case a block is added.

Sounds good.

@lukecarbis lukecarbis merged commit dfa5f05 into develop Jul 23, 2019
@lukecarbis lukecarbis deleted the feature/351-global-styles branch July 23, 2019 03:38
lukecarbis added a commit to lukecarbis/block-lab that referenced this pull request Aug 18, 2019
@jcrooke
Copy link

jcrooke commented Sep 17, 2019

I don't think the stylesheet should get included when you're viewing the blocks on the front-end, it should only be included when in the Gutenberg editor - otherwise you have a block stylesheet being loaded alongside your regular stylesheet.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global CSS Template File
3 participants