simple-merge-class-names 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
# simple-merge-class-names
|
|
2
2
|
|
|
3
|
-
A straightforward utility for merging CSS class names in `React
|
|
3
|
+
A straightforward utility for merging CSS class names in `React + Tailwind` and other JavaScript projects.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
pnpm add simple-merge-class-names
|
|
9
|
-
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```bash
|
|
10
12
|
yarn add simple-merge-class-names
|
|
11
|
-
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```bash
|
|
12
16
|
npm install simple-merge-class-names
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
## Install Prettier with VSCode (Recommended)
|
|
19
|
+
## Install `Prettier` with VSCode (Most Recommended)
|
|
16
20
|
|
|
17
|
-
|
|
21
|
+
Install Prettier for VS Code for most optimal developer experience: [https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
|
|
22
|
+
|
|
23
|
+
Or install an equivalent auto code formatter for your IDE.
|
|
18
24
|
|
|
19
25
|
## Usage
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
`mergeClassNames(...args)` is the single exported function provided by the package.
|
|
22
28
|
|
|
23
29
|
```jsx
|
|
24
30
|
import { mergeClassNames } from "simple-merge-class-names";
|
|
@@ -40,24 +46,37 @@ function MyComponent() {
|
|
|
40
46
|
}
|
|
41
47
|
```
|
|
42
48
|
|
|
43
|
-
Using individual strings for each class name can be tedious, however it significantly enhances code readability and Developer Experience (DX). This is in contrast to hard-to-read strings like
|
|
49
|
+
Using individual strings for each class name can be tedious (see [Workflow to minimize typing strain](#workflow-to-minimize-typing-strain)), however it significantly enhances code readability and Developer Experience (DX). This is in contrast to hard-to-read strings like:
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
```jsx
|
|
52
|
+
function MyComponent() {
|
|
53
|
+
return (
|
|
54
|
+
<div className="app min-h-dvh grid grid-rows-[auto_1fr_auto] outline">
|
|
55
|
+
Hello, world!
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Workflow to minimize typing strain:
|
|
46
62
|
|
|
47
63
|

|
|
48
64
|
|
|
49
|
-
-
|
|
50
|
-
-
|
|
65
|
+
- Have `Prettier` installed
|
|
66
|
+
- Use single quotes (<kbd>'</kbd>) for class names, often a single key press on many keyboards.
|
|
67
|
+
- Save the file (<kbd>Ctrl+S</kbd>), and Prettier does the formatting heavy-lifting, it automatically:
|
|
51
68
|
- Replaces single quotes with double quotes.
|
|
52
69
|
- Neatly arranges each class name on a new line.
|
|
53
70
|
|
|
54
|
-
## Why the mismatch between Function, and Package name?
|
|
71
|
+
## Why the mismatch between exported Function, and Package name?
|
|
55
72
|
|
|
56
|
-
|
|
73
|
+
I wanted to name the package as `mergeClassNames` to reflect the single exported function, but the NPM Package Registry does not allow capital letters, only lower case and dash characters.
|
|
57
74
|
|
|
58
|
-
|
|
75
|
+
In addition there was already a package named `merge-class-names` but it is no longer maintained (and the developer recommends `clsx` instead).
|
|
59
76
|
|
|
60
|
-
|
|
77
|
+
## Where this package excels
|
|
78
|
+
|
|
79
|
+
While similar packages exist (`clsx`) with better features and potentially improved performance, `simple-merge-class-names` focuses on being very straightforward and easy to reason about, as defined in its source code.
|
|
61
80
|
|
|
62
81
|
## Source Code
|
|
63
82
|
|
|
@@ -98,6 +117,12 @@ export const mergeClassNames = (...args) => {
|
|
|
98
117
|
};
|
|
99
118
|
```
|
|
100
119
|
|
|
120
|
+
## Argument Handling
|
|
121
|
+
|
|
122
|
+
`mergeClassNames` accepts multiple arguments but filters out `null`, `undefined`, and empty strings (`""`), and the remaining values are either strings or are _implicitly converted_ to strings by the JavaScript engine.
|
|
123
|
+
|
|
124
|
+
Finally the end string values are merged and separated by spaces.
|
|
125
|
+
|
|
101
126
|
## Production Considerations
|
|
102
127
|
|
|
103
128
|
If you are considering this package for production, you might also want to look into `clsx` for more advanced features: [https://www.npmjs.com/package/clsx](https://www.npmjs.com/package/clsx)
|
|
@@ -105,3 +130,5 @@ If you are considering this package for production, you might also want to look
|
|
|
105
130
|
## License
|
|
106
131
|
|
|
107
132
|
This project is licensed under the AGPL-3.0 License. See `LICENSE.txt` for full details.
|
|
133
|
+
|
|
134
|
+
## Enjoy 😉
|
package/package.json
CHANGED