npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

piano-keys-webcomponent-v0

v1.0.3

Published

[![image of piano keys](images/preview.png)](https://crswty.github.io/piano-keys-webcomponent/)

Downloads

373

Readme

Piano Keys Web Component

image of piano keys

Overview

Piano Keys is a web component that renders a piano keyboard layout. It aims to be as flexible as possible, some of the things you can do with it are:

  • Render any number of keys and any keyboard layout
  • Programmatically trigger note up/down effects
  • Click on a key to 'play' it
  • Customize the component's look and feel

The keyboard is rendered as SVG so scales to work well at any size.

Examples

Refer to the full Examples & code samples to see the full range of what's possible.

Setup in HTML

To set up, all you need to do is import the script, you can then use the piano-keys tag

<script src="https://unpkg.com/[email protected]/dist/index.umd.min.js"></script>  
<piano-keys layout="C" keys=61></piano-keys>

Setup with NPM

To use with NPM simply add the module and then import it, you will then be able to use the component in your app.

# Install with yarn
yarn add piano-keys-webcomponent-v0

# Install with npm
npm install piano-keys-webcomponent-v0
import "piano-keys-webcomponent-v0";
<piano-keys layout="C" keys=61></piano-keys>

Typescript support

If you're using typescript and want to call methods on the component, you can import the PianoElement interface and use it like so:

import {PianoElement} from "piano-keys-webcomponent-v0/dist/piano";
const piano = document.getElementById("piano") as PianoElement;
piano.setNoteDown("C", 4)

Configuration Options

The component supports the following HTML attributes

| Attribute | Default | Description | ---------------- | --------- | ----------- | key-count | 88 | Number of keys to render. | keyboard-layout | A | Note to start rendering from | read-only | off | Set attribute to disable clicking on notes

Events

The component omits the following custom events

| Attribute | Detail | Description | ---------------- | ---------------------------- | ----------- | note-down | note: string, octave: number | Key received mousedown event | note-up | note: string, octave: number | Key received mouseup event

Methods

These methods are available after to call programmatically, i.e.

document.getElementById("piano").setNoteDown("C", 4);

setNoteDown

Sets the state of the note to pressed or not

setNoteDown(note: string, octave: number)

setNoteUp

Sets the state of the note to not be pressed

setNoteUp(note: string, octave: number)

Styling

Styling can be overridden with CSS variables, simply apply them to the component like so:

piano-keys {
    --natural-key-color: blue
}

| Variable | Description | ---------------------------- | ----------- | --natural-key-color | Fill color of the natural keys | --natural-key-outline-color | Border color of the natural keys | --sharp-key-color | Fill color of the sharp keys | --sharp-key-outline-color | Border color of the sharp keys | --depressed-key-color | Color of keys when they are pressed | --depressed-key-transform | Transformation to run when key is pressed