Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/lttb/taddy

Compile-time Atomic CSS-in-JS
https://github.com/lttb/taddy

atomic-css babel-plugin css css-in-js

Last synced: about 1 month ago
JSON representation

Compile-time Atomic CSS-in-JS

Awesome Lists containing this project

README

        


taddy


taddy


Compile-time Atomic CSS-in-JS



taddy npm


@taddy/core npm bundle size


taddy npm bundle size


## Quick Start

```sh
npm install --save taddy
```

```jsx
import React from 'react'

import {css} from 'taddy'

export function Title() {
return (


Hello, taddy!


)
}
```

## Usage

### css

There is an agnostic `css` function, that returns an object of `className` and `style`.

That's a framework-agnostic function, so it's ready for the usage at any environment.

```js
// button = {className: 'hash1 hash2', style: {}}
const button = css({padding: '10px', border: 'none'});
```

#### pseudo classes

```js
const button = css({
padding: '10px',
border: 'none',
color: 'red',

':hover': {
color: 'blue',
},
});
```

### css.mixin

In terms of `taddy`, mixin is a special styling object, that can be used as a part of styles by `css`.

To declare the mixin styles, there is a special function `css.mixin`:

```js
const heading = css.mixin({
fontSize: '20px',
fontWeight: 'bold',
});
```

`mixin` also could be used as a named export:

```js
import {mixin} from 'taddy';

const heading = mixin({
fontSize: '20px',
fontWeight: 'bold',
});
```

#### merge

Mixin can be applied by spreading to the styles, consumed by `css`:

```js
const heading = css.mixin({
fontSize: '20px',
fontWeight: 'bold',
});

const Title = ({children}) => (

{children}


);
```

Mixins also could be used on the nested level:

```js
const halfTransparent = css.mixin({
opacity: 0.5,
});

const Title = ({children}) => (


{children}


);
```

#### composes

Mixins are cool, but they have some restrictions.

For example, let's consider two mixins:

```js
const colorStateful = css.mixin({
color: 'red',

':hover': {
color: 'blue',
},
});

const opacityStateful = css.mixin({
opacity: 1,

':hover': {
opacity: 0.5,
},
});
```

In terms of merge, the result of `css({...colorStateful, ...opacityStateful})` would be `{color: 'red', opacity: 1, ':hover': {opacity: 0.5}}`

But what if we want to apply both mixins together?

There is `composes` interface for that (mixins and styles as `css` arguments):

```js
const Title = ({children}) => (


{children}


);
```