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,182 @@
|
||||
---
|
||||
id: wiki-2026-0508-styled-components
|
||||
title: Styled Components
|
||||
category: 10_Wiki/Topics
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [styled-components, CSS-in-JS]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [react, css-in-js, frontend, styling]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
tech_stack:
|
||||
language: typescript
|
||||
framework: react
|
||||
---
|
||||
|
||||
# Styled Components
|
||||
|
||||
## 매 한 줄
|
||||
> **"매 CSS 의 component 의 안에 — 매 tagged template literal 로 매 React component + style 의 atomic unit"**. Glen Maddern, Max Stoiber (2016). 매 CSS-in-JS 의 reference. 2026 매 styled-components v6+ 가 매 React Server Components 의 partial 지원 — 매 RSC native era 에서 매 Tailwind / vanilla-extract / CSS Modules 의 challenge.
|
||||
|
||||
## 매 핵심
|
||||
|
||||
### 매 mechanic
|
||||
- 매 tagged template literal: ``styled.button`color: red```.
|
||||
- 매 runtime 의 unique class name 의 generation, 매 stylesheet 의 inject.
|
||||
- 매 props-based dynamic styling: ``${props => props.primary ? '#0070f3' : '#fff'}``.
|
||||
|
||||
### 매 features
|
||||
- **Theming**: ThemeProvider context.
|
||||
- **`as` prop**: 매 polymorphic element.
|
||||
- **Extending**: ``styled(Button)`...```.
|
||||
- **Animations**: keyframes helper.
|
||||
- **Global styles**: createGlobalStyle.
|
||||
|
||||
### 매 응용
|
||||
1. React design system (Material-like component lib).
|
||||
2. Theme switcher (dark mode).
|
||||
3. Per-component style isolation.
|
||||
|
||||
## 💻 패턴
|
||||
|
||||
### Basic styled component (TypeScript)
|
||||
```tsx
|
||||
import styled from "styled-components";
|
||||
|
||||
const Button = styled.button<{ $primary?: boolean }>`
|
||||
padding: 8px 16px;
|
||||
border-radius: 6px;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
background: ${(p) => (p.$primary ? "#0070f3" : "#eee")};
|
||||
color: ${(p) => (p.$primary ? "#fff" : "#222")};
|
||||
&:hover { opacity: 0.9; }
|
||||
`;
|
||||
|
||||
export default function App() {
|
||||
return <Button $primary>Buy</Button>;
|
||||
}
|
||||
```
|
||||
|
||||
### Theme + ThemeProvider
|
||||
```tsx
|
||||
import { ThemeProvider, DefaultTheme } from "styled-components";
|
||||
|
||||
const dark: DefaultTheme = { bg: "#111", fg: "#eee", accent: "#0af" };
|
||||
const light: DefaultTheme = { bg: "#fff", fg: "#111", accent: "#06c" };
|
||||
|
||||
const Card = styled.div`
|
||||
background: ${(p) => p.theme.bg};
|
||||
color: ${(p) => p.theme.fg};
|
||||
padding: 16px;
|
||||
`;
|
||||
|
||||
export default function App() {
|
||||
const [mode, setMode] = useState<"light" | "dark">("dark");
|
||||
return (
|
||||
<ThemeProvider theme={mode === "dark" ? dark : light}>
|
||||
<Card>Hello</Card>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### Extending another styled component
|
||||
```tsx
|
||||
const Base = styled.button`padding: 8px; border-radius: 4px;`;
|
||||
const Danger = styled(Base)`background: #e00; color: white;`;
|
||||
```
|
||||
|
||||
### `as` polymorphic prop
|
||||
```tsx
|
||||
const Box = styled.div`padding: 16px;`;
|
||||
<Box as="section" /> // renders <section>
|
||||
<Box as={Link} to="/x" /> // renders react-router Link
|
||||
```
|
||||
|
||||
### Keyframes animation
|
||||
```tsx
|
||||
import styled, { keyframes } from "styled-components";
|
||||
const pulse = keyframes`
|
||||
0% { transform: scale(1); }
|
||||
50% { transform: scale(1.1); }
|
||||
100% { transform: scale(1); }
|
||||
`;
|
||||
const Pulser = styled.div`animation: ${pulse} 1s infinite;`;
|
||||
```
|
||||
|
||||
### Global styles
|
||||
```tsx
|
||||
import { createGlobalStyle } from "styled-components";
|
||||
const Global = createGlobalStyle`
|
||||
body { margin: 0; font-family: Inter, sans-serif; background: ${(p) => p.theme.bg}; }
|
||||
`;
|
||||
```
|
||||
|
||||
### css helper for shared mixin
|
||||
```tsx
|
||||
import { css } from "styled-components";
|
||||
const truncate = css`
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
`;
|
||||
const Title = styled.h2`${truncate} font-size: 24px;`;
|
||||
```
|
||||
|
||||
### Next.js 14+ App Router (RSC) — 매 'use client'
|
||||
```tsx
|
||||
"use client";
|
||||
import styled from "styled-components";
|
||||
export const Button = styled.button`color: red;`;
|
||||
```
|
||||
|
||||
```tsx
|
||||
// app/layout.tsx — registry pattern for SSR
|
||||
import StyledRegistry from "./StyledRegistry";
|
||||
export default function Root({ children }) {
|
||||
return <html><body><StyledRegistry>{children}</StyledRegistry></body></html>;
|
||||
}
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| React SPA, 매 dynamic theming heavy | styled-components / emotion |
|
||||
| React Server Components 의 native | vanilla-extract / CSS Modules / Tailwind |
|
||||
| Utility-first, design system | Tailwind CSS v4 |
|
||||
| Build-time zero-runtime | vanilla-extract / Linaria |
|
||||
| Component lib for distribution | CSS Modules + tokens |
|
||||
|
||||
**기본값** (2026): 매 새 React project — Tailwind 의 default. styled-components 의 dynamic + theme heavy app 에 still-valid.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[CSS_Architecture_and_Styling|CSS-in-JS]] · [[React]]
|
||||
- 변형: [[vanilla-extract]]
|
||||
- 응용: [[Design System]] · [[Theme Switching]]
|
||||
- Adjacent: [[CSS_Architecture_and_Styling|Tailwind CSS]] · [[CSS Modules]] · [[React Server Components — 경계 의식]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: dynamic prop-based styles 의 heavy, theme switching 의 first-class, existing CSS-in-JS app.
|
||||
**언제 X**: 매 RSC-first new app — runtime cost + 'use client' boundary 의 friction. 매 Tailwind / vanilla-extract 의 prefer.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **Inline style prop interpolation 의 every render**: 매 className thrash 의 perf hit. 매 attrs / static class 의 사용.
|
||||
- **No `$` prefix on props**: 매 DOM warning (unknown attribute). 매 transient prop 의 사용 — `$primary`.
|
||||
- **createGlobalStyle 의 multiple instances**: 매 conflict.
|
||||
- **SSR without registry**: 매 FOUC. Next.js registry 의 setup.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (styled-components.com docs v6, 2025; Next.js 14 App Router CSS-in-JS guide).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — styled-components v6 + RSC era guidance |
|
||||
Reference in New Issue
Block a user