2.1.50 • Published 5 months ago

@slimr/styled v2.1.50

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

🪶 @slimr/styled npm package

A tiny (~2kb) React css-in-js library inspired by chakra-ui, emotion, and styled-components libs

Demo: CodeSandbox

Features:

  • Easily create React components with styles using familiar syntax
  • Much less bundle size and runtime sluggishness than others
  • Supports declaring css and styled components inside of Components for better code colocating
  • Zx/Css shorthand props like chakra-ui
  • Concise responsive CSS syntax Breakpoints shorthand similar to chakra-ui
  • Import pre-enhanced HTML Elements like Div or A for profit

Context

@slimr is a set of slim React (hence '@slimr') libs. Check them all out on github!

Setup/Install

npm i @slimr/styled

API

Includes @slimr/css exports

See npm for more info.

import {addCSs, createClass, css} from '@slimr/styled'
addCss('.foo { color: purple }')
c1 = createClass('c: red;')
c4 = css`c: red;`
<div className={css`c: red;`} /> // will resolve to 's0' like above
c6 = css`w: [100%, null, 400px]` // width = 100% on mobile and table, 400px on desktop

ZX and Stateful CSS Props

Props to help style based on CSS state

import {styled} from '@slimr/styled'

const MyDiv = styled.div`
  _zx={{color: 'blue}} // applies color = blue
  _active={{color: 'blue'}} // applied on :active
  _dark={{color: 'blue'}} // applied when browser prefers dark modes
  _focus={{color: 'blue'}} // applied on :focus
  _focusVisible={{color: 'blue'}} // applied on :focusVisible
  _focusWithin={{color: 'blue'}} // applied on :focusWithin
  _hover={{color: 'blue'}} // applied on :hover
  _light={{color: 'blue'}} // applied on :light
  _target={{color: 'blue'}} // applied on :target
  _visited={{color: 'blue'}} // applied on :visited
`

Shorthand props

Some styles are available as shorthand -- all of them here.

import {styled} from '@slimr/styled'
const MyDiv = styled.div`
  _bgColor="blue"
  _c="green"
  _p={18}
  _pos="absolute"
  _w={100}

Responsive Props

Specify responsive styles as arrays, similar to chakra-ui

Default breakpoints are [30em, 48em, 62em, 80em, 96em] and can be overridden by setting css.breakpoints

import {styled} from '@slimr/styled'
const MyDiv = styled.div`
  _w=[100%, null, 200px] // width = 100% on mobile, tablet. 200px on > tablet
  _zx={{w: ['100%', null, '200px']}} // is equivalent to _w

Pre-Enhanced HTML Elements

Import pre-enhanced HTML Elements like Div or A for profit. With a few exceptions, most elements accept ANY CSS style as a prop when prefixed by '_'

import {Div, A} from '@slimr/styled'
<Div _p=[8, null, 18]> // a div with responsive padding
  <P _fontSize={30} _lineHeight="1rem"> // style props
  <A _active={{ scale: 1.5 }} _hover={{ c: 'green' }}> // stateful styles
    I grow during keypress and am green on hover
  </A>
</Div>

Comparisons

Chakra-UI

  • A popular css-in-js lib that inspired this lib

Pros

  • More mature, SSR support
  • Lots of premade components

Cons

  • Is crazy large bundle impact (80+kb)

Styled-Components

  • A popular css-in-js lib that inspired this lib

Pros

  • More mature, SSR support

Cons

  • Is massive (~12kb), plus has dependency on emotion (~11kb)
  • Does not support zx prop or css shorthand props

Emotion

  • A popular css-in-js lib similar to styled-components

Pros

  • More mature, SSR support

Cons

  • Is large (>10kb)
  • Many features require addons, which make bundle even larger
  • Does not support zx prop or css shorthand props

Goober

  • another tiny 1kb styled-components like css-in-js

Pros:

  • More mature, SSR support

Cons:

  • Many features require addons, which in sum may make the bundle larger than slimr
  • Does not support zx prop or css shorthand props
2.1.50

5 months ago

2.1.49

8 months ago

2.1.47

8 months ago

2.1.48

8 months ago

2.1.45

8 months ago

2.1.46

8 months ago

2.1.43

8 months ago

2.1.44

8 months ago

2.1.41

9 months ago

2.1.42

8 months ago

2.1.29

10 months ago

2.1.38

9 months ago

2.1.36

9 months ago

2.1.37

9 months ago

2.1.34

9 months ago

2.1.35

9 months ago

2.1.32

9 months ago

2.1.33

9 months ago

2.1.30

10 months ago

2.1.31

9 months ago

2.1.18

1 year ago

2.1.19

1 year ago

2.1.27

1 year ago

2.1.25

1 year ago

2.1.26

1 year ago

2.1.23

1 year ago

2.1.6

1 year ago

2.0.7

1 year ago

2.1.24

1 year ago

2.1.5

1 year ago

2.0.6

1 year ago

2.1.21

1 year ago

2.1.22

1 year ago

2.1.7

1 year ago

2.1.20

1 year ago

2.1.17

1 year ago

2.1.14

1 year ago

2.1.15

1 year ago

2.1.12

1 year ago

2.1.13

1 year ago

2.1.10

1 year ago

2.1.11

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago