1.0.2 • Published 5 years ago

xylophone-react v1.0.2

Weekly downloads
149
License
ISC
Repository
github
Last release
5 years ago

Xylophone

A React based xylophone ready to use out of the box

Install

Your app must be using React and ReactDom.

$ npm install xylophone-react

Usage

import Xylophone from 'xylophone-react';

return <Xylophone />;

Props

PropDefaultValuesTypeDescription
numberOfKeys81 - ∞numberThe number of keys
colors8No limits{color?: string, colorPressed?: string, background?: string}[]The color scheme of all keys
shapeshrinkingshrinking, growing, flatstringThe shape of the whole xylophone
height2001 - ∞numberThe height of the smallest key (px)
widthStretch to fit container1 - ∞numberThe width of all keys (px)
startingOctave21 - ∞numberThe starting octave of the first key
pressedKeyNoneNone(number) => voidReturns which key was pressed most recently

Props in detail

numberOfKeys:

12 colors have been set by default. In order to increase the numberOfKeys over 12, you need to create your own custom color scheme.

colors:

colors will use the last element to paint all remaining keys. For example,

colors={[
  {
    color: 'pink',
    colorPressed: 'grey',
    background: 'salmon'
  },
  {
    color: 'teal'
  }
]}

only the first key will be pink, and the remaining will be teal.

This allows you to avoid duplication for colors that are the same for each key.

pressedKey:

pressedKey allows you to pass in a function which can be used to determine which key was pressed most recently.

constructor(props) {
  super(props);
  this.state = { pressedKey: 0 };
  this.setPressedKey = this.setPressedKey.bind(this);
}

...

<Xylophone
  pressedKey={this.setPressedKey}
/>

...

setPressedKey(key) {
  this.setState({pressedKey: key})
}

Develop

All changes should be made within the ./components folder.

After making changes, run yarn build. This command will compile the files to ES5, convert Sass to CSS, and update any Sass imports.

To test that your changes worked, install this project into a React app using npm install path/to/this/folder and render the <Xylophone /> component.

Feedback

Feel free to open an issue with feedback or a feature request. All are welcome 🤗!

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago