1
1
import * as React from 'react'
2
- import { withStyles } from '@mui/styles'
3
2
import Code from '@mui/icons-material/Code'
4
3
import Collapse from '@mui/material/Collapse'
5
4
import Button from '@mui/material/Button'
6
5
import IconButton from '@mui/material/IconButton'
7
6
import Typography from '@mui/material/Typography'
8
7
import Tooltip from '@mui/material/Tooltip'
8
+ import Box from '@mui/material/Box'
9
9
10
10
const { useState, useCallback } = React
11
11
12
- const styles = {
13
- title : {
14
- marginTop : 40 ,
15
- marginBottom : 0 ,
16
- } ,
17
- root : {
18
- margin : '20px auto' ,
19
- } ,
20
- toolbar : {
21
- display : 'flex' ,
22
- alignItems : 'center' ,
23
- } ,
24
- toolbarSpacer : {
25
- flex : '1 1 auto' ,
26
- } ,
27
- code : {
28
- margin : 0 ,
29
- padding : 20 ,
30
- backgroundColor : 'white' ,
31
- borderRadius : 4 ,
32
- } ,
33
- example : {
34
- backgroundColor : '#eee' ,
35
- borderRadius : 4 ,
36
- display : 'flex' ,
37
- alignContent : 'center' ,
38
- alignItems : 'center' ,
39
- justifyContent : 'center' ,
40
- padding : 40 ,
41
- } ,
42
- titleAnchor : {
43
- color : '#aaa' ,
44
- marginLeft : 10 ,
45
- textDecoration : 'none' ,
46
- visibility : 'hidden' ,
47
- '$title:hover > &' : {
48
- visibility : 'visible' ,
49
- } ,
50
- } ,
51
- }
52
-
53
- const Demo = ( {
54
- headerId,
55
- classes,
56
- title,
57
- code,
58
- example,
59
- hooksCode,
60
- hooksExample,
61
- } ) => {
12
+ const Demo = ( { headerId, title, code, example, hooksCode, hooksExample } ) => {
62
13
const [ showSource , setShowSource ] = useState ( false )
63
14
const [ api , setApi ] = useState ( 'hooks' )
64
15
const setRenderProps = useCallback ( ( ) => setApi ( 'render-props' ) , [ ] )
65
16
const setHooks = useCallback ( ( ) => setApi ( 'hooks' ) , [ ] )
66
17
return (
67
- < div className = { classes . root } >
68
- < Typography variant = "h4" className = { classes . title } id = { headerId } >
18
+ < Box sx = { { margin : '20px auto' } } >
19
+ < Typography
20
+ variant = "h4"
21
+ sx = { {
22
+ marginTop : '40px' ,
23
+ marginBottom : 0 ,
24
+ '&:hover > a' : {
25
+ visibility : 'visible' ,
26
+ } ,
27
+ } }
28
+ id = { headerId }
29
+ >
69
30
{ title }
70
31
{ headerId && (
71
- < a href = { `#${ headerId } ` } className = { classes . titleAnchor } >
32
+ < Box
33
+ component = "a"
34
+ href = { `#${ headerId } ` }
35
+ sx = { {
36
+ color : '#aaa' ,
37
+ marginLeft : '10px' ,
38
+ textDecoration : 'none' ,
39
+ visibility : 'hidden' ,
40
+ } }
41
+ >
72
42
#
73
- </ a >
43
+ </ Box >
74
44
) }
75
45
</ Typography >
76
- < div className = { classes . toolbar } >
46
+ < Box sx = { { display : 'flex' , alignItems : 'center' } } >
77
47
{ code != null && hooksCode != null && (
78
48
< React . Fragment >
79
49
< Button
@@ -90,23 +60,41 @@ const Demo = ({
90
60
</ Button >
91
61
</ React . Fragment >
92
62
) }
93
- < div className = { classes . toolbarSpacer } />
63
+ < Box sx = { { flex : '1 1 auto' } } />
94
64
< Tooltip title = "Show Source" placement = "top" >
95
65
< IconButton onClick = { ( ) => setShowSource ( ! showSource ) } size = "large" >
96
66
< Code />
97
67
</ IconButton >
98
68
</ Tooltip >
99
- </ div >
69
+ </ Box >
100
70
< Collapse in = { showSource } >
101
- < pre className = { classes . code } >
71
+ < Box
72
+ component = "pre"
73
+ sx = { {
74
+ margin : 0 ,
75
+ padding : '20px' ,
76
+ backgroundColor : 'white' ,
77
+ borderRadius : '4px' ,
78
+ } }
79
+ >
102
80
{ api === 'hooks' ? hooksCode || code : code || hooksCode }
103
- </ pre >
81
+ </ Box >
104
82
</ Collapse >
105
- < div className = { classes . example } >
83
+ < Box
84
+ sx = { {
85
+ backgroundColor : '#eee' ,
86
+ borderRadius : '4px' ,
87
+ display : 'flex' ,
88
+ alignContent : 'center' ,
89
+ alignItems : 'center' ,
90
+ justifyContent : 'center' ,
91
+ padding : '40px' ,
92
+ } }
93
+ >
106
94
{ api === 'hooks' ? hooksExample || example : example || hooksExample }
107
- </ div >
108
- </ div >
95
+ </ Box >
96
+ </ Box >
109
97
)
110
98
}
111
99
112
- export default withStyles ( styles ) ( Demo )
100
+ export default Demo
0 commit comments