0.0.15 • Published 3 years ago

custom-piano-keys v0.0.15

Weekly downloads
9
License
MIT
Repository
github
Last release
3 years ago

Published on webcomponents.org npm version minified minified & zipped

custom-piano-keys

A web component for creating custom HTML elements that depict piano keys.

2 live demos available here and here

Screenshot

Features

Custom-piano-keys is a stand-alone vanilla JS web component that does not use shadow DOM.

Following component attributes are configurable:

  • element height
  • octave width
  • number of octaves
  • stroke width
  • black key height and width
  • marked keys
  • mark color, shape, diameter and shift

Including the component to an HTML file

  1. Import polyfill, this is not needed for modern browsers:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/custom-elements/1.3.2/custom-elements.min.js"></script>
  2. Import custom element:

    <script defer src='custom-piano-keys.min.js'></script>
  3. Start using it!

    <custom-piano-keys> </custom-piano-keys>

Including the component from NPM

  1. Install and import polyfill, this is not needed for modern browsers:

    See https://www.npmjs.com/package/@webcomponents/custom-elements

  2. Install custom-piano-keys NPM package:

    npm i custom-piano-keys
  3. Import custom element:

    import 'custom-piano-keys'
  4. Start using it:

    var pianokeys = document.createElement("custom-piano-keys")
    pianokeys.setAttribute("marked-keys", "1 5 8")
    document.body.appendChild(pianokeys)

Attributes

NameTypeDescriptionUnit / ValuesDefault value
oct-countNumberNumber of octavesZero or positive integer1
heightNumberElement heightElement height in pixels100
oct-w-factorNumberOctave width factorFactor producing the width from element height1.5
stroke-wNumberStroke width0 - 100 percents of element height2
b-key-hNumberBlack key height0 - 100 percents of element height60
b-key-wNumberBlack key width0 - 100 percents of white key width50
marked-keysStringMarked keysSpace separated list of integers*N/A
mark-colorString/HexMark colorColor keyword / 3 digit hex / 6 digit hex**red
mark-shapeStringMark shapecircle / rectcircle
mark-diameterNumberMark diameter0 - 100 percents of white key width40
b-key-mark-shiftNumberBlack key mark shift1 - 100 percents of black key height50
w-key-mark-shiftNumberWhite key mark shift1 - 100 percents of the white key stub height50

*Valid values for marked-keys are integers from 1 to 96. Setting a new value will remove the previous marks.

**Setting color to black will display black marks on white keys and white marks on black keys

Methods

Keys can be marked directly by calling the setMarkedKeys method of the custom element instance.

Method has a single argument: an array of integers. Valid values in the array are integers from 1 to 96.

Marks can be removed by providing an empty array as an argument.

Keys can also be marked by setting the marked-keys attribute value. Using setMarkedKeys method is an alternative way to set marks on keys by using an array instead of string.

Usage example:

var pianokeys = document.createElement("custom-piano-keys")
pianokeys.setMarkedKeys([1,5,8])
document.body.appendChild(pianokeys)

Removing the marks:

pianokeys.setMarkedKeys([])

License

Copyright (c) 2019 Jussi Utunen

Licensed under the MIT License

0.0.15

3 years ago

0.0.14

4 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago