Skip to content

Commit

Permalink
Documentation: Adding withInstanceId HoC documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 12, 2017
1 parent ee8097b commit 9d57a33
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function loadStories() {
window.wp = { ...window.wp, element };
require( '../components/story' );
require( '../components/button/story' );
require( '../components/higher-order/story' );
require( '../components/higher-order/with-instance-id/story' );
}

setOptions( {
Expand Down
6 changes: 6 additions & 0 deletions components/higher-order/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Higher Order Components
=======================

This directory includes a library of generic Higher Order React Components.

[Learn more abouth Higher Order Components](https://facebook.github.io/react/docs/higher-order-components.html)
15 changes: 15 additions & 0 deletions components/higher-order/story/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* External dependencies
*/
import ReactMarkdown from 'react-markdown';
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';

/**
* Internal dependencies
*/
import readme from '../README.md';

storiesOf( 'Higher Order Components', module )
.addDecorator( withKnobs )
.add( 'Intro', () => <ReactMarkdown source={ readme } /> );
24 changes: 24 additions & 0 deletions components/higher-order/with-instance-id/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
withInstanceId
==============

Some components need to generate a unique id for each instance. This could serve as suffixes to element ID's for example.
Wrapping a component with `withInstanceId` provides a unique `instanceId` to serve this purpose.

## Usage

```jsx
/**
* WordPress dependencies
*/
import { withInstanceId } from 'components';

function MyCustomElement( { instanceId } ) {
return (
<div id={ `my-custom-element-${ instanceId }` }>
content
</div>
);
}

export default withInstanceId( MyCustomElement );
```
15 changes: 15 additions & 0 deletions components/higher-order/with-instance-id/story/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* External dependencies
*/
import ReactMarkdown from 'react-markdown';
import { storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';

/**
* Internal dependencies
*/
import readme from '../README.md';

storiesOf( 'Higher Order Components', module )
.addDecorator( withKnobs )
.add( 'withInstanceId', () => <ReactMarkdown source={ readme } /> );
2 changes: 1 addition & 1 deletion components/story/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ import readme from '../README.md';

storiesOf( 'Components', module )
.addDecorator( withKnobs )
.add( 'Welcome', () => <ReactMarkdown source={ readme } /> );
.add( 'Intro', () => <ReactMarkdown source={ readme } /> );

0 comments on commit 9d57a33

Please sign in to comment.