You can also add multiple classes to mix in shared styles from other pages.
We usually recommend adding things to the global /library at this point,
but not always (like for logged out pages with specific stuff).
- content_for :body_class, 'my-page my-page-shared-components'
Now you don't have to worry about your stuff leaking to other pages.
.my-page {
.some-page-specific-components {
// WHOO
}
}
Keep components flat to avoid fighting the cascade of inherited styles.
.my-page {
.component {
}
.component__child {
}
.component__child__child {
}
}
Conventions increase scannability of code. Adherence reduces friction for other developers.
But of course, if you oppose a piece of the convention, we welcome PRs that demonstrate a better way.
See the guide below for your options.
Hired frontend is designed to "go with the flow" of code growth rather than fight it. Let's walk through a typical page's lifecycle and the abstractions we'd choose at each.
Primitive building blocks and existing copy + design come in handy.
.box.box--red.xs-p2.xs-text-center
%h4 Here's some great content.
Create or find the existing page CSS sandbox for your HAML file.
.my-box
%h4 Here's some great content.
.my-page {
.my-box {
background-color: $brand-red;
color: $brand-black;
padding: 2 * $base-spacing-unit;
text-align: center;
}
}
Notice how late in the cycle we add it to /library. By not documenting experimental product, we empower our teams to iterate on code nuance and avoid premature abstraction.
There is a simple heuristic to determine when it’s time to document a thing: