1- import React , { Children } from 'react'
1+ import React from 'react'
22import styled from 'styled-components'
3- import { Color , Size } from '../const'
3+ import { Color } from '../const'
44
55interface LayoutProps {
66 children : React . ReactNode
77}
88
9+ const Layout = ( props : LayoutProps ) => < Container > { props . children } </ Container >
10+
911const Container = styled . div `
1012 display: flex;
1113 justify-content: center;
1214`
1315
14- const Layout = ( props : LayoutProps ) => < Container > { props . children } </ Container >
15-
1616const Header = ( ) => (
1717 < Layout >
18- < h1 > Function Components</ h1 >
18+ < h1 > Styled Components</ h1 >
1919 </ Layout >
2020)
2121
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-
3522interface CustomButtonProps {
3623 children : React . ReactNode
3724}
@@ -50,7 +37,37 @@ export const App = () => (
5037 < StyledButton onClick = { ( ) => alert ( 'Styled Button' ) } >
5138 Styled Button
5239 </ StyledButton >
53- < StyledButton as = { CustomButton } > Custome Button</ StyledButton >
40+ < StyledButton styleType = { 'long' } as = { CustomButton } >
41+ Custome Button
42+ </ StyledButton >
5443 </ Layout >
5544 </ React . Fragment >
5645)
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