#
vincentlu
9 天以前 1bc33546a044cbc84dd9595c19dbcd9a4e309fc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";
import { useTranslate } from "react-admin";
import { Fab } from '@mui/material';
import CropFreeIcon from '@mui/icons-material/CropFree';
import CropIcon from '@mui/icons-material/Crop';
import CircularProgress from '@mui/material/CircularProgress';
import * as Tool from '../tool';
 
const AreaFab = (props) => {
    const { curZone, showAreas, setShowAreas } = props;
    const translate = useTranslate();
 
    const [loading, setLoading] = React.useState(false);
 
    const handleClick = () => {
        if (showAreas) {
            Tool.hideAreas(curZone, setShowAreas);
        } else {
            Tool.showAreas(curZone, setShowAreas, setLoading);
        }
    }
 
    return (
        <>
            <Fab
                variant="extended"
                color={showAreas ? 'primary' : 'default'}
                size="small"
                disabled={loading}
                onClick={handleClick}
                sx={{
                    minWidth: 100
                }}
            >
                <CropIcon />
                &nbsp;{translate('page.map.action.area')}&nbsp;
                {loading && (
                    <>
                        <svg width={0} height={0}>
                            <defs>
                                <linearGradient id="my_gradient" x1="0%" y1="0%" x2="0%" y2="100%">
                                    <stop offset="0%" stopColor="#e01cd5" />
                                    <stop offset="100%" stopColor="#1CB5E0" />
                                </linearGradient>
                            </defs>
                        </svg>
                        <CircularProgress size={18} thickness={8} sx={{ 'svg circle': { stroke: 'url(#my_gradient)' } }} />
                    </>
                )}
            </Fab>
        </>
    )
}
 
export default AreaFab;