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

css-class-builder

v1.0.1

Published

A small typescript package built to work with ReactJS to shorten manipulation and handling of css classes by combining useful methods and function into one single package.

Downloads

21

Readme

npm GitHub Workflow Status Typescript MIT license CodeFactor A+

CSS Class Builder

A small typescript package built to work with ReactJS to shorten manipulation and handling of css classnames by combining useful methods and functions into one single package.

How to use

Installation

You can install the package to your javascript/typescript project, using below command

npm i css-class-builder

Setup

After installation import the package in your project file,

import cssClassBuilder from 'css-class-builder';

Then initialize the builder function,

const classname = cssClassBuilder();

This initialization creates a store where we can add, remove or toggle classnames. We can use classname to interact with the store.

Features

Initializing with value

The builder function can be initialized with a single or multiple classnames.

const classname = cssClassBuilder('initial'); // -> initial
const headingClass = cssClassBuilder('heading h-6'); // -> heading h-6

Extending css class

Once you have initialized the builder function you can use extend method to add classname(s) to the store.

const classname = cssClassBuilder();
classname.extend('another-css-class'); // -> another-css-class
classname.extend('red green'); // -> another-css-class red green

Removing css class

remove method can be used to remove classname(s) from the store.

const classname = cssClassBuilder('bold italic');
classname.remove('italic'); // -> bold

Toggling class dynamically

Classname(s) can be extended or removed from the store. We can use toggle method to toggle classname(s) over a boolean value.

  • For true, the classname will be added to the current classname.
  • For false, the class will be removed from the current classname.
const classname = cssClassBuilder('initial');
let anotherBooleanValue: boolean = true;
classname.toggle('blue', anotherBooleanValue); // -> initial blue
otherValue = false;
classname.toggle('blue', anotherBooleanValue); // -> initial

Using stored classnames

When ready to use the classname(s) stored in the builder for the className or class attribute of the HTML/JSX tags, unzip method can be used to get all classname(s) as a single string.

const classname = cssClassBuilder('initial');
classname.extend('bold italic');

return <div class={classname.unzip}></div>;

Above div will have the following classnames: initial, bold, italic.

Changelog

Please see the changelog to know about the latest updates.

Contributions

Contribution to this project are most welcomed.

If you find bugs or want more features, but don't know how to fix/implement them, please fill an issue.

If you fixed bugs or implemented new features, please send a pull request.