Skip to content

Commit

Permalink
Remove whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Mar 12, 2021
1 parent 3284fb8 commit cfeb23a
Show file tree
Hide file tree
Showing 40 changed files with 203 additions and 201 deletions.
2 changes: 2 additions & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
[remote "origin"]
url = git@github.com:askirmas/react-classnaming.git
fetch = +refs/heads/*:refs/remotes/origin/*
[apply]
whitespace = fix
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"args": [
"${fileBasenameNoExtension}",
"--testTimeout", "9999999",
"--testTimeout", "9999999",
"--watch",
"--onlyFailures",
"--runInBand",
Expand All @@ -34,6 +34,6 @@
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
}
]
}
2 changes: 1 addition & 1 deletion __examples__/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function App(props: AppProps) {
const {classnames} = props

const cssClassesMapping = classNamesMap(classnames)

return <>{ "/// App.tsx" }
{/* className=`${className} app__container` */}
<div {...withClassName({"app__container": true})}>
Expand Down
2 changes: 1 addition & 1 deletion __examples__/MyComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type MyComponentProps = ClassNamesProperty<{
}>
export default function MyComponent({classnames}: MyComponentProps) {
const cssClasses = classNaming({classnames})

return <>
{ "/// MyComponent.tsx" }
{/* className="btn" */}
Expand Down
6 changes: 3 additions & 3 deletions __examples__/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const some_module_css = {
"btn": "hash-btn",
"icon": "hash-icon",
"btn__icon": "hash-btn__icon"
}
}

