
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@bluealba/with-state
Advanced tools
Wrapper around @dump247/storybook-state to be used as an storybook decorator
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.
You can install it with npm
using
npm install @bluealba/withState
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.
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 } })
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
Wrapper around @dump247/storybook-state to be used as an storybook decorator
The npm package @bluealba/with-state receives a total of 0 weekly downloads. As such, @bluealba/with-state popularity was classified as not popular.
We found that @bluealba/with-state demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.