diff --git a/types/classnames/bind.d.ts b/types/classnames/bind.d.ts new file mode 100644 index 0000000000..b6a4242507 --- /dev/null +++ b/types/classnames/bind.d.ts @@ -0,0 +1,5 @@ +export type ClassNamesFn = ( + ...args: Array> +) => string; + +export function bind(styles: Record): ClassNamesFn; diff --git a/types/classnames/classnames-tests.ts b/types/classnames/classnames-tests.ts index 1938acb4f9..14760dff0d 100644 --- a/types/classnames/classnames-tests.ts +++ b/types/classnames/classnames-tests.ts @@ -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" diff --git a/types/classnames/index.d.ts b/types/classnames/index.d.ts index 42352fc9b8..9ea79d3b97 100644 --- a/types/classnames/index.d.ts +++ b/types/classnames/index.d.ts @@ -5,7 +5,9 @@ // Jason Killian // Sean Kelley // Michal Adamczyk +// Marvin Hagemeister // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 type ClassValue = string | number | ClassDictionary | ClassArray | undefined | null | false; diff --git a/types/classnames/tsconfig.json b/types/classnames/tsconfig.json index 8eeaf9b1ca..bb39a9d874 100644 --- a/types/classnames/tsconfig.json +++ b/types/classnames/tsconfig.json @@ -17,6 +17,7 @@ }, "files": [ "index.d.ts", + "bind.d.ts", "classnames-tests.ts" ] -} \ No newline at end of file +}