Skip to content

Commit

Permalink
Merge pull request #66 from wittlock/master
Browse files Browse the repository at this point in the history
Configuration for Esc-to-close cheat sheet help
  • Loading branch information
brtnshrdr authored Feb 13, 2018
2 parents 68a58b6 + 9302c1c commit c00c281
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ Based off of the [angular-hotkeys library](https://github.com/chieffancypants/an
To enable the cheat sheet, simply add `<hotkeys-cheatsheet></hotkeys-cheatsheet>` to your top level component template.
The `HotkeysService` will automatically register the `?` key combo to toggle the cheat sheet.

**NB!** Only hotkeys that have a description will apear on the cheat sheet. The Hotkey constructor takes a description as
an optional fourth parameter as a string or optionally as a function for dynamic descriptions.

```typescript
this._hotkeysService.add(new Hotkey('meta+shift+g', (event: KeyboardEvent): boolean => {
console.log('Secret message');
return false;
}, undefined, 'Send a secret message to the console.'));
```

The third parameter, given as `undefined`, can be used to allow the Hotkey to fire in INPUT, SELECT or TEXTAREA tags.

### Cheat Sheet Customization

1. You can now pass in custom options in `HotkeysModule.forRoot(options: IHotkeyOptions)`.
Expand All @@ -83,6 +95,10 @@ export interface IHotkeyOptions {
* Use also ESC for closing the cheat sheet. Default: false
*/
cheatSheetCloseEsc?: boolean;
/**
* Description for the ESC key for closing the cheat sheet (if enabed). Default: 'Hide this help menu'
*/
cheatSheetCloseEscDescription?: string;
/**
* Description for the cheat sheet hot key in the cheat sheet. Default: 'Show / hide this help menu'
*/
Expand Down
4 changes: 4 additions & 0 deletions src/hotkey.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface IHotkeyOptions {
* Use also ESC for closing the cheat sheet. Default: false
*/
cheatSheetCloseEsc?: boolean;
/**
* Description for the ESC key for closing the cheat sheet (if enabed). Default: 'Hide this help menu'
*/
cheatSheetCloseEscDescription?: string;
/**
* Description for the cheat sheet hot key in the cheat sheet. Default: 'Show / hide this help menu'
*/
Expand Down
2 changes: 1 addition & 1 deletion src/hotkeys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class HotkeysService {
this.cheatSheetToggle.next(false);
}.bind(this),
['HOTKEYS-CHEATSHEET'],
'Hide this help menu',
this.options.cheatSheetCloseEscDescription || 'Hide this help menu',
));
}

Expand Down

0 comments on commit c00c281

Please sign in to comment.