Skip to content

⚙️Setting: cn utils#19

Merged
jjangminii merged 8 commits intodevelopfrom
setting/#18/cn-lib-setting
Oct 16, 2025
Merged

⚙️Setting: cn utils#19
jjangminii merged 8 commits intodevelopfrom
setting/#18/cn-lib-setting

Conversation

@jjangminii
Copy link
Contributor

@jjangminii jjangminii commented Oct 15, 2025

🔥 작업 내용

  • ex) 로그인 페이지 UI 및 반응형 구현
  • cn utils 제작
  • 유틸 cn() 도입: clsx + tailwind-merge(확장)로 클래스 머지 일원화 디자인 토큰(색/타이포) 인식하도록 tailwind-merge 확장

컴포넌트 분기(variant/size/state)는 CVA(Class Variance Authority) 기반으로 정리

🔗 이슈

PR Point (To Reviewer)

유틸 cn() 도입

className 조합을 더 읽기 쉽고 안전하게 만들기 위해 cn()(= clsx + 확장된 tailwind-merge)와 cva를 도입했어요. 기존 방식은 삼항 연산자와 조건부 클래스가 군데군데 흩어져 중복, 충돌이 잦고, 최종 적용 색/타이포가 무엇인지 코드만으로 파악하기 어려웠어요. cn()은 임의 클래스와 조건을 자유롭게 섞으면서도 우리 디자인 토큰(팔레트·타이포)을 인식해 같은 계열이 겹치면 마지막 것만 남기도록 자동 정리해 줍니다.
덕분에 스타일 우선순위를 개발자가 수동으로 관리할 필요가 줄고, 코드가 단순해져 변경에 용이해요.

사실 이유는 여러개 있지만 디자인 혹은 동작 분기 처리해서 코드짤때 유용해요

const button = cva(
  'inline-flex items-center justify-center transition-colors',
  {
    variants: {
      size: { sm: 'text-body-sm px-2 py-1', md: 'text-body-md px-3 py-2', lg: 'text-body-lg px-4 py-3' },
      intent: { primary: 'bg-mint-600 text-white', secondary: 'bg-gray-100 text-gray-900', danger: 'bg-red-400 text-white' },
      round: { true: 'rounded-full', false: 'rounded-md' },
    },
    defaultVariants: { size: 'md', intent: 'primary', round: false },
  }
);
// 사용
<button className={cn(button({ size: 'lg', intent: 'secondary', round: true }))} />

이런식으로 사용할 수 있어요

혹은 한곳에서 스타일이 많아 코드에 가독성이 떨어질때 다음과 같이 사용할 수 도 있어요

<div
                  id="level-info-card"
                  className={cn(
                    'pointer-events-none absolute left-0 top-[3rem] z-[20]',
                    'opacity-0 transition-opacity duration-150',
                    'peer-hover:pointer-events-auto peer-focus-visible:pointer-events-auto',
                    'peer-hover:opacity-100 peer-focus-visible:opacity-100'
                  )}
                >

이것외에도 다양하게 사용 가능한데 한번 찾아보고 본인 스타일대로 유용하게 사용하시길바랍니다~

📸 피그마 스크린샷 or 기능 GIF

(작업 내역 스크린샷)

Summary by CodeRabbit

  • Chores
    • Added runtime dependency tailwind-merge and development dependency class-variance-authority for improved CSS class handling.
    • Introduced utility functions for managing CSS class names with enhanced Tailwind CSS conflict resolution support.

@jjangminii jjangminii self-assigned this Oct 15, 2025
@jjangminii jjangminii linked an issue Oct 15, 2025 that may be closed by this pull request
@vercel
Copy link

vercel bot commented Oct 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
af-fe Ready Ready Preview Comment Oct 16, 2025 4:31pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

This PR adds a cn utility function to the shared library that combines clsx and tailwind-merge for composing and resolving Tailwind CSS class conflicts. Two new dependencies (tailwind-merge and class-variance-authority) are added to the project.

Changes

Cohort / File(s) Summary
Dependencies
package.json
Added tailwind-merge as runtime dependency and class-variance-authority as dev dependency
Utility Module
src/shared/lib/utils.ts
New utility module exporting cn function that combines clsx and twMerge with extended Tailwind theme tokens for text and color classes
Public Exports
src/shared/lib/index.ts
Added re-export of all exports from ./utils module

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

