classnames: Support bind constructor

This commit is contained in:
Marvin Hagemeister
2017-08-15 11:25:54 +02:00
parent d4f42ab007
commit 256046e660
4 changed files with 21 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
export type ClassNamesFn = (
...args: Array<string | string[] | Record<string, boolean | undefined | null>>
) => string;
export function bind(styles: Record<string, string>): ClassNamesFn;
+12
View File
@@ -1,5 +1,6 @@
import classNames = require('classnames');
import * as classNames2 from 'classnames';
import * as cn from 'classnames/bind';
classNames2('foo', 'bar'); // => 'foo bar'
@@ -23,3 +24,14 @@ classNames(null, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
// Supporting booleans is tricky since we should only support passing in false, which is ignored
// classNames(false, 'bar', 0, 1, { baz: null }, ''); // => 'bar 1'
// Support for CSS-Modules. Example from README:
// https://github.com/JedWatson/classnames/blob/master/README.md#alternate-bind-version-for-css-modules
const styles = {
foo: 'abc',
bar: 'def',
baz: 'xyz'
};
const cx = cn.bind(styles);
const className = cx('foo', ['bar'], { baz: true }); // => "abc def xyz"
+2
View File
@@ -5,7 +5,9 @@
// Jason Killian <https://github.com/JKillian>
// Sean Kelley <https://github.com/seansfkelley/>
// Michal Adamczyk <https://github.com/mradamczyk>
// Marvin Hagemeister <https://github.com/marvinhagemeister>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
type ClassValue = string | number | ClassDictionary | ClassArray | undefined | null | false;
+2 -1
View File
@@ -17,6 +17,7 @@
},
"files": [
"index.d.ts",
"bind.d.ts",
"classnames-tests.ts"
]
}
}