@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
2
2
import PropTypes from 'prop-types' ;
3
3
import { Highlight , Prism , themes } from 'prism-react-renderer' ;
4
4
import Editor from 'react-simple-code-editor' ;
5
- import { alpha , Box , Button } from '@mui/material' ;
5
+ import { alpha , Box , Button , CircularProgress } from '@mui/material' ;
6
6
import { styled , useTheme } from '@mui/material/styles' ;
7
7
import { PlayArrowOutlined } from '@mui/icons-material' ;
8
8
import { CopyButton } from './CopyButton' ;
@@ -25,25 +25,32 @@ const StyledEditor = styled((props) => <Editor padding={0} textareaClassName={'c
25
25
* @return {JSX.Element }
26
26
* @constructor
27
27
*/
28
- export const RunButton = ( { code, onRun } ) => {
28
+ export const RunButton = ( { code, onRun, loading } ) => {
29
29
return (
30
- < Button variant = "outlined" endIcon = { < PlayArrowOutlined /> } onClick = { ( ) => onRun ( code ) } data-testid = "code-block-run" >
31
- Run
30
+ < Button
31
+ variant = "outlined"
32
+ endIcon = { loading ? < CircularProgress size = { 24 } color = "inherit" /> : < PlayArrowOutlined /> }
33
+ onClick = { ( ) => onRun ( code ) }
34
+ disabled = { loading }
35
+ data-testid = "code-block-run"
36
+ >
37
+ { loading ? 'Running...' : 'Run' }
32
38
</ Button >
33
39
) ;
34
40
} ;
35
41
36
42
RunButton . propTypes = {
37
43
code : PropTypes . string . isRequired ,
38
44
onRun : PropTypes . func . isRequired ,
45
+ loading : PropTypes . bool ,
39
46
} ;
40
47
41
48
/**
42
49
* Code block with syntax highlighting
43
50
* @return {JSX.Element }
44
51
* @constructor
45
52
*/
46
- export const CodeBlock = ( { codeStr, language, withRunButton, onRun, title, editable = true } ) => {
53
+ export const CodeBlock = ( { codeStr, language, withRunButton, onRun, title, editable = true , loading } ) => {
47
54
const [ code , setCode ] = useState ( codeStr ) ;
48
55
const theme = useTheme ( ) ;
49
56
const prismTheme = theme . palette . mode === 'light' ? themes . nightOwlLight : themes . vsDark ;
@@ -102,7 +109,7 @@ export const CodeBlock = ({ codeStr, language, withRunButton, onRun, title, edit
102
109
>
103
110
{ withRunButton && onRun && (
104
111
< Box sx = { { flexGrow : '1' } } >
105
- < RunButton code = { code } onRun = { onRun } />
112
+ < RunButton code = { code } onRun = { onRun } loading = { loading } />
106
113
</ Box >
107
114
) }
108
115
{ title && < Box > { title } </ Box > }
@@ -131,4 +138,5 @@ CodeBlock.propTypes = {
131
138
onRun : PropTypes . func ,
132
139
title : PropTypes . string ,
133
140
editable : PropTypes . bool , // by default code block is editable
141
+ loading : PropTypes . bool ,
134
142
} ;
0 commit comments