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

superstyle

v1.0.0-1

Published

Experimental CSS-in-JS library based on the CSS Object Model

Downloads

4

Readme

superstyle

CSSOM-based CSS-in-JS library

npm i superstyle

Superstyle is an experimental CSS-in-JS utility library that uses CSSOM to patch updates to styles after injection. Using plain JavaScript objects to author styles, superstyle helps promote style encapsulation while making use of native browser CSS APIs.

View Demo

// Usage
import superstyle from 'superstyle'

// create a superstyle rule object
const rule = superstyle({ color: 'blue' })

const h1 = document.getElementById('h1')

// Add className to an element
h1.className = rule.className

// Update the style in the CSSOM
rule.set({ color: 'tomato' })

Superstyle also supports nested objects for pseudoselectors and media queries

const rule = superstyle({
  color: 'tomato',
  ':hover': {
    color: 'plum'
  },
  '@media screen and (min-width: 40em)': {
    color: 'lime'
  }
})

API

superstyle

(function) returns a superstyle rule object

superstyle({ color: 'magenta' })

superstyle.sheet

(CSSStyleSheet) stylesheet object with additional helper methods

sheet.css

(getter) returns a string of CSS rules

const css = sheet.css

sheet.insert()

(function) accepts an array of CSS rule strings and returns an array of corresponding CSSRule objects

const cssRules = sheet.insert([ '.hello{color: magenta}' ])

rule

(object) core object with className, set method and references to CSSRules

const rule = superstyle({ color: 'magenta' })

rule.className

(string) unique className for the ruleset

el.className = rule.className

rule.set()

(function) method to update the style object

rule.set({ color: 'magenta' })

rule.rules

(array) array of CSSRules that correspond to the given rule

rule.css

(getter) returns an array of CSS strings for the rule

React higher-order component

Superstyle also includes a React higher order component (HOC) for creating components with static styles that can be updated with a css prop. Import the HOC from superstyle/react.

import superstyle from 'superstyle/react'

// Any component that accepts the `className` prop
const Button = props =>
  <button {...props} />
)

// Static style object
const style = {
  display: 'inline-flex',
  fontFamily: 'inherit',
  fontSize: 'inherit',
  margin: 0,
  paddingTop: 12,
  paddingBottom: 12,
  paddingLeft: 24,
  paddingRight: 24,
  color: 'white',
  backgroundColor: '#07c',
  border: 0,
  borderRadius: 3,
  appearance: 'none'
}

export default superstyle(style)(Button)
<div>
  <Button css={{ backgroundColor: 'magenta' }}>
    Hello
  </Button>
</div>

The higher order component also accepts strings for HTML tags to create primitive components.

const Button = superstyle({
  ...style
})('button')

Is this production-ready?

No. This is a proof-of-concept and has not been tested well enough for use in production. For a more stable CSS-in-JS library, try glamor, cxs, or styled-components


MIT License