UNPKG

1.48 kBJavaScriptView Raw
1import React from "react";
2import styled from "styled-components";
3/**
4 * ----------------------------------------
5 * 带图标, 摘要/统计项等综合描述使用
6 * @param {String} label - 标签
7 * @param {Any} value - 数字
8 * @param {Slot} children - 图标位置内容
9 * @param {Boolean} [rounded=true] - 是否显示圆角
10 * @param {String} [color] - 图标背景颜色
11 * ----------------------------------------
12 */
13export default function SumCard({
14 label,
15 value,
16 children,
17 rounded = true,
18 color = "#118adb",
19 style,
20}) {
21 const boxStyle = { borderColor: color, borderRadius: "4px", ...style };
22 if (rounded) {
23 boxStyle.borderRadius = "46px";
24 }
25
26 return (
27 <SBox style={boxStyle}>
28 <SIcon
29 style={{
30 background: color,
31 borderRadius: rounded ? "50%" : "2px",
32 }}
33 >
34 {children}
35 </SIcon>
36 <STitle>{label}</STitle>
37 <div style={{ flex: 1 }}></div>
38 <SValue>{value}</SValue>
39 </SBox>
40 );
41}
42
43const SBox = styled.div`
44 display: flex;
45 align-items: center;
46 margin-bottom: 20px;
47 border: 1px solid;
48 padding: 10px;
49 background: white;
50`;
51
52const SIcon = styled.div`
53 flex-shrink: 0;
54 width: 50px;
55 height: 50px;
56 display: flex;
57 align-items: center;
58 justify-content: center;
59 margin-right: 10px;
60`;
61
62const STitle = styled.div`
63 color: gray;
64 letter-spacing: 1px;
65 font-size: 14px;
66 margin-right: 5px;
67`;
68
69const SValue = styled.div`
70 font-size: 30px;
71`;