gatsby-plugin-otion

Gatsby plugin for otion, the atomic CSS-in-JS library


Keywords
gatsby, gatsby-plugin, otion, css-in-js, atomic, atomic-css, microlibrary, styling, typescript
License
MIT
Install
npm install gatsby-plugin-otion@0.5.0

Documentation

otion

Atomic CSS-in-JS with a featherweight runtime

npm Language grade: JavaScript Travis (.com)

Backstory

Design systems embrace a component-oriented mindset. Inspired by Tailwind CSS, utility classes provide reusable styles with no unwanted side-effects. However, they have to be generated upfront.

Atomicity generalizes the former concept by instantiating style rules on demand. Serving as a solid foundation for constraint-based layouts, atomic CSS-in-JS has come to fluorish at scale.

Key features

  • 馃幊 Support for shorthand properties
  • 馃嵄 Reliable pseudo selector ordering
  • 馃攼 Type safety with autocompletion
  • 馃 Auto-prefixing and fallback values
  • 馃摎 Embedded JSDoc reference
  • 馃惥 Negligible runtime footprint
  • 馃挮 Works without a framework

Getting started

Install the library with a package manager of choice, e.g.:

npm install otion

Additionally, configure frameworks as shown below:

Example

The following demo covers a wide range of use-cases.

As a core function, css returns a space-separated string of unique class names. Each property鈥搗alue pair is only injected once to the library-managed style sheet.

Please refer to the core package manual for further information.

import { css, keyframes } from "otion";

// Animation keyframes are lazily initialized
const pulse = keyframes({
  from: { opacity: 1 },
  to: { opacity: 0 }
});

// Use of JSX is optional, as the solution is framework-agnostic
function Component() {
  return (
    <>
      <p className={css({ color: "blue" })}>I am blue</p>
      <p
        className={css({
          color: "blue",
          ":hover": {
            animation: `${pulse} 3s infinite alternate`
          }
        })}
      >
        I am also blue, reusing the CSS class injected by my sibling
      </p>
      <p
        className={css({
          color: "blue",
          "@media": {
            "(min-width: 768px)": {
              color: "orange"
            }
          }
        })}
      >
        I am orange if your viewport is wider than 768px
      </p>
    </>
  );
}

Contributors

Thanks goes to these wonderful people (emoji key):


Krist贸f Poduszl贸

馃毀 馃捇 馃摉 馃挕 馃 馃殗

efflam

馃悰 馃

Katja Lutz

馃悰 馃

Mark Kvetny

馃

Jared Palmer

馃摉

Tiago Souza

馃摉 馃摝 馃挕 馃捇

This project follows the all-contributors specification. Contributions of any kind welcome!

Acknowledgements

The project's name is an ode to Emotion, an extensive CSS-in-JS runtime. Similar libraries had great impact on the initial development process, including but not limited to:

  • Styled Components, with its thoroughly tested approaches
  • Styletron, for openly discussing the caveats of atomic styling
  • glamor, by its simplistic and comprehensible implementation

The logo's ocean emoji is courtesy of Twemoji.