File tree 1 file changed +20
-27
lines changed
1 file changed +20
-27
lines changed Original file line number Diff line number Diff line change 25
25
}
26
26
</ style >
27
27
< 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
+ }
52
38
53
39
const element = (
54
40
< 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 >
58
51
</ div >
59
52
)
60
53
You can’t perform that action at this time.
0 commit comments