@@ -16,6 +16,11 @@ <h1>Basic Example</h1>
1616 styled . injectGlobal `
1717 body {
1818 background-color: #fefefe;
19+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
20+ }
21+
22+ *, *::before, *::after {
23+ box-sizing: border-box;
1924 }
2025 ` ;
2126
@@ -31,29 +36,43 @@ <h1>Basic Example</h1>
3136
3237 // Create a <CustomTitle> vue component that renders an <h1> which is
3338 // centered, palevioletred and sized at 1.5em
34- const CustomTitle = styled . default . h1 `
39+ const CustomTitle = styled . default ( 'h1' , { animate : Boolean } ) `
3540 font-size: 2em;
3641 text-align: center;
3742 color: ${ props => props . theme . primary } ;
38- animation: ${ animation } 2s linear infinite ;
43+ text-transform: uppercase ;
3944
4045 @supports (-webkit-text-stroke: 1px) {
4146 -webkit-text-stroke: 2px ${ props => props . theme . primary } ;
4247 color: transparent
4348 }
49+
50+ ${ props => props . animate &&
51+ `animation: ${ animation } 2s linear infinite;`
52+ }
4453 ` ;
4554
4655 const H2 = CustomTitle . withComponent ( 'h2' )
4756
57+ const MyComponent = {
58+ props : [ 'visible' ] ,
59+ template : `<h1><slot /></h1>`
60+ }
61+
62+ const SuperCustomTitle = styled . default ( MyComponent , { color : String } ) `
63+ color: ${ props => props . color || 'red' } ;
64+ opacity: ${ props => props . visible ? 1 : 0 } ;
65+ `
66+
4867 // Create a <Wrapper> vue component that renders a <section> with
4968 // some padding and a papayawhip background
5069 const Wrapper = styled . default . section `
5170 padding: 4em;
5271 background: ${ props => props . theme . secondary } ;
5372 ` ;
5473
55- const W2 = styled . default ( Wrapper ) `
56- color: red ;
74+ const W2 = Wrapper . extend `
75+ background: ${ props => props . theme . tertiary } ;
5776 ` ;
5877
5978 const W3 = styled . default ( W2 ) `
@@ -62,32 +81,72 @@ <h1>Basic Example</h1>
6281 }
6382 `
6483
84+ const StyledInput = styled . default . input `
85+ display: block;
86+ width: 100%;
87+ height: 60px;
88+ border: solid 3px transparent;
89+ padding: 0 0.6em;
90+ font-size: 1em;
91+ line-height: 1;
92+
93+ &:focus {
94+ outline: none;
95+ border: solid 3px ${ props => props . theme . primary } ;
96+ }
97+ `
98+
6599 const Btn = styled . default ( 'button' , { visible : Boolean } ) `
66- background-color: red;
100+ outline: none;
101+ border: none;
102+ border-radius: 6em;
103+ padding: 1em 2em;
104+ color: #fff;
105+ cursor: pointer;
106+ margin: 1.5em 0;
107+ background-color: ${ props => props . theme . primary } ;
67108 opacity: ${ props => props . visible ? 1 : 0 } ;
68109 `
69110
70111 const SuperBtn = styled . default ( Btn , { visible : Boolean , big : Boolean } ) `
71- font-size: ${ props => props . big ? 22 : 18 } px ;
112+ font-size: ${ props => props . big ? 0.8 : 1 } em ;
72113 `
73114
74115 new Vue ( {
75116 el : '#container' ,
117+ data : {
118+ text1 : 'Hello World, this is my first styled component!' ,
119+ text2 : 'Hello World, this is my first styled component!' ,
120+ animated1 : false ,
121+ animated2 : false
122+ } ,
76123 template : `
77124 <theme-provider :theme="{
78125 primary: 'palevioletred',
79- secondary: 'papayawhip'
126+ secondary: 'papayawhip',
127+ tertiary: 'lavenderblush'
80128 }">
81129 <wrapper>
82- <custom-title> Hello World, this is my first styled component! </custom-title>
83- <btn visible> Button </btn>
130+ <custom-title :visible="true" :animate="animated1"> {{text1}} </custom-title>
131+ <styled-input v-model="text1" />
132+ <btn visible @click="animated1 = !animated1"> A Styled Button </btn>
84133 </wrapper>
134+ <w-2>
135+ <h-2 :animate="animated2"> {{text2}} </h-2>
136+ <styled-input v-model="text2" />
137+ <super-btn visible @click="animated2 = !animated2"> An extension of Styled Button </super-btn>
138+ </w-2>
85139 </theme-provider>` ,
86140 components : {
87- 'custom-title' : H2 ,
88- wrapper : W3 ,
89- btn : SuperBtn ,
90- 'theme-provider' : styled . ThemeProvider
141+ CustomTitle,
142+ Wrapper,
143+ W2 ,
144+ H2 ,
145+ Btn,
146+ SuperBtn,
147+ SuperCustomTitle,
148+ StyledInput,
149+ 'theme-provider' : styled . ThemeProvider ,
91150 } ,
92151 } ) ;
93152 </ script >
0 commit comments