-
Notifications
You must be signed in to change notification settings - Fork 20
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
Allow individual components to be imported into apps #1159
Conversation
88d7d17
to
2c2e334
Compare
2c2e334
to
b64ce9f
Compare
b64ce9f
to
62cee1f
Compare
in GOV.UK Frontend we built a mechanism in Sass that will only export components Sass once, no matter how many times it's imported - that's why aevery component's Sass in wrapped in an exports include is there the same need in this implementation? |
@kr8n3r possibly, although I'm currently more concerned about importing too much of the rest of govuk-frontend than I am of duplicating sass imports for our components. Although at some point we definitely want to import all of it, since we'll use all of it in apps somewhere. |
@andysellick 👍
from govuk-frontend as these should not output any code |
c77f143
to
d6212fa
Compare
d6212fa
to
a6489ad
Compare
Note to self: this change to the model may be beneficial for static, in that it might be possible to make govuk-frontend's mixins available to static via the 'component_support' sass file here, see alphagov/static#2023 for an example of duplication that this could remove. |
a6489ad
to
7b2999b
Compare
7892c58
to
175d6ab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a quick look at this in preparation for today's meeting. While I like the "suggested sass" feature, I'm not sure about the approach to split the helpers. In a world where static will be using the public-frontend layout I don't see a need for it to require any helpers.
app/controllers/govuk_publishing_components/component_guide_controller.rb
Show resolved
Hide resolved
app/assets/stylesheets/govuk_publishing_components/govuk-frontend.scss
Outdated
Show resolved
Hide resolved
69a8957
to
797ae24
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically this looks ok and I understand this unblocks the ongoing work in static (by reducing unnecessary code duplication and enabling mixins usage from govuk-frontend). I do however expect govuk_frontend_support.scss
and component_support.scss
not to be separated for long as we're working to introduce the public frontend layout which means static shouldn't require any styles. Also, long-term, applications should ideally only require one file to pull in sass from govuk_publishing_components
.
- code searches the view for instances of component use and creates a list on the component guide of those components
- streamline supporting sass into one line - only add a component to it if it has a sass file - wrap in a textarea for ease of copying and pasting
- put govuk-frontend import into separate sass file - static needs govuk-frontend but not everything else in component support - that was fine, but brand colours added weight to the CSS (everything else is mixins and variables) - splitting it out like this means that static can import govuk-frontend and use it, all other apps just have to import one extra file
- print sass doesn't need component_support, would drastically increase the print css file size
797ae24
to
dfb272c
Compare
What
Change the components gem to support the model proposed in RFC 108 where individual components are included in an application rather than all of them.
The Sass now contains two additional files necessary for applications when importing individual components:
govuk_frontend_support
, which contains general settings from the gem plus everything from govuk-frontend that adds no weight to the compiled CSS (settings, tools and helpers)component_support
, which contains everything else from govuk-frontend, plus helpers and mixins from the gem used by various componentsSo an application would import both of these files, then the sass for the components it needs. This has been split into two files like this so that static can import the first one without incurring additional CSS size or duplication, while still being able to make use of govuk-frontend mixins and variables (we need this now we're removing toolkit from static).
The component guide's sass is separate and has been updated to include all components, since several are used.
The previous mechanism for including the gem's Sass is untouched, so this change should be backwards compatible.
Why
See the RFC.
Visual Changes
Visual changes to a component guide inside an application. Now generates a list of components at the top that are used by this application. Also added numbers to all of the headings.
Underneath this heading is a snippet of Sass that can be used in the app to replace the
@import all_components
line, again generated.View Changes
https://govuk-publishing-compo-pr-1159.herokuapp.com/component-guide
Impact of the change
I've done some testing to see what impact these changes have on CSS files in applications. Here's some early results.
We also want to check how long the Sass takes to compile compared to previously. Here are some numbers, but they seem to vary considerably between tests with the same app, so they may not be reliable.
These tests are done by:
bundle exec rake assets:clean
rm -rf public/NAME-OF-APP/*
time bundle exec rake assets:precompile
The cookie banner question
The cookie banner is displayed from static. Currently, since every application pulls in every component, when a page is rendered the markup for the cookie banner comes from static but the styles come from the gem, via the app.
The new auto-generated list of sass files needed by an app therefore doesn't include the cookie banner, because the app doesn't use it. So I'm seeing the cookie banner unstyled when testing. There are two solutions:
Importing the cookie banner sass into static seems like the best option - it avoids duplication and puts the sass where it's actually used. This might need documenting somewhere when we change static to include these changes, I'm writing this to remind myself.