npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@slimr/styled

v2.1.50

Published

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

Downloads

8

Readme

🪶 @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