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

themz

v2.0.0

Published

Selectors for theming in StyledComponents and JSS

Downloads

6

Readme

Themz

Build Status npm David license

Readme

Themz is helpers library for easy theming with StyledComponents, ReactJSS, StyledJSS

Installation

npm install --save themz

Usage

Just import named functions.

import {
  theme,
  cond,
  breakpoint,
  palette,
  size,
  propIfElse,
  propIf,
} from 'themz'

And define theme object

const theme = {
  palette: {
    primary: '#ff0',
    primaryLight: '#ff9',
    accent: '#f00',
    accentDark: '#900',
  },
  breakpoints: {
    mobile: {
      small: '320px',
      middle: '480px',
    },
    desktop: {
      wide: '1920px',
    },
  },
  sizes: {
    large: '22px',
    middle: '15px',
    small: '8px',

    control: '12px',
  },
}

StyledComponents

import styled from 'styled-components'
import { palette, size } from 'themz'

export const Button = styled.button`
  border: none;
  padding: ${size('middle')};
  background-color: ${palette('accent')};
`

ReactJSS

import React from 'react'
import injectSheet from 'react-jss'
import { propIfElse, palette, size } from 'themz'

const styles = {
  button: {
    backgroundColor: propIfElse('accent', palette('accent'), palette('control', 'Light')),
    padding: size('middle'),
  }
}

const Button = ({ classes, children }) => (
  <button className={classes.button}>
    {children}
  </button>
)

export default injectSheet(styles)(Button)

StyledJSS

import styled from 'styled-jss'
import { propIf, palette, breakpoint } from 'themz'

export const Button = styled('button')({
  boxShadow: propIf('shadowed', `1px 1px 5px -1px black`),
  backgroundColor: palette('accent', 'Dark'),
  width: breakpoint('mobile', 'small'),
})

API

See tests

theme

Just select properties from theme property

const styles = {
  value: theme('palette'), // will be object
  color: theme(['palette', 'accentLight']), // like: palette('accent', 'Light')
  width: theme(['width', 'control', 'medium']), // same as: props => props.theme.width.control.medium
}

cond

Apply value if property exists in props object

const styles = {
  backgroundColor: cond('opened', ['palette', 'accent']),
  textDecoration: cond('active', 'underline'),
}

breakpoint

Simple select breakpoint from theme. (Default size is medium)

const Demo = styled.div`
  @media screen and (max-width: ${breakpoint('desktop')}) {
    padding: ${size('controlPadding')};
  }

  @media screen and (max-width: ${breakpoint('desktop', 'small')}) {
    padding: ${size('controlSmall')};
  }
`

palette

Select color from theme. By default shade is ''

const styles = {
  backgroundColor: palette('accent', 'Light'), // same as props => props.theme.palette.accentLight
  color: palette('black'), // props => props.theme.palette.black
}

size

Get size from theme.sizes

const styles = {
  width: size('block1/2'), // props => props.theme.sizes['block1/2']
}

propIf

Execute condition, and it true return branch

const styles = {
  padding: propIf(props => props.type === 'global', size('controlLarge')),
  color: propIf('active', palette('secondary', 'Light')),
  boxShadow: propIf('active', '1px 0 9px -1px #121412'),
}

propIfElse

const styles = {
  padding: propIf(
    props => props.type === 'global',
    size('controlLarge'),
    size('controlMedium')
  ),
  color: propIf('active', palette('secondary', 'Light'), palette('accent')),
  boxShadow: propIf('active', '1px 0 9px -1px #121412', 'none'),
}