Skip to content

Instantly share code, notes, and snippets.

@subvertallchris
Created August 22, 2017 19:53
Show Gist options
  • Save subvertallchris/b1d6101a2e50c3514664b582237f5142 to your computer and use it in GitHub Desktop.
Save subvertallchris/b1d6101a2e50c3514664b582237f5142 to your computer and use it in GitHub Desktop.
TypeScript defs for avocode/react-shortcuts
// Type definitions for react-shortcuts v1.6.0
// Project: https://github.com/avocode/react-shortcuts
// Definitions by: Chris Grigg <https://github.com/subvertallchris>
/// <reference types="react"/>
declare namespace ReactShortcuts {
type PlatformType = 'osx' | 'windows' | 'linux' | 'other';
interface Keymap {
[namespace: string]: KeyboardShortcut;
}
interface KeyboardShortcut {
[action: string]: string | string[] | PlatformKeymap;
}
interface PlatformKeymap {
osx?: string | string[];
windows?: string | string[];
linux?: string | string[];
other?: string | string[];
}
class ShortcutManager {
constructor(keymap: Keymap);
addUpdateListener: (callback: () => any) => void;
removeUpdateListener: (callback: () => any) => void;
_parseShortcutDescriptor: (item: any) => item | string;
setKeymap: (keymap: Keymap) => void;
extendKeymap: (keymap: Keymap) => void;
getAllShortcuts: () => any;
getAllShortcutsForPlatform: (platformName: PlatformType) => any;
getAllShortcutsForCurrentPlatform: () => any;
getShortcuts: (componentName: string) => any | undefined;
_parseShortcutKeyName: (obj: any, keyName: string) => any | undefined;;
findShortcutName: (keyName: string, componentName: string) => any | undefined;
}
class Shortcuts extends React.Component<ShortcutsProps, object> {};
interface ShortcutsProps {
handler: (action: keyof Keymap, e: KeyboardEvent) => void;
name: string;
tabIndex?: number;
eventType?: string;
stopPropagation?: boolean;
preventDefault?: boolean;
targetNodeSelector?: string;
global?: boolean;
isolate?: boolean;
alwaysFireHandler?: boolean;
}
}
declare module 'react-shortcuts' {
import ReactSc = ReactShortcuts;
export = ReactSc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment