Skip to content

Commit

Permalink
feat: add cn utility
Browse files Browse the repository at this point in the history
Release-As: 0.2.0
  • Loading branch information
jozan committed Apr 28, 2024
1 parent 41cf7ce commit caaaaca
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
is has **zero dependencies**. ofc you need to have `tailwindcss` set up
in your project.

currently it has only one plugin: `ligatures`. more might be added in
the future.
currently it has only one plugin `ligatures` and one utility `cn`. more
might be added in the future.

## usage

Expand All @@ -28,6 +28,10 @@ bun add @latehours/tailwind
yarn add @latehours/tailwind
```

### `ligatures` plugin

define how ligatures should behave.

in your `tailwind.config.mjs`:

```typescript
Expand Down Expand Up @@ -55,6 +59,19 @@ in your `file.html` or `component.tsx`:
<div class="ligatures-no-contextual">no contextual ligatures</div>
```

### `cn` utility

merge classnames together.

first add `clsx` and `tailwind-merge` to your deps then you can use `cn`:

```typescript
import { cn } from "@latehours/tailwind/cn";

const padding = "p-4";
const classes = cn("text-red-500", "bg-blue-500", padding);
```

## development

To install dev dependencies:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"keywords": [
"tailwind",
"tailwind plugin",
"ligatures"
"ligatures",
"cn",
"classnames",
"tailwindcss"
],
"author": "jozan <johan@latehours.net>",
"sideEffects": false,
Expand All @@ -24,16 +27,19 @@
"types": "./dist/dts/ligatures.d.ts",
"import": "./dist/esm/ligatures.js",
"default": "./dist/esm/ligatures.js"
},
"./cn": {
"types": "./dist/dts/cn.d.ts",
"import": "./dist/esm/cn.js",
"default": "./dist/esm/cn.js"
}
},
"files": [
"./dist/**/*.js",
"./dist/**/*.d.ts",
"./dist/**/*.map"
],
"files": ["./dist/**/*.js", "./dist/**/*.d.ts", "./dist/**/*.map"],
"devDependencies": {
"@biomejs/biome": "1.7.1",
"@types/bun": "latest",
"clsx": "^2.1.1",
"tailwind-merge": "^2.3.0",
"tailwindcss": "^3.4.3",
"typescript": "^5.0.0"
},
Expand Down
6 changes: 6 additions & 0 deletions src/cn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}

0 comments on commit caaaaca

Please sign in to comment.