From dca8a6286ba05992961f5d27a90688136f75868d Mon Sep 17 00:00:00 2001 From: RunningCoderLee Date: Mon, 18 Feb 2019 10:50:15 +0800 Subject: [PATCH] [storybook__addon-info] add some properties of options * add components * add TableComponent * add excludedPropTypes --- types/storybook__addon-info/index.d.ts | 14 +++++++- .../storybook__addon-info-tests.tsx | 35 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/types/storybook__addon-info/index.d.ts b/types/storybook__addon-info/index.d.ts index 9e5089d443..6adc628c31 100644 --- a/types/storybook__addon-info/index.d.ts +++ b/types/storybook__addon-info/index.d.ts @@ -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 // Mattias Wikstrom +// Kevin Lee // 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 diff --git a/types/storybook__addon-info/storybook__addon-info-tests.tsx b/types/storybook__addon-info/storybook__addon-info-tests.tsx index 505780bf7e..0e581c822d 100644 --- a/types/storybook__addon-info/storybook__addon-info-tests.tsx +++ b/types/storybook__addon-info/storybook__addon-info-tests.tsx @@ -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; +}> }) => ( + + + + + + + + + + + + {propDefinitions.map(row => ( + + + + + + + ))} + +
propertypropTyperequireddefaultdescription
{row.property}{row.required ? 'yes' : '-'} + {row.defaultValue === undefined ? '-' : row.defaultValue} + {row.description}
+); + 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: [], })(() => Click the "?" mark at top-right to view the info. )