setting

Suggested reviewers

  • skyblue1232

Poem

🐰 Hops through classes with delight,
Tailwind merging, oh what a sight!
cn function, so neat and clean,
Best CSS handler we've seen!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The description follows most of the repository template by detailing the 작업 내용, linking the issue, providing a PR point, and reserving a screenshot section, but it omits the mandatory "### 🤔 추후 작업 사항" section and uses an incorrect heading level under PR Point. Please add the "### 🤔 추후 작업 사항" section with any upcoming tasks or a placeholder if none, and ensure the "### PR Point (To Reviewer)" heading and its content match the template’s formatting.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly indicates that this pull request sets up the cn utility module, which is the main change introduced, and reflects the core addition without unnecessary noise.
Linked Issues Check ✅ Passed The changes implement the cn() utility by combining clsx and an extended tailwind-merge, integrate Class Variance Authority for component variants, and provide usage examples exactly as specified in linked issue #18.
Out of Scope Changes Check ✅ Passed All modifications—including the new dependencies, the re-export in index.ts, and the utils.ts implementation—directly support the cn utility objectives and introduce no unrelated or extraneous changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch setting/#18/cn-lib-setting

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f69045a and d6ce1b4.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • package.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-and-deploy

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the comment 필요한 주석 추가 및 변경 label Oct 15, 2025
@github-actions
Copy link

🏷️ Labeler has automatically applied labels based on your PR title, branch name, or commit message.
Please verify that they are correct before merging.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
package.json (1)

16-16: Critical: Remove duplicate clsx entry.

clsx is declared in both dependencies (line 16) and devDependencies (line 36). This duplication will cause package manager conflicts and should be resolved.

Apply this diff to remove the duplicate from devDependencies:

     "tailwindcss": "4.1.14",
     "typescript": "^5",
     "tailwind-merge": "^3.3.1",
     "class-variance-authority": "^0.7.1",
-    "clsx": "^2.1.1"

Also applies to: 36-36

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36b3f43 and 14fa8ac.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/shared/lib/index.ts (1 hunks)
  • src/shared/lib/utils.ts (1 hunks)
🔇 Additional comments (2)
src/shared/lib/index.ts (1)

1-1: LGTM!

The barrel export pattern is appropriate and provides a clean public API for the shared library utilities.

src/shared/lib/utils.ts (1)

71-73: LGTM: The cn utility implementation is correct.

The pattern clsx(inputs) works correctly because clsx accepts arrays. The inputs rest parameter is already an array, and passing it directly to clsx produces the expected behavior.

package.json Outdated
Comment on lines +34 to +35
"tailwind-merge": "^3.3.1",
"class-variance-authority": "^0.7.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Move runtime utilities to dependencies.

tailwind-merge and clsx are used at runtime by the cn() utility in src/shared/lib/utils.ts. They should be in dependencies, not devDependencies, to ensure they're installed in production environments.

