question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Chakra components with storybook controls and args

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

I am trying to extend Chakra components for our design system and show them in storybook, my problem is that the controls tab and prop table are bloated with the styled props I was trying to make a story for the Checkbox component and this is how the control tab and props table looked

control tab

bloated control tab

props table

bloated props table

I want to show only the main props (isChecked, isDisabled, value, etc.) that are the same as the one in the docs

Describe the solution you’d like

I am not sure exactly how to approach this issue, in storybook main.js file there is a way to filter props as mentioned here but what props should we filter on? I am aware that chakra exports propNames but am still left with 115 controls 😓. 115 control tab propNames doesn’t include props such as [sx, style, aria-hidden, onInput, …] so maybe chakra can export a more comprehensive propNames.

Describe alternatives you’ve considered

in storybook you could make it not infer the types from the component and you write the args manually as specified here I guess this would work but that means we’ll have to manually write the main props for each component.

Additional context

Am not sure if this issue is directly related to Chakra, maybe it could be better submitted in the storybook repo

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
mkosircommented, Jun 2, 2021

If somebody is missing full context where to put filtering props, it’s in the Storybook main.js file.
In my case I added it as such

module.exports = {
...
  typescript: {
    check: false,
    checkOptions: {},
    reactDocgen: 'react-docgen-typescript',
    reactDocgenTypescriptOptions: {
      compilerOptions: {
        allowSyntheticDefaultImports: false,
        esModuleInterop: false,
      },
      shouldExtractLiteralValuesFromEnum: true,
      propFilter: (prop) => {
        const isStyledSystemProp = excludedPropNames.includes(prop.name);
        const isHTMLElementProp = prop.parent?.fileName.includes('node_modules') ?? false;
        return !(isStyledSystemProp || isHTMLElementProp);
      },
    },
  },
};
4reactions
cameronevanscommented, Jan 22, 2021

@hazem3500 this filter is working for me to just document component’s own props & inherited chakra component props

propFilter: (prop) =>
            prop.parent !== undefined &&
            (!prop.parent.fileName.includes('node_modules') ||
              (prop.parent.fileName.includes('node_modules') &&
                prop.parent.fileName.includes('node_modules/@chakra-ui/') &&
                !prop.parent.fileName.includes(
                  'node_modules/@chakra-ui/styled-system'
                ))),
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chakra UI Addon | Storybook: Frontend workshop for UI ...
Use Chakra UI in your Storybook stories. This Plugin wraps each of your stories with ChakraProvider which can be configured using Storybook parameters....
Read more >
Chakra UI + Storybook
Chakra UI + Storybook. Use the official Storybook Addon for Chakra UI to configure Storybook to automatically wrap your stories with the <ChakraProvider...
Read more >
Next-level component showcasing with Storybook controls
Learn about controls, a new Storybook addon that lets you dynamically interact with your React components for demo and testing purposes.
Read more >
Controlling global decorators via Storybook `args` and ...
Specifically, I want to use Storybook controls to dynamically set the Redux state. I couldn't find any existing strategies for this in the...
Read more >
Frontend Handbook | React / Chakra UI - Infinum
The main difference is that __css prop will be merged before sx prop (github). We should ONLY use it for building primitive core...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found