1- // @ts -check
21import React , {
32 useCallback ,
43 useEffect ,
@@ -8,20 +7,20 @@ import React, {
87import {
98 StatefulButton ,
109} from '@openedx/paragon' ;
11- import PropTypes from 'prop-types' ;
10+
11+ interface LoadingButtonProps {
12+ label : string ;
13+ onClick ?: ( e : any ) => ( Promise < void > | void ) ;
14+ disabled ?: boolean ;
15+ size ?: string ;
16+ variant ?: string ;
17+ className ?: string ;
18+ }
1219
1320/**
14- * A button that shows a loading spinner when clicked.
15- * @param {object } props
16- * @param {string } props.label
17- * @param {function= } props.onClick
18- * @param {boolean= } props.disabled
19- * @param {string= } props.size
20- * @param {string= } props.variant
21- * @param {string= } props.className
22- * @returns {JSX.Element }
21+ * A button that shows a loading spinner when clicked, if the onClick function returns a Promise.
2322 */
24- const LoadingButton = ( {
23+ const LoadingButton : React . FC < LoadingButtonProps > = ( {
2524 label,
2625 onClick,
2726 disabled,
@@ -37,7 +36,7 @@ const LoadingButton = ({
3736 componentMounted . current = false ;
3837 } , [ ] ) ;
3938
40- const loadingOnClick = useCallback ( async ( e ) => {
39+ const loadingOnClick = useCallback ( async ( e : any ) => {
4140 if ( ! onClick ) {
4241 return ;
4342 }
@@ -67,21 +66,4 @@ const LoadingButton = ({
6766 ) ;
6867} ;
6968
70- LoadingButton . propTypes = {
71- label : PropTypes . string . isRequired ,
72- onClick : PropTypes . func ,
73- disabled : PropTypes . bool ,
74- size : PropTypes . string ,
75- variant : PropTypes . string ,
76- className : PropTypes . string ,
77- } ;
78-
79- LoadingButton . defaultProps = {
80- onClick : undefined ,
81- disabled : undefined ,
82- size : undefined ,
83- variant : '' ,
84- className : '' ,
85- } ;
86-
8769export default LoadingButton ;
0 commit comments