Apply this diff to move them to dependencies:

   "dependencies": {
     "axios": "^1.12.2",
     "clsx": "^2.1.1",
     "next": "15.5.4",
     "react": "19.1.0",
     "react-dom": "19.1.0",
     "react-hook-form": "^7.64.0",
-    "svgo": "^4.0.0"
+    "svgo": "^4.0.0",
+    "tailwind-merge": "^3.3.1"
   },
   "devDependencies": {
     "@eslint/eslintrc": "^3",
     "@tailwindcss/postcss": "^4",
     "@types/node": "^20",
     "@types/react": "^19",
     "@types/react-dom": "^19",
     "eslint": "^9",
     "eslint-config-next": "15.5.4",
     "svg-sprite-loader": "^6.0.11",
     "tailwindcss": "4.1.14",
     "typescript": "^5",
-    "tailwind-merge": "^3.3.1",
-    "class-variance-authority": "^0.7.1",
-    "clsx": "^2.1.1"
+    "class-variance-authority": "^0.7.1"
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"tailwind-merge": "^3.3.1",
"class-variance-authority": "^0.7.1",
"dependencies": {
"axios": "^1.12.2",
"clsx": "^2.1.1",
"next": "15.5.4",
"react": "19.1.0",
"react-dom": "19.1.0",
"react-hook-form": "^7.64.0",
"svgo": "^4.0.0",
"tailwind-merge": "^3.3.1"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.5.4",
"svg-sprite-loader": "^6.0.11",
"tailwindcss": "4.1.14",
"typescript": "^5",
"class-variance-authority": "^0.7.1"
}
🤖 Prompt for AI Agents
In package.json around lines 34-35, tailwind-merge (and clsx, used by cn() in
src/shared/lib/utils.ts) are currently in devDependencies; move them to
dependencies by removing their entries from devDependencies and adding them
under the dependencies object with the same versions (e.g., "tailwind-merge":
"^3.3.1", "clsx": "<current-version>"). After editing package.json, run your
package manager to update lockfile (npm/yarn/pnpm) so production installs
include these packages.

package.json Outdated
"typescript": "^5"
"typescript": "^5",
"tailwind-merge": "^3.3.1",
"class-variance-authority": "^0.7.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

❓ Verification inconclusive

Verify usage of class-variance-authority.

class-variance-authority is added to devDependencies but is not imported in any of the provided files. The PR description mentions CVA for component variants, but no usage is demonstrated yet.

Run the following script to check if CVA is used elsewhere in the codebase:


🏁 Script executed:

#!/bin/bash
# Search for class-variance-authority imports or cva usage
rg -n --type=ts --type=tsx -C2 "from ['\"]class-variance-authority['\"]|import.*cva"

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Search for class-variance-authority imports or cva usage in .ts and .tsx files
rg -n -C2 "from ['\"]class-variance-authority['\"]|import.*cva" -g "*.ts" -g "*.tsx"
rg -n -C2 "cva\(" -g "*.ts" -g "*.tsx"

Length of output: 0


Remove or consume class-variance-authority: it’s listed in devDependencies but no imports or cva() calls exist—either add the CVA usage for your component variants or remove this dependency.

🤖 Prompt for AI Agents
In package.json around line 35, "class-variance-authority" is declared but not
used; either remove it from devDependencies or consume it: to remove, delete the
line and run npm/yarn to update lockfile; to consume, add a cva usage in the
relevant component(s) by importing cva from 'class-variance-authority', define
your variant styles with cva(...), and replace existing conditional class logic
with the cva helper (or move the package to dependencies if it’s needed at
runtime).

skyblue1232
skyblue1232 previously approved these changes Oct 15, 2025
Copy link
Contributor

@skyblue1232 skyblue1232 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용법이 잘 나와있네요!! 참고해서 공컴 구현하겠습니다~

skyblue1232
skyblue1232 previously approved these changes Oct 15, 2025
KongMezu
KongMezu previously approved these changes Oct 15, 2025
Copy link
Contributor

@KongMezu KongMezu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cva는 이번에 처음 사용해보는데 좋은 공부가 될 거 같습니다. 세팅 해주셔서 감사합니다 🫡🫡

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/pages/index.tsx (1)

19-21: Clarify whether this duplicate content is intentional.

The paragraph duplicates the text from lines 16-18 with different styling. If this is temporary for testing the text-display-md design token, consider removing it before merging. If it's intentional, this would be a good opportunity to demonstrate the new cn() utility introduced in this PR.

For example, if testing the utility:

-          <p className='text-display-md'>
+          <p className={cn('text-display-md', 'text-center')}>
             Next.js(Page Router) + TS + Tailwind + Axios
           </p>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8efef54 and f69045a.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • src/pages/index.tsx (1 hunks)
  • src/shared/lib/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shared/lib/utils.ts

Copy link
Contributor

@KongMezu KongMezu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

세팅할 때 덕분에 많이 배워갑니다... 이렇게까지 해본적 사실 별로 없거든요
여담으로 별 다른 오류 없었으면 좋겠습니다..

@jjangminii jjangminii merged commit d2d7fba into develop Oct 16, 2025
6 checks passed
@jjangminii jjangminii changed the title Setting: cn utils ⚙️ Setting: cn utils Oct 17, 2025
@skyblue1232 skyblue1232 changed the title ⚙️ Setting: cn utils ⚙️Setting: cn utils Oct 17, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comment 필요한 주석 추가 및 변경

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[setting] cn 라이브러리 제작

3 participants