Skip to content

Commit c167228

Browse files
author
Andrii Kirmas
committed
#35 Change global interface usage to be more common
1 parent fd6a984 commit c167228

File tree

11 files changed

+42
-35
lines changed

11 files changed

+42
-35
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typings/
8080
# Nuxt.js build / generate output
8181
.nuxt
8282
dist
83+
types
8384

8485
# Gatsby files
8586
.cache/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Default options BEM naming:
241241
- Modifier's and value's separator is a double hyphen `"--"`
242242
- Element's separator is a double underscore `"__"`
243243
244-
It is required to change this options twice, both on JS (`setOpts(...)`) and TS `namespace ReactClassNaming { interface BemOptions {...} }`) levels
244+
It is required to change this options twice, both on JS (`setOpts(...)`) and TS `namespace ReactClassNaming { interface BemOptions {...} }`) levels. See [./\__recipes__/](https://github.com/askirmas/react-classnaming/tree/main/__recipes__/)
245245
246246
### function [`classNamesMap`](https://github.com/askirmas/react-classnaming/projects/5)
247247

__recipes__/global.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="react-classnaming" />
2+
3+
declare namespace ReactClassNaming {
4+
interface BemOptions {
5+
elementDelimiter: "_";
6+
modDelimiter: "-";
7+
}
8+
}
9+

__recipes__/index.test.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1-
//-/ <reference path="node_modules/react-classnaming/dist" />
21
import {classBeming, ClassNamed, ClassNamesProperty, setOptions} from "react-classnaming"
3-
import type {ClassHash, ReactClassNaming} from "react-classnaming"
4-
5-
declare module "react-classnaming" {
6-
namespace ReactClassNaming {
7-
interface BemOptions {
8-
elementDelimiter: "_";
9-
modDelimiter: "-";
10-
}
11-
}
12-
}
2+
import type {ClassHash} from "react-classnaming"
133

144
setOptions({
155
elementDelimiter: "_",
166
modDelimiter: "-",
177
})
188

199
type CssModule = Record<
20-
|"block-m"
21-
|"block_el"|"block_el-m-X"|"block_el-m-Y",
10+
|"block1-m"
11+
|"block2_el-m-X"|"block2_el-m-Y",
2212
ClassHash
2313
>
2414

2515
it("go", () => {
2616
const bem = classBeming<ClassNamesProperty<CssModule> & ClassNamed>()
2717
, classNamed = bem(true, {
28-
block: "m",
29-
block_el: {"m": "X"}
18+
block1: "m",
19+
block2: true,
20+
block2_el: {"m": "X"}
3021
})
3122
expect(classNamed).toStrictEqual({
32-
className: "block block-m block_el block_el-m-X"
23+
className: "block1 block1-m block2 block2_el block2_el-m-X"
3324
})
3425
})

__recipes__/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"compilerOptions": {
33
"types": [
4-
"jest"
4+
"jest",
5+
"react-classnaming"
56
]
67
},
78
"exclude": [

__sandbox__/bem.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Ever0, Extends, PartDeep } from "src/ts-swiss.types"
2-
import type {ReactClassNaming} from "../src"
32
import { CssModule } from "../src/definitions.types"
43

54
it("tree2classes", () => {

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.15.0",
44
"description": "Tools to establish CSS classes as an explicit abstraction layer and to handle it as an interface between React and CSSStyleDeclaration",
55
"main": "dist",
6+
"types": "types",
67
"scripts": {
78
"dev": "npm run jest -- --collectCoverageFrom=[] --bail=false --onlyFailures --watch",
89
"test": "npm run jest --",
@@ -14,8 +15,8 @@
1415
"-prerelease": "./prerelease.sh",
1516
"postrelease": "./postrelease.sh",
1617
"compile": "tsc --project tsconfig.compile.json",
17-
"precompile": "rm -rf dist",
18-
"postcompile": "mkdir -p dist/types && find src -name '*.d.ts' -exec cp {} dist \\;",
18+
"precompile": "rm -rf dist types",
19+
"postcompile": "find src -name '*.d.ts' -exec cp {} types \\;",
1920
"spec": "cd __recipes__ && npm run test --",
2021
"setup": "git config include.path ../.gitconfig && git-hooks-wrapper init",
2122
"jest": "jest --runInBand"
@@ -48,7 +49,7 @@
4849
"access": "public"
4950
},
5051
"peerDependencies": {
51-
"@types/react": ">=15"
52+
"@types/react": "*"
5253
},
5354
"devDependencies": {
5455
"@types/classnames": "^2.2.11",

src/bem.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
Ever
1010
} from "./ts-swiss.types"
1111
import type { ClassNamed } from "./main.types"
12-
import type {ReactClassNaming} from "."
1312

1413
export type ClassBeming<
1514
ClassNames extends CssModule,

src/global.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** namespace ReactClassNaming */
2+
declare namespace ReactClassNaming {
3+
/** interface BemOptions */
4+
interface BemOptions {
5+
$default: {
6+
elementDelimiter: "__",
7+
modDelimiter: "--"
8+
}
9+
}
10+
}

src/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** Comment */
2+
13
import { classNaming } from "./naming"
24

35
export type {
@@ -15,12 +17,3 @@ export { classNamesCheck } from "./check"
1517
export { classNamesMap } from "./map"
1618
export { classBeming } from "./bem"
1719
export { setOptions } from "./bem.core"
18-
19-
export declare namespace ReactClassNaming {
20-
export interface BemOptions {
21-
$default: {
22-
elementDelimiter: "__",
23-
modDelimiter: "--"
24-
}
25-
}
26-
}

0 commit comments

Comments
 (0)