react-classlist-helper
Advanced tools
Comparing version 1.2.1 to 1.3.0
{ | ||
"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" | ||
] | ||
} | ||
} |
@@ -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'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16353
230
109
1