@@ -4,14 +4,16 @@ import Card from '@mui/material/Card';
4
4
import CardActions from '@mui/material/CardActions' ;
5
5
import CardContent from '@mui/material/CardContent' ;
6
6
import CardMedia from '@mui/material/CardMedia' ;
7
- import Button from '@mui/material/Button' ;
8
7
import Grid from '@mui/material/Grid' ;
9
8
import Typography from '@mui/material/Typography' ;
10
9
import { alpha , useTheme } from '@mui/material/styles' ;
11
10
import IconButton from '@mui/material/IconButton' ;
12
11
import Tooltip from '@mui/material/Tooltip' ;
13
- import Stack from '@mui/material/Stack' ;
14
12
import SvgIcon from '@mui/material/SvgIcon' ;
13
+ import GitHubIcon from '@mui/icons-material/GitHub' ;
14
+ import ContentCopyRounded from '@mui/icons-material/ContentCopyRounded' ;
15
+ import CheckRounded from '@mui/icons-material/CheckRounded' ;
16
+ import copy from 'clipboard-copy' ;
15
17
import { Example , versionGitHubLink } from './examplesUtils' ;
16
18
17
19
interface ExamplesGridProps {
@@ -36,13 +38,22 @@ function CodeSandboxIcon() {
36
38
37
39
export default function ExamplesGrid ( props : ExamplesGridProps ) {
38
40
const t = useTranslate ( ) ;
41
+ const [ copiedId , setCopiedId ] = React . useState < string | null > ( null ) ;
42
+
43
+ const handleCopy = ( text : string , id : string ) => {
44
+ copy ( text ) ;
45
+ setCopiedId ( id ) ;
46
+ setTimeout ( ( ) => setCopiedId ( null ) , 2000 ) ;
47
+ } ;
39
48
40
49
const examples = props . examples . filter ( ( example : Example ) => example . featured !== true ) ;
41
50
const docsTheme = useTheme ( ) ;
42
51
43
52
return (
44
53
< Grid container spacing = { 2 } sx = { { pt : 2 , pb : 4 } } >
45
54
{ examples . map ( ( example ) => {
55
+ const exampleName = example . source . split ( '/' ) . pop ( ) ;
56
+ const installCommand = `pnpm create toolpad-app --example ${ exampleName } ` ;
46
57
const computedSrc =
47
58
docsTheme ?. palette ?. mode === 'dark' && example . srcDark ? example . srcDark : example . src ;
48
59
return (
@@ -99,45 +110,63 @@ export default function ExamplesGrid(props: ExamplesGridProps) {
99
110
p : 0 ,
100
111
display : 'flex' ,
101
112
alignItems : 'center' ,
102
- justifyContent : 'space-between' ,
113
+ justifyContent : 'flex-start' ,
114
+ gap : 1 ,
103
115
} }
104
116
>
105
- < Button
106
- component = "a"
107
- href = { versionGitHubLink ( example . source ) }
108
- size = "small"
109
- target = "_blank"
110
- >
111
- { t ( 'source' ) }
112
- </ Button >
113
- < Stack direction = "row" spacing = { 1 } >
114
- { example . stackBlitz === true ? (
115
- < Tooltip title = "Edit in StackBlitz" >
116
- < IconButton
117
- component = "a"
118
- href = { `https://stackblitz.com/github/${ example . source . replace ( 'https://github.com/' , '' ) } ` }
119
- target = "_blank"
120
- rel = "noopener noreferrer"
121
- size = "small"
122
- >
123
- < StackBlitzIcon />
124
- </ IconButton >
125
- </ Tooltip >
126
- ) : null }
127
- { example . codeSandbox === true ? (
128
- < Tooltip title = "Edit in CodeSandbox" >
129
- < IconButton
130
- component = "a"
131
- href = { `https://codesandbox.io/p/sandbox/github/${ example . source . replace ( 'https://github.com/' , '' ) } ` }
132
- target = "_blank"
133
- rel = "noopener noreferrer"
134
- size = "small"
135
- >
136
- < CodeSandboxIcon />
137
- </ IconButton >
138
- </ Tooltip >
139
- ) : null }
140
- </ Stack >
117
+ < Tooltip title = { t ( 'source' ) } >
118
+ < IconButton
119
+ component = "a"
120
+ href = { versionGitHubLink ( example . source ) }
121
+ size = "small"
122
+ target = "_blank"
123
+ >
124
+ < GitHubIcon fontSize = "small" />
125
+ </ IconButton >
126
+ </ Tooltip >
127
+
128
+ { example . stackBlitz === true ? (
129
+ < Tooltip title = "Edit in StackBlitz" >
130
+ < IconButton
131
+ component = "a"
132
+ href = { `https://stackblitz.com/github/${ example . source . replace ( 'https://github.com/' , '' ) } ` }
133
+ target = "_blank"
134
+ rel = "noopener noreferrer"
135
+ size = "small"
136
+ >
137
+ < StackBlitzIcon />
138
+ </ IconButton >
139
+ </ Tooltip >
140
+ ) : null }
141
+
142
+ { example . codeSandbox === true ? (
143
+ < Tooltip title = "Edit in CodeSandbox" >
144
+ < IconButton
145
+ component = "a"
146
+ href = { `https://codesandbox.io/p/sandbox/github/${ example . source . replace ( 'https://github.com/' , '' ) } ` }
147
+ target = "_blank"
148
+ rel = "noopener noreferrer"
149
+ size = "small"
150
+ >
151
+ < CodeSandboxIcon />
152
+ </ IconButton >
153
+ </ Tooltip >
154
+ ) : null }
155
+
156
+ < Tooltip title = { installCommand } >
157
+ < IconButton
158
+ size = "small"
159
+ onClick = { ( ) => {
160
+ handleCopy ( installCommand , example . title ) ;
161
+ } }
162
+ >
163
+ { copiedId === example . title ? (
164
+ < CheckRounded fontSize = "small" />
165
+ ) : (
166
+ < ContentCopyRounded fontSize = "small" />
167
+ ) }
168
+ </ IconButton >
169
+ </ Tooltip >
141
170
</ CardActions >
142
171
</ Card >
143
172
</ Grid >
0 commit comments