UNPKG

1.48 kBJavaScriptView Raw
1import React from "react";
2import styled from "styled-components";
3import { useHistory } from "react-router-dom";
4/**
5 * ----------------------------------------
6 * 统计信息
7 * @param {String} label - 标题
8 * @param {Number} value - 数值
9 * @param {String} [color] - 颜色
10 * @param {String} [path] - 跳转
11 * ----------------------------------------
12 */
13export default function Stat({ label, value, color, path }) {
14 const history = useHistory();
15 const onClick = () => {
16 if (path) {
17 history.push(path);
18 }
19 };
20
21 const style = {};
22 if (color) {
23 style.backgroundColor = color;
24 style.color = "white";
25 }
26 if (path) {
27 style.cursor = "pointer";
28 }
29
30 return (
31 <SBox
32 onClick={onClick}
33 style={{ backgroundColor: style.backgroundColor, cursor: style.cursor }}
34 >
35 <Slabel style={{ color: style.color }}>{label}</Slabel>
36 <Svalue style={{ color: style.color }}>{value}</Svalue>
37 </SBox>
38 );
39}
40
41const SBox = styled.div`
42 border-radius: 4px;
43 background: white;
44 width: 130px;
45 height: 100px;
46 margin-right: 10px;
47 margin-bottom: 10px;
48 text-align: center;
49 position: relative;
50 box-shadow: 4px 4px 20px rgba (0, 0, 0, 0.075);
51`;
52const Slabel = styled.div`
53 color: gray;
54 width: 100%;
55 position: absolute;
56 top: 15px;
57 letter-spacing: 1px;
58`;
59
60const Svalue = styled.div`
61 font-size: 38px;
62 width: 100%;
63 position: absolute;
64 top: 34px;
65 font-family: "SF Pro Display";
66 font-weight: 400;
67`;