Skip to content

Commit

Permalink
Merge pull request #26200 from storybookjs/kasper/empty-controls
Browse files Browse the repository at this point in the history
Docs: Don't show empty arg tables in doc pages
  • Loading branch information
kasperpeulen committed Feb 27, 2024
2 parents cb4ca53 + f104e66 commit 153a8f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
15 changes: 13 additions & 2 deletions code/ui/blocks/src/blocks/Controls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ import * as ExampleStories from '../examples/ControlsParameters.stories';
import * as SubcomponentsExampleStories from '../examples/ControlsWithSubcomponentsParameters.stories';
import { within } from '@storybook/test';
import type { PlayFunctionContext } from '@storybook/csf';
import * as EmptyArgTypesStories from '../examples/EmptyArgTypes.stories';

const meta: Meta<typeof Controls> = {
const meta = {
component: Controls,
parameters: {
relativeCsfPaths: [
'../examples/ControlsParameters.stories',
'../examples/EmptyArgTypes.stories',
'../examples/ControlsWithSubcomponentsParameters.stories',
],
docsStyles: true,
},
};
} satisfies Meta<typeof Controls>;
export default meta;

type Story = StoryObj<typeof meta>;
Expand Down Expand Up @@ -142,3 +144,12 @@ export const SubcomponentsSortProp: Story = {
sort: 'alpha',
},
};

/**
* When a story is defined without any argTypes or args, the Docs UI should not display the control component.
*/
export const EmptyArgTypes: Story = {
args: {
of: EmptyArgTypesStories.Default,
},
};
3 changes: 3 additions & 0 deletions code/ui/blocks/src/blocks/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export const Controls: FC<ControlsProps> = (props) => {
const hasSubcomponents = Boolean(subcomponents) && Object.keys(subcomponents).length > 0;

if (!hasSubcomponents) {
if (!(Object.keys(filteredArgTypes).length > 0 || Object.keys(args).length > 0)) {
return null;
}
return (
<PureArgsTable
rows={filteredArgTypes}
Expand Down
19 changes: 19 additions & 0 deletions code/ui/blocks/src/examples/EmptyArgTypes.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Meta, StoryObj } from '@storybook/react';
import type { ControlsParameters } from './ControlsParameters';
import React from 'react';

const meta = {
title: 'examples/Empty ArgTypes for Control blocks',
// note that component is not specified, so no argtypes can be generated
render: () => <div>I am a story without args or argTypes</div>,
parameters: { chromatic: { disableSnapshot: true } },
} satisfies Meta<typeof ControlsParameters>;

export default meta;
type Story = StoryObj<typeof meta>;

/**
* There are no argTypes or args, so this story won't show any controls in the docs page.
* In the control addon it will show a UI how to set up controls.
*/
export const Default: Story = {};

0 comments on commit 153a8f1

Please sign in to comment.