DashboardInfoCount.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React from "react";
  15. import { observer } from "mobx-react";
  16. import styled from "styled-components";
  17. import { Link } from "react-router";
  18. import StatusImage from "@src/components/ui/StatusComponents/StatusImage";
  19. import { ThemePalette, ThemeProps } from "@src/components/Theme";
  20. const Wrapper = styled.div<any>`
  21. background: ${ThemePalette.grayscale[0]};
  22. display: flex;
  23. overflow: auto;
  24. border-radius: ${ThemeProps.borderRadius};
  25. `;
  26. const CountBlock = styled.div<any>`
  27. flex-grow: 1;
  28. display: flex;
  29. flex-direction: column;
  30. align-items: center;
  31. margin: 32px 0;
  32. padding: 0 16px;
  33. border-left: 1px solid white;
  34. height: 96px;
  35. justify-content: center;
  36. &:first-child {
  37. border-left: 1px solid ${ThemePalette.grayscale[0]};
  38. }
  39. @media (max-width: 832px) {
  40. align-items: flex-start;
  41. }
  42. `;
  43. const LoadingWrapper = styled.div<any>`
  44. overflow: hidden;
  45. margin-bottom: 16px;
  46. `;
  47. const CountBlockValue = styled(Link)`
  48. font-size: 53px;
  49. font-weight: ${ThemeProps.fontWeights.extraLight};
  50. text-decoration: none;
  51. color: inherit;
  52. `;
  53. const CountBlockLabel = styled(Link)`
  54. font-size: 12px;
  55. font-weight: ${ThemeProps.fontWeights.medium};
  56. text-transform: uppercase;
  57. color: ${props => props.color};
  58. text-decoration: none;
  59. `;
  60. type Props = {
  61. data: {
  62. label: string;
  63. value: number;
  64. color: string;
  65. link: string;
  66. loading: boolean;
  67. }[];
  68. };
  69. @observer
  70. class DashboardInfoCount extends React.Component<Props> {
  71. render() {
  72. return (
  73. <Wrapper>
  74. {this.props.data.map(item => (
  75. <CountBlock key={item.label}>
  76. {!item.value && item.loading ? (
  77. <LoadingWrapper>
  78. <StatusImage status="RUNNING" size={48} />
  79. </LoadingWrapper>
  80. ) : (
  81. <CountBlockValue to={item.link}>{item.value}</CountBlockValue>
  82. )}
  83. <CountBlockLabel color={item.color} to={item.link}>
  84. {item.label}
  85. </CountBlockLabel>
  86. </CountBlock>
  87. ))}
  88. </Wrapper>
  89. );
  90. }
  91. }
  92. export default DashboardInfoCount;