Skip to content

Commit 3c33f66

Browse files
committed
Implement HTML cheatsheet
[pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci
1 parent 954226a commit 3c33f66

File tree

15 files changed

+743
-110
lines changed

15 files changed

+743
-110
lines changed

cheatsheet/gatsby-browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import './src/styles/global.css'
1+
import "./src/styles/global.css";

cheatsheet/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@
1616
"typecheck": "tsc --noEmit"
1717
},
1818
"dependencies": {
19+
"@fortawesome/fontawesome-svg-core": "^6.1.1",
20+
"@fortawesome/free-solid-svg-icons": "^6.1.1",
21+
"@fortawesome/react-fontawesome": "^0.1.18",
1922
"@mdx-js/mdx": "^1.6.22",
2023
"@mdx-js/react": "^1.6.22",
2124
"gatsby": "^4.10.2",
2225
"gatsby-plugin-mdx": "^3.10.2",
26+
"gatsby-plugin-react-helmet": "^5.13.0",
2327
"gatsby-source-filesystem": "^4.10.1",
2428
"react": "^17.0.1",
25-
"react-dom": "^17.0.1"
29+
"react-dom": "^17.0.1",
30+
"react-helmet": "^6.1.0"
2631
},
2732
"devDependencies": {
2833
"@types/node": "^17.0.21",
2934
"@types/react": "^17.0.41",
3035
"@types/react-dom": "^17.0.14",
36+
"@types/react-helmet": "^6.1.5",
3137
"autoprefixer": "^10.4.5",
3238
"gatsby-plugin-postcss": "^5.13.0",
3339
"postcss": "^8.4.12",

cheatsheet/postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = () => ({
22
plugins: [require("tailwindcss")],
3-
})
3+
});

cheatsheet/src/cheatsheetLegend.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
interface CheatsheetLegendEntry {
2+
term: string;
3+
definition: string;
4+
link?: string;
5+
id: string;
6+
}
7+
8+
export type CheatsheetLegend = CheatsheetLegendEntry[];
9+
10+
const cheatsheetLegend: CheatsheetLegend = [
11+
{
12+
term: "F",
13+
definition: 'Formatter (eg "camel", "snake"). Say "format help" for a list',
14+
id: "formatter",
15+
},
16+
{
17+
term: "P",
18+
definition: "Paired delimiter",
19+
link: "#paired-delimiters",
20+
id: "paired-delimiter",
21+
},
22+
{
23+
term: "S",
24+
definition: "Current selection(s)",
25+
id: "selection",
26+
},
27+
{
28+
term: "T",
29+
definition: "Cursorless target",
30+
link: "https://www.cursorless.org/docs/#targets",
31+
id: "target",
32+
},
33+
];
34+
35+
export default cheatsheetLegend;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from "react";
2+
import { CheatsheetLegend } from "../cheatsheetLegend";
3+
import SmartLink from "./SmartLink";
4+
5+
type Props = {
6+
data: CheatsheetLegend;
7+
};
8+
9+
export default function CheatsheetLegendComponent({
10+
data,
11+
}: Props): JSX.Element {
12+
return (
13+
<div
14+
id="legend"
15+
className="border border-violet-300 rounded-lg bg-violet-100"
16+
>
17+
<h2 className="text-xl text-center my-1 text-violet-900">Legend</h2>
18+
<table className="w-full">
19+
<tr className="text bg-violet-300">
20+
<th className="px-1 font-normal">Term</th>
21+
<th className="px-1 border-l border-violet-400 font-normal">
22+
Definition
23+
</th>
24+
</tr>
25+
{data.map(({ term, definition, link }) => (
26+
<tr className="odd:bg-violet-200">
27+
<td className="px-1">{`<${term}>`}</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>
35+
</tr>
36+
))}
37+
</table>
38+
</div>
39+
);
40+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import * as React from "react";
2+
import { CheatsheetSection } from "../pages/Section";
3+
4+
type Props = {
5+
section: CheatsheetSection;
6+
};
7+
8+
export default function CheatsheetListComponent({
9+
section,
10+
}: Props): JSX.Element {
11+
const spokenForms = section.items.flatMap((item) =>
12+
item.spokenForms.map((spokenForm) => ({
13+
item,
14+
spokenForm,
15+
}))
16+
);
17+
18+
spokenForms.sort((form1, form2) =>
19+
form1.spokenForm.spokenForm.localeCompare(form2.spokenForm.spokenForm)
20+
);
21+
22+
return (
23+
<div
24+
id={section.id}
25+
className="border border-stone-300 rounded-lg bg-stone-100"
26+
>
27+
<h2 className="text-xl text-center my-1">{section.name}</h2>
28+
<table className="w-full">
29+
<tr className="text bg-stone-300">
30+
<th className="px-1 font-normal">Spoken form</th>
31+
<th className="px-1 border-l border-stone-400 font-normal">
32+
Meaning
33+
</th>
34+
</tr>
35+
{spokenForms.map(({ item, spokenForm }) => (
36+
<tr className="odd:bg-stone-200">
37+
<td className="px-1">
38+
<span className="text-stone-400">"</span>
39+
{spokenForm.spokenForm}
40+
<span className="text-stone-400">"</span>
41+
</td>
42+
<td className="border-l border-stone-400 px-1">
43+
{spokenForm.description}
44+
</td>
45+
</tr>
46+
))}
47+
</table>
48+
</div>
49+
);
50+
}
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)