Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bluealba/with-state

Package Overview
Dependencies
Maintainers
4
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bluealba/with-state

Wrapper around @dump247/storybook-state to be used as an storybook decorator

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

@bluealba/withState

This is a wrapper around @dump247/storybook-state designed to be used as an storybook decorator. This is a VERY small and rather hacky util.

Install

You can install it with npm using

npm install @bluealba/withState

Usage

Just add withState decorator using storybook's addDecorator function

import React from "react";
import { storiesOf } from "@storybook/react";
import { withState } from "@bluealba/withState";
import { Checkbox } from "./Checkbox";

storiesOf("Checkbox", module)

	.addDecorator(withState({ isSelected: false }))

	.add("An ordinary unmanaged component", ({store}) => (
		<Checkbox
			className="checkbox size-check"
			isSelected={store.state.isSelected}
			onChange={() => {
				store.set({ isSelected: !store.state.isSelected });
			}}
		/>
	))

withState function receives as very first parameter the initial state that will be used for all the stories that don't provide an initial state.

Specifying the intial state

Stories can overwrite the initialState value through their story parameters

withState function receives as very first parameter the initial state that will be used for any story that doesn't specify it. Stories can overwrite such value through their parameters:

storiesOf("Checkbox", module)

	.addDecorator(withState({ isSelected: false }))

	.add("An ordinary unmanaged component, checked by default", ({store}) => (
		<Checkbox
			className="checkbox size-check"
			isSelected={store.state.isSelected}
			onChange={() => {
				store.set({ isSelected: !store.state.isSelected });
			}}
		/>
	), { initialState: { isSelected: true } })

Combining with other decorators

Since original @dump247/storybook-state HOC object is added later we are now able to combine this decorator with others that rely on component introspection. In other words, this now works perfectly:

import React from "react";
import { storiesOf } from "@storybook/react";
import { withState } from "@bluealba/withState";
import { withInfo } from "@storybook/addon-info";
import { Checkbox } from "./Checkbox";

storiesOf("Checkbox", module)

	.addDecorator(withInfo(""))
	.addDecorator(withState({ isSelected: false }))

	.add("An ordinary unmanaged component", ({store}) => (
		<Checkbox
			className="checkbox size-check"
			isSelected={store.state.isSelected}
			onChange={() => {
				store.set({ isSelected: !store.state.isSelected });
			}}
		/>
	))

FAQs

Package last updated on 28 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc