Skip to content

Extract component-specific stylesheets#6168

Closed
aduth wants to merge 6 commits intomainfrom
aduth-component-stylesheets
Closed

Extract component-specific stylesheets#6168
aduth wants to merge 6 commits intomainfrom
aduth-component-stylesheets

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Apr 6, 2022

Why:

  • So that, like with component-specific scripts, we can create stylesheet bundles which are loaded only on pages where the component is used, rather than as part of the single common "application" stylesheet, thereby reducing the size of the common stylesheet, and allowing for stylesheets to be broken up for parallel download.
  • To bring greater alignment between common component implementations
    • For example, the TroubleshootingOptionsComponent Rails ViewComponent and corresponding TroubleshootingOptions React component
  • Simplified path for incorporating JavaScript package SCSS files into build pipeline
    • Previously required an extra stylesheet in app/assets/stylesheets, which is no longer necessary

Draft:

  • Specs

aduth added 2 commits April 6, 2022 15:35
**Why**: So that, like with component-specific scripts, we can create stylesheet bundles which are loaded only on pages where the component is used, rather than as part of the single common "application" stylesheet, thereby reducing the size of the common stylesheet, and allowing for stylesheets to be broken up for parallel download.

changelog: Internal, Optimization, Reduce size of common stylesheet
'widescreen': false,
);

$line-height: 1.5;
Copy link
Contributor Author

@aduth aduth Apr 6, 2022

Choose a reason for hiding this comment

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

This file organization is unsustainable, but I think we should embrace the unsustainability to force us to improve how these are managed: Namely, the typographical settings should be applied universally at the design system.

Comment on lines +10 to +11
def self.stylesheets
@stylesheets ||= sidecar_files_basenames(['scss'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, this behavior is unused, and is a remnant of early implementation approach. That being said, it feels like it's a reasonably expected behavior to align with how self.scripts is implemented, if we're going to support both self.scripts and self.stylesheets regardless (even if self.stylesheets would be implemented by the individual component).

end

def render_assets
if helpers.respond_to?(:enqueue_component_scripts) && self.class.scripts.present?
Copy link
Contributor

Choose a reason for hiding this comment

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

I see it was in the old code, but can you remind me why we need to do a respond_to? check for that method?

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 see it was in the old code, but can you remind me why we need to do a respond_to? check for that method?

A bit of speculative thinking that these components could be used outside Rails, based on #5398 (comment) , where enqueue_component_scripts would be optionally provided by the framework as a way to control how scripts (and now styles) are printed.

@@ -1,4 +1,5 @@
@import 'identity-style-guide/dist/assets/scss/packages/required';
@import '@18f/identity-idp-required-scss';
@import '@18f/identity-components/troubleshooting-options';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It feels a little fragile to have to pull in stylesheets based on the components being used in this pack. Also, this is duplicating the styles into the document-capture pack, rather than using the existing pack. I might want to think on this a bit more...

@aduth
Copy link
Contributor Author

aduth commented Apr 11, 2022

I probably won't have much capacity to revisit this in the near future. I'll plan to close the pull request, with the expectation that I'd like to resume it again in the future at some point.

@aduth aduth closed this Apr 11, 2022
@aduth aduth deleted the aduth-component-stylesheets branch April 11, 2022 17:53
@aduth
Copy link
Contributor Author

aduth commented May 10, 2023

I'm interested to pick this up again, especially with USWDS v3's new component-specific imports. For example, this would have been nice to pair with #8307 as a way to include the USWDS "Tooltip" component only on pages where the clipboard button is used.

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.

2 participants