@mandujs/mcp 0.9.19 → 0.9.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/README.md +320 -0
  2. package/package.json +1 -1
  3. package/src/activity-monitor.ts +847 -231
  4. package/src/resources/handlers.ts +244 -0
  5. package/src/resources/skills/guides.ts +1136 -0
  6. package/src/resources/skills/index.ts +12 -0
  7. package/src/resources/skills/loader.ts +218 -0
  8. package/src/resources/skills/mandu-composition/SKILL.md +91 -0
  9. package/src/resources/skills/mandu-composition/metadata.json +13 -0
  10. package/src/resources/skills/mandu-composition/rules/_sections.md +26 -0
  11. package/src/resources/skills/mandu-composition/rules/_template.md +77 -0
  12. package/src/resources/skills/mandu-composition/rules/comp-arch-avoid-boolean-props.md +146 -0
  13. package/src/resources/skills/mandu-composition/rules/comp-arch-compound-components.md +164 -0
  14. package/src/resources/skills/mandu-composition/rules/comp-island-event.md +161 -0
  15. package/src/resources/skills/mandu-composition/rules/comp-island-slot-split.md +167 -0
  16. package/src/resources/skills/mandu-composition/rules/comp-pattern-children.md +149 -0
  17. package/src/resources/skills/mandu-composition/rules/comp-state-context-interface.md +148 -0
  18. package/src/resources/skills/mandu-composition/rules/comp-state-lift-state.md +150 -0
  19. package/src/resources/skills/mandu-deployment/SKILL.md +92 -0
  20. package/src/resources/skills/mandu-deployment/_sections.md +41 -0
  21. package/src/resources/skills/mandu-deployment/_template.md +38 -0
  22. package/src/resources/skills/mandu-deployment/metadata.json +13 -0
  23. package/src/resources/skills/mandu-deployment/rules/deploy-build-bun.md +109 -0
  24. package/src/resources/skills/mandu-deployment/rules/deploy-build-output.md +115 -0
  25. package/src/resources/skills/mandu-deployment/rules/deploy-cicd-github.md +219 -0
  26. package/src/resources/skills/mandu-deployment/rules/deploy-docker-bun.md +150 -0
  27. package/src/resources/skills/mandu-deployment/rules/deploy-docker-compose.md +223 -0
  28. package/src/resources/skills/mandu-deployment/rules/deploy-platform-fly.md +152 -0
  29. package/src/resources/skills/mandu-deployment/rules/deploy-platform-render.md +179 -0
  30. package/src/resources/skills/mandu-deployment/rules/deploy-platform-supabase.md +323 -0
  31. package/src/resources/skills/mandu-deployment/rules/deploy-platform-vercel.md +140 -0
  32. package/src/resources/skills/mandu-fs-routes/SKILL.md +82 -0
  33. package/src/resources/skills/mandu-fs-routes/metadata.json +12 -0
  34. package/src/resources/skills/mandu-fs-routes/rules/_sections.md +36 -0
  35. package/src/resources/skills/mandu-fs-routes/rules/_template.md +69 -0
  36. package/src/resources/skills/mandu-fs-routes/rules/routes-api-methods.md +65 -0
  37. package/src/resources/skills/mandu-fs-routes/rules/routes-dynamic-param.md +93 -0
  38. package/src/resources/skills/mandu-fs-routes/rules/routes-naming-page.md +55 -0
  39. package/src/resources/skills/mandu-guard/SKILL.md +129 -0
  40. package/src/resources/skills/mandu-guard/metadata.json +12 -0
  41. package/src/resources/skills/mandu-guard/rules/_sections.md +36 -0
  42. package/src/resources/skills/mandu-guard/rules/_template.md +82 -0
  43. package/src/resources/skills/mandu-guard/rules/guard-config-rules.md +100 -0
  44. package/src/resources/skills/mandu-guard/rules/guard-layer-direction.md +76 -0
  45. package/src/resources/skills/mandu-guard/rules/guard-preset-mandu.md +81 -0
  46. package/src/resources/skills/mandu-guard/rules/guard-validate-import.md +80 -0
  47. package/src/resources/skills/mandu-hydration/SKILL.md +91 -0
  48. package/src/resources/skills/mandu-hydration/metadata.json +12 -0
  49. package/src/resources/skills/mandu-hydration/rules/_sections.md +31 -0
  50. package/src/resources/skills/mandu-hydration/rules/_template.md +72 -0
  51. package/src/resources/skills/mandu-hydration/rules/hydration-data-event.md +109 -0
  52. package/src/resources/skills/mandu-hydration/rules/hydration-directive-use-client.md +55 -0
  53. package/src/resources/skills/mandu-hydration/rules/hydration-island-setup.md +113 -0
  54. package/src/resources/skills/mandu-hydration/rules/hydration-priority-visible.md +68 -0
  55. package/src/resources/skills/mandu-performance/SKILL.md +85 -0
  56. package/src/resources/skills/mandu-performance/metadata.json +14 -0
  57. package/src/resources/skills/mandu-performance/rules/_sections.md +31 -0
  58. package/src/resources/skills/mandu-performance/rules/_template.md +64 -0
  59. package/src/resources/skills/mandu-performance/rules/perf-async-defer-await.md +103 -0
  60. package/src/resources/skills/mandu-performance/rules/perf-async-parallel.md +95 -0
  61. package/src/resources/skills/mandu-performance/rules/perf-bun-file.md +124 -0
  62. package/src/resources/skills/mandu-performance/rules/perf-bun-serve.md +125 -0
  63. package/src/resources/skills/mandu-performance/rules/perf-bundle-imports.md +80 -0
  64. package/src/resources/skills/mandu-performance/rules/perf-bundle-island-lazy.md +145 -0
  65. package/src/resources/skills/mandu-performance/rules/perf-cache-react.md +98 -0
  66. package/src/resources/skills/mandu-performance/rules/perf-render-transitions.md +154 -0
  67. package/src/resources/skills/mandu-security/SKILL.md +87 -0
  68. package/src/resources/skills/mandu-security/metadata.json +13 -0
  69. package/src/resources/skills/mandu-security/rules/_sections.md +31 -0
  70. package/src/resources/skills/mandu-security/rules/_template.md +74 -0
  71. package/src/resources/skills/mandu-security/rules/sec-auth-guard.md +127 -0
  72. package/src/resources/skills/mandu-security/rules/sec-env-management.md +133 -0
  73. package/src/resources/skills/mandu-security/rules/sec-input-validate.md +148 -0
  74. package/src/resources/skills/mandu-security/rules/sec-protect-csrf.md +146 -0
  75. package/src/resources/skills/mandu-security/rules/sec-protect-headers.md +138 -0
  76. package/src/resources/skills/mandu-slot/SKILL.md +85 -0
  77. package/src/resources/skills/mandu-slot/metadata.json +12 -0
  78. package/src/resources/skills/mandu-slot/rules/_sections.md +36 -0
  79. package/src/resources/skills/mandu-slot/rules/_template.md +63 -0
  80. package/src/resources/skills/mandu-slot/rules/slot-basic-structure.md +38 -0
  81. package/src/resources/skills/mandu-slot/rules/slot-ctx-response.md +56 -0
  82. package/src/resources/skills/mandu-slot/rules/slot-guard-auth.md +59 -0
  83. package/src/resources/skills/mandu-slot/rules/slot-http-methods.md +64 -0
  84. package/src/resources/skills/mandu-styling/SKILL.md +118 -0
  85. package/src/resources/skills/mandu-styling/_sections.md +36 -0
  86. package/src/resources/skills/mandu-styling/_template.md +32 -0
  87. package/src/resources/skills/mandu-styling/metadata.json +13 -0
  88. package/src/resources/skills/mandu-styling/rules/style-component-compound.md +235 -0
  89. package/src/resources/skills/mandu-styling/rules/style-component-slots.md +255 -0
  90. package/src/resources/skills/mandu-styling/rules/style-component-tokens.md +205 -0
  91. package/src/resources/skills/mandu-styling/rules/style-island-animations.md +272 -0
  92. package/src/resources/skills/mandu-styling/rules/style-island-scoping.md +167 -0
  93. package/src/resources/skills/mandu-styling/rules/style-island-variants.md +221 -0
  94. package/src/resources/skills/mandu-styling/rules/style-perf-critical.md +209 -0
  95. package/src/resources/skills/mandu-styling/rules/style-perf-purge.md +192 -0
  96. package/src/resources/skills/mandu-styling/rules/style-setup-modules.md +162 -0
  97. package/src/resources/skills/mandu-styling/rules/style-setup-panda.md +164 -0
  98. package/src/resources/skills/mandu-styling/rules/style-setup-tailwind.md +161 -0
  99. package/src/resources/skills/mandu-styling/rules/style-theme-darkmode.md +229 -0
  100. package/src/resources/skills/mandu-testing/SKILL.md +99 -0
  101. package/src/resources/skills/mandu-testing/metadata.json +13 -0
  102. package/src/resources/skills/mandu-testing/rules/_sections.md +26 -0
  103. package/src/resources/skills/mandu-testing/rules/_template.md +65 -0
  104. package/src/resources/skills/mandu-testing/rules/test-component-island.md +195 -0
  105. package/src/resources/skills/mandu-testing/rules/test-e2e-playwright.md +196 -0
  106. package/src/resources/skills/mandu-testing/rules/test-mock-fetch.md +219 -0
  107. package/src/resources/skills/mandu-testing/rules/test-slot-unit.md +192 -0
  108. package/src/resources/skills/mandu-ui/SKILL.md +117 -0
  109. package/src/resources/skills/mandu-ui/_sections.md +23 -0
  110. package/src/resources/skills/mandu-ui/_template.md +32 -0
  111. package/src/resources/skills/mandu-ui/metadata.json +13 -0
  112. package/src/resources/skills/mandu-ui/rules/ui-accessibility-aria.md +232 -0
  113. package/src/resources/skills/mandu-ui/rules/ui-accessibility-focus.md +238 -0
  114. package/src/resources/skills/mandu-ui/rules/ui-composition-patterns.md +259 -0
  115. package/src/resources/skills/mandu-ui/rules/ui-island-integration.md +258 -0
  116. package/src/resources/skills/mandu-ui/rules/ui-radix-patterns.md +213 -0
  117. package/src/resources/skills/mandu-ui/rules/ui-shadcn-setup.md +209 -0
  118. package/src/resources/skills/recipes.ts +932 -0
  119. package/src/server.ts +3 -0
  120. package/src/tools/hydration.ts +8 -8
  121. package/src/tools/index.ts +1 -0
  122. package/src/tools/seo.ts +417 -0
