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-fixtures

v0.12.0

Published

Add data fixtures to your components by using local data (JSON files or hardcoded) or even URLs to fetch the data from.

Downloads

2,100

Readme

storybook-fixtures

Add data fixtures to your components by using local data (JSON files or hardcoded) or even URLs to fetch the data from.

React examples Vue examples HTML examples

storybook-fixtures screenshot

Install

npm install -D storybook-fixtures

Add storybook-fixtures to your addons list in .storybook/main.js

module.exports = {
  addons: ['storybook-fixtures'],
};

A new 'Fixtures' panel will appear which contains fixture sections as sub tabs. Fixture sections contain fixture variants which can be toggled by clicking or keyboard shortcuts - keys 1 to 9 correspond to the first 9 variants.

Variants can also be switched in sequentially using Vim-style navigation keys: j and k to go up and down the variant list.

Section tabs can be switched using h and l to switch to left and right tab respectively.

Usage

Fixture definitions must contain fixture section name as key and variants as its properties.

import { withFixtures } from 'storybook-fixtures';
import pantheraData from '../__fixtures__/panthera.json';

// Global fixtures available in all stories for a given module
export default {
  title: 'storybook-fixtures',
  decorators: [
    withFixtures({
      // override the default setting and show single fixture tab
      __singleTab: true,
      // fixture sections
      collection: pantheraData,
    }),
  ],
};

// Currently selected fixture is injected in story context
export const myLocalFixture = ({ fixture }) => {
  return <MyComponent data={fixture} />;
};

// Fixtures that have strings as values are assumed remote URL and will be fetched
// when the story is selected.
export const myRemoteFixture = ({ fixture }) => {
  return <MyComponent data={fixture} />;
};
// Fixtures can be added per story via story parameters
myRemoteFixture.parameters = {
  fixtures: {
    // fixture sections (key is a tab label for multiple variant sets)
    variantTypes: {
      // variants (key is label)
      'Text fixture': 'Lorem ipsum',
      'Array fixture': ['One', 'Two'],
      'Object fixture': {
        title: 'Tiger',
        description: 'Largest species of the cat family',
      },
      'My remote fixture': 'https://example.com/data.json',
    },
  },
};

Variants can be grouped into sets and controlled independently. When only one set is defined the set tab is hidden.

Any selections are stored in local storage and any fixture selections can be opened in a new tab in isolation (without Storybook UI). The selection is encoded in a query string.

Each variant value can be a URL, in which case it'll be fetched, and the result returned as its value.

In Storybook v6 the add-on automatically includes the fixtures decorator globally. Just add storybook-fixtures to the addons array in main.js and any story can receive fixtures object using parameters static property (see above).

Fixture Settings

withFixtures decorator has special properties prefixed with double underscore. These properties can change certain behaviour of how fixtures are displayed.

  • __singleTab (defaults to false) - Fixtures are grouped into multiple tabs. Each key in the fixtures object is mapped to the tab. When there's only a single property in the fixture object the single tab is not shown by default.

Imports

withFixtures

Fixtures decorator which communicates with Storybook Fixtures panel and shows selected fixture variants.

keyBy

Export of Lodash utility to convert a collection (array of objects) to object, to grouped by a chosen key.