Skip to content

Commit

Permalink
Merge pull request #10 from diegolanda/master
Browse files Browse the repository at this point in the history
Added PureComponent do docgenConverter and examples
  • Loading branch information
pvasek authored May 2, 2017
2 parents b675929 + 4bea1fa commit c0133f0
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 1 deletion.
48 changes: 48 additions & 0 deletions examples/react-styleguidist-example/components/ConstExport.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react';

/**
* Row properties.
*/
export interface IRowProps {
/** prop1 description */
prop1?: string;
/** prop2 description */
prop2: number;
/**
* prop3 description
*/
prop3: () => void;
/** prop4 description */
prop4: 'option1' | 'option2' | "option3";
}

/**
* test
*
*/
export const test = (one: number) => {
return one;
}

export const myObj = {
foo: 'bar',
}

/**
* Form row.
*/
export const ConstExportRow = (props: IRowProps) => {
const innerFunc = (props: IRowProps) => {
return <span>Inner Func</span>
};
const innerNonExportedFunc = (props: IRowProps) => {
return <span>Inner Func</span>
};
return <div>Test</div>;
};

const nonExportedFunc = (props: IRowProps) => {
return <div>No Export</div>
};

export default ConstExportRow;
29 changes: 29 additions & 0 deletions examples/react-styleguidist-example/components/PureRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';

/**
* Row properties.
*/
export interface IRowProps {
/** prop1 description */
prop1?: string;
/** prop2 description */
prop2: number;
/**
* prop3 description
*/
prop3: () => void;
/** prop4 description */
prop4: 'option1' | 'option2' | "option3";
}

/**
* Form row.
*/
export class PureRow extends React.PureComponent<IRowProps, {}> {

render() {
return <div>Test</div>;
}
};

export default PureRow;
26 changes: 26 additions & 0 deletions src/__tests__/docgenConverter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,30 @@ describe('docgenConverter', () => {
assert.equal('name1', result.displayName);
assert.equal('comment1', result.description);
});

it('Should work with class PureComponent', () => {
let result: StyleguidistComponent = null;
const originalWarn = console.warn;
let warnCallCount = 0;
console.warn = () => warnCallCount++;
try {
result = convertToDocgen({
classes: [
{
name: 'name1',
comment: 'comment1',
extends: 'PureComponent',
propInterface: null,
}
],
interfaces: []
});
} finally {
console.warn = originalWarn;
}

assert.equal(1, warnCallCount);
assert.equal('name1', result.displayName);
assert.equal('comment1', result.description);
});
});
2 changes: 1 addition & 1 deletion src/docgenConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface StyleguidistComponent {
}

export function convertToDocgen(doc: FileDoc): StyleguidistComponent {
const reactClasses = doc.classes.filter(i => i.extends === 'Component' || i.extends === 'StatelessComponent');
const reactClasses = doc.classes.filter(i => i.extends === 'Component' || i.extends === 'StatelessComponent' || i.extends === 'PureComponent');

if (reactClasses.length === 0) {
return null;
Expand Down

0 comments on commit c0133f0

Please sign in to comment.