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

styled-shortcuts

v2.1.2

Published

A props shortcut helper for styled-components.

Downloads

36

Readme

Styled Shortcuts 💅

Build Status npm version Coverage Status

TL;DR

  • Now with Theme Support!
  • Provides convenient props shortcut helper for Styled Components 💅
  • Small footprint with No Dependencies!
  • With Styled Shortcuts you can now do this:
    font-size: ${'fontSize:px'};
    instead of this:
    font-size: ${({ fontSize }) => `${fontSize}px`};
  • Use any unit (e.g. px, %, cm, you name it) or no unit at all.

Install

$ npm i --save styled-shortcuts

API

Here's the beauty... There's only one function! Styled Shortcut provides a higher order function that you use to wrap Styled Components, like this:

import rawStyled from 'styled-components';
import shortcuts from 'styled-shortcuts';

const styled = shortcuts(rawStyled);

And to make everyone's life easier, there's now a package that does this for you. In fact, it is a direct replacement for styled-components. It imports both styled-components and styled-shortcuts and exports the wrapped styled.

All you have to do is make a one-line change your components to import from styled-shortcut-components instead of styled-components.

// import styled from 'styled-components';
import styled from 'styled-shortcut-components';

Usage

Any template string value is assumed to be a props key. For example, ${'color'} will return the prop named color. Your can also assign a "unit" suffix. It can be anything, such as px, %, em, etc. Simply separate the unit from the prop key with a colon. For example ${'width:px'} will return the width prop with the "px" suffix.

See this example below:

import styled from 'styled-shortcut-components';

const Button = styled.button`
  padding: ${'padding:em'};
  border-radius: ${'borderRadius:px'};
  width: ${'width:%'};
  color: ${'color'};
`;

Button.defaultProps = {
  padding: 1,
  borderRadius: 4,
  width: 100,
  color: 'red',
};

Using with Themes

You can specify a props key that contains a dotted object notation.

For example:

const Button = styled.button`
  padding: 0.25em 1em;
  border-radius: ${'theme.button.borderRadius:px'};
  color: ${'theme.color'};
  border: 2px solid ${'theme.color'};
`;

See the Styled Components documentation for complete details on how to enable theming.

Do It Live!

Check out this live example on CodeSandbox.

Do It Live!