Block

The Block component is a helper component that lets you write these common less-reusable elements more succinctly inline.

One of the most common needs when building web apps is creating layout elements that have certain layout and typography styles.

For more traditional apps that use global stylesheets, many of the popular CSS frameworks have helper classes to quickly create styled elements (see Bootstrap, Tachyons).

The move to CSS-in-JS sort of eliminates these classes in favor of encapsulating styles within components. This is a generally a good thing because it promotes reusability, however the reality is that there are dozens or hundreds of different layout/spacing/typography combinations in any app, and there's not always a clear semantic meaning or potential for reuse. In practice you end up just defining and naming a bunch of things at the top of the file:

Examples

Block basic Usage
primary100
primary200
primary300
primary400
primary500
primary600
primary700
negative100
negative200
negative300
negative400
negative500
negative600
negative700
warning100
warning200
warning300
warning400
warning500
warning600
warning700
positive100
positive200
positive300
positive400
positive500
positive600
positive700
Block with font customization
font100
font200
font250
font300
font350
font400
font450
font500
font600
font700
font800
font900
font1000
Block as a flexbox
Positioned with flexbox
Positioned with flexbox
Positioned with flexbox
Positioned with flexbox
Block with grid usage
1
2
3
4
5
6

Responsive Layouts

Block component props accept either a single value or array of values. When an array is provided, it will create media queries for each item based on the theme breakpoint values.

By default, the breakpoint values are

breakpoints: { small: 320, medium: 600, large: 1280, }

Given a marginTop value of ['10px', '20px', '30px', '40px'] Block will create the css rules below:

@media screen and (min-width: 1280px) { margin-top: 40px; } @media screen and (min-width: 600px) { margin-top: 30px; } @media screen and (min-width: 320px) { margin-top: 20px; } margin-top: 10px;

Responsive Properties
Overrides

These styles are provided by styletron