Giter Site home page Giter Site logo

Function in Props about addon-jsx HOT 10 CLOSED

storybookjs avatar storybookjs commented on August 24, 2024 3
Function in Props

from addon-jsx.

Comments (10)

ndelangen avatar ndelangen commented on August 24, 2024 9

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.

stramel avatar stramel commented on August 24, 2024 9

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.

apaatsio avatar apaatsio commented on August 24, 2024 1

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.

JasonTheAdams avatar JasonTheAdams commented on August 24, 2024 1

@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.

hipstersmoothie avatar hipstersmoothie commented on August 24, 2024 1

A thing like this would have to be solved upstream via https://github.com/algolia/react-element-to-jsx-string/

from addon-jsx.

keiththomps avatar keiththomps commented on August 24, 2024 1

@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.

FourwingsY avatar FourwingsY commented on August 24, 2024

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.

crimx avatar crimx commented on August 24, 2024

You can do something like this

addParameters({
  jsx: {
    functionValue: (fn: Function) => `${fn.name}()`
  }
})

from addon-jsx.

keiththomps avatar keiththomps commented on August 24, 2024

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.

hipstersmoothie avatar hipstersmoothie commented on August 24, 2024

🚀 Issue was released in v7.3.1 🚀

from addon-jsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.