1 | import * as React from 'react';
|
2 | import ShortcutManager from '../ShortcutManager';
|
3 |
|
4 | export interface Context {
|
5 | shortcutManager?: ShortcutManager;
|
6 | }
|
7 |
|
8 | export interface Props {
|
9 | children?: React.ReactNode;
|
10 | }
|
11 |
|
12 | export const {Provider, Consumer} = React.createContext<Context>({});
|
13 |
|
14 | export default class ShortcutProvider extends React.Component<Props, never> {
|
15 | private shortcutManager = new ShortcutManager();
|
16 |
|
17 | componentDidMount() {
|
18 | this.shortcutManager.setup();
|
19 | }
|
20 |
|
21 | render() {
|
22 | const context: Context = {
|
23 | shortcutManager: this.shortcutManager,
|
24 | };
|
25 |
|
26 | return <Provider value={context}>{this.props.children}</Provider>;
|
27 | }
|
28 | }
|