1.2.0 • Published 5 years ago

monad-ui v1.2.0

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

MONAD UI

A Utility first CSS-in-JS

Inspired by:

  • Rebass
  • TailwindCSS
  • Smooth UI
  • Material UI

Implemented in EmotionJS

Getting Started

Install emotion.js

In this tutorial we're going to use emotion's css prop API

import * as S from 'monad-ui`

In component

<div css={S.bg('blue)}>
    Monad UI
</div>

With more styles

<div css={[
    S.bg('blue'),
    S.color('red),
]}>
Monad UI
</div>

It will styles the div's background to blue and color to red

3 Ways to make the style Responsive

Currenlty, We have 4 breakpoints:

  sm: '576px'
  md: '768px'
  lg: '992px'
  xl: '1200px'

1. Array Responsive API

  <div css={
    S.bg(['red', 'green', 'blue'])}
  >Monad UI</div>

It will make the div's background to red.

When the screen size is above 576px. It will be green

When the screen size is above 768px. It will be blue

And so on.

2.Object Responsive API

<div css={
    S.bg({
        sm: 'red',
        lg: 'blue',
    })}
>
    Monad UI
</div>

This is just another form of responsive API.

On screen size sm it will be red.

On screen size lg it will be blue.

Notice that I didn't specify md. When it's not specified. It will take the previous value. Which is red in this case

3. High Order Responsive API

<div css={
    S.up('sm')(hidden)
}>
    Monad UI
</div>

This will hide the div when screen size is below 576px

<div css={
    S.up('sm')(hidden)
}>
    Monad UI
</div>

This will hide the div when screen size is above 576px

<div css={
    S.up('sm')(S.bg('blue'))
}>
    Monad UI
</div>

This will turn div's background into blue when screen size is above 576px

Available API

TypeArray Responsive APIObject Responsive APIHigh Order Responsive API
Dynamic
Static

Dynamic => It accept arg

For example, `bg('blue')

That means this can be used with

Array Responsive API:

bg(['red', 'green', 'blue']);

Object Responsive API:

bg({
  sm: 'red',
  lg: 'blue'
});

and High Order Responsive API

up('md')(
    bg('blue')
);

Static => It doesn't accept arg

So it can only be used with High Order Responsive API

down('md')(
    hidden
);

Media Queries

Prop
up
down

Display

Proptype
hiddenstatic
blockstatic
inlinestatic
flexstatic
inlineFlexstatic

Flex

Proptype
flexWrapdynamic
flexDirectiondynamic
alignItemsdynamic
justifyContentdynamic
justifyBetweenstatic
flexColstatic

Flex Utility

PropType
centerXstatic
centerYstatic
centerstatic
  • CenterX => Center Horizontally, it's just an alias for [S.flex, S.justifyContent('center')]
  • CenterY => Center Veritcally, it's just an alias for [S.flex, S.alignItems('center')]
  • Center => An alias for CenterX + CenterY

Margin

PropType
mldynamic
mrdynamic
mtdynamic
mbdynamic
mxdynamic
mydynamic
mdynamic

Padding

PropType
pldynamic
prdynamic
ptdynamic
pbdynamic
pxdynamic
pydynamic
pdynamic

Color

PropType
bgdynamic
colordynamic

Size

PropType
wdynamic
maxWdynamic
  • w is an alias for width
  • maxW is an alias formaxWidth

Typography

PropType
lhdynamic
fsdynamic
fwdynamic

Border

PropType
rounddynamic
roundedstatic
borderdynamic

Helper

PropType
linkstatic
  • link is an alias for
  textDecoration: 'none',
  color: 'inherit',
  cursor: 'pointer'

Misc

Do I always have to import * as S from 'monad-ui'

If you only use a few style

You can also import it this way

import {bg, hidden} from 'monad-ui'

And use it like this

<div css={bg('blue')}></div>

Too many styles ?

Consider extracting your style outside

import {css} from `@emotion/core`
import {bg, color} from 'monad-ui'

const style = css([
    bg('blue'),
    color('red')
])

// ... in component

<div class={style}></div>