Skip to content

Commit 59c9c7b

Browse files
committed
refactor: update styled-components
1 parent 7d31628 commit 59c9c7b

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

packages/styled-components/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# styled-components-base
1+
# styled-components
22

33
[styled-components docs](https://www.styled-components.com/docs/basics)
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
1-
import React, { Children } from 'react'
1+
import React from 'react'
22
import styled from 'styled-components'
3-
import { Color, Size } from '../const'
3+
import { Color } from '../const'
44

55
interface LayoutProps {
66
children: React.ReactNode
77
}
88

9+
const Layout = (props: LayoutProps) => <Container>{props.children}</Container>
10+
911
const Container = styled.div`
1012
display: flex;
1113
justify-content: center;
1214
`
1315

14-
const Layout = (props: LayoutProps) => <Container>{props.children}</Container>
15-
1616
const 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-
3522
interface 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

Comments
 (0)