forked from kentcdodds/beginners-guide-to-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10-styling.html
56 lines (54 loc) · 1.43 KB
/
10-styling.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<body>
<div id="root"></div>
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/[email protected]/babel.js"></script>
<style>
.box {
border: 1px solid #333;
display: flex;
flex-direction: column;
justify-content: center;
text-align: center;
}
.box--large {
width: 270px;
height: 270px;
}
.box--medium {
width: 180px;
height: 180px;
}
.box--small {
width: 90px;
height: 90px;
}
</style>
<script type="text/babel">
function Box({style, size, className = '', ...rest}) {
const sizeClassName = size ? `box--${size}` : ''
return (
<div
className={`box ${className} ${sizeClassName}`}
style={{fontStyle: 'italic', ...style}}
{...rest}
/>
)
}
const element = (
<div>
<Box size="small" style={{backgroundColor: 'lightblue'}}>
small lightblue box
</Box>
<Box size="medium" style={{backgroundColor: 'pink'}}>
medium pink box
</Box>
<Box size="large" style={{backgroundColor: 'orange'}}>
large orange box
</Box>
<Box>sizeless box</Box>
</div>
)
ReactDOM.render(element, document.getElementById('root'))
</script>
</body>