https://github.com/moimikey/react-konamikey
💅🏻 trigger a callback function on anything with a sequence of key presses
https://github.com/moimikey/react-konamikey
keypress konami konamicode react react-component react-components
Last synced: 20 days ago
JSON representation
💅🏻 trigger a callback function on anything with a sequence of key presses
- Host: GitHub
- URL: https://github.com/moimikey/react-konamikey
- Owner: moimikey
- License: mit
- Created: 2017-12-22T20:41:37.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-10-25T22:06:11.000Z (over 1 year ago)
- Last Synced: 2024-10-31T17:56:04.513Z (7 months ago)
- Topics: keypress, konami, konamicode, react, react-component, react-components
- Language: JavaScript
- Size: 480 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-konamikey [](https://circleci.com/gh/moimikey/react-konamikey/tree/master)
Trigger a callback function on anything with a sequence of key presses.
## Install
```bash
# requires react@>=16
yarn add react-konamikey
```## Usage
```jsx
import * as React from 'react'
import Konami from 'react-konamikey'
// const Konami = require('react-konamikey').default
```### attach to an element (using `refFn`)
```jsx
(
)}
payload={() => console.log('KONAMI!!!')}
sequence={['g', 'a', 'm', 'm', 'a']}
/>
```### attach to `document`
```jsx
console.log('KONAMI!!!')}
sequence={['a', 'b', 'c']}
>
hello world```
### live example
https://codesandbox.io/s/blissful-pare-c7hvb
## Props
### element
Type: _HTMLElement_ | _Function_
An HTMLElement, document, or function to attach `keydown` event handlers to.
### payload
Type: _Function_
A payload function to execute, once the Konami sequence has been fulfilled.
### sequence
Type: _Array [required]_
An array of strings representing key names.
## License
MIT