-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathCheatsheetLegendComponent.tsx
More file actions
57 lines (53 loc) · 1.75 KB
/
Copy pathCheatsheetLegendComponent.tsx
File metadata and controls
57 lines (53 loc) · 1.75 KB
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
import * as React from "react";
import type { CheatsheetLegend } from "../cheatsheetLegend";
import useIsHighlighted from "../hooks/useIsHighlighted";
import { formatCaptures } from "./formatCaptures";
import SmartLink from "./SmartLink";
type Props = {
data: CheatsheetLegend;
};
export default function CheatsheetLegendComponent({
data,
}: Props): React.JSX.Element {
const isHighlighted = useIsHighlighted("legend");
const borderClassName = isHighlighted
? "border-violet-500 dark:border-violet-300"
: "border-violet-300 dark:border-violet-500";
return (
<div
id="legend"
className={`border ${borderClassName} overflow-hidden rounded-lg bg-violet-100 dark:bg-violet-900`}
>
<h2 className="my-1 text-center text-xl text-violet-900 dark:text-violet-100">
Legend
</h2>
<table className="w-full">
<thead>
<tr className="text bg-violet-300 dark:bg-violet-500">
<th className="w-1/2 px-1 font-normal">Term</th>
<th className="border-l border-violet-400 px-1 font-normal">
Definition
</th>
</tr>
</thead>
<tbody>
{data.map(({ term, definition, link, id }) => (
<tr
key={id}
className="odd:bg-violet-200 dark:bg-violet-800 odd:dark:bg-violet-600"
>
<td className="px-1">{formatCaptures(`<${term}>`)}</td>
<td className="border-l border-violet-400 px-1">
{link != null ? (
<SmartLink to={link}>{definition}</SmartLink>
) : (
formatCaptures(definition)
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
);
}