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

react-classlist-helper

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-classlist-helper - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

7

package.json
{
"name": "react-classlist-helper",
"version": "1.2.1",
"version": "1.3.0",
"description": "Helper to defining multiple classes on a react component.",

@@ -45,3 +45,8 @@ "main": "./dist/react-classlist-helper.min.js",

"lodash.isundefined": "^3.0.1"
},
"nyc": {
"include": [
"src/index.js"
]
}
}

36

README.md

@@ -12,3 +12,3 @@ # React classList Helper

```
Also available with Yarn:
Also available in Yarn:
```

@@ -35,5 +35,5 @@ yarn add react-classlist-helper

Also works with Arrays `['className', 'className2']` and Objects `{ ClassName: boolean }`;
It also works with Arrays `['className', 'className2', ...]` and Objects `{ ClassName: boolean, ... }`;
Object form is usefull for creating conditional classes:
The Object form is usefull for creating conditional classes:

@@ -45,5 +45,6 @@ ```javascript

const classMap = {};
classMap[mobileClass] = isMobile;
classMap[desktopClass] = !isMobile;
const classMap = {
myAwesomeMobileClass: isMobile,
myDesktopClass: !isMobile,
};
// { myAwesomeMobileClass: true, myDesktopClass: false }

@@ -70,6 +71,6 @@

const isACOn = true;
const coldClass = 'cool';
const coolClass = 'cool';
const Component = () => (
<div className={ toggleClass(coldClass, isACOn) } />
<div className={ toggleClass(coolClass, isACOn) } />
);

@@ -83,2 +84,21 @@ // <div class="cool"></div>

### classList (cL) and toggleClass (tC) aliases
Wanna save some space? Use the alias:
```
import { cL, tC } from 'react-classlist-helper';
...
const myCond = true;
const myClass = 'dangerZone';
const someClasses = ['something', 'something'];
const Component = () => (
<div className={ cl(someClasses, tC(myClass, myCond)) } />
);
// <div class="something something dangerZone"></div>
```
Happy coding!

@@ -85,0 +105,0 @@

@@ -38,3 +38,3 @@ import isBoolean from 'lodash.isboolean';

return classBuffer.join(' ');
return classBuffer.join(' ').trim();
}

@@ -65,4 +65,7 @@

export const cL = classList;
export const tC = toggleClass;
const defaultFunc = classList;
export default defaultFunc;
import { expect } from 'chai';
import { classList, toggleClass } from './index';
import { classList, toggleClass, cL, tC } from './index';

@@ -127,1 +127,19 @@

});
describe('React classList alias', () => {
it('should be defined and be the classList function', () => {
expect(cL).to.equal(classList);
expect(cL).to.be.a('function');
});
});
describe('React toggleClass alias', () => {
it('should be defined and be the toggleClass function', () => {
expect(tC).to.equal(toggleClass);
expect(tC).to.be.a('function');
});
});
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