3.46.12 • Published 2 years ago

@structured-types/react-plugin v3.46.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Table of contents

Overview

structured-types plugin to extract react specific properties from typesript prop types. If you are using react-prop-types, please see the react-prop-types plugin.

Getting started

1. Installation

$ npm install @structured-types/react-plugin --save-dev

2. Your API source file (Component.tsx):

import React, { FC } from 'react';
/**
 * MyComponent properties.
 */
type OwnProps = {
  /** stringProp description */
  stringProp?: string,

  /** numberProp description */
  numberProp: number,
};

/**
 * MyComponent special component
 */
const MyComponent: FC<OwnProps> = ({ stringProp }) => <div>{stringProp}</div>;

MyComponent.defaultProps = {
  stringProp: 'test',
};

export default MyComponent;

3. Your documentation extraction

import { parseFiles } from '@structured-types/api';
import reactPlugin from '@structured-types/react-plugin';

const docs = parseFiles(['../src/components/Component.tsx'], {
  plugins: [reactPlugin],
});

4. The result

{
  "default": {
    "name": "MyComponent",
    "extension": "react",
    "kind": 11,
    "properties": [
      {
        "parent": "OwnProps",
        "optional": true,
        "name": "stringProp",
        "kind": 1,
        "description": "stringProp description",
        "value": "test"
      },
      {
        "parent": "OwnProps",
        "name": "numberProp",
        "kind": 2,
        "description": "numberProp description"
      }
    ]
  }
}

Configuration

The react typescript plugin exports some default properties, and you can also add or modify some of the other parsing options that will be specific only for the found react components. For other typescript/jsdoc types, the global options passed to parseFiles will still apply.

Enable the children props.

By default, the plugin removes the children property that is part of most react components, here is an example of how to re-enable the children properties by disabling the default filter:

import { parseFiles } from '@structured-types/api';
import reactPlugin from '@structured-types/react-plugin';


const docs = parseFiles(['../src/components/Component.tsx'], {
  plugins: [{ ...reactPlugin, filter: undefined }],
});

ParsePlugin

type

Plugin type - provides the plugin name and the type resolver

defined in @structured-types/api/packages/api/src/ts-utils.ts

properties

NameTypeParentDefaultDescription
tsOptionsts.CompilerOptionsDocsOptions
internalTypesRecord<string, PropKind>ParseOptionsinternal types - libs by default includes classes such as String , Function ...
extractstring[]ParseOptionslist of export names to be extracted. by default all exports are extracted
filterfunction (prop*kind: name: stringalias: stringparentname*: stringloc: SourceLocationlocfilePath: stringloc: SourcePositionsoptional: booleanreadonly: booleanabstract: booleanasync: booleanvisibility: "private" | "protected" | "public"static: booleantype: stringextension: stringdescription: stringfires: string[]see: string[]examples: JSDocExample[]tags: JSDocPropTag[]summary: stringdeprecated: string | trueignore: booleanusage: type[]) => booleanParseOptionsfilter properties function. By default filter out all props with ignore === true
maxDepthnumberParseOptions6max depth for extracting child props.
collectHelpersbooleanParseOptionswhether to save "helper" props that are used by the main parsed props if set to false will result in a smaller result set
collectGenericsbooleanParseOptionstruewhether to collect generics parameters
collectParametersboolean
3.46.12

2 years ago

3.46.11

2 years ago

3.46.9

2 years ago

3.46.8

2 years ago

3.46.7

2 years ago

3.41.0

2 years ago

3.41.1

2 years ago

3.43.0

2 years ago

3.41.2

2 years ago

3.43.1

2 years ago

3.45.0

2 years ago

3.43.2

2 years ago

3.43.3

2 years ago

3.43.4

2 years ago

3.40.0

2 years ago

3.40.1

2 years ago

3.42.0

2 years ago

3.40.2

2 years ago

3.42.1

2 years ago

3.44.0

2 years ago

3.40.4

2 years ago

3.44.1

2 years ago

3.40.5

2 years ago

3.46.0

2 years ago

3.44.2

2 years ago

3.46.1

2 years ago

3.44.3

2 years ago

3.40.7

2 years ago

3.46.2

2 years ago

3.40.10

2 years ago

3.46.3

2 years ago

3.40.9

2 years ago

3.46.4

2 years ago

3.46.5

2 years ago

3.46.6

2 years ago

3.39.10

2 years ago

3.36.0

2 years ago

3.36.2

2 years ago

3.38.1

2 years ago

3.39.5

2 years ago

3.39.6

2 years ago

3.39.7

2 years ago

3.39.8

2 years ago

3.37.0

2 years ago

3.35.2

3 years ago

3.37.1

2 years ago

3.35.3

3 years ago

3.39.3

2 years ago

3.39.4

2 years ago

3.35.1

3 years ago

3.35.0

3 years ago

3.34.2

3 years ago

3.33.0

3 years ago

3.34.0

3 years ago

3.34.1

3 years ago

3.32.0

3 years ago

3.31.0

3 years ago

3.30.0

3 years ago

3.26.0

3 years ago

3.25.0

3 years ago

3.28.0

3 years ago

3.27.0

3 years ago

3.24.6

3 years ago

3.29.0

3 years ago

3.28.1

3 years ago

3.24.4

3 years ago

3.24.3

3 years ago

3.24.2

3 years ago

3.24.1

3 years ago

3.24.0

3 years ago

3.23.0

3 years ago

3.22.0

3 years ago

3.21.1

3 years ago

3.21.0

3 years ago

3.20.4

3 years ago

3.20.2

3 years ago

3.20.1

3 years ago

3.20.3

3 years ago

3.20.0

3 years ago

3.19.0

3 years ago

3.18.1

3 years ago

3.18.0

3 years ago

3.17.2

3 years ago

3.17.1

3 years ago