Skip to content

Commit 6925019

Browse files
author
Andrii Kirmas
committed
Update meta
1 parent 8be6541 commit 6925019

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is a basic workflow to help you get started with Actions
22

3-
name: CI
3+
name: build
44

55
# Controls when the action will run.
66
on:

README.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,70 @@
11
# react-classnaming
22

3-
Easy applied function to use optionally with [CSS modules](https://github.com/css-modules/css-modules) and do not get lost in CSS classes
3+
Easy applied function to use optionally with [CSS modules](https://github.com/css-modules/css-modules) and do not get lost in CSS classes by powerful TypeScript notation
44

5-
![keywords](https://img.shields.io/github/package-json/keywords/askirmas/react-classnaming) ![test@ci](https://github.com/askirmas/react-classnaming/workflows/CI/badge.svg?branch=main) ![coverage](https://img.shields.io/codecov/c/github/askirmas/react-classnaming) ![version](https://img.shields.io/npm/v/react-classnaming) ![license](https://img.shields.io/npm/l/react-classnaming)
5+
![keywords](https://img.shields.io/github/package-json/keywords/askirmas/react-classnaming) [![build@ci](https://github.com/askirmas/react-classnaming/workflows/build/badge.svg?branch=main)](https://www.npmjs.com/package/react-classnaming) ![coverage](https://img.shields.io/codecov/c/github/askirmas/react-classnaming) [![Maintainability](https://api.codeclimate.com/v1/badges/6d424425b4bd07a77a43/maintainability)](https://codeclimate.com/github/askirmas/react-classnaming/maintainability) ![quailty](https://img.shields.io/scrutinizer/quality/g/askirmas/react-classnaming/main) ![version](https://img.shields.io/npm/v/react-classnaming) ![license](https://img.shields.io/npm/l/react-classnaming)
66

77
## Installation
88

99
```bash
1010
npm install --save react-classnaming
1111
```
1212

13-
## Examples
13+
## Examples of usage
14+
15+
Check the tests with detailed usage: [src/basic.spec.tsx](./src/basic.spec.tsx) and [src/ctx.spec.tsx](./src/ctx.spec.tsx)
16+
17+
With create-react-application: [./\_\_recipes\_\_/cra/src/App.tsx](./__recipes__/cra/src/App.tsx)
18+
19+
### Basic
1420

1521
```tsx
16-
import classNaming from "react-classnaming"
22+
import {classNamingBasic} from "react-classnaming"
23+
import classNamingBasic from "react-classnaming/basic"
1724

18-
<div {...classNaming("class1", {class2, class3})}>
19-
<div className={`${classNaming({class4})}`}>
20-
<div {...classNaming(classNames)({class1: bool1}, bool2 && class2)}>
25+
const {className, classNames: {class2, class3, class4, class5}} = props
26+
27+
<div {...classNamingBasic("class1", {class2, class3})}>
28+
<div className={`${classNamingBasic({class4})}`}>
29+
<div className={classNamingBasic<string>({class5})}>
2130
```
2231

23-
Check the tests with detailed usage: [./src/index.test.ts](./src/index.test.ts)
32+
### From css-module or simulation
2433

25-
With create-react-application: [./__recipes__/cra/src/App.tsx](./__recipes__/cra/src/App.tsx)
34+
```tsx
35+
import {classNamingCtx} from "react-classnaming"
36+
import classNamingCtx from "react-classnaming/ctx"
37+
import css from "./some.css" // {"class1": "hash1", "class2": "hash2"}
38+
39+
const classNaming = classNamingCtx({className: "App", classNames: css})
40+
41+
<div {...classes(true, {class1: true, class2: false})}/> // className="App hash1"
42+
<div {...classes("class2")}/> // className="hash2"
43+
```
2644

27-
## TS Generic for props
45+
### TS generic for props
2846
```ts
2947
import type { ClassNames } from "react-classnaming"
3048

31-
ClassNames<true>
49+
ClassNames<true> // requires `className`
3250

33-
ClassNames<"class1"|"class2">
51+
ClassNames<"class1"|"class2"> // requires to supply `.class1` and `.class2`
3452

35-
ClassNames<Props1, Props2>
53+
ClassNames<Props1, Props2> // requires to supply `classNames` for `Props1` and `Props2`
3654

37-
ClassNames<true, "class1", Props, typeof Component1, typeof FunctionalComponent>
55+
ClassNames<true, "class1", Props, typeof Component, typeof FunctionalComponent> //requires `className` and to supply `.class1`, `classNames` from `Props`, class component `Component` and function component `FunctionalComponent`
3856
```
3957

40-
## Root apply
58+
### Root apply
4159
```tsx
4260
import {classNamesCheck} from "react-classnaming"
4361

4462
ReactDOM.render( <Root classNames={classNamesCheck()}/> )
4563
ReactDOM.render( <Root classNames={classNamesCheck<"class1"|"class2">()}/> )
4664

47-
import classNames from "./modules.scss"
65+
import classNames from "./modules.css"
4866

49-
ReactDOM.render( <Root classNames={names(classNames))}/> )
67+
ReactDOM.render( <Root classNames={classNamesCheck(classNames))}/> )
5068
```
5169

5270
## vs [classnames](https://github.com/JedWatson/classnames#readme)

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
"url": "git+https://github.com/askirmas/react-classnaming.git"
2323
},
2424
"keywords": [
25-
"react",
26-
"className",
25+
"React",
26+
"className", "class",
2727
"classNames",
28-
"css",
29-
"modules"
28+
"classNaming",
29+
"css", "modules",
30+
"CSS modules",
31+
"css-modules"
3032
],
3133
"author": "Andrii Kirmas <[email protected]>",
3234
"license": "MIT",

0 commit comments

Comments
 (0)