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

[Feature Request]: Automatically type arg mapping + conditional controls #22228

Open
tmeasday opened this issue Apr 24, 2023 · 0 comments
Open

Comments

@tmeasday
Copy link
Member

tmeasday commented Apr 24, 2023

Is your feature request related to a problem? Please describe

It's possible for args to change from the unmapped ("input") args in various ways before reaching the story's render function:

  • arg enhancers (undocumented)
    • only currently used by actions, AFAIK, and approximated by our TS support
  • arg mapping
  • conditional controls
  • decorators adding args (undocumented, probably we want to deprecate this).

Currently we treat the "input" args as the same type as the component's props, but this is incorrect. For conditional controls, it is not an issue, as if an arg is optional, then the component's prop must be optional too.

Describe the solution you'd like

For arg mappings, we can use the type of the mapping object to transform TArgs taken from the component to TInputArgs used in story objects:

export const MyComponent = ({ children }: { children: ReactNode }) => {};

const meta: Meta<typeof MyComponent> {
  render(args:TArgs) {
    // TArgs should = ComponentProps<typeof MyComponent>, so you can do:
    return <MyComponent {...args} />; // or similar
  },
  argTypes: {
    children: {
      mapping: {
        icon: <Icon />,
        button: <Button />
      }
    }
  },
  // However the type of args here should be TInputArgs,
  // where TInputArgs['children'] = 'icon' | 'button'
  args: {
    children: 'icon'
  }
}



### Describe alternatives you've considered

_No response_

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

no

### Additional context

_No response_
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