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:
Block basic Usage
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;
Block API
Warning
any
= "Prop types are not shown in dev mode"
extract-react-types is not being run in dev mode for speed reasons. If you need to
see prop types add the environment variable FORCE_EXTRACT_REACT_TYPES
eg:
FORCE_EXTRACT_REACT_TYPES=true yarn start <packageName>
FORCE_EXTRACT_REACT_TYPES=true yarn start:<team>