class-references
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

class-references

A framework-agnostic library for managing multiple references to class names.

For more details, see the main README file.

Installation

Using npm:

npm install --save class-references

Using yarn:

yarn add class-references

Usage

Any time you want to add a class (eg. MyClassName) to an element (eg. document.body), use:

import { requestTokenForClass } from "class-references";

const token = requestTokenForClass(document.body, "MyClassName");

When you're ready to remove the class, make sure you can recall the token, and use:

import { releaseToken } from "class-references";

releaseToken(document.body, token);

Advanced examples

import { releaseToken, requestTokenForClass } from "class-references";

const className = "u-preventScroll";
const element = document.body;

const token1 = requestTokenForClass(element, className); // Class is added
const token2 = requestTokenForClass(element, className); // Class was already added, but another token reserves it.

releaseToken(element, token1); // token1 is released; token2 not released, class remains
releaseToken(element, token2); // both tokens are released, class removed

Readme

Keywords

none

Package Sidebar

Install

npm i class-references

Weekly Downloads

217

Version

0.1.0

License

MIT

Unpacked Size

20.6 kB

Total Files

18

Last publish

Collaborators

  • simon360