A javascript microframework to shorten daily use CSS class manipulator methods by adding them all into a single method

Overview

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.

You might also like...
A single page application that allows people to donate money.

This application was written in ReactJS. This is a SINGLE PAGE APPLICATION(SPA) that uses Pay On API to collect donation from users.Users can only make donations once in every hour

Lightweight auth library based on oidc-client for React single page applications (SPA). Support for hooks and higher-order components (HOC).

Lightweight auth library based on oidc-client for React single page applications (SPA). Support for hooks and higher-order components (HOC).

A Single Page Application Of Nike Built With React
A Single Page Application Of Nike Built With React

Projeto Nike React Desde já, gostaria de salientar que este projeto foi feito ap

Combine single-spa with module federation

single-spa-mf combine single-spa with module federation API import { registerApp

Single Page Resume Builder
Single Page Resume Builder

Free and open source, fully customizable professional single page resume builder

Moviesflix - a Single Page Application(SPA) that was developed with ReactJS
Moviesflix - a Single Page Application(SPA) that was developed with ReactJS

This project is a Single Page Application(SPA) that was developed with ReactJS.

Use js to download and unzip the npm package. only supports use in the browser.

Use js to download and unzip the npm package. only supports use in the browser.

Converts HTML pages into React components
Converts HTML pages into React components

Extract annotated portions of HTML into React components as separate modules. The structure of HTML is preserved by importing child components and rep

In this repo you will find the sample project where we dive deeper into the nuances of how hooks work, particularly in the context of the React render/rerender cycle.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: ya

Owner
Ankit Mishra
Aspiring Software Engineer || JavaScript/ES6, Flutter, ReactJS, HTML, CSS || Pursuing Bachelor's in Science, Delhi University
Ankit Mishra
:tada: React Universal Hooks : just use****** everywhere (Functional or Class Component). Support React DevTools!

react-universal-hooks React Universal Hooks : just use****** everywhere. Support React >= 16.8.0 Installation Using npm: $ npm install --save react-un

Salvatore Ravidà 177 Oct 10, 2022
Repository responsible for all code developed during the JavaScript Beginners Series

Série de Vídeos para Iniciantes em JavaScript Uma série de vídeos ensinando conc

Glaucia Lemos 622 Dec 20, 2022
We have updated our application over to using hooks and functional components to replace any class components we had before.

Crwn hooks We have updated our application over to using hooks and functional components to replace any class components we had before. How to fork an

Shazil Sattar 2 Feb 10, 2022
Stitches-like variant API for plain class names.

classname-variants Stitches-like variant API for plain class names. The library is framework agnostic and can be used with any kind of CSS flavor. It

Felix Gnass 133 Dec 23, 2022
This command line can be used to convert React class components to become functional components

class-to-function This command line can be used to convert React class components to become functional components. Installation Install it as a global

null 4 Mar 8, 2022
React exercicio challenge for this class is a memory game

React exercicio challenge for this class is a memory game

Sarah Souza Pontes 1 Mar 31, 2022
Class Reactive is a utility library that endore multiple programing principles like (Separate of concern, DDD, reactive).

Class Reactive Class Reactive is a utility library that endore multiple programing principles like (Separate of concern, DDD, reactive). Design mainly

null 1 May 12, 2022
Save mouse positions and visit them using shortcut keys

Bookmark mouse position Save mouse positions using a shortcut key and quickly traverse to them using another shortcut key. bookmark-mouse-positions.1.

Nishan 5 Oct 27, 2022
Solana-base-app - Solana-base-app is for Solana beginners to get them up and running fast

solana-base-app solana-base-app is for Solana beginners to get them up and runni

UjjwalGupta49 33 Dec 27, 2022
Calypso is the new WordPress.com front-end – a beautiful redesign of the WordPress dashboard using a single-page web application

Calypso is the new WordPress.com front-end – a beautiful redesign of the WordPress dashboard using a single-page web application, powered by the WordPress.com REST API. Calypso is built for reading, writing, and managing all of your WordPress sites in one place.

Automattic 12.2k Dec 30, 2022