An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# react-konamikey [![CircleCI](https://circleci.com/gh/moimikey/react-konamikey/tree/master.svg?style=svg)](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