it("render App with css-module", () => expectRender(

/// index.tsx
<App className="theme--dark" classnames={classNamesCheck(some_module_css)} />

).toSame(<>
{ "/// App.tsx" }
<div className="theme--dark hash-app__container">
Expand Down Expand Up @@ -51,4 +51,4 @@ it("render App with global css", () => expectRender(
</div>
</div>
</>))

64 changes: 32 additions & 32 deletions __sandbox__/bem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ it("tree2classes", () => {
type BemTree = {
[block: string]: {
// ""?: {[blockMod: string]: true}
[element: string]: boolean | {[elMod: string]: boolean}
[element: string]: boolean | {[elMod: string]: boolean}
}
}

type El2Classes<DMod extends string, S extends Record<string, boolean|Record<string, boolean>>> = {[K in string & keyof S]:
K | (S[K] extends Record<string, boolean> ? `${K}${DMod}${string & keyof S[K]}` : never)
}[string & keyof S]

type BemTree2Classes<DEl extends string, DMod extends string, S extends BemTree> = {[K in string & keyof S]:
K | `${K}${DEl}${El2Classes<DMod,S[K]>}`
}[string & keyof S]


const bem2 = {
"Button": {
"Container": true,
Expand All @@ -30,9 +30,9 @@ it("tree2classes", () => {
"Form": {
"Container": true,
"Button": true
}
}
}

const suite: Record<BemTree2Classes<"__", "--", typeof bem2>, boolean> = {
Button: true,
Button__Icon: true,
Expand All @@ -44,7 +44,7 @@ it("tree2classes", () => {
Form__Container: true
}

expect(suite).toBeInstanceOf(Object)
expect(suite).toBeInstanceOf(Object)
})

type ClassNames = {
Expand Down Expand Up @@ -93,10 +93,10 @@ describe("upon delimiter", () => {

it("args", () => {
type GetMods<T, B extends string, E extends string|undefined> = {
[K in string & keyof T]: E extends string
[K in string & keyof T]: E extends string
? K extends `${B}__${E}--${infer M}` ? M : never
: K extends `${B}--${infer M}` ? M : never
}[keyof T]
}[keyof T]
type Bemer<ClassNames extends CssModule> = (
<
BE extends StripFromObj<ClassNames, "--">,
Expand All @@ -112,20 +112,20 @@ describe("upon delimiter", () => {
}${
Element extends string ? ` ${Block}__${Element}` : ""
}${
Modifier extends string
Modifier extends string
? ` ${Block}${
Element extends string ? `__${Element}` : ""
}--${Modifier}`
: ""
}`
)


function beming<ClassNames extends CssModule>() {
const host: Bemer<ClassNames> = ((block, element?, modifier?) => {
const elemened = element ? `${block}__${element}` : ""
const moded = modifier ? ` ${element ? elemened : block}--${modifier}` : ""

return `${
block
}${
Expand All @@ -136,18 +136,18 @@ describe("upon delimiter", () => {
moded
}`
}) as Bemer<ClassNames>

return host
}


const bemer = beming<ClassNames>()
, $return = bemer("Btn", "Icon", "big")
, typed: typeof $return = "Btn Btn__Icon Btn__Icon--big"

expect($return).toBe(typed)
})

it("query", () => {
// Can be used on #30

Expand All @@ -162,7 +162,7 @@ describe("upon delimiter", () => {
: ReactClassNaming.BemOptions["$default"]["modDelimiter"],
bModKey extends string = "$" /*"blockModKey" extends keyof ReactClassNaming.BemOptions
? ReactClassNaming.BemOptions["blockModKey"]
: ReactClassNaming.BemOptions["$default"]["blockModKey"]*/
: ReactClassNaming.BemOptions["$default"]["blockModKey"]*/
> = classes extends `${b}${delE}${infer E}`
? Strip<E, delM>
: classes extends `${b}${delM}${string}`
Expand All @@ -184,12 +184,12 @@ describe("upon delimiter", () => {
[b in Strip<Strip<classes, delM>, delE>]: boolean
| Exclude<MVs<classes, b, bModKey>, `${string}${delM}${string}`>
| (
Extends<classes, `${b}${delE | delM}${string}`,
Extends<classes, `${b}${delE | delM}${string}`,
{
[e in Elements<classes, b>]: boolean
| Exclude<MVs<classes, b, e>, `${string}${delM}${string}`>
| (
{[m in Strip<MVs<classes, b, e>, delM>]:
{[m in Strip<MVs<classes, b, e>, delM>]:
false | (
Ever0<
classes extends `${b}${
Expand All @@ -204,8 +204,8 @@ describe("upon delimiter", () => {
}
>
)
}>
}>

type MVs<
classes extends string,
b extends string,
Expand All @@ -222,7 +222,7 @@ describe("upon delimiter", () => {
> = classes extends `${b}${
e extends bModKey ? "" : `${delE}${e}`
}${delM}${infer MV}` ? MV : never

type BemInGeneral = {
[block: string]: undefined | boolean | string | {
[el: string]: undefined | boolean | string
Expand All @@ -231,30 +231,30 @@ describe("upon delimiter", () => {
}
}
}

type BemQuerier<
ClassNames extends CssModule,
delE extends string = "__",
delM extends string = "--",
bModKey extends string = "$",
> =
> =
<
// classes extends keyof ClassNames,
// BE extends StripFromObj<ClassNames, delM>,
Q extends BemQuery<
keyof ClassNames,
delE,
delM,
bModKey
bModKey
// BE,
// Strip<BE, delE>
>
>(arg: Q) => {[K in
>(arg: Q) => {[K in
{[b in keyof Q]: Q[b] extends boolean ? b : never}[keyof Q]
// | {[b in keyof Q]: Q[b] extends Primitive ? never : `${b}${delE}${keyof Q[b]}`}[keyof Q]
// | {
// [b in keyof Q]: {[e in keyof Q[b]]: Q[b][e] extends Primitive ? never :
// {[m in keyof Q[b][e]]:
// {[m in keyof Q[b][e]]:
// Q[b][e][m] extends string
// ? `${b}${delE}${e}${delM}${m}${delM}${Q[b][e][m]}`
// : `${b}${delE}${e}${delM}${m}`
Expand All @@ -267,7 +267,7 @@ describe("upon delimiter", () => {
]: boolean}

//@ts-expect-error
const q = x => x as unknown as BemQuerier<ClassNames>
const q = x => x as unknown as BemQuerier<ClassNames>
, res = q({
"App": {
"Header": false,
Expand Down Expand Up @@ -303,7 +303,7 @@ describe("upon delimiter", () => {
// "App__Header": false,
// "Btn": true,
// "Btn--disabled": false,
// "Btn--info--error": true,
// "Btn--info--error": true,
// "Btn__Icon": true,
// "Btn__Icon--big": true,
// "Footer": false,
Expand Down
10 changes: 5 additions & 5 deletions __sandbox__/double-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ function _doubleShape<
injection: undefined|string,
...args: (Falsy | A)[]
) {
const {applied, classnames, className} = ctx
const {applied, classnames, className} = ctx
//@ts-expect-error
, nextApplied = !applied ? [] : applied.push(...args.filter(x => x)) as Record<U | keyof A, ClassHash|boolean>[]
, nextApplied = !applied ? [] : applied.push(...args.filter(x => x)) as Record<U | keyof A, ClassHash|boolean>[]

, host = <
// T extends {[K in Exclude<S, U | keyof A>]?: boolean} | {[K in Exclude<S, U | keyof A>]?: ClassHash}
T extends {[K in Exclude<S, U>]?: ClassHash | boolean},
>(
withClassName: boolean,
injection: undefined|string,
injection: undefined|string,
...args: (Falsy | T)[]
) => _doubleShape(
{classnames, className, applied: nextApplied},
Expand Down Expand Up @@ -70,8 +70,8 @@ function _doubleShape<
//@ts-expect-error
keys[i] = v
}
}
}

const chunk = keys.flat().join(" ")
if (!chunk)
delete args[i]
Expand Down
Loading

0 comments on commit cfeb23a

Please sign in to comment.