Comments (6)
I like to learn more about this. Is that showing the same stories but with some different profiles (like CSS stuff and so on).
I also want know about what we can do when we select a profile. How the components in the story get to know about this.
from storybook.
Say I was building an app that provided a displayDensity
setting for the user with options for "Comfortable", "Cozy" or "Compact (like Gmail). This is a global setting, and most/many components would render differently based on the setting. Rather than add duplicate stories in React Storybook for each displayDensity
setting, it would be ideal to make that choice once, and have all stories reflect the updated value.
To give a loose proposal for how this could be implemented, in the example above I would add a configuration object to the configure()
method call in config.js
, like this:
// .storybook/config.js
import { configure } from '@kadira/storybook';
function loadStories() {
require('../components/stories/button');
// require as many stories as you need.
}
configure(loadStories, {
contexts: [
{label: 'Comfortable', values: {displayDensity: 'comfortable'}},
{label: 'Cozy', values: {displayDensity: 'cozy'}},
{label: 'Compact', values: {displayDensity: 'compact'}},
],
}, module);
And then in the stories themselves, you would get passed a context
object that you can use however you see fit:
// components/stories/button.js
import React from 'react';
import { storiesOf, action } from '@kadira/storybook';
storiesOf('Button', module)
.add('with text', ({context}) => (
<button displayDensity={context.displayDensity} onClick={action('clicked')}>
My First Button
</button>
))
.add('with no text', ({context}) => (
<button displayDensity={context.displayDensity}></button>
));
Then in the UI there could be a simple drop down to choose your context, with the first one in the list always being the default.
from storybook.
dark layout +1
from storybook.
@isuvorov Could you submit a new issue about the Dark Layout.
I hope this is something else.
from storybook.
#1209 I'm going to take this idea and give it thought when implementing api-v2
from storybook.
Is this possible to achieve in any way ?
Could be good for something like theme (light dark)
from storybook.
Related Issues (20)
- [Bug]: `csf-plugin` fails to read stories with names not matching hardcoded regex
- [Bug]: findBy* not working properly in story steps (Angular 17)
- [Bug]: `options: any[]` in argTypes is not sufficient HOT 7
- [Bug]: jsxDEV is not a function on production build with @storybook/react-vite 8.0.7
- [Bug]: viteConfigPath has wrong types.
- [Bug]: Custom .mdx stories not showing code snippet anymore
- [Documentation]: Configure the testing framework for portable stories (With Jest)
- [Bug]: Error installing 7.6.18 HOT 6
- [Bug]: Inconsistent action log when action argument is falsy
- [Bug]: The modulesCount cache is writing to disk too much
- [Bug]: error npm install @storybook/[email protected] HOT 1
- [Bug]: Can not install @storybook/node-logger on yarn v3,v4 HOT 4
- [Bug]: toHaveBeenCalledWith does not display expected / received values on failure HOT 1
- [Bug]: Storybook and Radix-vue memory leak
- [Bug]: Can't use enum from external file HOT 1
- [Bug]: can't pass tags array to CSF default export when is generated from a function (v7 AND v8)
- [Bug]: Storybook-build failing on Angular 17
- [Bug]: auto docs doesn't build in static-storybook 8
- [Bug]: chrome / VS Code debugger not working correctly with Storybook 8 (Vite / React) HOT 1
- [Bug]: `@storybook/test` breaks react-native storybook HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from storybook.