Skip to content

Commit 325a7f1

Browse files
committed
feat(ui): add count label to fields
1 parent e59edb4 commit 325a7f1

File tree

3 files changed

+47
-19
lines changed

3 files changed

+47
-19
lines changed

graphql-usage-ui/src/FieldLine.tsx

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from "react";
33
import Delimiter from "./Delimiter";
44
import FieldName from "./FieldName";
55
import FieldType from "./FieldType";
6+
import Label from "./Label";
67
import { ReportField } from "./reportTypes";
78

89
interface Props {
@@ -29,25 +30,10 @@ const FieldLine: React.FC<Props> = ({ field, filter, onFieldClick }) => {
2930
<FieldType highlight={!!filter && typeMatchesFilter}>{type}</FieldType>
3031
</div>
3132

32-
{occurrences.length === 0 && (
33-
<span
34-
style={{
35-
display: "inline-block",
36-
padding: ".25em .4em",
37-
fontSize: "75%",
38-
fontWeight: 700,
39-
lineHeight: 1,
40-
textAlign: "center",
41-
whiteSpace: "nowrap",
42-
verticalAlign: "baseline",
43-
borderRadius: ".25rem",
44-
backgroundColor: "#f25c54",
45-
color: "#fff",
46-
marginLeft: "8px"
47-
}}
48-
>
49-
Unused
50-
</span>
33+
{occurrences.length === 0 ? (
34+
<Label color="red">Unused</Label>
35+
) : (
36+
<Label>{occurrences.length}</Label>
5137
)}
5238
</div>
5339
);

graphql-usage-ui/src/Label.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from "react";
2+
3+
import { LIGHT_BLUE, RED, WHITE } from "./constants/colors";
4+
5+
type LabelColor = "red" | "blue";
6+
7+
interface LabelProps {
8+
color?: LabelColor;
9+
}
10+
11+
const Label: React.FC<LabelProps> = ({ children, color = "blue" }) => {
12+
const hexColor = {
13+
blue: LIGHT_BLUE,
14+
red: RED
15+
}[color];
16+
17+
return (
18+
<span
19+
style={{
20+
display: "inline-block",
21+
padding: ".25em .4em",
22+
fontSize: "75%",
23+
fontWeight: 700,
24+
lineHeight: 1,
25+
textAlign: "center",
26+
whiteSpace: "nowrap",
27+
verticalAlign: "baseline",
28+
borderRadius: ".25rem",
29+
backgroundColor: hexColor,
30+
color: WHITE,
31+
marginLeft: "8px"
32+
}}
33+
>
34+
{children}
35+
</span>
36+
);
37+
};
38+
39+
export default Label;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const LIGHT_BLUE = "#79d5f1";
2+
export const RED = "#f25c54";
3+
export const WHITE = "#ffffff";

0 commit comments

Comments
 (0)