-
Notifications
You must be signed in to change notification settings - Fork 36
[WIP][Experiment] Make the guide as a tool for decision-making, rather than a set of opinions #213
base: master
Are you sure you want to change the base?
Changes from all commits
959b87a
a97947a
c619f55
e16afb5
2735116
90795d9
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 |
---|---|---|
|
@@ -3,36 +3,42 @@ title: Architecture | |
permalink: /css/architecture/ | ||
sidenav: css | ||
--- | ||
# Architecture | ||
# Choosing a CSS methodology and architecture | ||
A site's architecture should be based on its goals and purposes. This means the | ||
guidance here should be adapted to different sites and situations. | ||
|
||
## Modular or component architecture | ||
When using a modular or component architecture, every page is broken into a | ||
series of modular components. There are two sets of these components: | ||
`components` and `modules`. The architecture starts out with basic HTML element | ||
rules: HTML, p, a, form, etc tags that than have components and modules written | ||
on top of them. Components are very basic structure such as buttons, blurbs, | ||
navs, and positioning structures like insets, island, and enclosure. From | ||
here, modules are built with these components. This architecture also attempts | ||
to keep the specificity trend in an upwards curve as you move down in the file | ||
In general, 18F recommends using a modular approach (specifically, [modified BEM]) | ||
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 suggest our first suggestion would be "Use USWDS" wouldn't it? |
||
to provide consistency and scalability to larger apps. However, for some applications | ||
(such as a rapid prototype), an atomic architecture may make more sense. Below are | ||
some considerations for choosing an architecture. | ||
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 wanted to get the actionable, "we generally recommend this" bit out in front of any ideological postulation. |
||
|
||
## Modular architecture | ||
Naming conventions like [BEM] and [SMACSS] popularized the idea of modular architecture. | ||
Modular architectures are very helpful for a few different kinds of projects: | ||
- larger, more complex sites with reusable components | ||
- sites maintained and built by multiple engineers | ||
- production sites that will be handed off to partner teams or vendors | ||
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. This bit here is my stab at documenting why you might choose a modular system. Very open to additions/criticisms. 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. Should we acknowledge that yes, it's ugly, clunky and tends to break the cascade, but it's ugly, clunky and tends to break the cascade in well-known, widely used and predictable ways? |
||
|
||
In a modular architecture, every page is broken into `components` and `modules`. | ||
*Components* provide basic recurring elements such as buttons, lists, and navs. | ||
*Modules* are built by combining these components into reusable structures. | ||
This helps keep the specificity trend in an upwards curve as you move down in the file | ||
(more on this to come). | ||
|
||
- Start with an elements file for all tag rules (a, h1-h5, p, \*, html, body). | ||
A few helpful things to keep in mind when building out a modular architecture: | ||
- Start with an elements file for all tag rules (`a`, `h1`-`h5`, `p`, `*`, `html`, `body`). | ||
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. Why? I don't think it's a bad idea, it just feels like a fairly strong opinion to not have a reason. |
||
- Create component files for each structural element, such as buttons, navs, | ||
etc. These are mainly class-based and use [BEM] or another [naming | ||
scheme](#css-naming). | ||
etc. | ||
- Create more specific structure with modules. For instance, if the logo image | ||
and text needs very specific treatment, use a module. | ||
- Build modules from components through mixins, extends, and HTML. | ||
- Modules can have higher specificity, it’s fine to use deeper nesting. | ||
- Build modules from components through Sass mixins, extends, and HTML. | ||
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 we have an opinion on mixin vs extend? I know a lot of folks do :-) |
||
- Have an overrides file or folder comprised of global rules that are meant to | ||
override components and modules. | ||
- These can be generic utilities. | ||
- A good thing to put here are breakpoint-specific rules, such as hiding | ||
something at small breakpoints. | ||
|
||
### File structure | ||
### Example file structure | ||
```sh | ||
_elements.scss | ||
_mixins.scss | ||
|
@@ -50,46 +56,10 @@ lib/neat.scss | |
_overrides.scss | ||
``` | ||
|
||
For the `util`, `typography`, `elements`, and `overrides` files, once they grow | ||
too large (300 lines or more) in size, split them into their own folder with | ||
sub files. | ||
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. "Too large" is a matter of opinion. I've literally never done this myself and have not seen it on a project in the wild. |
||
|
||
```sh | ||
elements/_all.scss | ||
elements/_p.scss | ||
elements/_h.scss | ||
typography/_body.scss | ||
typography/_links.scss | ||
overrides/_breakpoints.scss | ||
overrides/_util.scss | ||
util/_center.scss | ||
util/_clearfix.scss | ||
``` | ||
|
||
|
||
## Importing | ||
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. WTF is this doing in this section. Moved to "Specificity" for now. 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 think it was attempting to show how the files should be organized for predictability and findability, which seems useful, but awkward here. |
||
As you likely know, CSS rules that are later in the file override earlier | ||
rules. This means Sass imports can be used to control inheritance and | ||
specificity. | ||
|
||
- Start with base elements. | ||
- Move to single nested classes and utils. | ||
- Move next to more specific classes, often with nesting. | ||
- Move next to overrides, possibly with !important rules. | ||
- Import alphabetically. | ||
- Only modify import order for groups of files, not specific files. | ||
## Atomic architecture | ||
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. Help, I don't know what to write about atomic CSS because I can't stop hating it long enough to figure it out. :-p We should do some user interviews with folks like @hursey013 who have used/appreciated atomic CSS to figure out what they find it useful for. 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. Can't help you. I think it's only suitable for prototypes. |
||
|
||
```scss | ||
// Bad | ||
@import 'module/logo'; | ||
@import 'component/mask'; | ||
@import 'component/button'; /* Has to be imported after "mask" */ | ||
|
||
// Good | ||
@import 'component/button'; | ||
@import 'component/mask'; | ||
@import 'module/logo'; | ||
``` | ||
|
||
|
||
[BEM]: http://getbem.com/introduction/ | ||
[SMACSS]: http://smacss.com/ | ||
[modified BEM]: /css/naming |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,4 @@ sidenav: css | |
--- | ||
|
||
# CSS | ||
The purpose of the CSS coding styleguide is to create consistent CSS or | ||
preprocessor CSS code across 18F. The styleguide should be treated as a guide | ||
— rules can be modified according to project needs. | ||
The purpose of the CSS coding styleguide is to help 18F developers make decisions about CSS tools and implementations. The goal of this guide is not to be dogmatic, but to explain how and why we recommend certain approaches, and to help developers make their own decisions for their individual projects. | ||
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 guide hasn't created consistency, so it seems a bit pompous to suggest that that's the goal. 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 think we should be dogmatic, where being dogmatic is warranted. We should just say why we care. For example, at this point, I'm fairly comfortable saying atomic CSS should not be used for long-lived code unless the partner is already using it and you're adopting their house style. It's just too difficult to pick through when you want to make changes, and unfamiliar to too many partners. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,32 +3,4 @@ title: 18F Front-End Guide | |
permalink: / | ||
--- | ||
Welcome to the 18F Front-End Guide! This is where we keep all of our | ||
guidelines for front-end design and development. | ||
|
||
## What is front end? | ||
|
||
The Front-End Guild did a series of exercises to determine the | ||
fundamental differences between the front-end design and front-end | ||
developer roles at 18F. Using [some of our own research | ||
methods](https://methods.18f.gov), the Front-End Guild came up with | ||
the following recommendations on knowing the difference between the | ||
two disciplines: | ||
|
||
**Front-end designers** design, write, and implement the | ||
presentational code base for websites and applications. They should | ||
have a clear understanding of design fundamentals and systems, such | ||
as interface style guides, responsive design, grid systems, front-end | ||
frameworks, and accessibility best practices. Front-end designers | ||
should feel comfortable creating and implementing design systems | ||
using semantic HTML5, CSS/Sass and be able to assist in debugging | ||
this aspect of the code base. | ||
|
||
**Front-end developers** architect, write, and implement the | ||
functional code base for websites and applications. They should have | ||
a clear understanding of client-side render and response, such as | ||
HTTP methods, API consumption, the browser loading/rendering | ||
pipeline, and accessibility best practices. Front-end developers | ||
should feel comfortable developing and implementing client-side | ||
interactions and frameworks using semantic HTML5 and JavaScript, and | ||
should be able to help with debugging, testing, and performance | ||
optimization of the code base. | ||
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 torn about deleting this. On one hand, we haven't had front end designers at 18F for nearly two years. On the other hand, it feels valuable to define what we expect from front end developers (and what we don't expect). Perhaps that definition process is one that we should go through again new, though? 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 think we should keep the bit about front-end developers. |
||
guidelines for front-end design and development. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,14 @@ permalink: /javascript/frameworks/ | |
sidenav: js | ||
--- | ||
# Frameworks | ||
|
||
**We recommend using [React]() for projects when possible.** As a team, we enjoy using React because it has a strong component model, enables easy server side rendering, and faciliates debugging by making the UI elements a function of the application state. React is most akin to the "view layer" in an MVC (Model-View-Controller) architecture and is frequently used with some other libraries. In our projects, we tend to use: | ||
|
||
* [Redux](https://www.npmjs.com/package/redux) for managing state | ||
* [Webpack](https://www.npmjs.com/package/webpack) and [Babel](https://babeljs.io/) for compiling our Javascript | ||
|
||
However, we are not dogmatic about React - we just vastly prefer it. Here are some other popular frameworks that have been used at 18F and some of their key characteristics. | ||
|
||
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. Brought this over from the ancient PR that never got merged, just to have something to work with. 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 still think, especially given people's concerns about Facebook, that we should say "React or React-like" frameworks. I'd also feel comfortable being more dogmatic about it, and say "Use a react-like framework unless you have a compelling reason not to, such as the partner already using another framework". I just think the ramp-up time for developers diving into one person's fave framework from six months ago is much greater than any benefit from that framework in most cases. Unless we have a strong second choice, I'd be happy dropping the angular and Backbone sections, too. |
||
## Angular | ||
AngularJS (commonly referred to as "Angular") is an open-source web application framework maintained by Google and by a community of individual developers and corporations to address many of the challenges encountered in developing single-page applications ([Wikipedia](http://en.wikipedia.org/wiki/AngularJS)). | ||
|
||
|
@@ -61,7 +69,6 @@ Backbone.js is a JavaScript library with a RESTful JSON interface and is based o | |
- Since it has very little structure, inexperienced programmers can easily create unmaintainable code with Backbone. | ||
- Designed primarily for REST data. | ||
|
||
|
||
## React | ||
React (sometimes styled React.js or ReactJS) is an open-source JavaScript library for creating user interfaces that aims to address challenges encountered in developing single-page applications ([Wikipedia](https://en.wikipedia.org/wiki/React_(JavaScript_library))). | ||
|
||
|
This file was deleted.
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 think my strongest opinion when it comes to our CSS is that we're either writing a quick throwaway prototype or something we intend to hand over and have our partner maintain, and we need to figure that out and behave accordingly from the get-go. For the former, I don't care what you write or how you write it, or if you follow any methodology at all beyond the mad scientist voices in your head. For the latter, I don't care how smart you are, you can't make the deliverable smarter than their average developer.