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: Conditional arg disabling #13890

Closed
wants to merge 12 commits into from
19 changes: 19 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<h1>Migration</h1>

- [From version 6.2.x to 6.3.0](#from-version-62x-to-630)
- [6.3 Deprecations](#63-deprecations)
- [Improved args disabling](#improved-args-disabling)
- [From version 6.1.x to 6.2.0](#from-version-61x-to-620)
- [MDX pattern tweaked](#mdx-pattern-tweaked)
- [6.2 Angular overhaul](#62-angular-overhaul)
Expand Down Expand Up @@ -151,6 +154,22 @@
- [Packages renaming](#packages-renaming)
- [Deprecated embedded addons](#deprecated-embedded-addons)

## From version 6.2.x to 6.3.0

### 6.3 Deprecations

#### Improved args disabling

We've simplified disabling arg display in 6.3 by hoisting the `table.disable` property. It is now the `disable` property instead.

```js
// before
const argTypes = { foo: { table: { disable: true } } };

// after
const argTypes = { foo: { disable: true } };
```

## From version 6.1.x to 6.2.0

### MDX pattern tweaked
Expand Down
2 changes: 1 addition & 1 deletion addons/controls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default {

export const CustomControls = (args) => <Button {...args} />;
CustomControls.argTypes = {
borderWidth: { table: { disable: true } },
borderWidth: { disable: true },
label: { control: { disable: true } },
};
```
Expand Down
5 changes: 3 additions & 2 deletions addons/docs/docs/multiframework.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface ArgType {
name?: string;
description?: string;
defaultValue?: any;
disable?: boolean;
[key: string]: any;
}

Expand Down Expand Up @@ -106,7 +107,7 @@ The input is the story function and the story context (id, parameters, args, etc

## Dynamic source rendering

With the release of Storybook 6.0, we've improved how stories are rendered in the [Source doc block](https://storybook.js.org/docs/react/writing-docs/doc-blocks#source). One of such improvements is the `dynamic` source type, which renders a snippet based on the output the story function.
With the release of Storybook 6.0, we've improved how stories are rendered in the [Source doc block](https://storybook.js.org/docs/react/writing-docs/doc-blocks#source). One of such improvements is the `dynamic` source type, which renders a snippet based on the output the story function.

This dynamic rendering is framework-specific, meaning it needs a custom implementation for each framework.

Expand Down Expand Up @@ -151,7 +152,7 @@ import { jsxDecorator } from './jsxDecorator';
export const decorators = [jsxDecorator];
```

This configures the `jsxDecorator` to be run on every story.
This configures the `jsxDecorator` to be run on every story.

<div class="aside">
To learn more and see how it's implemented in context, check out <a href="https://github.com/storybookjs/storybook/blob/next/addons/docs/src/frameworks/react/jsxDecorator.tsx">the code</a> .
Expand Down
18 changes: 8 additions & 10 deletions docs/snippets/common/component-story-disable-controls.js.mdx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
```js
// YourComponent.stories.js | YourComponent.stories.ts

import { YourComponent } from './your-component'
import { YourComponent } from './your-component';

export default {
component: YourComponent,
title:'My Story',
argTypes:{
title: 'My Story',
argTypes: {
// foo is the property we want to remove from the UI
foo:{
table:{
disable:true
}
}
}
foo: {
disable: true,
},
},
};
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import { YourComponent } from './your-component'
<Meta
title='My Story'
argTypes={{
foo:{
table:{
disable:true
}
foo: {
disable:true
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
}
}} />

Expand All @@ -22,4 +20,4 @@ export const Template = (args) => <YourComponent {...args} />
{Template.bind({})}
</Story>
</Canvas>
```
```
1 change: 1 addition & 0 deletions examples/angular-cli/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
{
files: ['./src/stories/addon-jest.stories.ts'],
rules: {
'@typescript-eslint/ban-ts-comment': 'warn',
'import/no-useless-path-segments': ignore,
},
settings: {
Expand Down
1 change: 1 addition & 0 deletions lib/addons/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface ArgType {
name?: string;
description?: string;
defaultValue?: any;
disable?: boolean;
[key: string]: any;
}

Expand Down
1 change: 1 addition & 0 deletions lib/api/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface ArgType {
name?: string;
description?: string;
defaultValue?: any;
disable?: boolean;
[key: string]: any;
}

Expand Down
17 changes: 16 additions & 1 deletion lib/components/src/blocks/ArgsTable/ArgsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { FC } from 'react';
import pickBy from 'lodash/pickBy';
import { styled, ignoreSsrWarning } from '@storybook/theming';
import { opacify, transparentize, darken, lighten } from 'polished';
import dedent from 'ts-dedent';
import deprecate from 'util-deprecate';
import { Icons } from '../../icon/icon';
import { ArgRow } from './ArgRow';
import { SectionRow } from './SectionRow';
Expand All @@ -10,6 +12,15 @@ import { EmptyBlock } from '../EmptyBlock';
import { Link } from '../../typography/link/link';
import { ResetWrapper } from '../../typography/DocumentFormatting';

const warnTableDisableDeprecated = deprecate(
() => {},
dedent`
Use 'disable' instead of 'table.disable' to disable ArgsTable rows.

https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#improved-args-disabling
`
);

export const TableWrapper = styled.table<{ compact?: boolean; inAddonPanel?: boolean }>(
({ theme, compact, inAddonPanel }) => ({
'&&': {
Expand Down Expand Up @@ -349,8 +360,12 @@ export const ArgsTable: FC<ArgsTableProps> = (props) => {
sort = 'none',
} = props as ArgsTableRowProps;

if (Object.values(rows).some((row) => row?.table?.disable)) {
warnTableDisableDeprecated();
}

const groups = groupRows(
pickBy(rows, (row) => !row?.table?.disable),
pickBy(rows, (row) => !(row?.table?.disable || row?.disable)),
sort
);

Expand Down
1 change: 1 addition & 0 deletions lib/components/src/blocks/ArgsTable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface ArgType {
name?: string;
description?: string;
defaultValue?: any;
disable?: boolean;
[key: string]: any;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/src/components/layout/draggers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ const Handle = styled.div<{ isDragging: boolean; axis: Axis }>(
);

export { Draggable, Handle };
export type { DraggableEvent, DraggableData };
export type { DraggableEvent, DraggableData };