GithubHelp home page GithubHelp logo

atomss's Introduction

Atomss

An framework-agnostic atomic css-in-js library with support to nested and ssr

Installation

To install just run npm install atomss or yarn add atomss

Usage

import { css, clsx, keyframes } from 'atomss';

const animation = keyframes({
  // percents work too
  from: {
    color: 'red',
  },
  to: {
    color: 'blue',
  },
});

const styles = css({
  color: 'red',
  animation: `${animation} 5s ease infinite`,
  '&:hover': {
    color: 'gray',
  },
  '@media (min-width: 300px)': {
    color: 'yellow',
  },
});

const another = css({
  color: 'red', // will use the same classname
  backgroundColor: 'blue',
});

const classNames = clsx(styles, another);

SSR

To handle server usages, atomss will provide some helpers, such as hydrate and Cache

Client side

import { hydrate } from 'atomss';

hydrate(); // just run hydrate, this method will handle your previous generated cache

Server side

import { seal, getStyleTag, getScriptTag } from 'atomss';

router.get('/', (req, res) => {
  renderToString();

  res.send(`
    <html>
      <head>
        ${getStyleTag()}
      </head>
      <body>
        <div id="app"></div>
        ${getScriptTag()}
      </body>
    </html>
  `);

  seal(); // run clear to avoid mismatch
});

Alert

Today atomss doens't handle custom units or order in properties of same css declaration, the style is as is

How this works

You write a css-like object, atomss parse your input and create a hash key for every declaration, such your parents too. Then for equal declarations the clsx helper will use the same classname.

To avoid mismatch styles, atomss reverse the order of injection in clsx and filter the properties already used, the hash of a class like color: red will be different than @media (min-width: 300px) { color: red }. Then simple color declarations should not override the media query declaration.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.