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

storybook-addon-keys

v1.1.4

Published

Display keyboard presses in Storybook

Downloads

7

Readme

Logo

Storybook Addon Keys

Display keyboard presses in Storybook. Demo

Installation

npm i storybook-addon-keys --save

Setup

Load the addon into Storybook like so:

// .storybook/main.(js|ts)
module.exports = {
  addons: ['storybook-addon-keys'],
};

Configuration

Different parameters are available for use in configuring the way keys appear.

| Parameter | Description | Options | Default | | --------- | ----------- | ------- | ------- | | theme | The visual theme used when displaying the keys | light, dark, false (uses Storybook theme) | false | | position | Where to display the keys | top-right, top-left, bottom-right, bottom-left| top-right | | size | The size of the keys | small, medium, large | medium | | duration | The length of time in milliseconds to display the keys for | number | 800 | | keyMap | The mapping of the keys to their displayed value | Configuring key map | Default key map |

Modifying Parameters

You can modify the parameters using the 'keys' property.

// .storybook/preview.(js|ts)
import { KeysConfig } from 'storybook-addon-keys';

const preview: Preview = {
    parameters: {
        keys: <KeysConfig>{
            theme: 'dark',
            position: 'bottom-right',
            size: 'large',
            duration: 1000,
            keyMap: false,
        },
    }
}

See Storybook Parameters for a more detailed explanation on how to use parameters.

Configuring Key Map

Keys are mapped from KeyboardEvent.Key to their display value. It can be useful to configure this setting if your app has hot keys you want to label.

For example if I wanted to map the key 'Enter' to 'Accept' I can supply the following.

keys: {
  ...
  keyMap: {
    'Enter': 'Accept',
  }
}

Any changes to key maps will override the default mapping, see below on how to maintain the original key maps while adding in your own. If 'false' is supplied as a key map then the keys will display as they're recieved in the event.

Default Key Map

The default key map is as follows. If you want to use this map alongside your own mapped keys then copy it into your Storybook parameters and append your own keys.

keys: {
  ...
  keyMap: {
    ' ': 'Space',
    'Enter': ' ↵ ',
    'ArrowUp': ' ↑ ',
    'ArrowDown': ' ↓ ',
    'ArrowLeft': ' ← ',
    'ArrowRight': ' → ',
    'Escape': 'Esc',
    'Backspace': ' ⌫ ',
    'Tab': ' ⇥ ',
    'Shift': ' ⇧ ',
    'Control': 'Ctrl',
    'Meta': ' ⊞ ',
  }
}

Usage

Toggle the keys with the tool button provided. Assuming you haven't overriden the theme, the addon will automatically use your preferred Storybook theme.