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

@kohlmannj/jss-simple

v0.5.5

Published

Thin wrapper around jss that simplifies its interface and restricts you to a single stylesheet.

Downloads

3

Readme

jss-simple

Build Status Coverage Status js-standard-style

Thin wrapper around jss that simplifies its interface and restricts you to a single, global stylesheet.

Installation

$ npm install jss-simple

Usage

jss-simple is designed specifically for global, single-sheet, statically determined styles. Instead of creating stylesheets, jss-simple maintains a single stylesheet internally for you, which you can either toString or attach whenever your components have all been imported.

This means that before you call toString/attach all your style rules must have been added. So you must make sure that they are evaluated at import/require time - which generally means that they are in the outer-most scope of your module. E.g.

Bad:

import css from 'jss-simple'

export default function render ({props}) {
  const style = css({
    primary: {
      color: 'green'
    }
  })

  return <div class={style.primary}>{props.text}</div>
}

Good:

import css from 'jss-simple'

const style = css({
  primary: {
    color: 'green'
  }
})

export default function render ({props}) {
  return <div class={style.primary}>{props.text}</div>
}

Once you've required your top-level component (which requires all of your other components, transitively), your stylesheet should be complete. So at the top of your app you can do:

import App from 'components/app'
import * as jss from 'jss-simple'

jss.attach()
render(<App />)

Or on the server:

import App from 'components/app'
import * as jss from 'jss-simple'
import extend from 'jss-extend'
import nested from 'jss-nested'
import prefixer from 'jss-vendor-prefixer'
import camelCase from 'jss-camel-case'

const style = jss
  .use(extend)
  .use(nested)
  .use(camelCase)
  .use(prefixer)
  .toString()

export default function renderPage (args) {
  return `
    <html>
      <head>
        <style>
          ${style}
        </style>
      </head>
      <body>
        ${render(<App />, args)}
      </body>
    </html>`
}

Or with hot reloading on the client using vdux:

// ...imports...
import * as jss from 'jss-simple'

jss.attach()

let hmr
domready(() => hmr = vdux({
  middleware,
  reducer,
  initialState: window.__initialState__,
  app: state => <App state={state} />
}))

if (module.hot) {
  module.hot.decline()
  module.hot.accept(['./components/app', './reducer'], () => {
    jss.detach()
    hmr.replace(require('./components/app').default, require('./reducer').default)
    jss.attach()
  })
}

API

  • css(obj, opts, key) - Default export. Add obj to the global sheet's rules. Returns only the classes property from the sheet. So you have css({primary: {color: 'green'}}) -> {primary: <generatedClassName>}. The key parameter is optional, and can be used in development to prevent styles from accumulating when using hot module replacement.
  • use(plugin) - Add a jss plugin.
  • attach() - Attach the global sheet to the DOM.
  • toString() - Render the global sheet and return it as a string.
  • detach() - Detach the global sheet (useful for hot reloading, etc.).
  • clear() - Clear the internal stylesheet. (useful for hot reloading).

Plugins

jss-simple just uses regular jss plugins. Nothing special here, just .use them as you normally would.

Hot Reloading

You can just use jss-simple as demonstrated in the example above, and it will work just fine. However, since it can't tell which stylesheets are the new ones, they'll just keep accumulating, and your browser may become slow. To fix this, there is a second parameter to css called key. You can pass one yourself like this:

css({...style...}, __filename)

Or you can use this babel plugin in development to automatically do it for you: babel-plugin-jss-simple.

License

MIT