@@ -0,0 +1,272 @@
1
+ ---
2
+ title: Island Animations
3
+ impact: HIGH
4
+ impactDescription: Client-side animations for interactive Islands
5
+ tags: styling, island, animations, transitions
6
+ ---
7
+
8
+ ## Island Animations
9
+
10
+ **Impact: HIGH (Client-side animations for interactive Islands)**
11
+
12
+ Island 컴포넌트에서 부드러운 애니메이션을 구현하세요.
13
+
14
+ ## Tailwind 애니메이션
15
+
16
+ ```typescript
17
+ // tailwind.config.ts
18
+ export default {
19
+ theme: {
20
+ extend: {
21
+ animation: {
22
+ "fade-in": "fadeIn 0.2s ease-out",
23
+ "fade-out": "fadeOut 0.2s ease-out",
24
+ "slide-in": "slideIn 0.3s ease-out",
25
+ "slide-out": "slideOut 0.3s ease-out",
26
+ "scale-in": "scaleIn 0.2s ease-out",
27
+ "spin-slow": "spin 3s linear infinite",
28
+ },
29
+ keyframes: {
30
+ fadeIn: {
31
+ "0%": { opacity: "0" },
32
+ "100%": { opacity: "1" },
33
+ },
34
+ fadeOut: {
35
+ "0%": { opacity: "1" },
36
+ "100%": { opacity: "0" },
37
+ },
38
+ slideIn: {
39
+ "0%": { transform: "translateY(-10px)", opacity: "0" },
40
+ "100%": { transform: "translateY(0)", opacity: "1" },
41
+ },
42
+ slideOut: {
43
+ "0%": { transform: "translateY(0)", opacity: "1" },
44
+ "100%": { transform: "translateY(-10px)", opacity: "0" },
45
+ },
46
+ scaleIn: {
47
+ "0%": { transform: "scale(0.95)", opacity: "0" },
48
+ "100%": { transform: "scale(1)", opacity: "1" },
49
+ },
50
+ },
51
+ },
52
+ },
53
+ };
54
+ ```
55
+
56
+ ## 조건부 애니메이션
57
+
58
+ ```tsx
59
+ // app/dropdown/client.tsx
60
+ "use client";
61
+
62
+ import { useState } from "react";
63
+ import { cn } from "@/lib/utils";
64
+
65
+ export function DropdownIsland() {
66
+ const [isOpen, setIsOpen] = useState(false);
67
+
68
+ return (
69
+ <div className="relative">
70
+ <button onClick={() => setIsOpen(!isOpen)}>
71
+ Toggle
72
+ </button>
73
+
74
+ <div
75
+ className={cn(
76
+ "absolute top-full mt-2 w-48 rounded-md bg-white shadow-lg",
77
+ "transition-all duration-200",
78
+ isOpen
79
+ ? "animate-fade-in opacity-100 translate-y-0"
80
+ : "opacity-0 -translate-y-2 pointer-events-none"
81
+ )}
82
+ >
83
+ <ul className="py-2">
84
+ <li className="px-4 py-2 hover:bg-gray-100">Option 1</li>
85
+ <li className="px-4 py-2 hover:bg-gray-100">Option 2</li>
86
+ </ul>
87
+ </div>
88
+ </div>
89
+ );
90
+ }
91
+ ```
92
+
93
+ ## CSS Transition 패턴
94
+
95
+ ```tsx
96
+ // app/accordion/client.tsx
97
+ "use client";
98
+
99
+ import { useState, useRef, useEffect } from "react";
100
+
101
+ export function AccordionIsland({ title, children }) {
102
+ const [isOpen, setIsOpen] = useState(false);
103
+ const contentRef = useRef<HTMLDivElement>(null);
104
+ const [height, setHeight] = useState(0);
105
+
106
+ useEffect(() => {
107
+ if (contentRef.current) {
108
+ setHeight(isOpen ? contentRef.current.scrollHeight : 0);
109
+ }
110
+ }, [isOpen]);
111
+
112
+ return (
113
+ <div className="border-b">
114
+ <button
115
+ className="flex w-full items-center justify-between py-4"
116
+ onClick={() => setIsOpen(!isOpen)}
117
+ >
118
+ <span>{title}</span>
119
+ <span
120
+ className={cn(
121
+ "transition-transform duration-200",
122
+ isOpen && "rotate-180"
123
+ )}
124
+ >
125
+
126
+ </span>
127
+ </button>
128
+
129
+ <div
130
+ style={{ height }}
131
+ className="overflow-hidden transition-[height] duration-200 ease-out"
132
+ >
133
+ <div ref={contentRef} className="pb-4">
134
+ {children}
135
+ </div>
136
+ </div>
137
+ </div>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ## Loading States
143
+
144
+ ```tsx
145
+ // app/button/client.tsx
146
+ "use client";
147
+
148
+ export function LoadingButtonIsland({ loading, children, ...props }) {
149
+ return (
150
+ <button
151
+ disabled={loading}
152
+ className={cn(
153
+ "relative inline-flex items-center justify-center",
154
+ loading && "cursor-wait"
155
+ )}
156
+ {...props}
157
+ >
158
+ {loading && (
159
+ <span className="absolute inset-0 flex items-center justify-center">
160
+ <svg
161
+ className="h-5 w-5 animate-spin text-current"
162
+ fill="none"
163
+ viewBox="0 0 24 24"
164
+ >
165
+ <circle
166
+ className="opacity-25"
167
+ cx="12"
168
+ cy="12"
169
+ r="10"
170
+ stroke="currentColor"
171
+ strokeWidth="4"
172
+ />
173
+ <path
174
+ className="opacity-75"
175
+ fill="currentColor"
176
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"
177
+ />
178
+ </svg>
179
+ </span>
180
+ )}
181
+ <span className={cn(loading && "invisible")}>{children}</span>
182
+ </button>
183
+ );
184
+ }
185
+ ```
186
+
187
+ ## Skeleton Loading
188
+
189
+ ```tsx
190
+ // components/skeleton.tsx
191
+ export function Skeleton({ className, ...props }) {
192
+ return (
193
+ <div
194
+ className={cn(
195
+ "animate-pulse rounded-md bg-gray-200 dark:bg-gray-700",
196
+ className
197
+ )}
198
+ {...props}
199
+ />
200
+ );
201
+ }
202
+
203
+ // 사용
204
+ <div className="space-y-2">
205
+ <Skeleton className="h-4 w-3/4" />
206
+ <Skeleton className="h-4 w-1/2" />
207
+ </div>
208
+ ```
209
+
210
+ ## Page Transitions (View Transitions API)
211
+
212
+ ```tsx
213
+ // app/layout.tsx
214
+ export default function Layout({ children }) {
215
+ return (
216
+ <html>
217
+ <body>
218
+ <div className="[view-transition-name:main]">
219
+ {children}
220
+ </div>
221
+ </body>
222
+ </html>
223
+ );
224
+ }
225
+ ```
226
+
227
+ ```css
228
+ /* globals.css */
229
+ @media (prefers-reduced-motion: no-preference) {
230
+ ::view-transition-old(main),
231
+ ::view-transition-new(main) {
232
+ animation-duration: 0.3s;
233
+ }
234
+
235
+ ::view-transition-old(main) {
236
+ animation-name: fadeOut;
237
+ }
238
+
239
+ ::view-transition-new(main) {
240
+ animation-name: fadeIn;
241
+ }
242
+ }
243
+ ```
244
+
245
+ ## 접근성: Reduced Motion
246
+
247
+ ```tsx
248
+ // hooks/useReducedMotion.ts
249
+ export function useReducedMotion() {
250
+ const [prefersReduced, setPrefersReduced] = useState(false);
251
+
252
+ useEffect(() => {
253
+ const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
254
+ setPrefersReduced(mq.matches);
255
+
256
+ const handler = (e: MediaQueryListEvent) => setPrefersReduced(e.matches);
257
+ mq.addEventListener("change", handler);
258
+ return () => mq.removeEventListener("change", handler);
259
+ }, []);
260
+
261
+ return prefersReduced;
262
+ }
263
+
264
+ // 사용
265
+ const reducedMotion = useReducedMotion();
266
+
267
+ <div className={cn(
268
+ !reducedMotion && "animate-fade-in"
269
+ )}>
270
+ ```
271
+
272
+ Reference: [Tailwind Animation](https://tailwindcss.com/docs/animation)
@@ -0,0 +1,167 @@
1
+ ---
2
+ title: Island Style Scoping
3
+ impact: HIGH
4
+ impactDescription: Prevents style conflicts between independent Islands
5
+ tags: styling, island, scoping, isolation
6
+ ---
7
+
8
+ ## Island Style Scoping
9
+
10
+ **Impact: HIGH (Prevents style conflicts between independent Islands)**
11
+
12
+ Island는 독립적으로 hydrate되므로 스타일 충돌을 방지해야 합니다.
13
+
14
+ **문제 상황:**
15
+
16
+ ```tsx
17
+ // ❌ 전역 클래스 충돌 가능
18
+ <div className="card">...</div> // Island A
19
+ <div className="card">...</div> // Island B - 다른 스타일 의도
20
+ ```
21
+
22
+ ## 해결 방법 1: data-island 속성
23
+
24
+ ```tsx
25
+ // app/counter/client.tsx
26
+ "use client";
27
+
28
+ export function CounterIsland() {
29
+ return (
30
+ <div
31
+ data-island="counter"
32
+ className="p-4 rounded-lg bg-blue-500"
33
+ >
34
+ <button className="[&[data-island=counter]_&]:text-white">
35
+ Count
36
+ </button>
37
+ </div>
38
+ );
39
+ }
40
+ ```
41
+
42
+ ```css
43
+ /* Tailwind 커스텀 variant */
44
+ [data-island="counter"] {
45
+ /* Island 특화 스타일 */
46
+ }
47
+ ```
48
+
49
+ ## 해결 방법 2: CSS Modules (권장)
50
+
51
+ ```tsx
52
+ // app/counter/client.tsx
53
+ "use client";
54
+
55
+ import styles from "./counter.module.css";
56
+
57
+ export function CounterIsland() {
58
+ return (
59
+ <div className={styles.container}>
60
+ <button className={styles.button}>Count</button>
61
+ </div>
62
+ );
63
+ }
64
+ ```
65
+
66
+ ```css
67
+ /* app/counter/counter.module.css */
68
+ .container {
69
+ @apply p-4 rounded-lg bg-blue-500;
70
+ }
71
+
72
+ .button {
73
+ @apply text-white font-medium;
74
+ }
75
+ ```
76
+
77
+ ## 해결 방법 3: Tailwind Prefix
78
+
79
+ ```typescript
80
+ // tailwind.config.ts
81
+ export default {
82
+ prefix: "", // 전역은 prefix 없음
83
+ // 또는 Island별 prefix
84
+ };
85
+ ```
86
+
87
+ ```tsx
88
+ // 컴포넌트별 네임스페이스
89
+ const ns = "counter";
90
+
91
+ export function CounterIsland() {
92
+ return (
93
+ <div className={`${ns}-container p-4`}>
94
+ <button className={`${ns}-btn`}>Count</button>
95
+ </div>
96
+ );
97
+ }
98
+ ```
99
+
100
+ ## 해결 방법 4: CSS Layers
101
+
102
+ ```css
103
+ /* app/globals.css */
104
+ @layer components {
105
+ .island-counter {
106
+ @apply p-4 rounded-lg;
107
+ }
108
+ }
109
+
110
+ @layer islands.counter {
111
+ .container {
112
+ @apply bg-blue-500;
113
+ }
114
+ }
115
+
116
+ @layer islands.form {
117
+ .container {
118
+ @apply bg-green-500;
119
+ }
120
+ }
121
+ ```
122
+
123
+ ## Best Practice: Compound + Module 조합
124
+
125
+ ```tsx
126
+ // app/card/client.tsx
127
+ "use client";
128
+
129
+ import { cn } from "@/lib/utils";
130
+ import styles from "./card.module.css";
131
+
132
+ export const Card = {
133
+ Root: ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
134
+ <div className={cn(styles.root, className)} {...props} />
135
+ ),
136
+ Header: ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
137
+ <div className={cn(styles.header, className)} {...props} />
138
+ ),
139
+ Content: ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
140
+ <div className={cn(styles.content, className)} {...props} />
141
+ ),
142
+ };
143
+ ```
144
+
145
+ ```css
146
+ /* app/card/card.module.css */
147
+ .root {
148
+ @apply rounded-lg border bg-white shadow-sm;
149
+ }
150
+
151
+ .header {
152
+ @apply px-6 py-4 border-b;
153
+ }
154
+
155
+ .content {
156
+ @apply px-6 py-4;
157
+ }
158
+ ```
159
+
160
+ ## 스타일 충돌 체크리스트
161
+
162
+ - [ ] 전역 클래스명 사용 금지 (`.card`, `.button` 등)
163
+ - [ ] CSS Modules 또는 data-island 속성 사용
164
+ - [ ] cn() 함수로 클래스 병합 시 순서 주의
165
+ - [ ] 다크모드 변수는 :root에 정의
166
+
167
+ Reference: [Tailwind CSS Scoping](https://tailwindcss.com/docs/adding-custom-styles)
@@ -0,0 +1,221 @@
1
+ ---
2
+ title: Island Style Variants
3
+ impact: HIGH
4
+ impactDescription: Conditional styling patterns for Island components
5
+ tags: styling, island, variants, cva
6
+ ---
7
+
8
+ ## Island Style Variants
9
+
10
+ **Impact: HIGH (Conditional styling patterns for Island components)**
11
+
12
+ Island 컴포넌트의 조건부 스타일링을 체계적으로 관리하세요.
13
+
14
+ **class-variance-authority (cva) 설치:**
15
+
16
+ ```bash
17
+ bun add class-variance-authority
18
+ ```
19
+
20
+ ## cva 기본 패턴
21
+
22
+ ```tsx
23
+ // app/button/client.tsx
24
+ "use client";
25
+
26
+ import { cva, type VariantProps } from "class-variance-authority";
27
+ import { cn } from "@/lib/utils";
28
+
29
+ const buttonVariants = cva(
30
+ // Base styles
31
+ "inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50",
32
+ {
33
+ variants: {
34
+ variant: {
35
+ default: "bg-mandu-primary text-white hover:bg-mandu-primary/90",
36
+ destructive: "bg-red-500 text-white hover:bg-red-500/90",
37
+ outline: "border border-input bg-background hover:bg-accent",
38
+ secondary: "bg-mandu-secondary text-white hover:bg-mandu-secondary/80",
39
+ ghost: "hover:bg-accent hover:text-accent-foreground",
40
+ link: "text-mandu-primary underline-offset-4 hover:underline",
41
+ },
42
+ size: {
43
+ default: "h-10 px-4 py-2",
44
+ sm: "h-9 rounded-md px-3",
45
+ lg: "h-11 rounded-md px-8",
46
+ icon: "h-10 w-10",
47
+ },
48
+ },
49
+ defaultVariants: {
50
+ variant: "default",
51
+ size: "default",
52
+ },
53
+ }
54
+ );
55
+
56
+ interface ButtonProps
57
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
58
+ VariantProps<typeof buttonVariants> {}
59
+
60
+ export function ButtonIsland({ className, variant, size, ...props }: ButtonProps) {
61
+ return (
62
+ <button className={cn(buttonVariants({ variant, size }), className)} {...props} />
63
+ );
64
+ }
65
+
66
+ // Export for reuse
67
+ export { buttonVariants };
68
+ ```
69
+
70
+ ## 복합 Variants
71
+
72
+ ```tsx
73
+ const cardVariants = cva("rounded-lg border", {
74
+ variants: {
75
+ variant: {
76
+ default: "bg-white",
77
+ elevated: "bg-white shadow-lg",
78
+ outlined: "bg-transparent",
79
+ },
80
+ padding: {
81
+ none: "",
82
+ sm: "p-4",
83
+ md: "p-6",
84
+ lg: "p-8",
85
+ },
86
+ interactive: {
87
+ true: "cursor-pointer hover:shadow-md transition-shadow",
88
+ false: "",
89
+ },
90
+ },
91
+ compoundVariants: [
92
+ {
93
+ variant: "elevated",
94
+ interactive: true,
95
+ className: "hover:shadow-xl",
96
+ },
97
+ {
98
+ variant: "outlined",
99
+ interactive: true,
100
+ className: "hover:border-mandu-primary",
101
+ },
102
+ ],
103
+ defaultVariants: {
104
+ variant: "default",
105
+ padding: "md",
106
+ interactive: false,
107
+ },
108
+ });
109
+ ```
110
+
111
+ ## Boolean Variants
112
+
113
+ ```tsx
114
+ const inputVariants = cva(
115
+ "flex h-10 w-full rounded-md border px-3 py-2 text-sm",
116
+ {
117
+ variants: {
118
+ hasError: {
119
+ true: "border-red-500 focus:ring-red-500",
120
+ false: "border-gray-300 focus:ring-mandu-primary",
121
+ },
122
+ isDisabled: {
123
+ true: "bg-gray-100 cursor-not-allowed opacity-50",
124
+ false: "bg-white",
125
+ },
126
+ },
127
+ defaultVariants: {
128
+ hasError: false,
129
+ isDisabled: false,
130
+ },
131
+ }
132
+ );
133
+
134
+ export function InputIsland({ error, disabled, ...props }: InputProps) {
135
+ return (
136
+ <input
137
+ className={inputVariants({
138
+ hasError: !!error,
139
+ isDisabled: disabled,
140
+ })}
141
+ disabled={disabled}
142
+ {...props}
143
+ />
144
+ );
145
+ }
146
+ ```
147
+
148
+ ## Responsive Variants
149
+
150
+ ```tsx
151
+ // 반응형은 Tailwind 클래스로 처리
152
+ export function CardIsland({ className, ...props }: CardProps) {
153
+ return (
154
+ <div
155
+ className={cn(
156
+ cardVariants({ variant: "default", padding: "md" }),
157
+ // 반응형 오버라이드
158
+ "md:p-8 lg:p-10",
159
+ className
160
+ )}
161
+ {...props}
162
+ />
163
+ );
164
+ }
165
+ ```
166
+
167
+ ## Slot Pattern과 조합
168
+
169
+ ```tsx
170
+ // app/alert/client.tsx
171
+ "use client";
172
+
173
+ import { cva } from "class-variance-authority";
174
+
175
+ const alertVariants = cva(
176
+ "relative w-full rounded-lg border p-4",
177
+ {
178
+ variants: {
179
+ variant: {
180
+ default: "bg-background text-foreground",
181
+ info: "border-blue-200 bg-blue-50 text-blue-900",
182
+ success: "border-green-200 bg-green-50 text-green-900",
183
+ warning: "border-yellow-200 bg-yellow-50 text-yellow-900",
184
+ error: "border-red-200 bg-red-50 text-red-900",
185
+ },
186
+ },
187
+ defaultVariants: {
188
+ variant: "default",
189
+ },
190
+ }
191
+ );
192
+
193
+ const iconVariants = cva("h-5 w-5", {
194
+ variants: {
195
+ variant: {
196
+ default: "text-foreground",
197
+ info: "text-blue-600",
198
+ success: "text-green-600",
199
+ warning: "text-yellow-600",
200
+ error: "text-red-600",
201
+ },
202
+ },
203
+ });
204
+
205
+ export const Alert = {
206
+ Root: ({ variant, className, ...props }) => (
207
+ <div className={cn(alertVariants({ variant }), className)} {...props} />
208
+ ),
209
+ Icon: ({ variant, className, ...props }) => (
210
+ <span className={cn(iconVariants({ variant }), className)} {...props} />
211
+ ),
212
+ Title: ({ className, ...props }) => (
213
+ <h5 className={cn("font-medium leading-none", className)} {...props} />
214
+ ),
215
+ Description: ({ className, ...props }) => (
216
+ <div className={cn("text-sm opacity-90", className)} {...props} />
217
+ ),
218
+ };
219
+ ```
220
+
221
+ Reference: [class-variance-authority](https://cva.style/docs)