forked from kofal.net/zmk
feat(docs): add keymap upgrader
Added a documentation page with a script that upgrades deprecated key codes and behaviors to their replacements. Fixes #299
This commit is contained in:
47
docs/src/components/KeymapUpgrader/index.jsx
Normal file
47
docs/src/components/KeymapUpgrader/index.jsx
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: CC-BY-NC-SA-4.0
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { useAsync } from "react-async";
|
||||
|
||||
import { initParser, upgradeKeymap } from "@site/src/keymap-upgrade";
|
||||
import CodeBlock from "@theme/CodeBlock";
|
||||
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
export default function KeymapUpgrader() {
|
||||
const { error, isPending } = useAsync(initParser);
|
||||
|
||||
if (isPending) {
|
||||
return <p>Loading...</p>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <p className="error">Error: {error.message}</p>;
|
||||
}
|
||||
|
||||
return <Editor />;
|
||||
}
|
||||
|
||||
function Editor() {
|
||||
const [keymap, setKeymap] = React.useState("");
|
||||
const upgraded = upgradeKeymap(keymap);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<textarea
|
||||
className={styles.editor}
|
||||
placeholder="Paste keymap here"
|
||||
spellCheck={false}
|
||||
value={keymap}
|
||||
onChange={(e) => setKeymap(e.target.value)}
|
||||
></textarea>
|
||||
<div className={styles.result}>
|
||||
<CodeBlock metastring={'title="Upgraded Keymap"'}>{upgraded}</CodeBlock>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
26
docs/src/components/KeymapUpgrader/styles.module.css
Normal file
26
docs/src/components/KeymapUpgrader/styles.module.css
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) 2020 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: CC-BY-NC-SA-4.0
|
||||
*/
|
||||
|
||||
.editor {
|
||||
font-family: var(--ifm-font-family-monospace);
|
||||
font-size: var(--ifm-font-size-base);
|
||||
line-height: var(--ifm-pre-line-height);
|
||||
tab-size: 4;
|
||||
|
||||
color: var(--ifm-pre-color);
|
||||
background-color: var(--ifm-pre-background);
|
||||
|
||||
border: none;
|
||||
border-radius: var(--ifm-pre-border-radius);
|
||||
|
||||
width: 100%;
|
||||
min-height: 10em;
|
||||
padding: var(--ifm-pre-padding);
|
||||
}
|
||||
|
||||
.result {
|
||||
tab-size: 4;
|
||||
}
|
||||
Reference in New Issue
Block a user