diff --git a/README.md b/README.md index f3a738a..312c79c 100644 --- a/README.md +++ b/README.md @@ -261,14 +261,16 @@ stories.add( | ---------------------------------- | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | skipPropsWithName | string[] or string | Avoid including docgen information for the prop or props specified. | | skipPropsWithoutDoc | boolean | Avoid including docgen information for props without documentation. | -| componentNameResolver | function | If a string is returned, then the component will use that name. Else it will fallback to the default logic of parser. https://github.com/styleguidist/react-docgen-typescript#parseroptions | -| propFilter | function | Filter props using a function. If skipPropsWithName or skipPropsWithoutDoc is defined the function will not be used. Function accepts two arguments: object with information about prop and an object with information about component. Return true to include prop in documentation. https://github.com/styleguidist/react-docgen-typescript#parseroptions | +| componentNameResolver | function | If a string is returned, then the component will use that name. Else it will fallback to the default logic of parser. https://github.com/styleguidist/react-docgen-typescript#options | +| propFilter | function | Filter props using a function. If skipPropsWithName or skipPropsWithoutDoc is defined the function will not be used. Function accepts two arguments: object with information about prop and an object with information about component. Return true to include prop in documentation. https://github.com/styleguidist/react-docgen-typescript#options | | tsconfigPath | string | Specify the location of the tsconfig.json to use. Can not be used with compilerOptions. | | compilerOptions | typescript.CompilerOptions | Specify TypeScript compiler options. Can not be used with tsconfigPath. | | docgenCollectionName | string or null | Specify the docgen collection name to use. All docgen information will be collected into this global object. Set to `null` to disable. Defaults to `STORYBOOK_REACT_CLASSES` for use with the Storybook Info Addon. https://github.com/gongreg/react-storybook-addon-docgen | | setDisplayName | boolean | Automatically set the components' display name. If you want to set display names yourself or are using another plugin to do this, you should disable this option. Defaults to `true`. This is used to preserve component display names during a production build of Storybook. | -| shouldExtractLiteralValuesFromEnum | boolean | If set to true, string enums and unions will be converted to docgen enum format. Useful if you use Storybook and want to generate knobs automatically using [addon-smart-knobs](https://github.com/storybookjs/addon-smart-knobs). https://github.com/styleguidist/react-docgen-typescript#parseroptions | -| savePropValueAsString | boolean | If set to true, defaultValue to props will be string. https://github.com/styleguidist/react-docgen-typescript#parseroptions | +| shouldExtractLiteralValuesFromEnum | boolean | If set to true, string enums and unions will be converted to docgen enum format. Useful if you use Storybook and want to generate knobs automatically using [addon-smart-knobs](https://github.com/storybookjs/addon-smart-knobs). https://github.com/styleguidist/react-docgen-typescript#options | +| shouldExtractValuesFromUnion | boolean | If set to true, every unions will be converted to docgen enum format. https://github.com/styleguidist/react-docgen-typescript#options | +| shouldRemoveUndefinedFromOptional | boolean | If set to true, types that are optional will not display " \| undefined" in the type. https://github.com/styleguidist/react-docgen-typescript#options | +| savePropValueAsString | boolean | If set to true, defaultValue to props will be string. https://github.com/styleguidist/react-docgen-typescript#options | | typePropName | string | Specify the name of the property for docgen info prop type. | ## Performance diff --git a/package.json b/package.json index f60fc15..69b7295 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dependencies": { "@webpack-contrib/schema-utils": "^1.0.0-beta.0", "loader-utils": "^1.2.3", - "react-docgen-typescript": "^1.15.0" + "react-docgen-typescript": "^1.20.1" }, "peerDependencies": { "typescript": "*" diff --git a/src/LoaderOptions.ts b/src/LoaderOptions.ts index abf3756..205b7c6 100644 --- a/src/LoaderOptions.ts +++ b/src/LoaderOptions.ts @@ -60,13 +60,25 @@ export default interface LoaderOptions { /** * If set to true, string enums and unions will be converted to docgen enum format. * Useful if you use Storybook and want to generate knobs automatically using [addon-smart-knobs](https://github.com/storybookjs/addon-smart-knobs). - * @see https://github.com/styleguidist/react-docgen-typescript#parseroptions + * @see https://github.com/styleguidist/react-docgen-typescript#options * */ shouldExtractLiteralValuesFromEnum?: boolean; + /** + * If set to true, every unions will be converted to docgen enum format. + * @see https://github.com/styleguidist/react-docgen-typescript#options + */ + shouldExtractValuesFromUnion?: boolean; + + /** + * If set to true, types that are optional will not display " | undefined" in the type. + * @see https://github.com/styleguidist/react-docgen-typescript#options + */ + shouldRemoveUndefinedFromOptional?: boolean; + /** * If set to true, defaultValue to props will be string. - * @see https://github.com/styleguidist/react-docgen-typescript#parseroptions + * @see https://github.com/styleguidist/react-docgen-typescript#options * */ savePropValueAsString?: boolean; diff --git a/src/loader.ts b/src/loader.ts index 1693048..6340215 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -81,6 +81,9 @@ function processResource( : options.propFilter, shouldExtractLiteralValuesFromEnum: options.shouldExtractLiteralValuesFromEnum, + shouldExtractValuesFromUnion: options.shouldExtractValuesFromUnion, + shouldRemoveUndefinedFromOptional: + options.shouldRemoveUndefinedFromOptional, savePropValueAsString: options.savePropValueAsString, }; diff --git a/src/validateOptions.ts b/src/validateOptions.ts index 03efd80..56da3b0 100644 --- a/src/validateOptions.ts +++ b/src/validateOptions.ts @@ -61,6 +61,14 @@ const schema = { type: "boolean", }, + shouldExtractValuesFromUnion: { + type: "boolean", + }, + + shouldRemoveUndefinedFromOptional: { + type: "boolean", + }, + savePropValueAsString: { type: "boolean", }, diff --git a/yarn.lock b/yarn.lock index c279c1d..22624c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3979,10 +3979,10 @@ rc@^1.2.7: minimist "^1.2.0" strip-json-comments "~2.0.1" -react-docgen-typescript@^1.15.0: - version "1.15.0" - resolved "https://registry.yarnpkg.com/react-docgen-typescript/-/react-docgen-typescript-1.15.0.tgz#963f14210841f9b51ed18c65152a6cc37f1c3184" - integrity sha512-8xObdkRQbrc0505tEdVRO+pdId8pKFyD6jhLYM9FDdceKma+iB+a17Dk7e3lPRBRh8ArQLCedOCOfN/bO338kw== +react-docgen-typescript@^1.20.1: + version "1.20.1" + resolved "https://registry.yarnpkg.com/react-docgen-typescript/-/react-docgen-typescript-1.20.1.tgz#774ed8b4a7111acaaa536cad4cfd61c504a46f7e" + integrity sha512-vU6puLsSwfCS+nI/6skQ52sJIx/uW7+9aMI/V/zPHAXr6s8OQzD5LeL9rXx/Hdt2aNfm4yTX9oJ8ClH/5PKQNg== react-is@^16.8.4: version "16.9.0"