1.1.0 • Published 6 years ago

@drookyn/react-easteregg v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

react-easteregg

Installation

with npm:

npm install --save @drookyn/react-easteregg

with yarn:

yarn add @drookyn/react-easteregg

Basic Usage

Just import the component and you are good to go. The default used sequence is the konami code ↑↑↓↓←→←→ba.

import EasterEgg from 'react-easteregg';

// ...

render() {
  return (
    <EasterEgg>
      <span>It works!</span>
    </EasterEgg>
  );
}

// ...

Advanced Usage

import EasterEgg, { strToSequence } from 'react-easteregg';

// ...

state = { disabled: false };

disableEasterEgg = () => {
  this.setState(() => ({ disabled: true }));
}

itWorks() {
  alert('It works!');
}

render() {
  const { disabled } = this.state;
  const sequence = strToSequence('myCustomSequence');

  return (
    <EasterEgg
      sequence={sequence}
      callback={this.itWorks}
      disabled={disabled}
    >
      <span onClick={this.disableEasterEgg}>It works!</span>
    </EasterEgg>
  );
}

// ...

Props

KeyValueDefaultRequiredDescription
sequencearray38, 38, 40, 40, 37, 39, 37, 39, 66, 65NoAn array of integer representing the sequence of keyCodes to listen to
childrennodenullNoA component to render when the user successfully entered the code
disablebooleanfalseNoA boolean to hide the easter egg
targetstring|nodewindowNoA string (window|document) or node to bind the keyUp listener to
timeoutnumbernullNoA number representing the milliseconds after the easter egg will resets itself
onShowfunctionnullNoA callback triggered when the user successfully entered the code
onResetfunctionnullNoA callback triggered after the easter egg was reset
onDisablefunctionnullNoA callback triggered after the easter egg was disabled
callback (deprecated)functionnullNoA callback triggered when the user successfully entered the code

Props passed to child

KeyValueDescription
resetEasterEggfunctionResets the easter egg
disableEasterEggfunctionDisables the easter egg

Dependencies

This project uses react-event-listener to bind event listeners.

Code Style

100% airbnb javascript (react) styleguide

Commands

  • Test the component and helper functions

    npm test
  • Test the component and helper functions (with coverage)

    npm run test:coverage

License

MIT