-
Notifications
You must be signed in to change notification settings - Fork 0
Ch02 Styled-Component 정리 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aa48f92
First Styled Component ✅
hyunmin200 0a925b5
ch02-2
hyunmin200 3fe610e
Props사용 및 확장
hyunmin200 f5a8709
as props를 사용한 tag교체와 attrs()를 사용한 tag속성 추가
hyunmin200 19acb8e
keyframes와 component안에 element를 넣는 법과 pesudo selector를 편하게 사용
hyunmin200 bb4b095
pesudo selector part two
hyunmin200 8eb220d
Themes
hyunmin200 7149fba
Styled-Components 정리
hyunmin200 b7142d9
Update README.md
hyunmin200 a021fd6
Update README.md
hyunmin200 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| # 알게 된 점 | ||
|
|
||
| - 직관성이 엄청나게 좋아진다. | ||
|
|
||
| ```JS | ||
| import styled from "styled-components"; | ||
| function App() { | ||
| return ( | ||
| <Father> | ||
| <Boxone /> | ||
| <Boxtwo /> | ||
| </Father> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| - props를 사용해서 값을 유동적으로 바꿀 수 있다. | ||
|
|
||
| ```JS | ||
| const Box = styled.div` | ||
| background-color: ${(props) => props.bgColor}; | ||
| width: 100px; | ||
| height: 100px; | ||
| `; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <Father> | ||
| <Box bgColor="teal"></Box> | ||
| <Box bgColor="tomato"></Box> | ||
| </Father> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| - 확장에 용이하다. | ||
|
|
||
| ```JS | ||
| const Box = styled.div` | ||
| background-color: ${(props) => props.bgColor}; | ||
| width: 100px; | ||
| height: 100px; | ||
| `; | ||
|
|
||
| const Circle = styled(Box)` | ||
| border-radius: 50%; | ||
| `; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <Father> | ||
| <Box bgColor="teal"></Box> | ||
| <Circle bgColor="tomato"></Circle> | ||
| </Father> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| - as props를 사용해서 tag를 바꿀 수 있다. | ||
|
|
||
| ```JS | ||
| function App() { | ||
| return ( | ||
| <Father> | ||
| <Btn>Log In</Btn> | ||
| <Btn as="a">Log In</Btn> | ||
| </Father> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| - attrs()를 사용해서 html tag의 속성을 넣어줄 수 있다. | ||
|
|
||
| ```JS | ||
| const Input = styled.input.attrs({ required: true })` | ||
| background-color: tomato; | ||
| `; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <Father> | ||
| <Input /> | ||
| <Input /> | ||
| <Input /> | ||
| </Father> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| - keyframes라는 helper를 추가해서 애니메이션을 사용할 수 있다. | ||
|
|
||
| ```JS | ||
| import styled, { keyframes } from "styled-components"; | ||
|
|
||
| const rotationAnime = keyframes` | ||
| 0% { | ||
| border-radius: 10px; | ||
| } | ||
| 50% { | ||
| border-radius: 100px; | ||
| } | ||
| 100% { | ||
| transform: rotate(360deg); | ||
| border-radius: 10px; | ||
| } | ||
| `; | ||
|
|
||
| const Box = styled.div` | ||
| height: 200px; | ||
| width: 200px; | ||
| background-color: tomato; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| animation: ${rotationAnime} 2s linear infinite forwards; | ||
| font-size: 70px; | ||
| `; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <Wrapper> | ||
| <Box> | ||
| <span>🤓👆</span> | ||
| </Box> | ||
| </Wrapper> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| - styled-component안에서는 하위 element span을 선택해서 css를 넣어줄 수 있다. | ||
|
|
||
| ```JS | ||
| const Box = styled.div` | ||
| height: 200px; | ||
| width: 200px; | ||
| background-color: tomato; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| animation: ${rotationAnime} 2s linear infinite forwards; | ||
| span { | ||
| font-size: 70px; | ||
| } | ||
| `; | ||
| ``` | ||
|
|
||
| - state selector를 &:▣▣▣와 같이 사용할 수 있다. | ||
|
|
||
| ```JS | ||
| const Box = styled.div` | ||
| height: 200px; | ||
| width: 200px; | ||
| background-color: tomato; | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| animation: ${rotationAnime} 2s linear infinite forwards; | ||
| span { | ||
| font-size: 70px; | ||
| &:hover { | ||
| // span:hover와 동일하다. | ||
| } | ||
| } | ||
| `; | ||
| ``` | ||
|
|
||
| - ${▣▣▣} {}와 같이 코드를 작성한다면 태그가 바뀌더라도 상관없이 적용이 된다. (조건 처럼도 사용 가능) | ||
|
|
||
| ```JS | ||
| ${Emoji} { | ||
| &:hover { | ||
| // span:hover와 동일하다. | ||
| font-size: 70px; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| - Theme이라는 것을 사용해서 쉽게 다크모드 화이트모드를 구현할 수 있다. (local Estate Management라는 것을 배우면 완벽하게 구현 가능하다고 ) | ||
|
|
||
| ```JS | ||
| import { ThemeProvider } from "styled-components"; | ||
|
|
||
| const darkTheme = { | ||
| textColor: "whitesmoke", | ||
| backgroundColor: "#111", | ||
| }; | ||
|
|
||
| const lightTheme = { | ||
| textColor: "111", | ||
| backgroundColor: "whitesmoke", | ||
| }; | ||
|
|
||
| const root = ReactDOM.createRoot(document.getElementById("root")); | ||
| root.render( | ||
| <ThemeProvider theme={darkTheme}> | ||
| <App /> | ||
| </ThemeProvider>, | ||
| ); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| # ReactMiddleClassIsCold | ||
|
|
||
| 현민이의 리액트 중급은 차갑다.. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.