Skip to content

Commit 38d5a58

Browse files
committed
improve styling ending state
1 parent 4a16297 commit 38d5a58

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

10-styling.html

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,29 @@
2525
}
2626
</style>
2727
<script type="text/babel">
28-
const smallBox = (
29-
<div
30-
className="box box--small"
31-
style={{fontStyle: 'italic', backgroundColor: 'lightblue'}}
32-
>
33-
small lightblue box
34-
</div>
35-
)
36-
const mediumBox = (
37-
<div
38-
className="box box--medium"
39-
style={{fontStyle: 'italic', backgroundColor: 'pink'}}
40-
>
41-
medium pink box
42-
</div>
43-
)
44-
const largeBox = (
45-
<div
46-
className="box box--large"
47-
style={{fontStyle: 'italic', backgroundColor: 'orange'}}
48-
>
49-
large orange box
50-
</div>
51-
)
28+
function Box({style, size, className = '', ...otherProps}) {
29+
const sizeClassName = size ? `box--${size}` : ''
30+
return (
31+
<div
32+
className={`box ${className} ${sizeClassName}`}
33+
style={{fontStyle: 'italic', ...style}}
34+
{...otherProps}
35+
/>
36+
)
37+
}
5238

5339
const element = (
5440
<div>
55-
{smallBox}
56-
{mediumBox}
57-
{largeBox}
41+
<Box size="small" style={{backgroundColor: 'lightblue'}}>
42+
small lightblue box
43+
</Box>
44+
<Box size="medium" style={{backgroundColor: 'pink'}}>
45+
medium pink box
46+
</Box>
47+
<Box size="large" style={{backgroundColor: 'orange'}}>
48+
large orange box
49+
</Box>
50+
<Box>sizeless box</Box>
5851
</div>
5952
)
6053

0 commit comments

Comments
 (0)