Build declarative, responsive layouts in React using CSS Grid.
<Visible>
component that conditionally displays given children:import React from 'react'
import { Visible } from 'atomic-layout'
const Page = () => (
<div>
<Visible from="md">Content</Visible>
</div>
)
Visible
works similar toOnly
, but unlike the latter it renders and visually hides the children. It's a useful pattern for SSR and React components tree hydration.
Only
(and other components that deal with conditional rendering) children would stagger during the parent's re-rendering (#234, #254)useResponsiveComponent
for easier declaration of Responsive components with styled-components
:import { useResponsiveComponent } from 'atomic-layout'
const Avatar = styled.img`
height: ${({ size }) => size}px;
width: ${({ size }) => size}px;
`
export default useResponsiveComponent(Avatar)
import Avatar from './Avatar'
const Post = () => (
<Avatar
src="image-sm.png"
size={50}
srcMd="image-md.png"
sizeMd={75}
/>
)
defaultOptions
to simplify the declaration of custom options:import Layout, { defaultOptions } from 'atomic-layout'
Layout.configure({
breakpoints: {
...defaultOptions.breakpoints,
portrait: {
orientation: 'portrait'
}
}
})
throttle()
in all responsive hooks to grant smoother experiences and eliminate UI jumps (#230)useRef
to preserve functions' identities (#229)useViewportChange
React hook (#232)<script src="https://unpkg.com/atomic-layout/umd/index.js"></script>
grid-template
syntax to define CSS Grid areas, rows and columns in a single template definition (#113)// Define grid row/columns and areas
const template = `
thumbnail heading 1fr
thumbnail actions 100px
/ 200px 1fr
`
<Composition template={template}>
{({ Thumbnail, Heading, Actions }) => (
<React.Fragment>
<Thumbnail>{...}</Thumbnail>
<Heading>{...}</Heading>
<Actions>{...}</Actions>
</React.Fragment>
)}
</Composition>
Layout.configure()
to throw "missing options" exception upon initial instantiation of the Layout class (#173, #176)useViewportChange
for smooth components re-render on breakpoint change (#167)1.0
release. Any consequent API changes will be released in a backward-compatible manner as minor versions.Proxy
to allow references and render attempts of potentially non-existent template areasLayout.configure()
(#63)styled-components
), which means you can specify which component to render instead of a default div
:<Composition as={Header} {...}>
{({ SomeArea }) => (
<SomeArea as="nav" />
)}
</Composition>
undefined
as the outputted value (#79)react-responsive@6
useViewportChange
hookuseBreakpointChange
hookuseResponsiveValue
hookuseResponsiveProps
hookgap
prop alias to semantically alias grid-gap
(instead of previous gutter
)Layout
instance (#153)grid-auto-rows
, grid-auto-columns
and grid-auto-flow
prop aliases (#130)ReactDOM.hydrate
call upon a conditional portion of a tree when rendering with Only
component (#117)grid-area
property when assigning on the generated area component. This broke the Iterative areas recipe.<Composition areas="singleArea">
{({ SingleArea }) => data.map((entry) => (
<SingleArea key={entry.id} col="auto">{entry.title}</SingleArea>
))}
</Composition>
react-responsive
dependency due to its sub-dependencies issues in stale packages.areas
prop on Composition
, aliasing grid-template-areas
(#123)flexDirection
, flexWrap
, flexGrow
and flexShrink
prop aliases on Box model