DashboardInfoCount.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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-dom'
  18. import StatusImage from '../../../ui/StatusComponents/StatusImage/StatusImage'
  19. import Palette from '../../../styleUtils/Palette'
  20. import StyleProps from '../../../styleUtils/StyleProps'
  21. const Wrapper = styled.div<any>`
  22. background: ${Palette.grayscale[0]};
  23. display: flex;
  24. overflow: auto;
  25. border-radius: ${StyleProps.borderRadius};
  26. `
  27. const CountBlock = styled.div<any>`
  28. flex-grow: 1;
  29. display: flex;
  30. flex-direction: column;
  31. align-items: center;
  32. margin: 32px 0;
  33. padding: 0 16px;
  34. border-left: 1px solid white;
  35. height: 96px;
  36. justify-content: center;
  37. &:first-child {
  38. border-left: 1px solid ${Palette.grayscale[0]};
  39. }
  40. @media (max-width: 832px) {
  41. align-items: flex-start;
  42. }
  43. `
  44. const LoadingWrapper = styled.div<any>`
  45. overflow: hidden;
  46. margin-bottom: 16px;
  47. `
  48. const CountBlockValue = styled(Link)`
  49. font-size: 53px;
  50. font-weight: ${StyleProps.fontWeights.extraLight};
  51. text-decoration: none;
  52. color: inherit;
  53. `
  54. const CountBlockLabel = styled(Link)`
  55. font-size: 12px;
  56. font-weight: ${StyleProps.fontWeights.medium};
  57. text-transform: uppercase;
  58. color: ${props => props.color};
  59. text-decoration: none;
  60. `
  61. type Props = {
  62. data: {
  63. label: string,
  64. value: number,
  65. color: string,
  66. link: string,
  67. loading: boolean,
  68. }[],
  69. }
  70. @observer
  71. class DashboardInfoCount extends React.Component<Props> {
  72. render() {
  73. return (
  74. <Wrapper>
  75. {this.props.data.map(item => (
  76. <CountBlock key={item.label}>
  77. {
  78. !item.value && item.loading ? <LoadingWrapper><StatusImage status="RUNNING" size={48} /></LoadingWrapper>
  79. : <CountBlockValue to={item.link}>{item.value}</CountBlockValue>
  80. }
  81. <CountBlockLabel color={item.color} to={item.link}>{item.label}</CountBlockLabel>
  82. </CountBlock>
  83. ))}
  84. </Wrapper>
  85. )
  86. }
  87. }
  88. export default DashboardInfoCount