Skip to content

Commit 2428ed1

Browse files
committed
can import classnames as standalone
1 parent 14b94fc commit 2428ed1

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Almost all Trunx components have a `bulma` prop that accepts:
4141

4242
- a string
4343
- an array of bulma classes
44-
- an object which keys are bulma classes
44+
- an object which keys are bulma classes, when value is truthy then the class is added
4545
- an array of any of the previous
4646

4747
You know, Trunx is a Super Sayan because it is written in TypeScript. The `bulma` prop can be autocompleted and typos can be avoided thanks to type checking.
@@ -70,7 +70,7 @@ export function MyComponent({ isSuccess }: { isSuccess: boolean }) {
7070

7171
#### Bulma related components
7272

73-
Trunx provides other React components that implement a Bulma element or a Bulma Component. This means that they usually add a related Bulma class. For example `Button` components renders a button tag with the Bulma `button` class. They may have props related to some Bulma class (.e.g. `color`, `size`). Most of the Bulma related props start with `is`, `has` and the prop name is just the camel-case version of its related Bulma class. For example `isRounded` prop corresponds to `is-rounded` Bulma class.
73+
Trunx provides React components that implement a Bulma element or a Bulma component. This means that they usually add a related Bulma class. For example `Button` component renders a button HTML tag with the Bulma `button` class. They may have props related to some Bulma class (.e.g. `color`, `size`). Most of the Bulma related props start with `is`, `has` and the prop name is just the camel-case version of its related Bulma class. For example `isRounded` prop corresponds to `is-rounded` Bulma class.
7474

7575
```tsx
7676
<Button color="primary" size="large" isRounded>
@@ -193,6 +193,8 @@ Bulma related:
193193

194194
Trunx package provides a utility for conditionally joining CSS classes together.
195195

196+
Syntax is similar to [classnames npm package](https://www.npmjs.com/package/classnames).
197+
196198
```js
197199
import { classnames } from "trunx"
198200

@@ -233,6 +235,15 @@ export function MyButton({
233235
}
234236
```
235237

238+
Notice that you can use Trunx without React! It can be used with any framework as well as with _Web Components_.
239+
The _classnames.js_ is only 299 bytes and can be imported directly with
240+
241+
```js
242+
import classnames from "trunx/classnames"
243+
```
244+
245+
The snippet above will avoid importing the React stuff.
246+
236247
## How to
237248

238249
### Use Trunx with Vite

minify.js

+3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ const minifiedClassnames = originalClassnames
1818
.replace(/ \=/g, "=")
1919
.replace(/\= /g, "=")
2020
.replace(/; /g, ";")
21+
.replace(/ &&/g, "&&")
22+
.replace(/&& /g, "&&")
2123
.replace(/if \(/g, "if(")
24+
.replace(/\) return/g, ")return")
2225

2326
const minifiedComponents = originalComponents
2427
.replace(/\{\n/g, "{")

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
".": {
1010
"import": "./dist/index.js",
1111
"types": "./dist/index.d.ts"
12+
},
13+
"./classnames": {
14+
"import": "./dist/classnames.js",
15+
"types": "./dist/classnames.d.ts"
1216
}
1317
},
1418
"scripts": {

src/classnames.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const classnames = <T extends string>(...args: ClassnamesArg<T>[]) =>
3333
// Make sure `arg` is not null,
3434
arg &&
3535
// and `arg` is a proper object.
36-
typeof arg === "object"
36+
typeof arg == "object"
3737
)
3838
return classnames(
3939
// Map `arg` object to an array of its keys, having a truthy value.

0 commit comments

Comments
 (0)