FEATURE: Improve keyboard shortcuts help modal (#9143)

This commit is contained in:
Jarek Radosz 2020-03-09 17:37:32 +01:00 committed by GitHub
parent ae3220fb88
commit fff0e0980d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 40 deletions

View File

@ -14,23 +14,22 @@ const PLUS = I18n.t(`${KEY}.shortcut_key_delimiter_plus`);
function buildHTML(keys1, keys2, keysDelimiter, shortcutsDelimiter) { function buildHTML(keys1, keys2, keysDelimiter, shortcutsDelimiter) {
const allKeys = [keys1, keys2] const allKeys = [keys1, keys2]
.reject(keys => keys.length === 0) .reject(keys => keys.length === 0)
.map(keys => keys.map(k => `<kbd>${k}</kbd>`).join(keysDelimiter)); .map(keys => keys.map(k => `<kbd>${k}</kbd>`).join(keysDelimiter))
.map(keys => (shortcutsDelimiter !== "space" ? wrapInSpan(keys) : keys));
const [shortcut1, shortcut2] = allKeys;
if (allKeys.length === 1) { if (allKeys.length === 1) {
return wrapInSpan(allKeys[0]); return shortcut1;
} } else if (shortcutsDelimiter === "or") {
return I18n.t(`${KEY}.shortcut_delimiter_or`, { shortcut1, shortcut2 });
const context = { shortcut1: allKeys[0], shortcut2: allKeys[1] };
let result = "";
if (shortcutsDelimiter === "or") {
result = I18n.t(`${KEY}.shortcut_delimiter_or`, context);
} else if (shortcutsDelimiter === "slash") { } else if (shortcutsDelimiter === "slash") {
result = I18n.t(`${KEY}.shortcut_delimiter_slash`, context); return I18n.t(`${KEY}.shortcut_delimiter_slash`, { shortcut1, shortcut2 });
} else if (shortcutsDelimiter === "space") { } else if (shortcutsDelimiter === "space") {
result = I18n.t(`${KEY}.shortcut_delimiter_space`, context); return wrapInSpan(
I18n.t(`${KEY}.shortcut_delimiter_space`, { shortcut1, shortcut2 })
);
} }
return wrapInSpan(result);
} }
function wrapInSpan(shortcut) { function wrapInSpan(shortcut) {
@ -51,6 +50,7 @@ export default Controller.extend(ModalFunctionality, {
onShow() { onShow() {
this.set("modal.modalClass", "keyboard-shortcuts-modal"); this.set("modal.modalClass", "keyboard-shortcuts-modal");
}, },
shortcuts: { shortcuts: {
jump_to: { jump_to: {
home: buildShortcut("jump_to.home", { keys1: ["g", "h"] }), home: buildShortcut("jump_to.home", { keys1: ["g", "h"] }),

View File

@ -1,7 +1,7 @@
{{#d-modal-body id="keyboard-shortcuts-help"}} {{#d-modal-body id="keyboard-shortcuts-help"}}
<div class="row"> <div class="column">
<div> <section>
<h4>{{i18n 'keyboard_shortcuts_help.jump_to.title'}}</h4> <h4>{{i18n "keyboard_shortcuts_help.jump_to.title"}}</h4>
<ul> <ul>
<li>{{{shortcuts.jump_to.home}}}</li> <li>{{{shortcuts.jump_to.home}}}</li>
<li>{{{shortcuts.jump_to.latest}}}</li> <li>{{{shortcuts.jump_to.latest}}}</li>
@ -16,7 +16,9 @@
{{/if}} {{/if}}
<li>{{{shortcuts.jump_to.drafts}}}</li> <li>{{{shortcuts.jump_to.drafts}}}</li>
</ul> </ul>
<h4>{{i18n 'keyboard_shortcuts_help.navigation.title'}}</h4> </section>
<section>
<h4>{{i18n "keyboard_shortcuts_help.navigation.title"}}</h4>
<ul> <ul>
<li>{{{shortcuts.navigation.back}}}</li> <li>{{{shortcuts.navigation.back}}}</li>
<li>{{{shortcuts.navigation.jump}}}</li> <li>{{{shortcuts.navigation.jump}}}</li>
@ -25,9 +27,11 @@
<li>{{{shortcuts.navigation.next_prev}}}</li> <li>{{{shortcuts.navigation.next_prev}}}</li>
<li>{{{shortcuts.navigation.go_to_unread_post}}}</li> <li>{{{shortcuts.navigation.go_to_unread_post}}}</li>
</ul> </ul>
</div> </section>
<div> </div>
<h4>{{i18n 'keyboard_shortcuts_help.application.title'}}</h4> <div class="column">
<section>
<h4>{{i18n "keyboard_shortcuts_help.application.title"}}</h4>
<ul> <ul>
<li>{{{shortcuts.application.hamburger_menu}}}</li> <li>{{{shortcuts.application.hamburger_menu}}}</li>
<li>{{{shortcuts.application.user_profile_menu}}}</li> <li>{{{shortcuts.application.user_profile_menu}}}</li>
@ -38,7 +42,9 @@
<li>{{{shortcuts.application.dismiss_topics}}}</li> <li>{{{shortcuts.application.dismiss_topics}}}</li>
<li>{{{shortcuts.application.log_out}}}</li> <li>{{{shortcuts.application.log_out}}}</li>
</ul> </ul>
<h4>{{i18n 'keyboard_shortcuts_help.composing.title'}}</h4> </section>
<section>
<h4>{{i18n "keyboard_shortcuts_help.composing.title"}}</h4>
<ul> <ul>
<li>{{{shortcuts.composing.return}}}</li> <li>{{{shortcuts.composing.return}}}</li>
<li>{{{shortcuts.composing.fullscreen}}}</li> <li>{{{shortcuts.composing.fullscreen}}}</li>
@ -48,9 +54,11 @@
<li>{{{shortcuts.actions.reply_post}}}</li> <li>{{{shortcuts.actions.reply_post}}}</li>
<li>{{{shortcuts.actions.quote_post}}}</li> <li>{{{shortcuts.actions.quote_post}}}</li>
</ul> </ul>
</div> </section>
<div> </div>
<h4>{{i18n 'keyboard_shortcuts_help.actions.title'}}</h4> <div class="column">
<section>
<h4>{{i18n "keyboard_shortcuts_help.actions.title"}}</h4>
<ul> <ul>
<li>{{{shortcuts.actions.bookmark_topic}}}</li> <li>{{{shortcuts.actions.bookmark_topic}}}</li>
<li>{{{shortcuts.actions.pin_unpin_topic}}}</li> <li>{{{shortcuts.actions.pin_unpin_topic}}}</li>
@ -69,6 +77,6 @@
<li>{{{shortcuts.actions.print}}}</li> <li>{{{shortcuts.actions.print}}}</li>
<li>{{{shortcuts.actions.topic_admin_actions}}}</li> <li>{{{shortcuts.actions.topic_admin_actions}}}</li>
</ul> </ul>
</div> </section>
</div> </div>
{{/d-modal-body}} {{/d-modal-body}}

View File

@ -597,13 +597,11 @@ pre {
} }
kbd { kbd {
background-color: $secondary;
border: 1px solid $primary-low;
border-radius: 3px; border-radius: 3px;
box-shadow: shadow("kbd"); box-shadow: shadow("kbd");
background: dark-light-choose(#fafafa, #333); background: dark-light-choose(#fafafa, #303030);
border: 1px solid dark-light-choose(#ccc, #555); border: 1px solid dark-light-choose(#d0d0d0, #505050);
border-bottom: medium none dark-light-choose(#fff, #000); border-bottom: none;
color: $primary; color: $primary;
display: inline-block; display: inline-block;

View File

@ -26,29 +26,54 @@
max-height: 560px; max-height: 560px;
} }
.keyboard-shortcuts-modal .modal-inner-container {
max-width: 880px;
}
#keyboard-shortcuts-help { #keyboard-shortcuts-help {
div.row { display: flex;
width: 100%;
div { .column {
float: left; width: 33.3%;
width: 32%;
}
} }
ul { ul {
list-style: none; list-style: none;
margin-bottom: 2rem;
margin-left: 0; margin-left: 0;
li { li {
margin: 5px 0; align-items: center;
display: flex;
flex-wrap: wrap;
margin-bottom: 6px;
}
span {
background: #f2f2f2;
border-radius: 3px;
display: inline-flex;
margin: 0 6px;
padding: 1px 0 5px;
}
span:first-child {
margin-left: 0;
} }
kbd { kbd {
font-size: $base-font-size; align-items: center;
box-sizing: border-box;
color: dark-light-choose(#333, #aaa);
display: inline-flex;
font-family: $base-font-family; font-family: $base-font-family;
margin: 0;
color: dark-light-choose(#444, #aaa);
font-weight: bold; font-weight: bold;
padding: 2px 6px; height: 24px;
justify-content: center;
margin: 0 3px;
min-width: 24px;
padding: 0 6px;
vertical-align: bottom;
white-space: nowrap; white-space: nowrap;
} }
} }