Skip to content
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

Bind template and arguments helper #14551

Closed
Bram-Zijp opened this issue Apr 11, 2021 · 2 comments
Closed

Bind template and arguments helper #14551

Bram-Zijp opened this issue Apr 11, 2021 · 2 comments

Comments

@Bram-Zijp
Copy link

Is your feature request related to a problem? Please describe
Most of my stories just need to render with x props, so I've learned using the latest version of storybook 6.2+ (nice!). To save some lines of code, I created this quick and dirty helper. It's not perfect but it works for me now. Perhaps it's an idea to include something like this into storybook.

Describe the solution you'd like

import { Story } from "@storybook/react";

type BindTemplate<P = any> = <T extends Story<P>>(
  template: T,
  args: T["args"]
) => T & { args: T["args"] };

export const bindTemplate: BindTemplate = (template, args) => {
  const boundTemplate = (template as any).bind({});
  boundTemplate.args = args;
  return boundTemplate;
};


import React from "react";
import { Meta, Story } from "@storybook/react";
import { bindTemplate } from "$utils/stories";
import { Box, BoxProps } from "./";

const config: Meta = {
  title: "Components/Box",
  component: Box,
};

export default config;

const Template: Story<BoxProps> = (args) => <Box {...args}>Box</Box>;

export const Primary = bindTemplate(Template, {
  className: "valid",
});

export const Secondary = bindTemplate(Template, {
  sx: { background: "blue" },
});

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Are you able to assist to bring the feature to reality?
yes

Additional context
Add any other context or screenshots about the feature request here.

@shilman
Copy link
Member

shilman commented Apr 11, 2021

We have some other plans for this, outlined in #12654

@Bram-Zijp
Copy link
Author

Nice, I like those plans. Closing in favor of #12654

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

No branches or pull requests

2 participants