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

SDK: refactor block CSS name-spacing #26662

Merged
merged 6 commits into from
Aug 15, 2018
Merged

Conversation

simison
Copy link
Member

@simison simison commented Aug 13, 2018

Refactor block CSS namespacing.

  • Namespace all the blocks with a8c (instead of jetpack). This could be coming from a variable and customizable via cli to be different for each environment.
  • Disable previous automated CSS namespacing by default. Enable it again with --namespace CLI arg
  • Namespace all CSS with .wp-block-a8c-blockname already in stylesheets. Could be done in Webpack but this way we have more flexibility:
    • Markdown uses wp-block-a8c-markdown__placeholder -format
    • Tiled Gallery .wp-block-a8c-tiled-gallery .tiled-gallery-image -format.
  • Doesn't take imported Calypso components into consideration yet but makes it a separate concern by not trying to namespace both the block and Calypso components using the same namespace.

Testing

Previously

If you build Jetpack bundle:

npm run sdk:gutenberg -- --editor-script=client/gutenberg/extensions/presets/jetpack/editor.js

...you would get CSS:

.jetpack .tiled-gallery-square { }

If you build Tiled gallery block:

npm run sdk:gutenberg -- --editor-script=client/gutenberg/extensions/tiled-gallery/tiled-gallery.jsx

...you would get CSS:

.tiled-gallery .tiled-gallery-square { }

After

With this PR you should always end up with:

.wp-block-a8c-tiled-gallery .tiled-gallery-square { }

@matticbot
Copy link
Contributor

@simison simison requested review from ehg, dmsnell and tyxla August 13, 2018 14:07
@simison simison changed the title Update/sdk fixed css namespacing SDK: refactor block CSS name-spacing Aug 13, 2018
@simison simison requested review from ockham and coderkevin August 13, 2018 14:10
.wp-block-a8c-markdown__preview p {
min-height: 1.8em;
white-space: pre-wrap;
}
Copy link
Member Author

@simison simison Aug 13, 2018

Choose a reason for hiding this comment

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

I took this CSS from the original Jetpack-Markdown PR: https://github.com/Automattic/jetpack/pull/9705/files#diff-3e61a3fdc3d89ac00c7baef9a6d68d6c (kudos @Ferdev)

I left this bit out because I didn't find it being used anywhere:

.wp-block-jetpack-markdown-block__live-preview__token {
	/* $dark-gray-300 from Gutenberg _colors.scss */
	color: #6c7781;
}

...although it would've been a nice example of importing a Gutenberg variable in.

@simison simison added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 14, 2018
bin/sdk-cli.js Outdated
@@ -72,6 +72,10 @@ yargs
description: 'Whether to watch for changes and automatically rebuild.',
type: 'boolean',
},
'namespace': {
description: 'Wheater CSS be namespaced.',
Copy link
Member

Choose a reason for hiding this comment

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

Typo here: should be whether. Also, I think it's missing a "should" right before "be".

@@ -72,7 +72,9 @@ exports.compile = args => {
};

const name = path.basename( path.dirname( options.editorScript ).replace( /\/$/, '' ) );
const baseConfig = getBaseConfig( { extensionName: name } );
const baseConfig = getBaseConfig( {
extensionName: options.namespace ? name : false
Copy link
Member

Choose a reason for hiding this comment

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

With --namespace, this would result in:

.tiled-gallery .wp-block-a8c-tiled-gallery .tiled-gallery-square

and

.jetpack .wp-block-a8c-tiled-gallery .tiled-gallery-square

is that expected?

If so, wouldn't it be more robust if we have the namespace option as a string instead, which would allow us to specifically set the namespace as we use the SDK from the CLI?

Copy link
Member Author

Choose a reason for hiding this comment

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

I hid the namespacer tool behind the flag instead of removing it because I think it might still be useful; I'm experimenting with it in #26683

Since it's broken like you describe, it should be considered only for development testing.

Do you reckon I should completely remove the namespacer in this PR even if we might add it back later on?

Copy link
Member

Choose a reason for hiding this comment

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

Seems like @dmsnell is opting for removing it in #26680.

import JetpackMarkdownBlockEditor from './jetpack-markdown-block-editor';
import JetpackMarkdownBlockSave from './jetpack-markdown-block-save';

registerBlockType( 'jetpack/markdown-block', {
registerBlockType( 'a8c/markdown', {
Copy link
Member

Choose a reason for hiding this comment

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

Do we also want to apply that to any other extensions? Publicize still uses jetpack-publicize, and we might want to be consistent with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Updated.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like this introduced a bug 😕

See #26726

Copy link
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

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

looks like this shouldn't affect Calypso

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

🚢

@simison simison merged commit 77296ed into master Aug 15, 2018
@simison simison deleted the update/sdk-fixed-css-namespacing branch August 15, 2018 10:03
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants