Use when refactoring Tailwind CSS class order in React/Next.js components, when className strings feel disorganized, or when establishing consistent CSS ordering conventions across a codebase
Tailwind CSS ํด๋์ค๋ฅผ ์ผ๊ด๋ ์์๋ก ์ ๋ ฌํ๋ ๊ธฐ๋ฒ์ ๋๋ค. ํต์ฌ ์์น: ์๊ฐ์ ๋ ๋๋ง ์์(๋ฐ๊นฅโ์์ชฝโ์ฝํ ์ธ )๋ฅผ ๋ฐ๋ฆ ๋๋ค.
Use when:
className ๋ฌธ์์ด์ด ๊ธธ๊ณ ๋ฌด์ง์ํด ๋ณด์ผ ๋Don't use for:
| ์์ | ์นดํ ๊ณ ๋ฆฌ | ์์ฑ |
|---|---|---|
| 0 | ์ปค์คํ CSS | card-tilt, hover-button ๋ฑ ํ๋ก์ ํธ ์ปค์คํ
ํด๋์ค (๋งจ ์) |
| 1 | ํฌ์ง์ | absolute, relative, fixed, sticky, static, inset-*, top-*, right-*, bottom-*, left-*, z-* |
| 2 | ๋ ์ด์์ | w-*, h-*, size-*, min-w-*, max-w-*, min-h-*, max-h-*, overflow-*, aspect-*, container, block, inline-*, hidden, visible, invisible |
| 3 | ๊ณต๋ฐฑ | m-*, mx-*, my-*, mt-*, mr-*, mb-*, ml-*, p-*, px-*, py-*, pt-*, pr-*, pb-*, pl-*, gap-*, gap-x-*, gap-y-*, space-x-*, space-y-* |
| 4 | ์ธ๊ณฝ ํจ๊ณผ | border-*, rounded-*, shadow-*, ring-*, outline-*, divide-* |
| 5 | ๋ฐฐ๊ฒฝ์ | bg-*, opacity-*, backdrop-*, gradient-*, from-*, via-*, to-* |
| 6 | Flex/Grid | flex, flex-row, flex-col, flex-wrap, flex-1, grow, shrink, basis-*, grid, grid-cols-*, grid-rows-*, col-span-*, row-span-*, justify-*, items-*, self-*, place-*, order-* |
| 7 | ํฐํธ | text-*, font-*, leading-*, tracking-*, whitespace-*, truncate, line-clamp-*, break-*, underline, line-through, no-underline, uppercase, lowercase, capitalize, italic, not-italic, list-*, indent-* |
| 8 | ์ ๋๋ฉ์ด์ | animate-* |
| 9 | ํธ๋์ง์ | transition-*, duration-*, ease-*, delay-* |
| - | ์ธํฐ๋์ | cursor-*, pointer-events-*, select-*, touch-*, scroll-*, snap-*, will-change-* โ ํด๋น ์์ฑ ๋ฐ๋ก ๋ค์ ๋ฐฐ์น (hover:/focus:์ ๋์ผ ์์น) |
| - | ์กฐ๊ฑด๋ถ | hover:, focus:, active:, disabled:, group-hover:, peer-*: โ ํด๋น ๊ธฐ๋ณธ ํด๋์ค ๋ฐ๋ก ๋ค์ ๋ฐฐ์น |
| - | ๋ฐ์ํ | sm:, md:, lg:, xl:, 2xl: โ ํด๋น ๊ธฐ๋ณธ ํด๋์ค ๋ฐ๋ก ๋ค์ ๋ฐฐ์น |
// โ Before: ๋ฌด์ง์ํ ์์
className =
'px-4 hover:bg-blue-600 py-2 bg-blue-500 text-white rounded-lg font-bold';
// โ
After: ์ ๋ ฌ๋ ์์ (์ธ๊ณฝโ๋ฐฐ๊ฒฝโ๊ณต๋ฐฑโํฐํธ)
className =
'rounded-lg bg-blue-500 hover:bg-blue-600 px-4 py-2 font-bold text-white';
์กฐ๊ฑด๋ถ ํด๋์ค(hover:, focus:, disabled:)๋ ํด๋น ๊ธฐ๋ณธ ํด๋์ค ๋ฐ๋ก ๋ค์ ๋ฐฐ์น:
// โ
์ฌ๋ฐ๋ฆ: bg-blue-500 ๋ฐ๋ก ๋ค์ hover:bg-blue-600
className = 'rounded-lg bg-blue-500 hover:bg-blue-600 px-4 py-2';
// โ ์๋ชป๋จ: hover๊ฐ bg์ ๋ถ๋ฆฌ๋จ
className = 'rounded-lg bg-blue-500 px-4 py-2 hover:bg-blue-600';
// โ Before
className = 'w-8 h-8';
// โ
After
className = 'size-8';
๋์ ํด๋์ค๊ฐ ํฌํจ๋ ๊ฒฝ์ฐ, ์ ์ ๋ถ๋ถ๋ง ์ ๋ ฌํ๊ณ ๋์ ๋ถ๋ถ์ ์๋ ์์น ์ ์ง:
// ๋์ ํด๋์ค (${cardColor})๋ ํด๋น ์นดํ
๊ณ ๋ฆฌ ์์น์ ๋ฐฐ์น
className={`card-tilt size-full p-4 border-6 ${cardColorByGrade} rounded-2xl flex flex-col`}
// ์ปค์คํ
๋ ์ด์์ ๊ณต๋ฐฑ ์ธ๊ณฝ ๋์ (์ธ๊ณฝ/๋ฐฐ๊ฒฝ) ์ธ๊ณฝ Flex
์กฐ๊ฑด๋ถ ์คํ์ผ ๊ฐ์ฒด๋ ์์ ๋ณ๊ฒฝ ์์ด ์ ์ง:
className={cn(
"rounded-lg bg-white px-4 py-2", // ์ ์ ๋ถ๋ถ๋ง ์ ๋ ฌ
isDarkMode && "bg-gray-800", // ์กฐ๊ฑด๋ถ๋ ๊ทธ๋๋ก
isActive && "ring-2 ring-blue-500" // ์กฐ๊ฑด๋ถ๋ ๊ทธ๋๋ก
)}
| ์ค์ | ์์ |
|---|---|
| ๊ณต๋ฐฑ์ด ์ธ๊ณฝ๋ณด๋ค ๋จผ์ | px-4 rounded-lg โ rounded-lg px-4 |
| ํฌ์ง์ ์ด ๋ ์ด์์ ๋ค์ | w-full relative โ relative w-full |
| ์กฐ๊ฑด๋ถ๊ฐ ๊ธฐ๋ณธ ํด๋์ค์ ๋ถ๋ฆฌ๋จ | ๊ธฐ๋ณธ ํด๋์ค ๋ฐ๋ก ๋ค๋ก ์ด๋ |
| w-8 h-8 ์ค๋ณต | size-8๋ก ํตํฉ |
๋๊ท๋ชจ ๋ฆฌํฉํ ๋ง ์ ๊ถ์ฅ ์ํฌํ๋ก์ฐ:
git checkout -b refactor/tailwind-class-order์์ ์ ์ฃผ์ ์ ํธ: