--- id: wiki-2026-0508-모듈식-컴포넌트-modular-components title: 모듈식 컴포넌트 (Modular Components) category: 10_Wiki/Topics status: verified canonical_id: self aliases: [Modular Components, Composable UI, Component-Driven Architecture] duplicate_of: none source_trust_level: A confidence_score: 0.9 verification_status: applied tags: [architecture, ui, design-system, composition] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: typescript framework: React 19 / Web Components --- # 모듈식 컴포넌트 (Modular Components) ## 매 한 줄 > **"매 single-responsibility의 재사용 가능한 unit을 composable interface로 묶어 system을 build"**. 2003 Brad Frost의 Atomic Design → 2013 React 도입 → 2020 design-token 기반 Headless UI (Radix, shadcn) → 2026 현재 Server Components + Web Components의 hybrid composition이 mainstream. ## 매 핵심 ### 매 5 Properties of Modular Component - **Single Responsibility**: 매 component 하나의 명확한 purpose. - **Encapsulation**: 매 internal state / DOM 외부 격리. - **Composability**: 매 children / slots 통한 nested 조합 가능. - **Configurability via props**: 매 behavior 외부 inject (no hard-coded). - **Testability in isolation**: 매 mock 없이 unit-test 가능. ### 매 Composition Patterns - **Compound Components**: 매 `` — context-shared. - **Slots / Render Props**: 매 children 위치 customization. - **Polymorphic `as` prop**: 매 ` ); }; Tabs.Panel = ({ value, children }: { value: string; children: ReactNode }) => { const ctx = useContext(TabsCtx)!; return ctx.active === value ?
{children}
: null; }; ``` ### Polymorphic Component ```tsx type AsProp = { as?: C }; type PolymorphicProps = P & AsProp & Omit, keyof (P & AsProp)>; export function Box( { as, children, ...rest }: PolymorphicProps ) { const Tag = as || 'div'; return {children}; } // usage: link ``` ### Headless Hook (Disclosure) ```tsx import { useState, useId, useCallback } from 'react'; export function useDisclosure(initial = false) { const [open, setOpen] = useState(initial); const id = useId(); return { isOpen: open, toggle: useCallback(() => setOpen(o => !o), []), open: useCallback(() => setOpen(true), []), close: useCallback(() => setOpen(false), []), triggerProps: { 'aria-expanded': open, 'aria-controls': id }, panelProps: { id, hidden: !open }, }; } ``` ### Web Component (Lit) ```ts import { LitElement, html, css } from 'lit'; import { customElement, property } from 'lit/decorators.js'; @customElement('ag-button') export class AgButton extends LitElement { static styles = css` button { padding: 0.5rem 1rem; border-radius: 0.375rem; } :host([variant="primary"]) button { background: var(--ag-primary, #2563eb); color: white; } `; @property() variant: 'primary' | 'ghost' = 'primary'; render() { return html``; } } ``` ### Design Token (CSS variables) ```css :root { --color-primary-50: #eff6ff; --color-primary-500: #3b82f6; --color-primary-900: #1e3a8a; --space-1: 0.25rem; --space-2: 0.5rem; --radius-md: 0.375rem; --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.05); } .btn { padding: var(--space-2) var(--space-2); background: var(--color-primary-500); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); } ``` ### React Server Component composition ```tsx // app/dashboard/page.tsx — Server Component import { Suspense } from 'react'; import { ChartCard } from '@/components/ChartCard'; import { ClientFilters } from './filters.client'; export default async function Page() { const data = await fetchDashboardData(); // server-only return (
}>
); } ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | 단일 React app | Compound + headless hooks | | Cross-framework / micro-frontend | Web Components | | Design system 배포 | Headless (Radix-style) + design tokens | | SSR-heavy | RSC + selective Client Components | | Mobile (RN) | Headless logic + platform-specific render | **기본값**: Compound components + design tokens + Storybook isolation. ## 🔗 Graph - 부모: [[Design_System]] - 변형: [[Headless_UI]] · [[Compound_Components]] - 응용: [[Storybook]] · [[Radix_UI]] · [[shadcn]] · [[Lit]] - Adjacent: [[Atomic_Design]] · [[Design_Tokens]] · [[React_Server_Components]] ## 🤖 LLM 활용 **언제**: scaffold component variants, prop-type derivation, story / test generation, a11y attribute fill-in. **언제 X**: 매 design decisions (token system shape, theming model) — 매 human design-system curator 영역. ## ❌ 안티패턴 - **God component**: 매 1000-line component, 다목적 props 30개. - **Prop drilling 5+ levels**: 매 context / composition으로 refactor. - **Style leakage**: 매 :global / inherited styles → encapsulation 깨짐. - **Tight coupling to data fetch**: 매 component 내부에서 직접 fetch → reuse 불가능. ## 🧪 검증 / 중복 - Verified (Brad Frost *Atomic Design*, React docs, Radix UI specs). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — modular component 5-property + composition patterns + RSC 정리 |