/
StackedCard.tsx
131 lines (113 loc) · 2.95 KB
/
StackedCard.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React, { DetailedHTMLProps, HTMLAttributes, ReactNode } from 'react';
import styled, { StyledComponentClass, css } from 'styled-components';
import { Theme, scale } from '@mycrypto/ui';
import Typography from './Typography';
type StackedCardEntry = string | ReactNode;
export interface StackedCardData {
heading: ReactNode;
entries: StackedCardEntry[][];
icons?: ReactNode[];
}
type Props = StackedCardData;
const StackedCardContainer = styled.section`
padding: 0.9375em;
border-bottom: 0.0625em solid #dde3ee;
`;
const StackedCardHead = styled.section`
display: flex;
align-items: center;
justify-content: space-between;
`;
const StackedCardHeading = styled(Typography)`
display: flex;
align-items: center;
margin: 0;
font-weight: bold;
line-height: 1.31;
font-size: ${scale(1)};
`;
StackedCardHeading.defaultProps = {
as: 'header'
};
// Arbitrary positioning of icons to respect AddressBook and AccountList designs
const StackedCardIcons = styled.div`
height: 100%;
display: flex;
justify-content: flex-end;
align-items: center;
> * {
width: 15px;
}
${props =>
props.qty &&
css`
width: calc(15px * ${props.qty || 1});
`}
${(props: { qty: number }) =>
props.qty === 2 &&
css`
> *:first-child {
margin-bottom: -2px;
}
> *:last-child {
margin-left: 8px;
}
`}
`;
// Arbitrary left margin to allow AccountList rows to align to
// the Identicon + label display.
// @TODO: remove arbitrary style.
const StackedCardBody = styled.div`
display: flex;
flex-direction: column;
margin-top: 1.5625em;
margin-left: calc(14px + 2em);
`;
const StackedCardEntry = styled.dl`
display: flex;
flex-direction: row;
align-items: center;
`;
type StyledHTMLElement = StyledComponentClass<
DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>,
Theme
>;
const StackedCardLabel = styled(Typography)`
flex: 0.7;
margin: 0;
color: ${props => props.theme.cardText};
letter-spacing: 0.106875em;
text-transform: uppercase;
font-weight: bold;
font-size: 0.856em;
line-height: 1em;
` as StyledHTMLElement;
StackedCardLabel.defaultProps = {
as: 'dt'
};
const StackedCardValue = styled(Typography)`
flex: 1;
margin: 0;
` as StyledHTMLElement;
StackedCardValue.defaultProps = {
as: 'dd'
};
export const StackedCard = ({ heading, icons = [], entries, ...rest }: Props) => {
return (
<StackedCardContainer {...rest}>
<StackedCardHead>
<StackedCardHeading>{heading}</StackedCardHeading>
<StackedCardIcons qty={icons.length}>{icons}</StackedCardIcons>
</StackedCardHead>
<StackedCardBody>
{entries.map(([label, value], index) => (
<StackedCardEntry key={index}>
<StackedCardLabel>{label}</StackedCardLabel>
<StackedCardValue>{value}</StackedCardValue>
</StackedCardEntry>
))}
</StackedCardBody>
</StackedCardContainer>
);
};
export default StackedCard;