• Stars
    star
    1,129
  • Rank 41,225 (Top 0.9 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build declarative, responsive layouts in React using CSS Grid.

Atomic Layout logo

Discord channel


Atomic Layout is a spatial distribution library for React. It uses CSS Grid to define layout areas and render them as React components. This pattern encourages separation of elements and spacing, preventing contextual implementations and boosting maintenance of layouts.

import React from 'react'
import { Composition } from 'atomic-layout'

// Define layout areas: visual representation
// of what composes a layout, detached from
// what components are actually rendered.
const areasMobile = `
  thumbnail
  header
  footer
`

// Declare responsive changes of your areas.
// Operate in two dimensions, remove areas
// or introduce new ones.
const areasTablet = `
  thumbnail header
  thumbnail footer
`

const Card = ({ title, imageUrl, actions }) => (
  <Composition areas={areasMobile} areasMd={areasTablet} gap={20}>
    {/* Get React components based on provided areas */}
    {({ Thumbnail, Header, Footer }) => (
      <React.Fragment>
        <Thumbnail>
          {/* Render anything, including another Composition */}
          <img src={imageUrl} alt={title} />
        </Thumbnail>
        {/* Preserve semantics with polymorphic prop */}
        <Header as="h3">{title}</Header>
        {/* Responsive props: just suffix with a breakpoint name */}
        <Footer padding={10} paddingMd={20}>
          {actions}
        </Footer>
      </React.Fragment>
    )}
  </Composition>
)

export default Card

Atomic Layout is responsive-first. It uses Bootstrap 4 breakpoints by default, which you can always customize for your needs.

Motivation

Modern layout development is about modularity and composition. Following the best practices of Atomic design, we strive toward independent UI units that gradually compose into more meaningful pieces. While the attention paid to units implementation is thorough, we often overlook how to achieve layout composition that scales. It's as if we forget that spacing defines composition.

When it comes to distributing the spacing things get more difficult. First of all, true contextless spacing is hard. To make things worse, all present solutions couple spacing with UI elements, inevitably making small reusable pieces contextful and, thus, hard to maintain.

Atomic Layout helps you to compose your elements by introducing a dedicated spacing layer called Composition. It encourages you to separate concerns between UI elements' visual appearance and spacing between them. With the first-class responsive support at your disposal you can build gorgeous responsive permutations of your elements without leaving the dedicated spacing layer, keeping UI elements contextless and predictable. Embrace the era of a true layout composition!

Implementations

Atomic Layout has multiple implementations depending on the styling solution:

Package name Latest version Styling library
atomic-layout Package version styled-components
@atomic-layout/emotion Package version @emotion/styled

Documentation

See the Official documentation.

Here are some shortcuts for quick access:

Examples

Although the examples below use atomic-layout package, they are fully compatible with other styling implementations of the library (i.e. @atomic-layout/emotion).

Basics

Basic composition: square and circle

Basic composition

Combine two UI elements into a single one using Composition.

Component with responsive props

Responsive props

Change a prop's value depending on a breakpoint.

Composition of other compositions

Nested composition

Any element can be a composition and a composite at the same time.

Intermediate

Conditional rendering

Conditional rendering

Render or display elements conditionally based on breakpoints.

Custom configuration

Custom configuration

Configure a default measurement unit, custom breakpoints, and responsive behaviors.

Shorthand media query

Shorthand media query

Use a shorthand query function to declare inline media queries in CSS.

Materials

Artem speaking at React Finland

Creating layouts that last (React Finland, 2019)

Find out the main aspects of a layout's maintainability and why spacing plays a crucial role in it. Learn how to wield layout composition as an actual React component–a missing glue for your elements and design systems.

SurviveJS logo

Layout composition as a React component (SurviveJS)

Read through the extensive interview about how Atomic layout came to be, how it's different from other solutions, and which practices it encourages.

The Future of Layouts β€” Artem Zakharchenko

The future of layouts (React Vienna, 2018)

Watch Artem discussing the biggest obstacle to achieve maintainable layouts, and showcases a way to combine existing technologies to build clean UI implementations using Atomic layout.

Community

Reach out to us to share an awesome project you're building, or ask a question:

Browser support

Atomic Layout's browser support is made by the browser support of underlying technologies the library uses. Pay attention if your project can support CSS Grid to be sure you can use Atomic Layout.

See the Support table for CSS Grid. For Internet Explorer support please read this issue.

Contributing

By contributing to Atomic Layout you shape the way developers create reusable UI.

Please refer to the Contribution guidelines before committing to this project. We are thankful for any kind of contribution you may bring: discussion, issue report, or a pull request.

More Repositories

1

naming-cheatsheet

Comprehensive language-agnostic guidelines on variables naming. Home of the A/HC/LC pattern.
13,893
star
2

react-advanced-form

Functional reactive forms. Multi-layer validation, custom styling, field grouping, reactive props, and much more.
JavaScript
217
star
3

vscode-nako-theme

Nako is a premium dark color theme for Visual Studio Code.
Shell
61
star
4

page-with

A library for usage example-driven in-browser testing of your code.
TypeScript
59
star
5

kettanaito.com

@kettanaito's personal blog.
MDX
55
star
6

remix-og-image

Build-time in-browser Open Graph image generation for Remix.
TypeScript
27
star
7

rettime

Type-safe dependency-free EventTarget-inspired event emitter for browser and Node.js.
TypeScript
25
star
8

msw-with-remix

Minimal example of using Mock Service Worker with Remix. Both server- and client-side.
JavaScript
23
star
9

create-typescript-library

A template repository for a superb library written in TypeScript (ESM/UMD/CJS, tree-shaking, CI).
TypeScript
19
star
10

movie-app

Movie App for the "Mocking REST and GraphQL APIs with MSW" course on Egghead.
TypeScript
19
star
11

zed-theme-evil-rabbit

An Evil Rabbit theme for Zed.
19
star
12

atomic-layout-docs

Documentation website for Atomic layout library.
JavaScript
18
star
13

react-data-preview

Fancy interactive preview of your JavaScript data.
JavaScript
17
star
14

graphql-server

Production-ready setup of GraphQL Express server based on Apollo Server.
JavaScript
15
star
15

protocol-handlers

Utilities to work with protocol handlers (like "vscode://") on the web.
TypeScript
13
star
16

react-advanced-form-addons

Form prototyping framework for React Advanced Form. Tailor production-ready forms in a matter of minutes. Write the logic, do the styles later.
JavaScript
12
star
17

until-connected

Wait for a connection at the given target without making any requests.
TypeScript
12
star
18

fs-teardown

Teardown API for testing file system-dependent code.
TypeScript
11
star
19

turborepo-remix-prisma

Turborepo with a Remix app and Prisma.
TypeScript
11
star
20

next-testing-library

Utilities for testing NextJS applications.
TypeScript
8
star
21

jest-custom-matchers

Source code for the "Practical Guide To Custom Jest Matchers" article.
TypeScript
8
star
22

webpack-http-server

On-demand runtime webpack compilations over HTTP.
TypeScript
6
star
23

service-worker

W3C specification-compliant implementation of Service Workers for Node.js.
TypeScript
6
star
24

test-flat

A test framework extension to support resources teardown and cleanup in flat tests.
TypeScript
6
star
25

react-advanced-form-docs

Documentation for React Advanced Form.
5
star
26

redux-dynamics

Strongly-typed collection of tools to make your Redux workflow more dynamic.
JavaScript
4
star
27

rsc-frameworkless

A frameworkless, barebones example of RSC usage.
JavaScript
4
star
28

kentcdodds-worker-redirect

JavaScript
3
star
29

readable-stream-polyfill

"ReadableStream" polyfill based on the eponymous implementation from Node.js.
TypeScript
3
star
30

namespace-station

Comprehensive function names suggestions based on language analyzis. Say what your function should do, get a function name back.
JavaScript
3
star
31

graphql-mongo

Utilities for faster GraphQL + MongoDB integration.
JavaScript
3
star
32

sentinel-dom

Dependency-free VanillaJS way to determine the visibility of DOM elements.
TypeScript
3
star
33

events-pool

Accumulate multiple events, and their data, from different sources into a single pool.
JavaScript
3
star
34

graphql-query-shortlink

Express middleware for creating GraphQL query shortlinks to GraphiQL.
TypeScript
2
star
35

service-worker-multiple

Example of registering multiple Service Workers on a single scope.
JavaScript
1
star
36

url-to-string-issue

JavaScript
1
star
37

tbg

Turn-based dice game just for fun.
TypeScript
1
star
38

create-prop-types

A utility function to create custom prop type validators for React with ".isRequired" chaining built in.
JavaScript
1
star
39

atomic-layout-docs-legacy

GitBook documentation for Atomic layout library.
1
star
40

msw-axios-happy-dom

JavaScript
1
star
41

tug-o-war

A tug-o-war game with Remix, WebSockets, and MSW.
TypeScript
1
star
42

whatwg-fetch-json

JavaScript
1
star
43

project-template-remix

Remix template for CodeSandbox Projects
TypeScript
1
star
44

cra-box

JavaScript
1
star
45

service-worker-readable-stream

Respond to "fetch" event with a ReadableStream.
JavaScript
1
star
46

jest-es6

Example repository with unit testing an ES6 code with Jest.
JavaScript
1
star
47

webpack-file-router-plugin

Webpack plugin that derives a JSON manifest from a directory to enable file system-based routing.
TypeScript
1
star