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-atomic-props

v1.0.0

Published

Utility for Styled-Components that converts props to styles, atomically.

Downloads

8

Readme

Atomic Styles via React Props for Styled Components

Installation

# via npm
npm install --save styled-atomic-props

# via yarn
yarn add styled-atomic-props

Configuration

In your react app's index.js:

!! IMPORTANT !!: CSS defined as propStyle MUST be terminated with a semicolon! Crucial bug prevention tip!

import React from 'react'
import App from './App'

import { addPropStyles } from 'styled-atomic-props'

addPropStyles({
  foo: 'background-color: #BFC9D8;',
  bar: 'color: #586272;',
  baz: 'padding: 1rem;',
  qux: 'border-radius: 0.25rem;',
  quux: 'border: 1px solid #A0ACBF;',
  corge: `
    /* any valid css that works in styled-components */
    ul {
      padding-left: 0;
      list-style: none;
      li {
        &:first-of-type {
          font-size: 110%;
          font-weight: 900;
          text-transform: uppercase;
        }
      }
    }
  `
})

ReactDOM.render(<App />, document.getElementById('root'))

Create a styled-component that accepts propStyles:

import styled from 'styled-components'
import getPropStyles from 'styled-atomic-props'

export const Div = styled.div`
  ${(props) => {
    return getPropStyles(props)
  }}
`
export default Div

Or use any of the core components provided by this package:

import {
  Div, // pasted above
  A,
  P,
  Img,
  Label,
  Span,
  Strong,
  Ul,
  Li,
  H1,
  H2,
  H3,
  H4,
  H5,
  H6
} from 'styled-atomic-props'

Usage

import { Div } from 'styled-atomic-props'

const SomeComponent = (props) => {
  return (
    <Div foo bar baz qux quux corge>
      <ul>
        <li>{'list item'}</li>
        <li>{'list item'}</li>
      </ul>
    </Div>
  )
}

Built-in propStyles

This package comes equipped with preset propStyles that are disabled by default.

To gain access to the built-in propStyles, pass true as the second argument to addPropStyles:

(you could also pass your favorite curse word or 'default' as a string, it's just a boolean check -- you do you boo)

addPropStyles(
  {
    someCustomPropStyle: 'background-color: black;'
  },
  true
)

// const addPropStyles: (userConfig: Object, withDefaults: Boolean) => Void

Previous example using built-in propStyles

See propStyles directory for complete set of built-in propStyles

PropStyles can also be passed as styled-components attributes as booleans.

import { Div, Ul } from 'styled-atomic-props'

const StyledUl = styled(Ul).attrs({
  listUnstyled: true
})`
  li {
    &:first-of-type {
      font-size: 110%;
      font-weight: 900;
      text-transform: uppercase;
    }
  }
`

const SomeComponent = (props) => {
  return (
    <Div bgGray300 gray600 padding border bcGray400 borderRadius>
      <StyledUl>
        <li>{'list item'}</li>
        <li>{'list item'}</li>
      </StyledUl>
    </Div>
  )
}