Skip to content

Commit a893dec

Browse files
rosskevindanez
authored andcommitted
Add more flow definitions
1 parent 39a4096 commit a893dec

File tree

7 files changed

+299
-49
lines changed

7 files changed

+299
-49
lines changed

src/Documentation.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
*
1111
*/
1212

13+
export type DocumentationObject = {
14+
props?: Object,
15+
context?: Object,
16+
childContext?: Object,
17+
composes?: Array<string>,
18+
};
19+
1320
class Documentation {
1421
_props: Object;
1522
_context: Object;
@@ -61,8 +68,8 @@ class Documentation {
6168
return propDescriptor;
6269
}
6370

64-
toObject(): Object {
65-
const obj = {};
71+
toObject(): DocumentationObject {
72+
const obj: DocumentationObject = {};
6673

6774
for (const [key, value] of this._data) {
6875
obj[key] = value;

src/__tests__/__snapshots__/main-test.js.snap

Lines changed: 180 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,27 +334,198 @@ Object {
334334
exports[`main fixtures processes component "component_12.js" without errors 1`] = `
335335
Object {
336336
"description": "",
337-
"displayName": "Foo",
337+
"displayName": "Paper",
338338
"methods": Array [],
339339
"props": Object {
340-
"prop1": Object {
341-
"description": "",
340+
"anchorOrigin": Object {
341+
"defaultValue": Object {
342+
"computed": false,
343+
"value": "{
344+
vertical: 'top',
345+
horizontal: 'left',
346+
}",
347+
},
348+
"description": "This is the point on the anchor where the popover's
349+
\`anchorEl\` will attach to. This is not used when the
350+
anchorReference is 'anchorPosition'.
351+
352+
Options:
353+
vertical: [top, center, bottom];
354+
horizontal: [left, center, right].",
355+
"flowType": Object {
356+
"name": "signature",
357+
"raw": "{
358+
horizontal: 'left' | 'center' | 'right' | number,
359+
vertical: 'top' | 'center' | 'bottom' | number,
360+
}",
361+
"signature": Object {
362+
"properties": Array [
363+
Object {
364+
"key": "horizontal",
365+
"value": Object {
366+
"elements": Array [
367+
Object {
368+
"name": "literal",
369+
"value": "'left'",
370+
},
371+
Object {
372+
"name": "literal",
373+
"value": "'center'",
374+
},
375+
Object {
376+
"name": "literal",
377+
"value": "'right'",
378+
},
379+
Object {
380+
"name": "number",
381+
},
382+
],
383+
"name": "union",
384+
"raw": "'left' | 'center' | 'right' | number",
385+
"required": true,
386+
},
387+
},
388+
Object {
389+
"key": "vertical",
390+
"value": Object {
391+
"elements": Array [
392+
Object {
393+
"name": "literal",
394+
"value": "'top'",
395+
},
396+
Object {
397+
"name": "literal",
398+
"value": "'center'",
399+
},
400+
Object {
401+
"name": "literal",
402+
"value": "'bottom'",
403+
},
404+
Object {
405+
"name": "number",
406+
},
407+
],
408+
"name": "union",
409+
"raw": "'top' | 'center' | 'bottom' | number",
410+
"required": true,
411+
},
412+
},
413+
],
414+
},
415+
"type": "object",
416+
},
417+
"required": false,
418+
},
419+
"children": Object {
420+
"description": "@ignore",
342421
"flowType": Object {
343-
"name": "string",
422+
"name": "Node",
344423
},
345-
"required": true,
424+
"required": false,
346425
},
347-
"prop2": Object {
426+
"classes": Object {
427+
"description": "Useful to extend the style applied to components.",
428+
"flowType": Object {
429+
"name": "Object",
430+
},
431+
"required": false,
432+
},
433+
"component": Object {
348434
"defaultValue": Object {
349435
"computed": false,
350-
"value": "'bar'",
436+
"value": "'div'",
351437
},
352-
"description": "",
438+
"description": "The component used for the root node.
439+
This currently has to be flow cast in defaultProps as of flow 0.59.0",
353440
"flowType": Object {
354-
"name": "string",
441+
"name": "ElementType",
442+
},
443+
"required": false,
444+
},
445+
"elevation": Object {
446+
"defaultValue": Object {
447+
"computed": false,
448+
"value": "2",
449+
},
450+
"description": "Shadow depth, corresponds to \`dp\` in the spec.
451+
It's accepting values between 0 and 24 inclusive.",
452+
"flowType": Object {
453+
"name": "number",
454+
},
455+
"required": false,
456+
},
457+
"labelRowsPerPage": Object {
458+
"defaultValue": Object {
459+
"computed": false,
460+
"value": "'Rows per page:'",
461+
},
462+
"description": "Useful to customize the rows per page label. Invoked with a \`{ from, to, count, page }\`
463+
object.",
464+
"flowType": Object {
465+
"name": "Node",
355466
},
356467
"required": false,
357468
},
469+
"timeout": Object {
470+
"defaultValue": Object {
471+
"computed": false,
472+
"value": "300",
473+
},
474+
"description": "The duration for the transition, in milliseconds.
475+
You may specify a single timeout for all transitions, or individually with an object.
476+
477+
Set to 'auto' to automatically calculate transition time based on height.",
478+
"flowType": Object {
479+
"elements": Array [
480+
Object {
481+
"name": "number",
482+
},
483+
Object {
484+
"name": "signature",
485+
"raw": "{ enter?: number, exit?: number }",
486+
"signature": Object {
487+
"properties": Array [
488+
Object {
489+
"key": "enter",
490+
"value": Object {
491+
"name": "number",
492+
"required": false,
493+
},
494+
},
495+
Object {
496+
"key": "exit",
497+
"value": Object {
498+
"name": "number",
499+
"required": false,
500+
},
501+
},
502+
],
503+
},
504+
"type": "object",
505+
},
506+
Object {
507+
"name": "literal",
508+
"value": "'auto'",
509+
},
510+
],
511+
"name": "union",
512+
"raw": "number | { enter?: number, exit?: number } | 'auto'",
513+
},
514+
"required": false,
515+
},
516+
"transition": Object {
517+
"description": "Transition component.",
518+
"flowType": Object {
519+
"elements": Array [
520+
Object {
521+
"name": "unknown",
522+
},
523+
],
524+
"name": "ComponentType",
525+
"raw": "ComponentType<*>",
526+
},
527+
"required": true,
528+
},
358529
},
359530
}
360531
`;
Lines changed: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,101 @@
1-
/*
2-
* Copyright (c) 2015, Facebook, Inc.
3-
* All rights reserved.
4-
*
5-
* This source code is licensed under the BSD-style license found in the
6-
* LICENSE file in the root directory of this source tree. An additional grant
7-
* of patent rights can be found in the PATENTS file in the same directory.
8-
*
9-
*/
1+
// @flow
102

113
/**
12-
* Test for documentation of React components with Flow annotations for props.
4+
* Test for documentation of flow class
135
*/
146

157
import React from 'react';
8+
import type { ComponentType, ElementType, Node } from 'react';
169

17-
type Props = {
18-
prop1: string,
19-
prop2: string,
10+
type ProvidedProps = {
11+
classes: Object,
2012
};
2113

22-
class Foo extends React.Component<Props> {
23-
render() {
24-
return (
25-
<div>
26-
{this.props.prop1}
27-
I am Foo!
28-
{this.props.prop2}
29-
</div>
30-
);
31-
}
32-
}
14+
export type Origin = {
15+
horizontal: 'left' | 'center' | 'right' | number,
16+
vertical: 'top' | 'center' | 'bottom' | number,
17+
};
18+
19+
export const duration = {
20+
standard: 300,
21+
};
3322

34-
Foo.defaultProps = {
35-
prop2: 'bar',
23+
export type TransitionDuration = number | { enter?: number, exit?: number } | 'auto';
24+
25+
export type Props = {
26+
/**
27+
* Other base element props.
28+
*/
29+
[otherProp: string]: any,
30+
/**
31+
* This is the point on the anchor where the popover's
32+
* `anchorEl` will attach to. This is not used when the
33+
* anchorReference is 'anchorPosition'.
34+
*
35+
* Options:
36+
* vertical: [top, center, bottom];
37+
* horizontal: [left, center, right].
38+
*/
39+
anchorOrigin?: Origin,
40+
/**
41+
* Useful to extend the style applied to components.
42+
*/
43+
classes?: Object,
44+
/**
45+
* @ignore
46+
*/
47+
children?: Node,
48+
/**
49+
* The component used for the root node.
50+
* This currently has to be flow cast in defaultProps as of flow 0.59.0
51+
*/
52+
component: ElementType,
53+
/**
54+
* Shadow depth, corresponds to `dp` in the spec.
55+
* It's accepting values between 0 and 24 inclusive.
56+
*/
57+
elevation: number,
58+
/**
59+
* Useful to customize the rows per page label. Invoked with a `{ from, to, count, page }`
60+
* object.
61+
*/
62+
labelRowsPerPage: Node,
63+
/**
64+
* Transition component.
65+
*/
66+
transition: ComponentType<*>,
67+
/**
68+
* The duration for the transition, in milliseconds.
69+
* You may specify a single timeout for all transitions, or individually with an object.
70+
*
71+
* Set to 'auto' to automatically calculate transition time based on height.
72+
*/
73+
timeout: TransitionDuration,
3674
};
3775

38-
export default Foo;
76+
class Paper extends React.Component<ProvidedProps & Props> {
77+
static defaultProps = {
78+
anchorOrigin: ({
79+
vertical: 'top',
80+
horizontal: 'left',
81+
}: Origin),
82+
labelRowsPerPage: ('Rows per page:': Node),
83+
component: ('div': ElementType),
84+
component: 'div',
85+
elevation: 2,
86+
timeout: (duration.standard: TransitionDuration),
87+
};
88+
89+
render() {
90+
const {
91+
classes,
92+
component: ComponentProp,
93+
transition,
94+
...other
95+
} = this.props;
96+
97+
return <ComponentProp className={classes.root} transition={transition} {...other} />;
98+
}
99+
}
100+
101+
export default Paper;

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import parse from './parse';
1515
import * as AllResolver from './resolver';
1616
import * as utils from './utils';
1717
import type { Options } from './babelParser';
18+
import type { DocumentationObject } from './Documentation';
1819

1920
const defaultResolver = AllResolver.findExportedComponentDefinition;
2021
const defaultHandlers = [
@@ -48,7 +49,7 @@ function defaultParse(
4849
resolver?: ?Resolver,
4950
handlers?: ?Array<Handler>,
5051
options?: Options = {},
51-
): Array<Object> | Object {
52+
): Array<DocumentationObject> | DocumentationObject {
5253
if (!resolver) {
5354
resolver = defaultResolver;
5455
}

0 commit comments

Comments
 (0)