Skip to content

Commit 3f54c63

Browse files
committed
Add links to legend
1 parent 6e32026 commit 3f54c63

File tree

9 files changed

+566
-119
lines changed

9 files changed

+566
-119
lines changed

cheatsheet/src/cheatsheetLegend.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
interface CheatsheetLegendEntry {
22
term: string;
33
definition: string;
4-
link: string;
4+
link?: string;
55
id: string;
66
}
77

@@ -10,26 +10,24 @@ export type CheatsheetLegend = CheatsheetLegendEntry[];
1010
const cheatsheetLegend: CheatsheetLegend = [
1111
{
1212
term: "F",
13-
definition: "Formatter (eg camel, snake)",
14-
link: "",
13+
definition: 'Formatter (eg camel, snake). Say "format help" for a list',
1514
id: "formatter",
1615
},
1716
{
1817
term: "P",
1918
definition: "Paired delimiter",
20-
link: "",
19+
link: "#paired-delimiters",
2120
id: "paired-delimiter",
2221
},
2322
{
2423
term: "S",
2524
definition: "Current selection(s)",
26-
link: "",
2725
id: "selection",
2826
},
2927
{
3028
term: "T",
3129
definition: "Cursorless target",
32-
link: "",
30+
link: "https://www.cursorless.org/docs/#targets",
3331
id: "target",
3432
},
3533
];

cheatsheet/src/components/CheatsheetLegendComponent.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react";
22
import { CheatsheetLegend } from "../cheatsheetLegend";
3+
import SmartLink from "./SmartLink";
34

45
type Props = {
56
data: CheatsheetLegend;
@@ -21,10 +22,16 @@ export default function CheatsheetLegendComponent({
2122
Definition
2223
</th>
2324
</tr>
24-
{data.map(({ term, definition }) => (
25+
{data.map(({ term, definition, link }) => (
2526
<tr className="odd:bg-violet-200">
2627
<td className="px-1">{`<${term}>`}</td>
27-
<td className="border-l border-violet-400 px-1">{definition}</td>
28+
<td className="border-l border-violet-400 px-1">
29+
{link != null ? (
30+
<SmartLink to={link}>{definition}</SmartLink>
31+
) : (
32+
definition
33+
)}
34+
</td>
2835
</tr>
2936
))}
3037
</table>

cheatsheet/src/components/CheatsheetListComponent.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export default function CheatsheetListComponent({
2020
);
2121

2222
return (
23-
<div className="border border-stone-300 rounded-lg bg-stone-100">
23+
<div
24+
id={section.id}
25+
className="border border-stone-300 rounded-lg bg-stone-100"
26+
>
2427
<h2 className="text-xl text-center my-1">{section.name}</h2>
2528
<table className="w-full">
2629
<tr className="text bg-stone-300">
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from "react";
2+
import SmartLink from "./SmartLink";
3+
4+
export default function CheatsheetNotesComponent(): JSX.Element {
5+
return (
6+
<div
7+
id="notes"
8+
className="p-2 border border-violet-300 rounded-lg bg-violet-100"
9+
>
10+
<h2 className="text-xl text-center mb-1 text-violet-900">Notes</h2>
11+
<ul>
12+
<li className="">
13+
See the{" "}
14+
<SmartLink to={"https://www.cursorless.org/docs/"}>
15+
full documentation
16+
</SmartLink>{" "}
17+
to learn more.
18+
</li>
19+
</ul>
20+
</div>
21+
);
22+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Link } from "gatsby";
2+
import * as React from "react";
3+
4+
type SmartLinkProps = {
5+
/**
6+
* The target of the link
7+
*/
8+
to: string;
9+
};
10+
11+
/**
12+
* Link component that will use `a` tag for external links and `Link` tag for
13+
* internal
14+
* @returns SmartLink component
15+
*/
16+
const SmartLink: React.FC<SmartLinkProps> = ({ to, children }) => (
17+
<span className="text-cyan-700 hover:text-violet-700">
18+
{to.startsWith("https://") ? (
19+
<a href={to} target="_blank" rel="noopener noreferrer">
20+
{children}
21+
</a>
22+
) : (
23+
<Link to={to}>{children}</Link>
24+
)}
25+
</span>
26+
);
27+
28+
export default SmartLink;

0 commit comments

Comments
 (0)