Merge pull request #17512 from selkinvitaly/master

added typings for bem-cn
This commit is contained in:
Paul van Brenk
2017-06-26 16:43:12 -07:00
committed by GitHub
4 changed files with 112 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
import * as block from "bem-cn";
// expected 'block'
block("block")();
// expected 'block__elem'
block("block")("elem")();
// expected 'block__elem block__elem_disabled block__elem_size_small'
block("block")("elem", { disabled: true, size: 'small' })();
// expected 'block block_disabled'
block("block")({ disabled: true})();
// expected 'block mix'
block("block").mix("mix");
// expected 'block mix mix2'
block("block").mix(["mix", "mix2"]);
// expected 'block is-hidden'
block("block").state({ hidden: true });
// expected 'block'
block("block").state({ hidden: false });
// expected 'block is-hidden is-error'
block("block").state({ hidden: true, error: true });
// expected 'block is-loading'
block("block").is({ loading: true });
// expected 'block has-content'
block("block").has({ content: true });
block.setup({
el: '~~',
mod: '--',
modValue: '-'
});
// expected 'block~~elem'
block("block")("elem");
// expected 'block block--mod-value'
block("block")({ mod: "value"});
+41
View File
@@ -0,0 +1,41 @@
// Type definitions for bem-cn 2.1
// Project: https://github.com/albburtsev/bem-cn
// Definitions by: Vitaly Selkin <https://github.com/selkinvitaly>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type StateFn = (states: { [key: string]: boolean }) => Inner;
interface Modifications {
[key: string]: (string | boolean);
}
interface Block {
(name: string): Inner;
reset(): void;
setup(settings?: Settings): void;
}
interface Inner {
(elem: string | Modifications): Inner;
(elem: string, mods: Modifications): Inner;
(): string;
mix(mixes: string | string[]): Inner;
has: StateFn;
state: StateFn;
is: StateFn;
toString(): string;
split(separator: string, limit?: number): string[];
}
interface Settings {
ns?: string;
el?: string;
mod?: string;
modValue?: string;
classMap?: { [className: string]: string } | null;
}
declare const block: Block;
export = block;
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"bem-cn-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}