10000 Render inputs for stories · Issue #58 · ocavue/astrobook · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Render inputs for stories #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
iyyafi opened this issue Oct 19, 2024 · 1 comment
Open

Render inputs for stories #58

iyyafi opened this issue Oct 19, 2024 · 1 comment

Comments

@iyyafi
Copy link
iyyafi commented Oct 19, 2024

Hi,

I really love this project, and i hope i can contribute in this project next time (i'm not confident enough with my skill).

I have a request, could you add custom render function as inputs in stories? like this one https://storybook.js.org/docs/api/csf#custom-render-functions.
The reasons are i need to show the mobile and desktop version of my component.

Thank you.

@ocavue
Copy link
Owner
ocavue commented Oct 19, 2024

Thanks for your kind words.

I can see the value of custom render functions, but their implementation varies depending on the framework. For example, React’s render functions return a JSX element, Vue’s render functions return an object and you cannot use Vue SFC in it, while Svelte doesn’t support render functions (since you cannot represent a Svelte component as a function). Because of that, it requires quite a lot of work to support render functions for different frameworks in Astrobook.

In the meantime, you can create your own wrapper component for showing mobile and desktop versions. Here is an example:

// MyComponent.tsx
// You actual component
export default function MyComponent () {
  return <div>...</div>
}
// MyComponentRendering.tsx
// A component that wraps MyComponent with different size of containers.
export default function MyComponentRendering ({size}: {size: 'mobile'|'desktop'}) {
  if (size === 'mobile') {
    return <div style={{maxWidth: "400px"}}><MyComponent/></div>
  } else {
    return <div style={{maxWidth: "1200px"}}><MyComponent/></div>
  }
}
// MyComponent.stories.ts
import MyComponentRendering from './MyComponentRendering.tsx'

export default {
  component: MyComponentRendering,
}

export const Mobile = {
  args: {
    size: 'mobile',
  }
}

export const Desktop = {
  args: {
    size: 'desktop',
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0