Giter Site home page Giter Site logo

moimikey / react-konamikey Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 492 KB

๐Ÿ’…๐Ÿป trigger a callback function on anything with a sequence of key presses

License: MIT License

JavaScript 100.00%
konamicode konami react react-components react-component keypress

react-konamikey's Introduction

react-konamikey CircleCI

Trigger a callback function on anything with a sequence of key presses.

Install

# requires react@>=16
yarn add react-konamikey

Usage

import * as React from 'react'
import Konami from 'react-konamikey'
// const Konami = require('react-konamikey').default

attach to an element (using refFn)

<Konami
  element={({ refFn }) => (
    <input type="text" placeholder="gamma" ref={refFn} />
  )}
  payload={() => console.log('KONAMI!!!')}
  sequence={['g', 'a', 'm', 'm', 'a']}
/>

attach to document

<Konami
  element={document}
  payload={() => console.log('KONAMI!!!')}
  sequence={['a', 'b', 'c']}
>
  <div>hello world</div>
</Konami>

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.