Skip to content

Commit

Permalink
#35 Change global interface usage to be more common
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Mar 12, 2021
1 parent fd6a984 commit c167228
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typings/
# Nuxt.js build / generate output
.nuxt
dist
types

# Gatsby files
.cache/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Default options BEM naming:
- Modifier's and value's separator is a double hyphen `"--"`
- Element's separator is a double underscore `"__"`
It is required to change this options twice, both on JS (`setOpts(...)`) and TS `namespace ReactClassNaming { interface BemOptions {...} }`) levels
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__/)
### function [`classNamesMap`](https://github.com/askirmas/react-classnaming/projects/5)
Expand Down
9 changes: 9 additions & 0 deletions __recipes__/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="react-classnaming" />

declare namespace ReactClassNaming {
interface BemOptions {
elementDelimiter: "_";
modDelimiter: "-";
}
}

23 changes: 7 additions & 16 deletions __recipes__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
//-/ <reference path="node_modules/react-classnaming/dist" />
import {classBeming, ClassNamed, ClassNamesProperty, setOptions} from "react-classnaming"
import type {ClassHash, ReactClassNaming} from "react-classnaming"

declare module "react-classnaming" {
namespace ReactClassNaming {
interface BemOptions {
elementDelimiter: "_";
modDelimiter: "-";
}
}
}
import type {ClassHash} from "react-classnaming"

setOptions({
elementDelimiter: "_",
modDelimiter: "-",
})

type CssModule = Record<
|"block-m"
|"block_el"|"block_el-m-X"|"block_el-m-Y",
|"block1-m"
|"block2_el-m-X"|"block2_el-m-Y",
ClassHash
>

it("go", () => {
const bem = classBeming<ClassNamesProperty<CssModule> & ClassNamed>()
, classNamed = bem(true, {
block: "m",
block_el: {"m": "X"}
block1: "m",
block2: true,
block2_el: {"m": "X"}
})
expect(classNamed).toStrictEqual({
className: "block block-m block_el block_el-m-X"
className: "block1 block1-m block2 block2_el block2_el-m-X"
})
})
3 changes: 2 additions & 1 deletion __recipes__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"types": [
"jest"
"jest",
"react-classnaming"
]
},
"exclude": [
Expand Down
1 change: 0 additions & 1 deletion __sandbox__/bem.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Ever0, Extends, PartDeep } from "src/ts-swiss.types"
import type {ReactClassNaming} from "../src"
import { CssModule } from "../src/definitions.types"

it("tree2classes", () => {
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.15.0",
"description": "Tools to establish CSS classes as an explicit abstraction layer and to handle it as an interface between React and CSSStyleDeclaration",
"main": "dist",
"types": "types",
"scripts": {
"dev": "npm run jest -- --collectCoverageFrom=[] --bail=false --onlyFailures --watch",
"test": "npm run jest --",
Expand All @@ -14,8 +15,8 @@
"-prerelease": "./prerelease.sh",
"postrelease": "./postrelease.sh",
"compile": "tsc --project tsconfig.compile.json",
"precompile": "rm -rf dist",
"postcompile": "mkdir -p dist/types && find src -name '*.d.ts' -exec cp {} dist \\;",
"precompile": "rm -rf dist types",
"postcompile": "find src -name '*.d.ts' -exec cp {} types \\;",
"spec": "cd __recipes__ && npm run test --",
"setup": "git config include.path ../.gitconfig && git-hooks-wrapper init",
"jest": "jest --runInBand"
Expand Down Expand Up @@ -48,7 +49,7 @@
"access": "public"
},
"peerDependencies": {
"@types/react": ">=15"
"@types/react": "*"
},
"devDependencies": {
"@types/classnames": "^2.2.11",
Expand Down
1 change: 0 additions & 1 deletion src/bem.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
Ever
} from "./ts-swiss.types"
import type { ClassNamed } from "./main.types"
import type {ReactClassNaming} from "."

export type ClassBeming<
ClassNames extends CssModule,
Expand Down
10 changes: 10 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** namespace ReactClassNaming */
declare namespace ReactClassNaming {
/** interface BemOptions */
interface BemOptions {
$default: {
elementDelimiter: "__",
modDelimiter: "--"
}
}
}
11 changes: 2 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** Comment */

import { classNaming } from "./naming"

export type {
Expand All @@ -15,12 +17,3 @@ export { classNamesCheck } from "./check"
export { classNamesMap } from "./map"
export { classBeming } from "./bem"
export { setOptions } from "./bem.core"

export declare namespace ReactClassNaming {
export interface BemOptions {
$default: {
elementDelimiter: "__",
modDelimiter: "--"
}
}
}
9 changes: 6 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"display": "CLI",
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"target": "es5",
"module": "CommonJS",
"isolatedModules": true,
"moduleResolution": "node",
Expand Down Expand Up @@ -46,18 +46,21 @@

"pretty": true,

"jsx": "react",

"declarationDir": "types",
"noEmit": true,
"sourceMap": false,
"outDir": "dist",
"declaration": true,
"jsx": "react"
"declaration": true
},
"include": [
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"dist",
"types",
"__recipes__"
]
}

0 comments on commit c167228

Please sign in to comment.