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

addon-controls - Disabling controls for a story does not hide them on argsTable #15780

Open
7studio opened this issue Aug 6, 2021 · 14 comments

Comments

@7studio
Copy link

7studio commented Aug 6, 2021

Describe the bug
When I set the controls parameter to { disabled: true } for a story, the "Control" column into <argsTable story=""> doesn't disappear, even if I override argTypes on story with control: { type: null }.

Case 1: <Story parameters={{ controls: { disable: true } }}></Story>
argsTable
argstable-with-controls
Control panel
controls-disabled

Case 2: <Story argTypes={{ title: { control: { type: null } } }}></Story>
argsTable
argstable-without-controls
Control panel
controls-type-null

To Reproduce
Steps to reproduce the behaviour:

  1. In a *.stories.mdx file:
import {
  Meta,
  Story,
  Canvas,
  ArgsTable,
} from '@storybook/addon-docs'
import html from './card.html'

<Meta
  title="Components/Card"
  parameters={{
    viewMode: 'docs',
  }}
  args={{
    title: '',
  }}
  argTypes={{
    title: {
      name: 'Titre',
      description: 'Titre de l’article',
      type: { name: 'string', required: true },
      table: {
        type: {
          summary: 'string',
        },
        defaultValue: { summary: '' },
      },
      control: { type: 'text' },
    }
  }}
/>

export const PlaygroundTmpl = (args) => `
<div class="Card">
    <h4 class="Card-title">${args.title}</h4>
</div>
`

# Card

<Canvas>
  <Story
    name="Card"
    height="600px"
    parameters={{
      controls: { disable: true },
      docs: { source: { code: html } },
      viewMode: 'story',
    }}
  >
    {PlaygroundTmpl.bind({})}
  </Story>
</Canvas>

<ArgsTable story="Card" />

<Canvas>
  <Story
    name="Card 1"
    height="600px"
    parameters={{
      controls: { disable: true },
      docs: { source: { code: html } },
      viewMode: 'story',
    }}
    argTypes={{
      title: { control: { type: null } },
    }}
  >
    {PlaygroundTmpl.bind({})}
  </Story>
</Canvas>

<ArgsTable story="Card 1" />
  1. Serve Storybook.
  2. Navigate to MyGreatComponent
  3. Click on the Canvas tab.
  4. See that the Controls tab is no visible.
  5. Click on the Docs tab.
  6. See that the "Control" column and the reload button are still visible.

Expected behaviour
When I disable controls for a story (or all controls are null), I expect the "Control" column and the reload button into <argsTable>component to disappear and the Control panel to be empty.

System

System:
    OS: Windows 10 10.0.19043
    CPU: (8) x64 Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
  Binaries:
    Node: 14.17.0 - C:\nodejs\node.EXE
    npm: 6.14.13 - C:\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.423.0), Chromium (92.0.902.62)
  npmPackages:
    @storybook/addon-essentials: ^6.3.4 => 6.3.6
    @storybook/addon-links: ^6.3.4 => 6.3.6
    @storybook/addons: ^6.3.6 => 6.3.6
    @storybook/html: ^6.3.4 => 6.3.6
    @storybook/preset-scss: ^1.0.3 => 1.0.3
    @storybook/theming: ^6.3.4 => 6.3.6
@maeriens
Copy link

I don't think that hiding the Controls column is supported; I know you can remove the rows from the table. There seems to be some mentions about hiding the column in #12345 and it might have some workarounds but that is the best Storybook can offer so far

@Sheparzo
Copy link

@7studio As a workaround you could wrap the <ArgsTable /> with a <div> and give it an id and use some CSS to hide the column.

In your stories.mdx file:

<div id="hide-controls-column">
  <ArgsTable story="Card" />
</div>

in a .storybook/storybook.css (override) file:

/* Hiding certain control columns from argstable */
#hide-controls-column > div > table > thead > tr > th:last-child,
#hide-controls-column > div > table > tbody > tr > td:last-child {
  display: none;
}

#hide-controls-column > div > table > thead > tr th:nth-child(1),
#hide-controls-column > div > table > tbody > tr td:nth-child(1) {
  width: 15%;
}

make sure to setup that storybook.css override in .storybook/preview.js:

import '../dist/esm/index.css';
import './storybook.css';

export const parameters = {
	viewMode: 'docs',
	actions: { argTypesRegex: "^on[A-Z].*" },
}

@eltranseunteurbano
Copy link

Controls does not hidden on args table, for that exist another property.

If you want to hidde some property on table, you have to use table.

title: { table: { disable: true } }

You can check the documentation here

@maeriens
Copy link

maeriens commented Sep 2, 2021

That would disable the entire row for an arg, not a specific property of it.
What OP wants is to show the row but not the control column in the argsTable, or at least not show the control field itself.

@ops1ops
Copy link

ops1ops commented Jun 27, 2022

