mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 07:21:16 +08:00
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import React, { FC } from 'react';
|
|
import { useArgs, useArgTypes, useParameter } from '@storybook/api';
|
|
import { ArgsTable, NoControlsWarning } from '@storybook/components';
|
|
|
|
import { PARAM_KEY } from './constants';
|
|
|
|
interface ControlsParameters {
|
|
expanded?: boolean;
|
|
hideNoControlsWarning?: boolean;
|
|
}
|
|
|
|
export const ControlsPanel: FC = () => {
|
|
const [args, updateArgs, resetArgs] = useArgs();
|
|
const rows = useArgTypes();
|
|
const isArgsStory = useParameter<boolean>('__isArgsStory', false);
|
|
const { expanded, hideNoControlsWarning = false } = useParameter<ControlsParameters>(
|
|
PARAM_KEY,
|
|
{}
|
|
);
|
|
|
|
const hasControls = Object.values(rows).some((arg) => arg?.control);
|
|
const showWarning = !(hasControls && isArgsStory) && !hideNoControlsWarning;
|
|
|
|
return (
|
|
<>
|
|
{showWarning && <NoControlsWarning />}
|
|
<ArgsTable
|
|
{...{
|
|
compact: !expanded && hasControls,
|
|
rows,
|
|
args,
|
|
updateArgs,
|
|
resetArgs,
|
|
inAddonPanel: true,
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
};
|