docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를 Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류. - 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로 자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거, 동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거. - 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming, Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business, Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로, 나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는 title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백). 원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지. - 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서. - 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는 지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지. - Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경. - 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
---
|
||||
id: wiki-2026-0508-dynamic-theming
|
||||
title: Dynamic Theming
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [Theming, Dark Mode, CSS Variables Theming]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [frontend, css, theming, design-system]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: TypeScript
|
||||
framework: React
|
||||
---
|
||||
|
||||
# Dynamic Theming
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 design token 을 runtime swap 할 수 있는 architecture"**. CSS custom properties (variables) 가 매 modern theming 의 backbone 이며, JS bundle 의 무관 하게 instant theme switching 의 가능. 2026 의 light/dark/high-contrast/brand-variant 의 매 standard.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 3-layer token 구조
|
||||
- **Primitive tokens**: raw values (`--blue-500: #3B82F6`).
|
||||
- **Semantic tokens**: intent-based (`--color-primary: var(--blue-500)`).
|
||||
- **Component tokens**: scope-specific (`--button-bg: var(--color-primary)`).
|
||||
|
||||
### 매 swap 메커니즘
|
||||
- `data-theme="dark"` 속성 의 `<html>` element 의 set.
|
||||
- CSS 의 `[data-theme="dark"] { --color-bg: #0a0a0a }` 의 override.
|
||||
- 매 zero JS re-render — 매 paint cycle 만 trigger.
|
||||
|
||||
### 매 응용
|
||||
1. Light/dark mode toggle.
|
||||
2. Brand white-labeling (multi-tenant SaaS).
|
||||
3. Accessibility (high-contrast, reduced-motion variant).
|
||||
4. Per-user customization (saved theme preference).
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Token 정의 (CSS)
|
||||
```css
|
||||
:root {
|
||||
/* Primitive */
|
||||
--blue-500: #3B82F6;
|
||||
--gray-900: #111827;
|
||||
--gray-50: #F9FAFB;
|
||||
|
||||
/* Semantic — light default */
|
||||
--color-bg: var(--gray-50);
|
||||
--color-fg: var(--gray-900);
|
||||
--color-primary: var(--blue-500);
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--color-bg: var(--gray-900);
|
||||
--color-fg: var(--gray-50);
|
||||
}
|
||||
|
||||
[data-theme="high-contrast"] {
|
||||
--color-bg: #000;
|
||||
--color-fg: #fff;
|
||||
--color-primary: #ffff00;
|
||||
}
|
||||
```
|
||||
|
||||
### Theme provider (React 19)
|
||||
```tsx
|
||||
import { createContext, use, useEffect, useState } from "react";
|
||||
|
||||
type Theme = "light" | "dark" | "system";
|
||||
const ThemeCtx = createContext<{ theme: Theme; set: (t: Theme) => void }>(null!);
|
||||
|
||||
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||
const [theme, setTheme] = useState<Theme>(
|
||||
() => (localStorage.getItem("theme") as Theme) ?? "system"
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const resolved =
|
||||
theme === "system"
|
||||
? matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
||||
: theme;
|
||||
document.documentElement.dataset.theme = resolved;
|
||||
localStorage.setItem("theme", theme);
|
||||
}, [theme]);
|
||||
|
||||
return <ThemeCtx value={{ theme, set: setTheme }}>{children}</ThemeCtx>;
|
||||
}
|
||||
|
||||
export const useTheme = () => use(ThemeCtx);
|
||||
```
|
||||
|
||||
### FOUC 방지 (inline script)
|
||||
```html
|
||||
<!-- <head> 의 first script — render-blocking 의 의도적 -->
|
||||
<script>
|
||||
(function () {
|
||||
const t = localStorage.getItem("theme") || "system";
|
||||
const resolved = t === "system"
|
||||
? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light")
|
||||
: t;
|
||||
document.documentElement.dataset.theme = resolved;
|
||||
})();
|
||||
</script>
|
||||
```
|
||||
|
||||
### Tailwind 4 의 통합
|
||||
```css
|
||||
@import "tailwindcss";
|
||||
|
||||
@theme {
|
||||
--color-bg: var(--bg);
|
||||
--color-fg: var(--fg);
|
||||
}
|
||||
|
||||
:root { --bg: #fff; --fg: #111; }
|
||||
[data-theme="dark"] { --bg: #0a0a0a; --fg: #f5f5f5; }
|
||||
```
|
||||
|
||||
```tsx
|
||||
<div className="bg-bg text-fg">매 theme-aware</div>
|
||||
```
|
||||
|
||||
### System preference 의 listen
|
||||
```ts
|
||||
const mq = matchMedia("(prefers-color-scheme: dark)");
|
||||
mq.addEventListener("change", (e) => {
|
||||
if (localStorage.getItem("theme") === "system") {
|
||||
document.documentElement.dataset.theme = e.matches ? "dark" : "light";
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### View Transitions API (smooth swap)
|
||||
```ts
|
||||
function toggleTheme() {
|
||||
if (!document.startViewTransition) {
|
||||
flipTheme();
|
||||
return;
|
||||
}
|
||||
document.startViewTransition(() => flipTheme());
|
||||
}
|
||||
```
|
||||
|
||||
```css
|
||||
::view-transition-old(root),
|
||||
::view-transition-new(root) {
|
||||
animation-duration: 250ms;
|
||||
}
|
||||
```
|
||||
|
||||
### Brand variant (multi-tenant)
|
||||
```css
|
||||
[data-brand="acme"] { --color-primary: #FF6B35; }
|
||||
[data-brand="globex"] { --color-primary: #2EB872; }
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| Static site / blog | CSS variable + `data-theme` |
|
||||
| SaaS multi-tenant | CSS variable + brand attribute layer |
|
||||
| RN / Native | Theme context + StyleSheet (no CSS vars) |
|
||||
| Tailwind 의 사용 | Tailwind 4 `@theme` + CSS variable |
|
||||
| Email template | Inline styles + `prefers-color-scheme` media query |
|
||||
|
||||
**기본값**: CSS custom properties + `data-theme` attribute + inline FOUC script.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[CSS_Architecture_and_Styling|CSS Architecture]] · [[Design Tokens]]
|
||||
- 변형: [[Tailwind CSS 4]] · [[CSS_Architecture_and_Styling|CSS-in-JS]]
|
||||
- 응용: [[Dark Mode]] · [[Accessibility (a11y)]]
|
||||
- Adjacent: [[View Transitions API]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: design token system 의 설계, dark mode 구현, multi-brand theming.
|
||||
**언제 X**: simple 의 single-color brand 의 — 매 over-engineering.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **JS-only theme**: setState 의 모든 component re-render — 매 slow 의.
|
||||
- **Hard-coded color in component**: token 의 bypass — 매 swap 불가능.
|
||||
- **No FOUC script**: hydration 전 wrong theme flash — 매 jarring UX.
|
||||
- **Theme 의 localStorage 의만 의존**: SSR 의 server-render mismatch.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (MDN, web.dev, Tailwind CSS docs, Adobe Spectrum 의 token system).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — 3-layer token + FOUC + View Transitions 추가 |
|
||||
Reference in New Issue
Block a user