forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Hotkeys * Making it work in AceEditor * Addressing comments
- Loading branch information
1 parent
af71fb5
commit 1a3fe58
Showing
4 changed files
with
118 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { OverlayTrigger, Popover } from 'react-bootstrap'; | ||
import { Table } from 'reactable'; | ||
|
||
import Mousetrap from 'mousetrap'; | ||
|
||
const propTypes = { | ||
hotkeys: PropTypes.arrayOf(PropTypes.shape({ | ||
key: PropTypes.string.isRequired, | ||
descr: PropTypes.string.isRequired, | ||
func: PropTypes.func.isRequired, | ||
})).isRequired, | ||
header: PropTypes.string, | ||
}; | ||
|
||
const defaultProps = { | ||
hotkeys: [], | ||
}; | ||
|
||
export default class Hotkeys extends React.PureComponent { | ||
componentDidMount() { | ||
this.props.hotkeys.forEach((keyConfig) => { | ||
Mousetrap.bind([keyConfig.key], keyConfig.func); | ||
}); | ||
} | ||
renderPopover() { | ||
return ( | ||
<Popover id="popover-hotkeys" title={this.props.header} style={{ width: '300px' }}> | ||
<Table | ||
className="table table-condensed" | ||
data={this.props.hotkeys.map(keyConfig => ({ | ||
Key: keyConfig.key, | ||
Action: keyConfig.descr, | ||
}))} | ||
/> | ||
</Popover>); | ||
} | ||
render() { | ||
return ( | ||
<OverlayTrigger | ||
overlay={this.renderPopover()} | ||
trigger={['hover', 'focus']} | ||
placement="top" | ||
> | ||
<i className="fa fa-keyboard-o fa-lg" /> | ||
</OverlayTrigger> | ||
); | ||
} | ||
} | ||
|
||
Hotkeys.propTypes = propTypes; | ||
Hotkeys.defaultProps = defaultProps; |