Skip to content

Commit eca5b95

Browse files
committed
refactor: update styled-components
1 parent 159c82d commit eca5b95

File tree

14 files changed

+68
-21
lines changed

14 files changed

+68
-21
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Learn React with TypeScript
1313
- [Base](https://github.com/locol23/learn-react-ts/tree/master/packages/function-components-base)
1414
- [Goal](https://github.com/locol23/learn-react-ts/tree/master/packages/function-components-goal)
1515
- Styled Components
16-
- [Base](https://github.com/locol23/learn-react-ts/tree/master/packages/styled-components-base)
16+
- [Base & Goal](https://github.com/locol23/learn-react-ts/tree/master/packages/styled-components)
1717
- Recompose
1818
- State(withStateHandlers)
1919
- [Base](https://github.com/locol23/learn-react-ts/tree/master/packages/recompose-state-base)

packages/styled-components-base/README.md

-1
This file was deleted.

packages/styled-components-base/src/components/App.tsx

-19
This file was deleted.
File renamed without changes.

packages/styled-components/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# styled-components-base
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, { Children } from 'react'
2+
import styled from 'styled-components'
3+
import { Color, Size } from '../const'
4+
5+
interface LayoutProps {
6+
children: React.ReactNode
7+
}
8+
9+
const Container = styled.div`
10+
display: flex;
11+
justify-content: center;
12+
`
13+
14+
const Layout = (props: LayoutProps) => <Container>{props.children}</Container>
15+
16+
const Header = () => (
17+
<Layout>
18+
<h1>Function Components</h1>
19+
</Layout>
20+
)
21+
22+
const Button = styled.button`
23+
border: solid 1px ${Color.PRIMARY};
24+
width: 100px;
25+
height: 30px;
26+
margin: 0 20px;
27+
`
28+
29+
const StyledButton = styled(Button)`
30+
color: ${Color.SECONDARY};
31+
border: solid 1px ${Color.SECONDARY};
32+
border-radius: 5px;
33+
`
34+
35+
interface CustomButtonProps {
36+
children: React.ReactNode
37+
}
38+
39+
const CustomButton = (props: CustomButtonProps) => (
40+
<button onClick={() => alert('CustomButton')} {...props}>
41+
{props.children}
42+
</button>
43+
)
44+
45+
export const App = () => (
46+
<React.Fragment>
47+
<Header />
48+
<Layout>
49+
<Button onClick={() => alert('Button')}>Nomal Button</Button>
50+
<StyledButton onClick={() => alert('Styled Button')}>
51+
Styled Button
52+
</StyledButton>
53+
<StyledButton as={CustomButton}>Custome Button</StyledButton>
54+
</Layout>
55+
</React.Fragment>
56+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const Size = {
2+
SMALL: 10,
3+
NORMAL: 15,
4+
LARGE: 20,
5+
}
6+
7+
export const Color = {
8+
PRIMARY: '#000',
9+
SECONDARY: '#ff8600',
10+
}
File renamed without changes.

0 commit comments

Comments
 (0)