operational-ui icon indicating copy to clipboard operation
operational-ui copied to clipboard

Shortcuts manager component

Open fabien0102 opened this issue 6 years ago • 1 comments

Summary

I would like to have a great component that can deal with application shortcuts as GitHub

image

API proposal

interface ApplicationShortcutProps {
  keyMap: Array<{
    /**
     * Category of the shortcut (for help documentation)
     */
    category?: string;
    /**
     * Name of the shortcut
     */
    name: string;
    /**
     * Sequence of keys to activate the shortcut
     * @example "esc", "g e", ["del", "backspace"]
     */
    sequence: string | string[];
    description: React.ReactNode;
    handler: () => void
  }>
  /**
   * Key sequence to open the help modal
   * @default: `?`
   */
  helpSequence?: string
  helpTitle: React.ReactNode
}

Usage

<ApplicationShortcut
  keyMap={[
    {
      category: "Bundle",
      name: "Go to Editor",
      sequence: "g e",
      description: <FormattedMessage id="shortcut.goToEditor" />,
      handler: () => pushState("/bundles/:id/editor")
    }
    /* ... */
  ]}
  helpTitle={<FormattedMessage id="shortcut.title" />}
/>;

The help modal will be managed by operational modal.

External lib to considered

https://github.com/greena13/react-hotkeys

fabien0102 avatar Nov 16 '18 13:11 fabien0102