[storybook__addon-info] add some properties of options

* add components
* add TableComponent
* add excludedPropTypes
This commit is contained in:
RunningCoderLee
2019-02-18 10:50:15 +08:00
parent 834caef36e
commit dca8a6286b
2 changed files with 48 additions and 1 deletions

View File

@@ -1,7 +1,8 @@
// Type definitions for @storybook/addon-info 3.4
// Type definitions for @storybook/addon-info 4.1
// Project: https://github.com/storybooks/storybook, https://github.com/storybooks/storybook/tree/master/addons/info
// Definitions by: Mark Kornblum <https://github.com/mkornblum>
// Mattias Wikstrom <https://github.com/fyrkant>
// Kevin Lee <https://github.com/RunningCoderLee>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -22,11 +23,22 @@ export interface Options {
propTables?: React.ComponentType[] | false;
propTablesExclude?: React.ComponentType[];
styles?: object;
components?: { [key: string]: React.ComponentType };
marksyConf?: object;
maxPropsIntoLine?: number;
maxPropObjectKeys?: number;
maxPropArrayLength?: number;
maxPropStringLength?: number;
TableComponent?: React.ComponentType<{
propDefinitions: Array<{
property: string;
propType: object | string; // TODO: info about what this object is...
required: boolean;
description: string;
defaultValue: any;
}>
}>;
excludedPropTypes?: string[];
}
// TODO: it would be better to use type inference for the parameters

View File

@@ -6,6 +6,38 @@ import { setDefaults, withInfo } from '@storybook/addon-info';
const { Component } = React;
const TableComponent = ({ propDefinitions }: { propDefinitions: Array<{
property: string;
propType: { [key: string]: any} | string;
required: boolean;
description: string;
defaultValue: any;
}> }) => (
<table>
<thead>
<tr>
<th>property</th>
<th>propType</th>
<th>required</th>
<th>default</th>
<th>description</th>
</tr>
</thead>
<tbody>
{propDefinitions.map(row => (
<tr key={row.property}>
<td>{row.property}</td>
<td>{row.required ? 'yes' : '-'}</td>
<td>
{row.defaultValue === undefined ? '-' : row.defaultValue}
</td>
<td>{row.description}</td>
</tr>
))}
</tbody>
</table>
);
addDecorator(withInfo);
setDefaults({
@@ -31,11 +63,14 @@ storiesOf('Component', module)
header: true,
source: true,
styles: {},
components: {},
marksyConf: {},
maxPropObjectKeys: 1,
maxPropArrayLength: 2,
maxPropsIntoLine: 3,
maxPropStringLength: 4,
TableComponent,
excludedPropTypes: [],
})(() =>
<Component>Click the "?" mark at top-right to view the info.</Component>
)