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

SPT: Isolate TemplateSelectorControl component #38445

Closed
wants to merge 11 commits into from

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Dec 16, 2019

Changes proposed in this Pull Request

Isolate TemplateSelectorControl component, and rename to TemplateSelector.

While working on #38403, I discovered that TemplateSelectorControl's styling is a bit weird, and doesn't lend itself easily to removing the white bar at the bottom of each item that contains the template name.

This is due to some padding-top: 100%, absolute positioning, translating, etc. I think that we can achieve the same styling in a more semantic way, that will also allow us to conditionally remove the label.

To that end, I'd like to isolate the TemplateSelectorControl component and styling, so it becomes easier to modify them, since currently, there's just one big style file in FSE.

This PR renames TemplateSelectorControl to TemplateSelector, and moves it (and its dependencies, and styling) to a separate folder.

Testing instructions

  • Verify that Gutenboarding still looks the same as before.
  • Build FSE and test it in your WP.com sandbox, and verify that it also still looks and feels the same.
  • Run tests in apps/full-site-editing/full-site-editing-plugin/starter-page-templates/page-template-modal/components/template-selector/test/:
    • cd apps/full-site-editing/ && npm ci && npm run test:unit

@matticbot
Copy link
Contributor

@ockham ockham force-pushed the isolate/spt-template-selector branch from 3cbbe53 to e06b61a Compare December 16, 2019 08:13
@ockham ockham added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Dec 16, 2019
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

I left a few questions about SASS variables.

Comment on lines 3 to 9
// Preview positioning
$preview-max-width: 960px;
$preview-right-margin: 24px;
$preview-left-sidebar-reduced: calc( 30% + #{$wp-org-sidebar-reduced} );
$preview-left-sidebar-full: calc( 30% + #{$wp-org-sidebar-full} );

$template-large-preview-title-height: 120px;
Copy link
Member

Choose a reason for hiding this comment

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

I believe these will become global, there's no module-scoping of variables in SASS.

It would be good to make sure "local" variables have namespace style prefixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied all of this from existing SPT styling 😅 Think there's potential for regression?

Comment on lines 1 to 2
$wp-org-sidebar-reduced: 36px;
$wp-org-sidebar-full: 160px;
Copy link
Member

Choose a reason for hiding this comment

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

Are these meant to replace some existing variables? This seems dangerous, see my other comment about global variables and namespaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think they're just used by SPT for some calculations.

We could use these upstream vars though: https://github.com/WordPress/gutenberg/blob/fdd69535ecbec018bfabad783c890de3d72b7e07/packages/base-styles/_variables.scss#L30-L32

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed f4adda3 and ba960df to that effect.

@ockham ockham requested a review from a team as a code owner December 16, 2019 10:18
$template-selector-modal-offset-right: 32px;
$template-selector-blank-template-mobile-height: 70px;

@mixin screen-reader-text() {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this mixin either in Calypso or Gutenberg base styles already? Could we import it from there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't find it in Calypso upon a quick search. It appears to be in Gutenberg, https://github.com/WordPress/gutenberg/blob/bfd1117846c7802d62dbba046c27968d961781e7/packages/block-editor/src/components/responsive-block-control/style.scss#L1-L12, so we might be able to use that -- unless there's more implicit dependencies (like this: WordPress/gutenberg#19159).

Overall, this PR is just moving around pre-existing styling; I'd like to limit changes that go beyond that in order to unblock it soon 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(We might actually want to use that entire component rather than just its styling.)

Copy link
Member

Choose a reason for hiding this comment

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

Just moving things around in this PR makes sense. 👍

$template-selector-border-color-selected: #555d66;
$template-selector-border-color-active: #00a0d2;
$template-selector-border-color-hover: #c9c9ca;
$template-selector-empty-background: #fff;
Copy link
Member

Choose a reason for hiding this comment

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

While it's ok to have them here, should these variables be pulled in from Gutenberg base styles or color studio? I.e.:

$template-selector-empty-background: $white;


// Template Selector Preview
.template-selector-preview {
@media screen and ( max-width: 659px ) {
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 have mixins or variables available in Gutenberg for these screen sizes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couldn't find any (tried grepping 660px and 659px).

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha — I guess in some follow up some day we could re-use breakpoints from ~@wordpress/base-styles/breakpoints

$preview-max-width: 960px;
$preview-right-margin: 24px;
$preview-left-sidebar-reduced: calc( 30% + #{$admin-sidebar-width-collapsed} );
$preview-left-sidebar-full: calc( 30% + #{$admin-sidebar-width} );
Copy link
Member

Choose a reason for hiding this comment

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

Will $admin-sidebar-width work both in wp-admin when WP sidebar is visible and when Gutenberg is iframed in Calypso and the sidebar is hidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

idk 😅 -- But all I did in f4adda3 is remove two SASS var definitions with two other ones that I'm importing from @wordpress/base-styles. That shouldn't change any behavior, should it?

Copy link
Member

Choose a reason for hiding this comment

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

That shouldn't change any behavior, should it?

It shouldn't indeed and sounds fair! :-) Just good to test both scenarios anyway always when CSS is touched for anything FSE plugin related.

@simison
Copy link
Member

simison commented Dec 16, 2019

Left a few scss variables questions as well — I haven't tested so I'm little ignorant about how things actually work, hence some questions might not make sense. 😁 Hope this helps anyway!

@@ -0,0 +1,189 @@
@import '~@wordpress/base-styles/variables';
Copy link
Member

Choose a reason for hiding this comment

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

Since WordPress/gutenberg#19159 is an issue at the moment, you could also import the whole set via this file:

@import '~@wordpress/base-styles/z-index';
@import '~@wordpress/base-styles/colors';
@import '~@wordpress/base-styles/variables';
@import '~@wordpress/base-styles/breakpoints';
@import '~@wordpress/base-styles/mixins';
@import '~@wordpress/base-styles/animations';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed be80333 which seems to be enough.

@Copons
Copy link
Contributor

Copons commented Dec 16, 2019

Ehm... this PR says hi: #38065 😅

@ockham
Copy link
Contributor Author

ockham commented Dec 17, 2019

Closing; obsolete as of #38456.

@ockham ockham closed this Dec 17, 2019
@ockham ockham deleted the isolate/spt-template-selector branch December 17, 2019 09:53
@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 Dec 17, 2019
@matticbot
Copy link
Contributor

matticbot commented Dec 18, 2019

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~30 bytes added 📈 [gzipped])

name                 parsed_size           gzip_size
entry-gutenboarding       +251 B  (+0.0%)      +30 B  (+0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

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

Successfully merging this pull request may close these issues.

5 participants