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

v0.7.8

Published

React Storybook Addon Development Kit

Downloads

20

Readme

React Storybook Addon Development Kit

Based on React Komposer and Podda addon core which solves the problem of communication between addons panel side and decorators side. It provides an ability to create story decorators controlled from the addon panel.

Since it's in the early stages some things could be changed

Features 💫

1 Keeps synchronous store on both sides: addon panel and decorator

2 Easy to create own components subscribed to addon's store

3 Each decorator has own store instance and init settings, the panel reflects an active decorator

4 Decorators keep the store during Hot Module Replacement

5 Possible to set api, default store data and React Components to decorators and panel

6 Story decorators can override the global ones. So it's possible to use them together

Install

if you building own Storybook addon:

npm i storybook-adk --save

if just using Storybook as a development tool:

npm i storybook-adk --save-dev

Usage

soon

Contribution guide:

git clone https://github.com/sm-react/storybook-adk.git
cd storybook-adk
yarn
yarn start

when it outputs like:

React Storybook started on => http://localhost:9001/

webpack built f2e66101efa945043d60 in 21615ms

open http://localhost:9001/

Store and channel

src/store/store.js

We using Podda as a simple data store. Panel and decorators need to use a channel for communication. Any changes of store are sent via channel, that's why both stores always synchronized. Root components (of panel or decorators) subscribe to store changes so they shows an actual data. Each side can initiate the connection at any time, but only one (the last) connection is enabled. That's why we can select another Story kind with own decorator which initiate a new connection when componentWillMount so panel will follow it. When a decorator componentWillUnmount, it stops the channel communication and panel reflects it. This principle works even when we use nested decorators: the innder decorator will override the global one.

Decorators

src/store/decorator.js

We pass initData to decorators when create them and keep decorator's store in module closure (own for each Story kind). So it's availible after HMR. The decorator root component solves all tasks about channel interaction and enabling/disabling nested decorators. It will render the addon decorator component as a child which you can pass in oder to customize your own decorator.

Composer

src/store/composer.js

Here we use React Komposer to subscribe to store changes. It allows the root component src/store/container.js (Panel and decorator) to keep the actual state of current store. We pass some API to this component from store.

Container

src/store/container.js

It's a root component using both for panel and decorator. It takes props from composer src/store/composer.js. Wraps and reders custom addon component.

API

src/store/api.js

It's possible to add an API to interact with the addon store. API function takes a poddaStore as a first argument and any number custom arguments. E.g.

setLabel(poddaStore, name, ind) {
    poddaStore.update(state => ({ index: ind, label: name }));
}

To use it in your component you need to pass it via composer:

function dataLoader(props, onData, { addonStore, apiMap }) {

    const sendData = (storeData) => {
        const propsToChild = {
            label: storeData.label,
            index: storeData.index,
            onLabel: apiMap.setLabel, 
        };
        onData(null, propsToChild);
    };

    const stopSubscription = addonStore.subscribe(sendData);

    sendData(addonStore.getAll());

    return stopSubscription;
}

then you can use it this way:

const { label, index, onLabel } = props;
return (
<div>
    <p>Label: <i>{label}</i>, Index: <i>{index}</i></p>
    <button onClick={onLabel('Alpha', 28)}>Alpha</button>
</div>);

Addon Composer

src/store/addonComposer.js

Allows to create custom addon components subscribed to the store. It's under development now


🙋 any contributions will be appreciated! 🎆🎆🎆

Credits

Created in smARTLight by UsulPro

Scaffolded by Storybook Boilerplate Project