Skip to content

Commit f22e088

Browse files
feat: add cn utility (#4)
1 parent 33dbccc commit f22e088

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
"types": "./dist/index.d.cts",
1717
"default": "./dist/index.cjs"
1818
}
19+
},
20+
"./utilities": {
21+
"import": {
22+
"types": "./dist/utilities.d.ts",
23+
"default": "./dist/utilities.js"
24+
},
25+
"require": {
26+
"types": "./dist/utilities.d.cts",
27+
"default": "./dist/utilities.cjs"
28+
}
1929
}
2030
},
2131
"main": "./dist/index.cjs",
@@ -24,6 +34,7 @@
2434
"dist"
2535
],
2636
"scripts": {
37+
"build": "tsup",
2738
"build-storybook": "storybook build",
2839
"format": "prettier -w src",
2940
"prepare": "husky install",
@@ -33,6 +44,10 @@
3344
"lint-staged": {
3445
"*.{css,js,md,ts,jsx,tsx,ts}": "prettier --write"
3546
},
47+
"dependencies": {
48+
"clsx": "^2.0.0",
49+
"tailwind-merge": "^1.14.0"
50+
},
3651
"devDependencies": {
3752
"@storybook/addon-essentials": "^7.3.1",
3853
"@storybook/addon-interactions": "^7.3.1",

pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { cn } from "./utilities";

src/utilities.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { clsx, type ClassValue } from "clsx";
2+
import { twMerge } from "tailwind-merge";
3+
4+
/**
5+
* Merges tailwind utilities, and allows the usage of the clsx syntax in addition
6+
* @param inputs list of class names
7+
* @returns
8+
*/
9+
export function cn(...inputs: ClassValue[]) {
10+
return twMerge(clsx(inputs));
11+
}

tsup.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineConfig } from "tsup";
22

3-
const pureCalls = [
3+
const reactPureCalls = [
44
"cloneElement",
55
"createContext",
66
"createElement",
@@ -13,10 +13,11 @@ const pureCalls = [
1313
];
1414

1515
export default defineConfig({
16-
entry: ["src/index.ts"],
16+
entry: ["src/index.ts", "src/utilities.ts"],
1717
treeshake: true,
1818
external: ["react"],
1919
format: ["cjs", "esm"],
2020
dts: true,
21-
pure: pureCalls
21+
pure: reactPureCalls,
22+
clean: true
2223
});

0 commit comments

Comments
 (0)