1.1.1 • Published 2 years ago

react-music-keyboard v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-music-keyboard

A simple easy-to-use and highly customizable React component emulating a musical keyboard.

Check out a live demo here: Demo!


Installation

npm i react-music-keyboard

OR

yarn add react-music-keyboard

Usage

import React from 'react'
import { Keyboard } from 'react-music-keyboard'
<Keyboard />

Props

PropsTypeDefaultDescription
heightnumber180The height of the keyboard in pixels.
whiteKeyWidthnumber50The width of each white key in pixels.
blackKeyWidthnumber20The width of each black key in pixels. Must not be greater than the width of a white key.
keySpacingnumber5The space between each white key in pixels.
startNotestring"C2"The starting note: name + octave. Note that black keys use sharps, e.g. F#4 instead of Gb6.
endNotestring"A4"The ending note. Same format as the starting note. Must be higher than the starting note.
soundbooleantrueWhether to play a sound when a key is pressed.
durationnumber0.5The duration of the sound in secounds.
onKeyPressfunction(key) => {}Function to execute when key is pressed. The key name is passed as the argument.
borderRadiusnumber15Border radius of the keys
whiteKeyColorstring (HEX color code)"#fff"Fill color of the white keys.
blackKeyColorstring (HEX color code)#000"Fill color of the black keys.
transitionnumber100Transition speed between hover animation in milliseconds.
whiteKeyStylesobject{}Additional styles applied to white keys.
blackKeyStylesobject{}Additional styles applied to black keys.
containerStylesobject{}Additional styles applied to the keyboard container.
whiteKeyClassstring""Additional classes applied to white keys.
blackKeyClassstring""Additional classes applied to black keys.
containerClassstring""Additional classes applied to the keyboard container.

Additional restrictions

  • All number props must be greater than 0.
  • Start and end notes must be white keys.
  • keySpacing must be between 1 and 10.

Using the additional classes

The additional classes are useful for non-JS styles, e.g. :hover.

Define the styles in a CSS file, and import it into your component file, but be sure to use the !important tag.

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago