MDX 문서화

MDX로 Story와 문서를 하나의 파일에서 작성하고 풍부한 콘텐츠를 제공합니다.

← Storybook 가이드로 돌아가기

📝 MDX란?

MDX는 Markdown에 JSX를 결합한 형식으로, 문서 안에 React 컴포넌트를 직접 임베드할 수 있습니다.

Markdown

간편한 텍스트 작성

+ JSX

컴포넌트 임베드

= 풍부한 문서

인터랙티브 가이드

🏗️ MDX 파일 구조

{/* Button.stories.mdx */}
import { Canvas, Meta, Story, ArgsTable, Source } from '@storybook/blocks';
import { Button } from './Button';

{/* Meta 정보 */}
<Meta 
  title="Components/Button" 
  component={Button}
/>

# Button 컴포넌트

재사용 가능한 버튼 컴포넌트로 다양한 스타일과 크기를 지원합니다.

## 설치

```bash
npm install @mycompany/button
```

## 기본 사용법

<Canvas>
  <Story name="Default">
    <Button>Click me</Button>
  </Story>
</Canvas>

## Props

<ArgsTable of={Button} />

## 예제

### Primary Button
<Canvas>
  <Story name="Primary">
    <Button variant="primary">Primary</Button>
  </Story>
</Canvas>

### Secondary Button
<Canvas>
  <Story name="Secondary">
    <Button variant="secondary">Secondary</Button>
  </Story>
</Canvas>

## 디자인 가이드라인

버튼은 사용자 액션을 명확하게 전달해야 합니다:

- ✅ **Do**: 짧고 명확한 텍스트 사용
- ❌ **Don't**: 모호한 문구 사용

## 접근성

- 키보드 탐색 지원 (Tab, Enter)
- 스크린 리더 호환
- 충분한 색상 대비 (WCAG AA)

## 코드 예제

<Source
  language="tsx"
  code={`
<Button 
  variant="primary" 
  size="large"
  onClick={() => console.log('Clicked!')}
>
  Submit Form
</Button>
`}
/>

📦 주요 MDX 컴포넌트

<Meta>

Story 메타데이터 정의

<Meta title="UI/Button" component={Button} />
<Canvas>

Story를 시각적으로 표시

<Canvas><Story>...</Story></Canvas>
<Story>

개별 Story 정의

<Story name="Primary">...</Story>
<ArgsTable>

Props 테이블 자동 생성

<ArgsTable of={Button} />
<Source>

코드 스니펫 표시

<Source code="const a = 1;" />

🎨 Markdown 문법

# 제목→ H1 헤딩
## 소제목→ H2 헤딩
**굵게**굵게
*기울임*기울임
`코드`→ 인라인 코드
- 항목→ 리스트
[링크](url)→ 하이퍼링크
![alt](img)→ 이미지

🚀 실전 예제: Alert 컴포넌트 문서

{/* Alert.stories.mdx */}
import { Canvas, Meta, Story, ArgsTable, ColorPalette, ColorItem } from '@storybook/blocks';
import { Alert } from './Alert';

<Meta title="Feedback/Alert" component={Alert} />

# Alert 알림 컴포넌트

사용자에게 중요한 정보를 전달하는 알림 컴포넌트입니다.

<Canvas>
  <Story name="Overview">
    <div className="space-y-4">
      <Alert variant="info">정보 메시지입니다.</Alert>
      <Alert variant="success">성공적으로 완료되었습니다.</Alert>
      <Alert variant="warning">주의가 필요합니다.</Alert>
      <Alert variant="error">오류가 발생했습니다.</Alert>
    </div>
  </Story>
</Canvas>

## 언제 사용하나요?

| 상황 | 사용 예시 |
|------|-----------|
| 📘 Info | 일반 정보, 도움말 |
| ✅ Success | 작업 완료, 저장 성공 |
| ⚠️ Warning | 주의사항, 경고 |
| ❌ Error | 오류, 실패 메시지 |

## Props

<ArgsTable of={Alert} />

## 변형 (Variants)

### Info
<Canvas>
  <Story name="Info">
    <Alert variant="info" title="알림">
      새로운 기능이 추가되었습니다. 설정에서 확인하세요.
    </Alert>
  </Story>
</Canvas>

### Success
<Canvas>
  <Story name="Success">
    <Alert variant="success" title="완료" closable>
      데이터가 성공적으로 저장되었습니다.
    </Alert>
  </Story>
</Canvas>

### Warning
<Canvas>
  <Story name="Warning">
    <Alert variant="warning" title="경고" icon="⚠️">
      이 작업은 되돌릴 수 없습니다.
    </Alert>
  </Story>
</Canvas>

### Error
<Canvas>
  <Story name="Error">
    <Alert variant="error" title="오류" closable>
      네트워크 연결을 확인해주세요.
    </Alert>
  </Story>
</Canvas>

## 색상 팔레트

<ColorPalette>
  <ColorItem
    title="Info"
    subtitle="정보 알림"
    colors={{ Background: '#EFF6FF', Border: '#3B82F6', Text: '#1E40AF' }}
  />
  <ColorItem
    title="Success"
    subtitle="성공 알림"
    colors={{ Background: '#F0FDF4', Border: '#22C55E', Text: '#15803D' }}
  />
  <ColorItem
    title="Warning"
    subtitle="경고 알림"
    colors={{ Background: '#FFFBEB', Border: '#F59E0B', Text: '#92400E' }}
  />
  <ColorItem
    title="Error"
    subtitle="오류 알림"
    colors={{ Background: '#FEF2F2', Border: '#EF4444', Text: '#991B1B' }}
  />
</ColorPalette>

## 사용 예제

### 기본 사용
<Source
  language="tsx"
  code={Alert `
<Alert variant="info">
  일반 정보 메시지
</Alert>
`}
/>

### 제목 포함
<Source
  language="tsx"
  code={`
<Alert variant="success" title="성공">
  작업이 완료되었습니다.
</Alert>
`}
/>

### 닫기 버튼
<Source
  language="tsx"
  code={`
<Alert 
  variant="warning" 
  closable 
  onClose={() => console.log('Closed')}
>
  이 알림을 닫을 수 있습니다.
</Alert>
`}
/>

## 접근성 (A11y)

- ✅ ARIA role="alert" 적용
- ✅ 스크린 리더 지원
- ✅ 키보드 네비게이션
- ✅ 색상 대비 WCAG AA 준수

<Canvas>
  <Story name="Accessibility">
    <Alert 
      variant="info"
      role="alert"
      aria-live="polite"
    >
      접근성이 고려된 알림입니다.
    </Alert>
  </Story>
</Canvas>

## 디자인 토큰

| Token | Value |
|-------|-------|
| --alert-padding | 16px |
| --alert-border-radius | 8px |
| --alert-border-width | 1px |
| --alert-font-size | 14px |

## 관련 컴포넌트

- [Toast](/docs/feedback-toast--docs) - 일시적 알림
- [Modal](/docs/overlay-modal--docs) - 중요한 메시지
- [Notification](/docs/feedback-notification--docs) - 시스템 알림

✅ MDX Best Practices

  • ✓ 명확한 제목 계층 구조
  • ✓ 실용적인 코드 예제 제공
  • ✓ Do/Don't 가이드 추가
  • ✓ 접근성 정보 포함
  • ✓ 관련 컴포넌트 링크
  • ✓ 시각적 요소 (표, 아이콘)
  • ✓ 사용 시나리오 설명

📚 문서 구조 템플릿

  • 1. 개요 및 설명
  • 2. 시각적 예제 (Canvas)
  • 3. Props 테이블
  • 4. 사용 예제
  • 5. 변형 (Variants)
  • 6. 접근성 가이드
  • 7. 디자인 토큰
  • 8. 관련 리소스

🎯 MDX vs TSX Story

MDX 사용 시기

  • ✅ 풍부한 문서화 필요
  • ✅ 디자인 가이드라인
  • ✅ 사용 예제 많음
  • ✅ 마케팅/랜딩 페이지
  • ✅ 팀 온보딩 가이드

TSX 사용 시기

  • ✅ 복잡한 로직
  • ✅ 동적 Story 생성
  • ✅ TypeScript 타입 안정성
  • ✅ 테스트 중심
  • ✅ 빠른 프로토타입

💡 고급 팁

커스텀 컴포넌트 임포트
import { CustomBadge } from '../Badge';

MDX 안에서 어떤 React 컴포넌트든 사용 가능

다국어 문서
Button.stories.ko.mdx
Button.stories.en.mdx

언어별 문서 파일 분리