From 17a2d48b2eaba252abe12630b47fcd9589c038c8 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 8 Mar 2021 17:05:48 +0100 Subject: [PATCH] Add help dialog with keybindings reference --- commands.js | 3 +++ components/app.js | 12 ++++++++++++ components/help.js | 36 ++++++++++++++++++++++++++++++++++++ style.css | 15 +++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 components/help.js diff --git a/commands.js b/commands.js index b5914e0..e9063e3 100644 --- a/commands.js +++ b/commands.js @@ -29,6 +29,9 @@ export default { "disconnect": (app, args) => { app.disconnect(); }, + "help": (app, args) => { + app.openHelp(); + }, "join": (app, args) => { var channel = args[0]; if (!channel) { diff --git a/components/app.js b/components/app.js index ff61830..d3856fe 100644 --- a/components/app.js +++ b/components/app.js @@ -6,6 +6,7 @@ import BufferHeader from "./buffer-header.js"; import MemberList from "./member-list.js"; import Connect from "./connect.js"; import Join from "./join.js"; +import Help from "./help.js"; import Composer from "./composer.js"; import ScrollManager from "./scroll-manager.js"; import Dialog from "./dialog.js"; @@ -879,6 +880,10 @@ export default class App extends Component { return fromList(buf.members.keys(), prefix); } + openHelp() { + this.setState({ dialog: "help" }); + } + handleBufferScrollTop() { var buf = this.state.buffers.get(this.state.activeBuffer); if (!buf || buf.type == BufferType.SERVER) { @@ -959,6 +964,13 @@ export default class App extends Component { var dialog = null; switch (this.state.dialog) { + case "help": + dialog = html` + <${Dialog} title="Help" onDismiss=${this.handleDialogDismiss}> + <${Help}/> + + `; + break; case "join": dialog = html` <${Dialog} title="Join channel" onDismiss=${this.handleDialogDismiss}> diff --git a/components/help.js b/components/help.js new file mode 100644 index 0000000..4820547 --- /dev/null +++ b/components/help.js @@ -0,0 +1,36 @@ +import { html, Component } from "../lib/index.js"; +import { keybindings } from "../keybindings.js"; + +function KeyBindingsHelp() { + var l = keybindings.map((binding) => { + var keys = []; + if (binding.ctrlKey) { + keys.psuh("Ctrl"); + } + if (binding.altKey) { + keys.push("Alt"); + } + keys.push(binding.key); + + keys = keys.map((name, i) => { + return html` + ${i > 0 ? "+" : null} + ${name} + `; + }); + + return html` +
${keys}
+
${binding.description}
+ `; + }); + + return html`
${l}
`; +} + +export default function Help() { + return html` +

Key bindings

+ <${KeyBindingsHelp}/> + `; +} diff --git a/style.css b/style.css index ccadd02..6b593e6 100644 --- a/style.css +++ b/style.css @@ -301,3 +301,18 @@ details summary { .dialog h2 { margin-top: 0; } + +kbd { + background-color: #f0f0f0; + border: 1px solid #bfbfbf; + box-shadow: inset 0 1px 0 0 #fff, inset 0 -2px 0 0 #d9d9d9; + display: inline-block; + font-size: 80%; + margin: 3px; + min-width: 1em; + text-align: center; + white-space: nowrap; + padding: 2px 4px; + font-family: monospace; + border-radius: 3px; +}