Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

class-name-prop

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-name-prop

A lightweight utility function to create a React className prop value for multiple classes.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
77
decreased by-16.3%
Maintainers
1
Weekly downloads
 
Created
Source

class-name-prop

npm version CI status

A lightweight utility function to create a React className prop value for multiple classes.

  • 📦 < 70 B, Size Limit tested.
  • 💪 Supports ancient browsers and Node.js.
  • ⚡️ Simple and fast API.
  • 🧠 Returns undefined if there are no classes, to prevent rendering a redundant class attribute; unlike packages like classnames.

Setup

To install from npm run:

npm install class-name-prop

API

Table of contents

function classNameProp

Creates a React className prop value for multiple classes.

ParameterTypeDescription
classes…*A parameter for each class; only non empty strings are added to the final string.

Returns: string | undefined — A className prop value; either a string of classes or undefined to prevent rendering an empty class attribute.

Examples

A React component for a link that can be declared active, whilst supporting custom classes.

const classNameProp = require('class-name-prop')
const PropTypes = require('prop-types')
const React = require('react')

const Link = ({ className, active, ...props }) => (
  <a className={classNameProp(className, active && 'active')} {...props} />
)

Link.propTypes = {
  className: PropTypes.string,
  active: PropTypes.bool
}

Keywords

FAQs

Package last updated on 24 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc