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

with-class-names

v0.0.4

Published

Tiny utility function for styled-components helps to override 3rd parties components with custom className props for their deep nested children or different states

Downloads

4

Readme

withClassNames 🤡 npm version

This is a tiny helpful utility function for styled-components which helps to override 3rd parties components with custom className props for their deep nested children or different states. For example activeClassName, or inputClassName etc.

Installation

Yarn:

yarn add with-class-names

npm:

npm install with-class-names --save

Usage example

You basically pass 3rd party Component to be styled, and then an object with keys as name of the props, and values as Tagged Template Literals with CSS, or with styled-component from which styles will be derived. Take a look at the example that have both of the options.

Edit with-class-names example

import withClassNames from 'with-class-names'
import styled, { css } from 'styled-components'

// 3rd party component with nested classNames options
const Component = ({
  className,
  nestedClassName,
  anotherNestedClassName,
  ...props
}) => (
  <div className={className} {...props}>
    {"Root"}
    <div className={nestedClassName}>
      {"Nested One Level"}
      <div className={anotherNestedClassName}>Another nested</div>
    </div>
  </div>
);

// styled-component which from you would like to derive styles
const DerivedFromStyledComponent = styled.div`
  background: palevioletred;
  color: ${props => props.purple};

  &:hover {
    background: mediumaquamarine;
  }
`

// Usage 
// arg0: Component to style
// arg1: (key: NestedClassNameProp, value: Tagged Template Literal/StyledComponent)
const StyledComponent = withClassNames(Component, {
  // This className will be populated with class of the DerivedFromStyledComponent  
  nestedClassName: DerivedFromStyledComponent,
  // If you want interpolations to work, use css from `styled-components` (PR welcome 😇)
  anotherNestedClassName: css`
    color: white;
    background: blue;
    border: ${p => p.color} 8px solid;
  `
  // Here is the styles of the wrapper. So the one that will come to className
  // as if you call styled(Component)``
})`
  background: black;
  color: ${p => p.color};
`;
//Note that if you don't need wrapper style, just call nothing ()

Known issues

If you want to interpolations to work for nested classNames please use css from styled-components for them to work like in the example here. PR Welcome to fix that 😍 I gave up trying 😇