github.com/minio/console@v1.4.1/web-app/src/screens/Console/Dashboard/BasicDashboard/CounterCard.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 get from "lodash/get";
    19  import styled from "styled-components";
    20  import { Box, breakPoints, Tooltip } from "mds";
    21  
    22  const CounterCardMain = 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 CounterCard = ({
    35    counterValue,
    36    label = "",
    37    icon = null,
    38    actions = null,
    39  }: {
    40    counterValue: string | number;
    41    label?: any;
    42    icon?: any;
    43    actions?: any;
    44  }) => {
    45    return (
    46      <CounterCardMain>
    47        <Box
    48          sx={{
    49            flex: 1,
    50            display: "flex",
    51            width: "100%",
    52            padding: "0 8px 0 8px",
    53            position: "absolute",
    54            [`@media (max-width: ${breakPoints.md}px)`]: {
    55              padding: "0 10px 0 10px",
    56            },
    57          }}
    58        >
    59          <Box
    60            sx={{
    61              flex: 1,
    62              display: "flex",
    63              flexFlow: "column",
    64              marginTop: "8px",
    65              zIndex: 10,
    66              overflow: "hidden",
    67            }}
    68          >
    69            <Box
    70              sx={{
    71                fontSize: "16px",
    72                fontWeight: 600,
    73              }}
    74            >
    75              {label}
    76            </Box>
    77  
    78            <Tooltip tooltip={counterValue} placement="bottom">
    79              <Box
    80                sx={{
    81                  fontWeight: 600,
    82                  overflow: "hidden",
    83                  textOverflow: "ellipsis",
    84                  maxWidth: 187,
    85                  flexFlow: "row",
    86                  fontSize: counterValue.toString().length >= 5 ? 50 : 55,
    87                  [`@media (max-width: ${breakPoints.sm}px)`]: {
    88                    flexFlow: "column",
    89                    maxWidth: 200,
    90                    fontSize: counterValue.toString().length >= 5 ? 20 : 35,
    91                  },
    92                  [`@media (max-width: ${breakPoints.md}px)`]: {
    93                    fontSize: counterValue.toString().length >= 5 ? 28 : 35,
    94                  },
    95                  [`@media (max-width: ${breakPoints.lg}px)`]: {
    96                    fontSize: counterValue.toString().length >= 5 ? 28 : 36,
    97                  },
    98                  [`@media (max-width: ${breakPoints.xl}px)`]: {
    99                    fontSize: counterValue.toString().length >= 5 ? 45 : 50,
   100                  },
   101                }}
   102              >
   103                {counterValue}
   104              </Box>
   105            </Tooltip>
   106          </Box>
   107          <Box
   108            sx={{
   109              display: "flex",
   110              flexFlow: "column",
   111              alignItems: "center",
   112              justifyContent: "flex-start",
   113              marginTop: "8px",
   114              maxWidth: "26px",
   115              "& .min-icon": {
   116                width: "16px",
   117                height: "16px",
   118              },
   119            }}
   120          >
   121            {icon}
   122  
   123            <Box
   124              sx={{
   125                display: "flex",
   126              }}
   127            >
   128              {actions}
   129            </Box>
   130          </Box>
   131        </Box>
   132      </CounterCardMain>
   133    );
   134  };
   135  
   136  export default CounterCard;