Comments (10)
Hmm, I think we could improve this by adding a toString on the action
returned function:
https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
from addon-jsx.
This is a quick util function I wrote.
import { action as _action } from '@storybook/addon-actions'
export const action = (...args) => {
const tempAction = _action(...args)
tempAction.toString = () => `action('${args[0]}')`
return tempAction
}
to use it just import the util function instead of the library function.
import { action } from './utils'
from addon-jsx.
Here's an example for quick workaround for the action
function:
const onClickAction = action('clicked');
onClickAction.toString = () => "action('clicked')";
storiesOf('Button', module)
.addWithJSX('default', () => <Button onClick={onClickAction}>Hello</Button>);
The output is
<Button onClick={action('clicked')}>
Hello
</Button>
from addon-jsx.
@ndelangen This has been around a bit and it would be handy to have this handled in the Storybook repo. Is there a corresponding issue or PR for this?
from addon-jsx.
A thing like this would have to be solved upstream via https://github.com/algolia/react-element-to-jsx-string/
from addon-jsx.
@hipstersmoothie Thanks, I'll see if this is something that they'd be interested in having addressed and try to contribute a solution if they'll take it.
from addon-jsx.
addon-actions can be handled in that way. But in my case, some defaultProps (like customizable renderer props) were printed as well. And it was soo dirty(bundled by webpack).
I will set toString in my functions.
from addon-jsx.
You can do something like this
addParameters({
jsx: {
functionValue: (fn: Function) => `${fn.name}()`
}
})
from addon-jsx.
This issue is pretty rough for render
props. For this story:
<ModalButton text={text("Button text", "Show Modal")} render={close => (
<div>
<h1>Testing w/ Render Props</h1>
<Button onClick={close}>Close</Button>
</div>
)} />
The JSX addon presents this:
<ModalButton
render={function render(close) {return react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", null, react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("h1", null, "Testing w/ Render Props"), react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(_buttons__WEBPACK_IMPORTED_MODULE_3__["Button"], {onClick: close}, "Close"));}}
text="Show Modal"
/>
Since the render props pattern is fairly common I would think that someone has solved this for their storybooks, but I'm pretty new to storybooks and at a bit of a loss as to where I should start.
from addon-jsx.
🚀 Issue was released in v7.3.1
🚀
from addon-jsx.
Related Issues (20)
- Docs are unclear HOT 1
- JSX formatting for component props HOT 2
- Actions show up as extra noise in JSX panel HOT 3
- Default Props are included in output HOT 1
- Allow JSX customization (boolean props, etc) HOT 2
- Is it possible to change the theme for a 'black' version ?
- Is it possible to change the theme for a 'black' version ?
- [Feature] Target content when used as a global decorator HOT 2
- [Bug] Copy Button Moves on Scroll HOT 2
- Is there an option to hide function implementation from props?
- [Bug] React 17 peer dependency HOT 4
- Skip not applied to Storybook Docs story source
- [Bug] Not enough children to skip elements for stories without children HOT 1
- [Bug] Not all constituents of type 'string | ClientApiReturnFn<StoryFnReactReturnType>' are callable. Type 'string' has no call signatures.
- [Bug] JSX tab remains visible when addon is disabled HOT 1
- [Bug] Addon not working correctly with Angular?
- [Bug] OnBeforeRender option has no effect whatsoever on Angular Storybook
- [Security] Critical Warnings on react-dev-utils that depends on immer
- [Bug] An issue when using addon-jsx globally
- [Improve] Upgrade to storybook 7 HOT 4
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 addon-jsx.