npm: possibly marvellous

    react-konamikey

    1.0.3 • Public • Published

    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

    Install

    npm i react-konamikey

    DownloadsWeekly Downloads

    3

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    236 kB

    Total Files

    32

    Last publish

    Collaborators

    • moimikey