styled-components
https://gyazo.com/928716ac23c95c6ea8c3d0639f6d64c4
website
github
2025/3/18、メンテナンスモードになった
Thank you - Open Collective
styled-componentsのComponentの継承にはclasNameを付ける必要がある
#WIP
styled-components v6
Basics
Motivation
Installation
Getting Started
Adapting based on props
Extending styles
Styling any component
Passed props
Coming from CSS
Attaching additional props
Animations
React Native
Advanced
Theming
Refs
Security
Existing CSS
Tagged Template Literals
Server Side Rendering
Referring to other components
Style Objects
API Reference
Primary
Helpers
Test Utilities
Supported CSS
TypeScript
Previous APIs
Tooling
Babel Plugin
SWC Plugin
Babel Macro
TypeScript Plugin
Jest Integration
Stylelint
Styled Theming
Syntax Highlighting
styled()で拡張したうえで、
更に追加のpropsを指定する方法はない?
既存のComponent Aを拡張してconst A_ = styled(A)を作る際に
A_固有のprops isHogeを追加できない
できるけど、型の書き方が不明
with Typescript
React + Storybook + styled-componentsをTypeScriptで動かす - Qiita
styled-components: API Reference
styled-componentsはnode_modulesからではなく自作のsrc/Theme/index.tsxから読み込む
型定義はstyled-components-react-nativeに変わったっぽい
https://styled-components.com/docs/faqs#missing-declarations-for-styledcomponentsnative
https://styled-components.com/docs/api#typescript
"as" polymorphic props
https://styled-components.com/docs/api#as-polymorphic-prop
他の要素で作成したコンポーネントを別要素として使う
code:ts
const GrayArea = styled.div`
background: #333;
color:white;
`
export default () => <React.Fragment>
// divで作ったが↓ buttonとして使いたい
<GrayArea as='button' onClick={() => alert('It works!')}>
Hello React
</GrayArea>
</React.Fragment>
css prop
ref
babel-plugin-styled-componentsを利用する
code:ts
<div
css={`
background: papayawhip;
color: ${props => props.theme.colors.text};
`}
/>k
<Button
css="padding: 0.5em 1em;"
/>
型エラーの修正 ref
(未解決)styled-componentsをSSGで使うとstyleが崩れることがある
babel-plugin-styled-components