-
Notifications
You must be signed in to change notification settings - Fork 36
[WIP] CSS section style/language overhaul #211
base: master
Are you sure you want to change the base?
Changes from 15 commits
850c90a
f4f0565
788d3e1
6f5b146
c93b807
ec75583
8f2903d
0b1a2a3
96e437b
48e1f87
64d0995
af7d5cb
48b56b6
03edec6
5de6b80
54fb554
c7a8375
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <nav> | ||
| <ul class="usa-sidenav-list"> | ||
| {% for link in include.links %} | ||
| {% assign _href = link.href %} | ||
| {% assign _current = false %} | ||
| {% if link.href == page.url or link.href == page.permalink %} | ||
| {% assign _current = true %} | ||
| {% endif %} | ||
| <li> | ||
| <a href="{% if link.external == true %}{{ link.href }}{% else %}{{ link.href | relative_url }}{% endif %}" | ||
| {% if _current %} class="usa-current" {% endif %} | ||
| {% if link.class %}class="{{ link.class }}" {% endif %} > | ||
| {{ link.text }} | ||
| </a> | ||
| {% if _current and page.subnav %} | ||
| <ul class="usa-sidenav-sub_list"> | ||
| {% include subnav.html links=page.subnav %} | ||
| </ul> | ||
| {% endif %} | ||
| {% if link.links %} | ||
| <ul class="usa-sidenav-sub_list"> | ||
| {% include subnav.html links=link.links %} | ||
| </ul> | ||
| {% endif %} | ||
| </li> | ||
| {% endfor %} | ||
| </ul> | ||
| </nav> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,15 +4,33 @@ permalink: /css/documentation/ | |
| sidenav: css | ||
| --- | ||
| # Documentation | ||
|
|
||
| You should always document: | ||
| - Magic numbers (when you absolutely cannot avoid using them) | ||
| - Overrides of imported frameworks like USWDS | ||
| - Rules that must be used in conjunction with one another | ||
| (using BEM naming conventions is somewhat self-documenting in this regard) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd welcome any additions to this list! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top level components you create, to leave a note of what they are, how they're used, any a11y concerns, etc. |
||
|
|
||
| We also recommend maintaining a project style guide of your choice. | ||
| Add examples of how to use classes that make up complex modules | ||
| when used in conjunction with one another. | ||
|
|
||
| ## Sass Comments | ||
| Be intentional when you use `//` (silent comments) versus `/* */` | ||
| (which are preserved in the CSS output). When in doubt, use `//`. | ||
|
|
||
| ## KSS | ||
| Use KSS for documentation. More information on KSS can be found on the | ||
| [official site](http://warpspire.com/kss/). | ||
| KSS is the most common CSS documentation method to date. It relies | ||
| on comments that follow a specific format to generate documentation | ||
| for you. The generated documentation can be modified through templates. | ||
| More information on KSS can be found on the | ||
| [official KSS site](http://warpspire.com/kss/). | ||
|
|
||
| ### Example | ||
| The original KSS repo is not maintained. There are numerous forks that are | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it accurate to say that it is not maintained? Is it not updated because it's abandoned, or because it's mature and needs little to no updating? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last update was 5 years ago, and other projects have forked it to implement their own versions. Smells unmaintained to me, but I'm down for tweaking the language! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about something like "While the original KSS repo has not been updated in several years, community development has continued in forks and it remains one of the most used CSS documentation tools" |
||
| maintained, the [Node.js KSS fork](https://github.com/kss-node/kss-node) being | ||
| one of the more active ones. | ||
|
|
||
| ### Example of KSS documentation | ||
|
|
||
| ```scss | ||
| // Button | ||
|
|
@@ -34,7 +52,3 @@ Use KSS for documentation. More information on KSS can be found on the | |
| .button-modified { | ||
| } | ||
| ``` | ||
|
|
||
| ### Rationale | ||
| KSS is the most common CSS documentation method to date. While it’s not perfect, | ||
| the generated documentation can be modified through templates. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,17 +9,30 @@ sidenav: css | |
|
|
||
| Sometimes, projects utilize other CSS frameworks such as: | ||
|
|
||
| 1. [Bourbon](https://www.bourbon.io/) | ||
| 2. [BassCSS](https://www.basscss.com/) | ||
| - [Bourbon](https://www.bourbon.io/) (particularly well-suited to working with Sass) | ||
| - [BassCSS](https://www.basscss.com/) (atomic CSS framework) | ||
|
|
||
| These frameworks were chosen because they're relatively unopinionated about | ||
| design decisions while still providing the helpers that make frameworks | ||
| essential to fast and accurate frontend work, for example, solutions for | ||
| responsive design, grids, and common design patterns. In addition, both | ||
| essential to fast and accurate front-end work (for example, solutions for | ||
| responsive design, grids, and common design patterns). In addition, both | ||
| frameworks, through modular design and excellent documentation, make it easy | ||
| for the designer or developer to only use the parts that they need, rather than | ||
| including a hefty library. | ||
|
|
||
| ## Considerations for choosing a CSS framework | ||
|
|
||
| When choosing a framework for your project, the following questions may be helpful in assessing your options: | ||
|
|
||
| - What does it offer that the U.S. Web Design System doesn't? | ||
| - How does it support responsive design? | ||
| - Are patterns for more complex interactions (accordions, tabs, menus) accessible? | ||
| - Does it allow for straightforward customization? | ||
| - Is it mature and currently supported? | ||
| - Does it support older browsers and provide fallbacks for newer techniques when necessary? | ||
| - Is the library size reasonable? | ||
| - Do other developers and designers on your team know how to work with this framework? | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these seem reasonable? What else should go in this list? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm of the opinion that we should revamp this list to strongly suggest starting with the USWDS unless you have really compelling reasons not to, and to strongly suggest NOT introducing Yet Another Framework. Even in the cases where BassCSS has been used already, I know there's been a fair bit of follow-up discussion wondering why it was essentially reproducing USWDS. If we think is the right basis for the front-end on government sites (and I think that's safe to say) then I think we should be a bit firmer in that opinion. |
||
|
|
||
| ## Do not use Bootstrap | ||
| 18F specifically does not recommend using [Bootstrap](http://getbootstrap.com/) for production work | ||
| because it can be difficult to adapt its opinionated styles to bespoke design work. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,10 +3,17 @@ title: Inheritance | |
| permalink: /css/inheritance/ | ||
| sidenav: css | ||
| --- | ||
| # Inheritance | ||
| # Working with inheritance in Sass | ||
|
|
||
| Two commonly used Sass features are [mixins and inheritance](https://sass-lang.com/guide) | ||
| (the @extend directive). These are very powerful if used correctly; however, | ||
| @extend in particular can bloat your stylesheets if used too liberally. | ||
|
|
||
| ## Mixins | ||
| - Use mixins for groups of properties that appear together intentionally and | ||
| are used multiple times. | ||
|
|
||
| Mixins are helpful for decreasing the amount of repetitive code you need to write. | ||
| For instance, if you want to create a clearfix that can be added to other classes | ||
| easily, you could create a clearfix mixin: | ||
|
|
||
| ```scss | ||
| @mixin clearfix { | ||
|
|
@@ -18,8 +25,23 @@ sidenav: css | |
| } | ||
| ``` | ||
|
|
||
| You can then use the mixin in other classes, without having to rewrite the rules: | ||
| ```scss | ||
| .media-block { | ||
| @include clearfix; | ||
| ... | ||
| } | ||
| ``` | ||
|
|
||
| Mixins can also take parameters. | ||
|
|
||
| For further guidance, see the [Sass documentation](https://sass-lang.com/guide). | ||
|
|
||
| ### When to use mixins | ||
|
|
||
| - Use mixins for groups of properties that appear together intentionally and are used multiple times. | ||
| - Use mixins for components to change size. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually don't know what this means. Anyone care to clarify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't either. I think this is trying to quickly explain why inheritance is great, but that really just comes down to "use mixins when you're repeating yourself a lot" and I don't think a lengthy explanation is probably necessary here... I think most people who are decent with CSS are already really aware of repeating themselves and inherited/cascading effects in general. So I like your addition, but would probably strike the "change size" bit. I think the bigger issue is the difference between include and extend, which is tricky to understand and has huge implications to the final CSS |
||
| - Use mixins when something requires parameters. | ||
| - Use mixins when a repeatable pattern requires parameters. For example: | ||
|
|
||
| ```scss | ||
| @mixin size($width, $height: $width) { | ||
|
|
@@ -28,20 +50,18 @@ sidenav: css | |
| } | ||
| ``` | ||
|
|
||
| - Do not use mixins for browser prefixes. Use [Autoprefixer](https://github.com/postcss/autoprefixer). | ||
|
|
||
| ```scss | ||
| // Bad | ||
| @mixin transform($value) { | ||
| -webkit-transform: $value; | ||
| -moz-transform: $value; | ||
| transform: $value; | ||
| } | ||
| ``` | ||
| ### When not to use mixins | ||
| Do not use mixins for browser prefixes. Use [Autoprefixer](https://github.com/postcss/autoprefixer). | ||
|
|
||
|
|
||
| ## Extend | ||
| Be very careful with using `@extend`. It's a powerful tool that can have | ||
| Any Sass selector can be extended. However, because `@extend` copies all of | ||
| the rules from one selector to another, it can cause a great deal of unintentional | ||
| CSS bloat when the CSS is compiled. Sass has the concept of [placeholder classes], | ||
| which help reduce unforeseen side effects. The Sass documentation has | ||
| [helpful information about using `@extend`](http://sass-lang.com/guide). | ||
|
|
||
| Be very careful and deliberate when using `@extend`. It's a powerful tool that can have | ||
| disastrous side-effects. Before using please consider: | ||
|
|
||
| - Where is my current selector going to be appended? | ||
|
|
@@ -52,12 +72,12 @@ If you're unsure of using `@extend`, follow these rules to avoid running into | |
| trouble: | ||
|
|
||
| - Use `@extend` from within a module, not across different modules. | ||
| - Use `@extend` on [placeholders] exclusively, not on actual selectors. | ||
| - Make sure the placeholder you extend is present as little as possible in the | ||
| - Use `@extend` on placeholder classes exclusively, not on actual selectors. | ||
| - Make sure the placeholder class you extend is present as little as possible in the | ||
| stylesheet. | ||
|
|
||
| You can use [mixins] in place of selectors. While mixins will copy more code, | ||
| the difference will often be negligible once the output file has been gzipped. | ||
|
|
||
| [mixins]: http://sass-lang.com/guide#mixins | ||
| [placeholders]: http://thesassway.com/intermediate/understanding-placeholder-selectors | ||
| [placeholder classes]: http://thesassway.com/intermediate/understanding-placeholder-selectors | ||
Uh oh!
There was an error while loading. Please reload this page.