Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kripod/otion

Atomic CSS-in-JS with a featherweight runtime
https://github.com/kripod/otion

atomic-css css-in-js microlibrary styling typescript

Last synced: 5 days ago
JSON representation

Atomic CSS-in-JS with a featherweight runtime

Awesome Lists containing this project

README

        


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.

[tailwind css]: https://tailwindcss.com/
[atomic css-in-js]: https://sebastienlorber.com/atomic-css-in-js

## 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.:

```shell
npm install otion
```

Additionally, configure frameworks as shown below:

- Create React App ([example](./packages/example-cra), [sandbox](https://githubbox.com/kripod/otion/tree/main/packages/example-cra))
- Gatsby ([plugin](./packages/gatsby-plugin-otion), [example](./packages/example-gatsby), [sandbox](https://githubbox.com/kripod/otion/tree/main/packages/example-gatsby))
- Next.js ([example](./packages/example-nextjs), [sandbox](https://githubbox.com/kripod/otion/tree/main/packages/example-nextjs))

## 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–value pair is only injected once to the library-managed style sheet.

Please refer to the [core package manual](./packages/otion/README.md) for further information.

```jsx
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 (
<>

I am blue



I am also blue, reusing the CSS class injected by my sibling



I am orange if your viewport is wider than 768px


>
);
}
```

## Is this ready for production?

The project is marked with a '0.Y.Z' version until thorough automatic tests are written for it. However, existing functionality should be safe to use.

If you decide to give otion a try, module aliasing may help migrating between CSS-in-JS libraries:

```jsonc
/* package.json */
{
"devDependencies": {
"emotion": "npm:otion@^X.Y.Z" // Could also be done in reverse
}
}
```

Please bear in mind that while the APIs of otion and Emotion are similar, they're not totally interchangeable. For example, custom selectors and [conditional group rules](https://developer.mozilla.org/docs/Web/CSS/At-rule#Conditional_group_rules) have no type-safe syntax in Emotion.

## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):



KristΓ³f PoduszlΓ³

🚧 πŸ’» πŸ“– πŸ’‘ πŸ€” πŸš‡

efflam

πŸ› πŸ€”

Katja Lutz

πŸ› πŸ€”

Mark Kvetny

πŸ€”

Jared Palmer

πŸ“–

Tiago Souza

πŸ“– πŸ“¦ πŸ’‘ πŸ’»

Eddy Wilson

πŸ€” πŸ›



Samuel Hobl

πŸ›

Juho VepsΓ€lΓ€inen

πŸ“–

Daniel Emod Kovacs

πŸ›

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Acknowledgements

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

- [Styled Components](https://styled-components.com/), with its thoroughly tested approaches
- [Styletron](https://www.styletron.org/), for openly discussing the caveats of atomic styling
- [glamor](https://github.com/threepointone/glamor), by its simplistic and comprehensible implementation

The logo's ocean emoji is courtesy of [Twemoji](https://twemoji.twitter.com/).