any news? its kind of weird that disabling table (which corresponds to doc page) deletes control, and i cant override it by directly writing "control",
according to current api, ArgsTable component has exclude property, but i need to recreate docs markup for each story where i want to disable some properties from doc - it requires a lot of code
easier would be to move this property to argTypes or fix current behavior with table disabling

P.S. What is wrong with docs? Why do i get know about "disable" property from issues on github?
Currently https://storybook.js.org/docs/react/writing-docs/doc-block-argstable#argstable does not have info about disable property and about exclue/include
image

@joelstransky
Copy link

@ops1ops Storybook docs are famously bad. They are more of a blog about storybook than a simple listing of api. I'm not sure why no one does this anymore.

@alvamanu
Copy link

@maeriens Exactly. Have you by any chance found a solution?

@alvamanu
Copy link

alvamanu commented Oct 12, 2022

Leaving the prop for documentation purposes only and disabling the ability to change the component can be done like so:

component: MyComponent,
title: 'MyComponent',
argTypes: {
    multiple: {
        control: { type: null }
    }
}

@KurtGokhan
Copy link

KurtGokhan commented Oct 23, 2022

I have another problem. For good measure I write this in global argTypes:

export const argTypes = {
  style: {
    table: {
      disable: true,
    },
  },
};

But if I do this, style prop is visible under every story. This does not always happen though. Also, it does not show in Docs tab, but only in Canvas tab. This is very weird.

@tfoxy
Copy link

tfoxy commented Aug 7, 2023

This is now mentioned here: https://storybook.js.org/docs/react/essentials/controls#disable-controls-for-specific-properties

  argTypes: {
    // remove the prop documentation from the table
    foo: {
      table: {
        disable: true,
      },
    },
  },
  argTypes: {
    // render the prop documentation, but without a control
    foo: {
      control: false,
    },
  },

@manavm1990
Copy link

Can we disable controls for the whole story without going into the each and every prop? There are only 2️⃣ , but still...:)

@FilipePfluck
Copy link

I have the same question as @manavm1990. I am usiong pandacss to style my components, and they can receive hundreds of styling properties, I want to hide them in storybook. And ain't no way Imma disable all of them manually.

@tfoxy
Copy link

tfoxy commented Aug 29, 2023

@manavm1990 @FilipePfluck you can overwrite extractArgTypes which is the function used to infer all the arg types of a component.

function extractArgTypes(component) {
  // return `argTypes` here
}

{
  parameters: {
    docs: {
      extractArgTypes,  
    }
  }
}

You can check how the default function is implemented here:

export const extractArgTypes: ArgTypesExtractor = (component) => {

The function implementation is different between frameworks. The one above is for React. You can look for the others inside the repo.

You can set this in preview.js to change all stories, in the default export of a file to change all stories in that file or in a single story.

@matthewrose
Copy link

@FilipePfluck and @manavm1990 Took me a while to figure this out, and it may not work for your needs, but I personally use the propFilter function to filter out props defined in node_modules via my typescript config in main.js:

  typescript: {
    check: false,
    reactDocgen: 'react-docgen-typescript',
    reactDocgenTypescriptOptions: {
      shouldExtractLiteralValuesFromEnum: true,
      shouldExtractValuesFromUnion: true,
      shouldRemoveUndefinedFromOptional: true,

      // filter out props from dependency modules
      propFilter: prop =>
        !!prop.declarations?.find(
          declaration => !declaration.fileName.includes('node_modules')
        ),
    },
  },

Source(ish): https://storybook.js.org/docs/react/configure/typescript#extending-the-default-configuration

fredvisser pushed a commit to ni/nimble that referenced this issue Apr 24, 2024
# Pull Request

## 🤨 Rationale

As part of #824 we want to improve the accuracy and comprehensiveness of
our storybook API documentation.

## 👩‍💻 Implementation

Apply the following patterns to the menu button docs:

1. create sections in the args table for attributes, slots, and events.
(We'd also add methods for components that expose interesting ones)
2. Ensure the title and description are accurate for each member
3. link to shared docs about component APIs. 

Other minor bug fixes:
1. hide the "patterns" page from public storybook
2. hide text from ✅ icon mapping in component status table

### Possible follow up work

1. update doc templates and the docs for other existing components
similarly
1. more detailed API overview docs
- explanation of event patterns in web components and how they map to
frameworks
    - using forms instead of change events
1. see if we can remove the type annotation from control descriptions
2. [wait for further feedback] more curated examples and highlight most
important APIs for each component
1. [out of scope] I wish I could hide the Default column since we don't
bother populating it but that doesn't seem to be possible
storybookjs/storybook#15780


## 🧪 Testing

Manual storybook interaction

## ✅ Checklist

<!--- Review the list and put an x in the boxes that apply or ~~strike
through~~ around items that don't (along with an explanation). -->

- [x] I have updated the project documentation to reflect my changes or
determined no changes are needed.
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