You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Make CSS classes to be explicit and predictable project layer
18
-
2. Enforce declaration style programming
19
-
3. Enforce contract based development via TypeScript
20
-
4. Enforce single source of truth
21
-
5. Enforce class-conditions to be strictly `boolean`, not ~~`falsy|truthy`~~
22
-
6. Use IDE type hints as developers UX for faster issues resolving
23
-
7. CSS-modules agnostic
17
+
1. Use CSS classes as an ontology of front-end project for clean communication between developers and non-tech staff
18
+
2. Make CSS classes be an explicit and predictable informational layer
19
+
3. Enforce declarative programming paradigm
20
+
4. Enforce contract programming (via TypeScript)
21
+
22
+
## Dev features
23
+
24
+
1. Enforce <u>single source of truth</u> of class appending – treat as TypeScript-driven dedupe
25
+
2. Require strict `boolean` for value of class condition
26
+
3. Use IDE type hints as developers' UX for faster issues resolving
27
+
4. BEM
28
+
5. CSS-modules agnostic
24
29
25
30
Use package like [`postcss-plugin-d-ts`](https://www.npmjs.com/package/postcss-plugin-d-ts) to prepare strict declaration of CSS
26
31
27
-
## Installation and import
32
+
## Installation and brief overview
28
33
29
34
```bash
30
35
npm install --save react-classnaming
31
36
```
32
37
33
38
```typescript
34
39
import {
35
-
classNaming, // Returns function for building `className: string` from conditioned CSS classes with "context" (if was provided) from `props` for using only declared CSS classes
36
-
classNamesMap, // Similar to classNaming, specifies mapping to component's (i.e. 3rd-party) `className`-related props
37
-
classNamesCheck// Identical function for TS restriction on classes determed in CSS and not used in component
40
+
// Returns function for building `className: string` from conditioned CSS classes with "context" (if was provided) from `props` for using only declared CSS classes
41
+
classNaming,
42
+
43
+
// Similar to classNaming, specifies mapping to component's (i.e. 3rd-party) `className`-related props
44
+
classNamesMap,
45
+
46
+
// Identical function for TS restriction on classes determed in CSS and not used in component
47
+
classNamesCheck,
48
+
49
+
// Works with BEM conditional object
50
+
classBeming
38
51
} from"react-classnaming"
39
52
40
53
// Default export is the most frequently used function
@@ -86,13 +102,13 @@ function FormButtons({isValid, readOnly}: Props) {
86
102
87
103
As shown, producing function `classNaming` returns a multipurpose object. It can be
88
104
89
-
- recalled to stack more CSS classes on conditions: `anotherClass = someClass({...})({...})`
90
-
- destructed in component's props as `className` singleton: `<div {...someClass}/><button {...anotherClass}/>`
91
-
- used as a string: ` ``${someClass} ${anotherClass}`` `
105
+
-<u>recalled</u> to stack more CSS classes on conditions: `anotherClass = someClass({...})({...})`
106
+
-<u>destructed in</u> component's <u>props</u> as `className` singleton: `<div {...someClass}/><button {...anotherClass}/>`
107
+
- used as a <u>string</u>: ` ``${someClass} ${anotherClass}`` `
92
108
93
109
## Demos
94
110
95
-
[<imgsrc="./images/vscode.png"style="width: 50%; float:right;" />](./images/vscode.png)You can find demonstration with all main points in folder [./\__examples__/](./__examples__/), in addition *`*.test.*`* and *`*.spec.*`*.
111
+
You can find demonstration with all main points in folder [./\__examples__/](./__examples__/), in addition *`*.test.*`* and *`*.spec.*`*.[<imgsrc="./images/vscode.png"width="50%"/>](./images/vscode.png)
96
112
97
113
## Getting more
98
114
@@ -127,6 +143,22 @@ Only declared CSS classes will be allowed as keys with IDE hint on possibilities
It is possible to use BEM as condition query. With explicitly declared CSS classes (i.e. via [`postcss-plugin-d-ts`](https://www.npmjs.com/package/postcss-plugin-d-ts)) TS and IDE will check and hint on available blocks, elements, modifiers and values. [\__tests__/readme.spec.tsx:165](./__tests__/readme.spec.tsx#L165-L186)
0 commit comments