-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathField.tsx
123 lines (112 loc) · 2.53 KB
/
Field.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
import React from "react";
import styled, { css } from "styled-components";
import { landscapeStyle } from "styles/landscapeStyle";
import { Link } from "react-router-dom";
import { useScrollTop } from "hooks/useScrollTop";
const FieldContainer = styled.div<FieldContainerProps>`
display: flex;
align-items: center;
justify-content: flex-start;
white-space: nowrap;
width: 100%;
.value {
flex-grow: 1;
text-align: end;
color: ${({ theme }) => theme.primaryText};
}
svg {
fill: ${({ theme }) => theme.secondaryPurple};
margin-right: 8px;
width: 14px;
flex-shrink: 0;
}
${({ isList }) =>
isList &&
css`
${landscapeStyle(
() => css`
width: auto;
.value {
flex-grow: 0;
text-align: center;
}
`
)}
`};
${({ isOverview, isJurorBalance }) =>
(isOverview || isJurorBalance) &&
css`
${landscapeStyle(
() => css`
width: auto;
gap: 8px;
.value {
flex-grow: 0;
text-align: none;
font-weight: 600;
}
svg {
margin-right: 0;
}
`
)}
`};
`;
const LinkContainer = styled.div``;
const StyledLink = styled(Link)`
color: ${({ theme }) => theme.primaryBlue};
text-wrap: auto;
justify-content: end;
`;
type FieldContainerProps = {
width?: string;
isList?: boolean;
isOverview?: boolean;
isJurorBalance?: boolean;
};
export interface IField {
icon: React.FunctionComponent<React.SVGAttributes<SVGElement>>;
name: string;
value: string;
link?: string;
width?: string;
displayAsList?: boolean;
isOverview?: boolean;
isJurorBalance?: boolean;
className?: string;
}
const Field: React.FC<IField> = ({
icon: Icon,
name,
value,
link,
width,
displayAsList,
isOverview,
isJurorBalance,
className,
}) => {
const scrollTop = useScrollTop();
return (
<FieldContainer isList={displayAsList} {...{ isOverview, isJurorBalance, width, className }}>
<Icon />
{(!displayAsList || isOverview || isJurorBalance) && <label>{name}:</label>}
{link ? (
<LinkContainer className="value">
<StyledLink
to={link}
onClick={(event) => {
event.stopPropagation();
scrollTop();
}}
>
{value}
</StyledLink>
</LinkContainer>
) : (
<label className="value">{value}</label>
)}
</FieldContainer>
);
};
export default Field;