1
- import React , { Children } from 'react'
1
+ import React from 'react'
2
2
import styled from 'styled-components'
3
- import { Color , Size } from '../const'
3
+ import { Color } from '../const'
4
4
5
5
interface LayoutProps {
6
6
children : React . ReactNode
7
7
}
8
8
9
+ const Layout = ( props : LayoutProps ) => < Container > { props . children } </ Container >
10
+
9
11
const Container = styled . div `
10
12
display: flex;
11
13
justify-content: center;
12
14
`
13
15
14
- const Layout = ( props : LayoutProps ) => < Container > { props . children } </ Container >
15
-
16
16
const Header = ( ) => (
17
17
< Layout >
18
- < h1 > Function Components</ h1 >
18
+ < h1 > Styled Components</ h1 >
19
19
</ Layout >
20
20
)
21
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
22
interface CustomButtonProps {
36
23
children : React . ReactNode
37
24
}
@@ -50,7 +37,37 @@ export const App = () => (
50
37
< StyledButton onClick = { ( ) => alert ( 'Styled Button' ) } >
51
38
Styled Button
52
39
</ StyledButton >
53
- < StyledButton as = { CustomButton } > Custome Button</ StyledButton >
40
+ < StyledButton styleType = { 'long' } as = { CustomButton } >
41
+ Custome Button
42
+ </ StyledButton >
54
43
</ Layout >
55
44
</ React . Fragment >
56
45
)
46
+
47
+ const Button = styled . button `
48
+ border: solid 1px ${ Color . PRIMARY } ;
49
+ width: 100px;
50
+ height: 30px;
51
+ margin: 0 20px;
52
+ `
53
+
54
+ type StyleMap = {
55
+ [ key : string ] : ( ) => string
56
+ }
57
+
58
+ const styleMap : StyleMap = {
59
+ default : ( ) => `width: 200px;` ,
60
+ long : ( ) => `width: 300px;` ,
61
+ }
62
+
63
+ type StyleButtonProps = {
64
+ styleType ?: string
65
+ }
66
+
67
+ const StyledButton = styled ( Button ) `
68
+ color: ${ Color . SECONDARY } ;
69
+ border: solid 1px ${ Color . SECONDARY } ;
70
+ border-radius: 5px;
71
+ ${ ( props : StyleButtonProps ) =>
72
+ props . styleType ? styleMap [ props . styleType ] ( ) : styleMap . default ( ) }
73
+ `
0 commit comments