github.com/minio/console@v1.4.1/web-app/src/screens/Console/Dashboard/Prometheus/Widgets/NumericStatCard.tsx (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2022 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  import React from "react";
    18  import styled from "styled-components";
    19  import get from "lodash/get";
    20  import { Box, breakPoints, Loader, Tooltip } from "mds";
    21  
    22  const StatCardMain = styled.div(({ theme }) => ({
    23    fontFamily: "Inter,sans-serif",
    24    color: get(theme, "signalColors.main", "#07193E"),
    25    maxWidth: "300px",
    26    display: "flex",
    27    marginLeft: "auto",
    28    marginRight: "auto",
    29    cursor: "default",
    30    position: "relative",
    31    width: "100%",
    32  }));
    33  
    34  const NumericStatCard = ({
    35    value,
    36    label = "",
    37    icon = null,
    38    loading = false,
    39  }: {
    40    value: string | number;
    41    label?: any;
    42    icon?: any;
    43    loading?: boolean;
    44  }) => {
    45    const getContent = () => {
    46      return (
    47        <Box
    48          sx={{
    49            flex: 1,
    50            display: "flex",
    51            width: "100%",
    52            padding: "0 8px 0 8px",
    53            [`@media (max-width: ${breakPoints.sm}px)`]: {
    54              padding: "0 10px 0 10px",
    55            },
    56          }}
    57        >
    58          <Box
    59            sx={{
    60              flex: 1,
    61              display: "flex",
    62              flexFlow: "column",
    63              marginTop: "12px",
    64              zIndex: 10,
    65              overflow: "hidden",
    66            }}
    67          >
    68            <Box
    69              sx={{
    70                fontSize: "16px",
    71                fontWeight: 600,
    72              }}
    73            >
    74              {label}
    75            </Box>
    76  
    77            <Tooltip tooltip={value} placement="bottom">
    78              <Box
    79                sx={{
    80                  fontWeight: 600,
    81                  overflow: "hidden",
    82                  textOverflow: "ellipsis",
    83                  maxWidth: 187,
    84                  flexFlow: "row",
    85                  fontSize: 55,
    86                  [`@media (max-width: ${breakPoints.sm}px)`]: {
    87                    fontSize: 35,
    88                    maxWidth: 200,
    89                    flexFlow: "column",
    90                  },
    91                  [`@media (max-width: ${breakPoints.md}px)`]: {
    92                    fontSize: 35,
    93                  },
    94                  [`@media (max-width: ${breakPoints.lg}px)`]: {
    95                    fontSize: 36,
    96                  },
    97                  [`@media (max-width: ${breakPoints.xl}px)`]: {
    98                    fontSize: 50,
    99                  },
   100                }}
   101              >
   102                {value}
   103              </Box>
   104            </Tooltip>
   105          </Box>
   106          <Box
   107            sx={{
   108              display: "flex",
   109              flexFlow: "column",
   110              alignItems: "center",
   111              justifyContent: "flex-start",
   112              marginTop: "8px",
   113              maxWidth: "26px",
   114              "& .min-icon": {
   115                width: "16px",
   116                height: "16px",
   117              },
   118            }}
   119          >
   120            {}
   121            {loading ? (
   122              <Loader style={{ width: "16px", height: "16px" }} />
   123            ) : (
   124              icon
   125            )}
   126          </Box>
   127        </Box>
   128      );
   129    };
   130  
   131    return <StatCardMain>{getContent()}</StatCardMain>;
   132  };
   133  
   134  export default NumericStatCard;