Skip to content

Commit 4d4af28

Browse files
authored
Add doc for more handlers (#780)
1 parent d0e0e29 commit 4d4af28

12 files changed

+203
-26
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
2+
"child-context-type-handler": "childContextTypeHandler",
23
"code-type-handler": "codeTypeHandler",
34
"component-docblock-handler": "componentDocblockHandler",
45
"component-methods-handler": "componentMethodsHandler",
6+
"context-type-handler": "contextTypeHandler",
57
"default-props-handler": "defaultPropsHandler",
68
"display-name-handler": "displayNameHandler",
79
"prop-docblock-handler": "propDocblockHandler",
8-
"proptype-composition-handler": "propTypeCompositionHandler",
9-
"proptype-handler": "propTypeHandler"
10+
"prop-type-composition-handler": "propTypeCompositionHandler",
11+
"prop-type-handler": "propTypeHandler"
1012
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# childContextTypeHandler

packages/website/src/pages/docs/reference/handlers/component-docblock-handler.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
Reads the react components leading block comment and adds its content as
44
description to the documentation. This works on all component types.
55

6-
## Example
6+
## Examples
77

8-
The following component will result in the following documentation
8+
When the `componentDocblockHandler` is active the following component will
9+
result in the output below
910

1011
```ts {1-3} filename="component.tsx"
1112
/**
@@ -14,7 +15,9 @@ The following component will result in the following documentation
1415
() => <div />;
1516
```
1617

17-
```json {3} filename="Result"
18+
## Output
19+
20+
```json {3} filename="JSON"
1821
[
1922
{
2023
"description": "This is my component and this is its description."

packages/website/src/pages/docs/reference/handlers/component-methods-handler.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ detected:
99
- Assignment of methods to static properties on Class or Function components
1010
- Methods defined in the `useImperativeHandle()` hook in Function components
1111

12-
## Example
12+
## Examples
1313

1414
When the `componentMethodsHandler` is active any of these components will result
15-
in the following documentation
15+
in the output below
1616

1717
```ts {2-3} filename="component.tsx"
1818
class MyComponent extends React.Component {
@@ -62,7 +62,9 @@ forwardRef(function MyComponent(_, ref) {
6262
});
6363
```
6464

65-
```json {3-23} filename="Result"
65+
## Output
66+
67+
```json {3-23} filename="JSON"
6668
[
6769
{
6870
"methods": [
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# contextTypeHandler

packages/website/src/pages/docs/reference/handlers/default-props-handler.mdx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ documentation. Supported variants are:
88
components
99
- Default values in destructuring the prop argument in Function components
1010

11-
## Example
11+
## Examples
1212

1313
When the `defaultPropsHandler` is active any of these components will result in
14-
the following documentation
14+
the output below
1515

1616
```ts {2-4} filename="component.tsx"
1717
class MyComponent extends React.Component {
@@ -48,7 +48,9 @@ MyComponent.defaultProps = {
4848
({ a = '1' }) => <div />;
4949
```
5050

51-
```json {5-9} filename="Result"
51+
## Output
52+
53+
```json {5-9} filename="JSON"
5254
[
5355
{
5456
"props": {

packages/website/src/pages/docs/reference/handlers/display-name-handler.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ names and will use the first one found in order:
99
- The name of a Function or Class component
1010
- The variable name that an anonymous Function Component is assigned to
1111

12-
## Example
12+
## Examples
1313

1414
When the `displayNameHandler` is active any of these components will result in
15-
the following documentation
15+
the output below
1616

1717
```ts {2} filename="component.tsx"
18-
class extends React.Component {
18+
export default class extends React.Component {
1919
static displayName = 'DisplayName';
2020
render() {
2121
return <div />;
@@ -59,7 +59,9 @@ function DisplayName() {
5959
const DisplayName = () => <div />;
6060
```
6161

62-
```json {3} filename="Result"
62+
## Output
63+
64+
```json {3} filename="JSON"
6365
[
6466
{
6567
"displayName": "DisplayName"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,70 @@
11
# propDocblockHandler
2+
3+
Tries to find the prop types on react components and extracts their Docblock
4+
description. It uses the same logic as the
5+
[`propTypeHandler`](./prop-type-handler.mdx) to find the prop types.
6+
7+
## Examples
8+
9+
When the `propDocblockHandler` is active any of these components will result in
10+
the output below
11+
12+
```ts {1,4-8} filename="component.tsx"
13+
import PropTypes from 'prop-types';
14+
15+
class MyComponent extends React.Component {
16+
static propTypes = {
17+
/** Foo */
18+
foo: PropTypes.string,
19+
bar: PropTypes.number,
20+
};
21+
render() {
22+
return <div />;
23+
}
24+
}
25+
```
26+
27+
```ts {1,9-13} filename="component.tsx"
28+
import PropTypes from 'prop-types';
29+
30+
class MyComponent extends React.Component {
31+
render() {
32+
return <div />;
33+
}
34+
}
35+
36+
MyComponent.propTypes = {
37+
/** Foo */
38+
foo: PropTypes.string,
39+
bar: PropTypes.number,
40+
};
41+
```
42+
43+
```ts {1,5-9} filename="component.tsx"
44+
import PropTypes from 'prop-types';
45+
46+
const MyComponent = () => <div />;
47+
48+
MyComponent.propTypes = {
49+
/** Foo */
50+
foo: PropTypes.string,
51+
bar: PropTypes.number,
52+
};
53+
```
54+
55+
## Output
56+
57+
```json {5,8} filename="JSON"
58+
[
59+
{
60+
"props": {
61+
"foo": {
62+
"description": "Foo"
63+
},
64+
"bar": {
65+
"description": ""
66+
}
67+
}
68+
}
69+
]
70+
```
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# propTypeHandler
2+
3+
Tries to find the prop types on react components. It looks for:
4+
5+
- A static property called `propTypes` on Class components
6+
- Assignment to a property called `propTypes` on Function or Class components
7+
8+
The prop types that are used need to be imported either from the `react` or the
9+
[`prop-types`](https://www.npmjs.com/package/prop-types) NPM package.
10+
11+
## Examples
12+
13+
When the `propTypeHandler` is active any of these components will result in the
14+
output below
15+
16+
```ts {1,4-7} filename="component.tsx"
17+
import PropTypes from 'prop-types';
18+
19+
class MyComponent extends React.Component {
20+
static propTypes = {
21+
foo: PropTypes.string,
22+
bar: PropTypes.number.isRequired,
23+
};
24+
render() {
25+
return <div />;
26+
}
27+
}
28+
```
29+
30+
```ts {1,9-12} filename="component.tsx"
31+
import PropTypes from 'prop-types';
32+
33+
class MyComponent extends React.Component {
34+
render() {
35+
return <div />;
36+
}
37+
}
38+
39+
MyComponent.propTypes = {
40+
foo: PropTypes.string,
41+
bar: PropTypes.number.isRequired,
42+
};
43+
```
44+
45+
```ts {1,5-8} filename="component.tsx"
46+
import PropTypes from 'prop-types';
47+
48+
const MyComponent = () => <div />;
49+
50+
MyComponent.propTypes = {
51+
foo: PropTypes.string,
52+
bar: PropTypes.number.isRequired,
53+
};
54+
```
55+
56+
## Output
57+
58+
```json {5-8,11-14} filename="JSON"
59+
[
60+
{
61+
"props": {
62+
"foo": {
63+
"type": {
64+
"name": "string"
65+
},
66+
"required": false
67+
},
68+
"bar": {
69+
"type": {
70+
"name": "number"
71+
},
72+
"required": true
73+
}
74+
}
75+
}
76+
]
77+
```

0 commit comments

Comments
 (0)