Skip to content

Commit 961af87

Browse files
authored
Split Tailwind utility functions out to a shared package (#5777)
## Summary Split tailwind utils out to a shared package within the monorepo. ## Changes - Creates `@comfyorg/tailwind-utils` package - Does not require export, publishing, etc - Uses `export` to ensure this change does not impact other PRs (many imports to update) - If we _want_ to update all imports, there are two commits ready to be re-applied - e.g. `git revert 80960c2` ## Review Focus - Is this pattern desirable? - Should we just include this in a broader design-system split? I kind of vote yes, but also it's a good small, first step. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-5777-Split-Tailwind-utility-functions-out-to-a-shared-package-2796d73d3650815f976fc73b4fb86ef3) by [Unito](https://www.unito.io)
1 parent 703de3e commit 961af87

File tree

7 files changed

+104
-20
lines changed

7 files changed

+104
-20
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"@alloc/quick-lru": "^5.2.0",
108108
"@atlaskit/pragmatic-drag-and-drop": "^1.3.1",
109109
"@comfyorg/comfyui-electron-types": "0.4.73-0",
110+
"@comfyorg/tailwind-utils": "workspace:*",
110111
"@iconify/json": "^2.2.380",
111112
"@primeuix/forms": "0.0.2",
112113
"@primeuix/styled": "0.3.2",
@@ -130,7 +131,6 @@
130131
"algoliasearch": "^5.21.0",
131132
"axios": "^1.8.2",
132133
"chart.js": "^4.5.0",
133-
"clsx": "^2.1.1",
134134
"dompurify": "^3.2.5",
135135
"dotenv": "^16.4.5",
136136
"es-toolkit": "^1.39.9",
@@ -148,7 +148,6 @@
148148
"primevue": "^4.2.5",
149149
"reka-ui": "^2.5.0",
150150
"semver": "^7.7.2",
151-
"tailwind-merge": "^3.3.1",
152151
"three": "^0.170.0",
153152
"tiptap-markdown": "^0.8.10",
154153
"vue": "^3.5.13",

packages/tailwind-utils/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# @comfyorg/tailwind-utils
2+
3+
Shared Tailwind CSS utility functions for the ComfyUI Frontend monorepo.
4+
5+
## Usage
6+
7+
The `cn` function combines `clsx` and `tailwind-merge` to handle conditional classes and resolve Tailwind conflicts.
8+
9+
```typescript
10+
import { cn } from '@comfyorg/tailwind-utils'
11+
12+
// Use with conditional classes (object)
13+
<div :class="cn('transition-opacity', { 'opacity-75': !isHovered })" />
14+
15+
// Use with conditional classes (ternary)
16+
<button
17+
:class="cn('px-4 py-2', isActive ? 'bg-blue-500' : 'bg-gray-500')"
18+
/>
19+
```
20+
21+
## Installation
22+
23+
This package is part of the ComfyUI Frontend monorepo and is automatically available to all workspace packages.
24+
25+
```json
26+
{
27+
"dependencies": {
28+
"@comfyorg/tailwind-utils": "workspace:*"
29+
}
30+
}
31+
```
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "@comfyorg/tailwind-utils",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"description": "Shared Tailwind CSS utilities for ComfyUI Frontend",
6+
"main": "./src/index.ts",
7+
"types": "./src/index.ts",
8+
"exports": {
9+
".": {
10+
"import": "./src/index.ts",
11+
"types": "./src/index.ts"
12+
}
13+
},
14+
"scripts": {
15+
"typecheck": "tsc --noEmit"
16+
},
17+
"nx": {
18+
"tags": [
19+
"scope:shared",
20+
"type:util"
21+
]
22+
},
23+
"dependencies": {
24+
"clsx": "^2.1.1",
25+
"tailwind-merge": "^2.2.0"
26+
},
27+
"devDependencies": {
28+
"typescript": "^5.4.5"
29+
}
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import clsx, { type ClassArray } from 'clsx'
2+
import { twMerge } from 'tailwind-merge'
3+
4+
export type { ClassValue } from 'clsx'
5+
6+
export function cn(...inputs: ClassArray) {
7+
return twMerge(clsx(inputs))
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "dist"
6+
},
7+
"include": ["src/**/*"]
8+
}

pnpm-lock.yaml

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

src/utils/tailwindUtil.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
import clsx, { type ClassArray } from 'clsx'
2-
import { twMerge } from 'tailwind-merge'
3-
4-
export type { ClassValue } from 'clsx'
5-
6-
export function cn(...inputs: ClassArray) {
7-
return twMerge(clsx(inputs))
8-
}
1+
export { cn, type ClassValue } from '@comfyorg/tailwind-utils'

0 commit comments

Comments
 (0)