Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit 2dd547a

Browse files
committed
docs: improves styleguidist documentation
1 parent 82966b9 commit 2dd547a

File tree

13 files changed

+134
-27
lines changed

13 files changed

+134
-27
lines changed

src/components/List/List.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
### How to use
2+
3+
```jsx static
4+
import React from 'react';
5+
import { List } from 'react-semantics';
6+
```
7+
8+
#### With render prop
9+
##### Output
10+
111
```jsx
2-
const data = [1,2,3,4,5,6,7,8,9].map(() => faker.name.findName());
12+
const data = [1,2,3].map(() => faker.name.findName());
313

414
<ul>
515
<List
@@ -12,3 +22,20 @@ const data = [1,2,3,4,5,6,7,8,9].map(() => faker.name.findName());
1222
/>
1323
</ul>
1424
```
25+
26+
#### With children
27+
##### Output
28+
29+
```jsx
30+
const data = [1,2,3].map(() => faker.name.findName());
31+
32+
<ul>
33+
<List items={data}>
34+
{n => (
35+
<li key={n}>
36+
<div>{n}</div>
37+
</li>
38+
)}
39+
</List>
40+
</ul>
41+
```

src/components/List/List.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
import * as PropTypes from 'prop-types';
22
import * as React from 'react';
33

4+
type ListItemCallbackFn = (
5+
value?: any,
6+
index?: number,
7+
array?: any[],
8+
) => React.ReactNode;
9+
410
export interface IListProps {
511
/** Array to map. */
612
items: any[];
713

814
/** Shorthand for primary content. */
9-
render?: (value?: any, index?: number, array?: any[]) => React.ReactNode;
15+
render?: ListItemCallbackFn;
1016

1117
/** Primary content. */
12-
children?: (value?: any, index?: number, array?: any[]) => React.ReactNode;
18+
children?: any;
1319
}
1420

1521
/**
16-
* Calls `render` or `children` on each element of `items`, and returns the result.
22+
* Semantic helper component that calls the specified callback function in either `render` or `children` on each element of `items`.
1723
*/
1824
const List: React.SFC<IListProps> = ({ items, render, children }) => {
1925
const func = children ? children : render;

src/components/Resolve/Resolve.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### How to use
2+
3+
```jsx static
4+
import React from 'react';
5+
import { Resolve } from 'react-semantics';
6+
```
7+
##### Output
8+
19
```jsx
210
const data = [1,2,3].map(() => faker.fake("{{lorem.sentence}}"));
311

@@ -7,12 +15,12 @@ class Example extends React.Component {
715
<>
816
<List
917
items={data}
10-
render={(v,i) => (
18+
render={v => (
1119
<Resolve
1220
promise={this._getData(v)}
13-
pending={<div key={i}>Fetching data...</div>}
21+
pending={<div key={v}>Fetching data...</div>}
1422
resolved={value => (
15-
<div key={i}>{v}</div>
23+
<div key={v}>{v}</div>
1624
)}
1725
/>
1826
)}

src/components/Resolve/Resolve.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const initialState = {
3131
type IResolveState = Readonly<typeof initialState>;
3232

3333
/**
34-
* Returns content based on specified promise.
34+
* Semantic helper component that returns content based on the status of the specified promise.
3535
*/
3636
class Resolve extends React.Component<IResolveProps, IResolveState> {
3737
public static propTypes = {

src/components/Show/Show.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
### How to use
2+
3+
```jsx static
4+
import React from 'react';
5+
import { Show } from 'react-semantics';
6+
```
7+
8+
#### With render prop
9+
##### Output
10+
11+
```jsx
12+
const data = faker.fake("{{lorem.words}}");
13+
14+
<Show
15+
when={true}
16+
render={() => (
17+
<div>{data}</div>
18+
)}
19+
/>
20+
```
21+
22+
23+
#### With children
24+
##### Output
125

226
```jsx
327
const data = faker.fake("{{lorem.words}}");

src/components/Show/Show.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface IShowProps {
1515
}
1616

1717
/**
18-
* Renders primary content if `when` equals true.
18+
* Semantic helper component that return content if `when` equals true.
1919
*/
2020
const Show: React.SFC<IShowProps> = ({ when, render, children }) => {
2121
if (when) {

src/components/Switch/Switch.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11

2+
### Static methods
3+
4+
These helper components can be accessed from the `Switch` component like this `<Switch.Case />`.
5+
6+
* [Case](#/SwitchCase)
7+
* [Default](#/SwitchDefault)
8+
9+
### How to use
10+
11+
```jsx static
12+
import React from 'react';
13+
import { Switch } from 'react-semantics';
14+
```
15+
16+
##### Output
17+
218
```jsx
319
<Switch value={3}>
420
<Switch.Case value={1}>

src/components/Switch/Switch.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export interface ISwitchProps {
1515
}
1616

1717
/**
18-
* Returns primary content of first case that matches, returns default if no match and null if no default.
18+
* Semantic helper component that returns content of the first case that matches `value`.
19+
* It returns default if it exists and null if no default exists.
1920
*/
2021
class Switch extends React.Component<ISwitchProps> {
2122
public static propTypes = {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
### How to use
3+
4+
```jsx static
5+
import React from 'react';
6+
import { Switch } from 'react-semantics';
7+
```
8+
9+
##### Output
10+
11+
```jsx
12+
<Switch.Case value={'anything'}>
13+
<div>Render me!</div>
14+
</Switch.Case>
15+
```

src/components/Switch/SwitchCase.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export interface ISwitchCaseProps {
1414
children?: React.ReactNode;
1515
}
1616

17+
/**
18+
* Semantic helper component that can be accessed from the `Switch` component.
19+
* Only ment to be used inside the children of the `Switch` component.
20+
*/
1721
const SwitchCase: React.SFC<ISwitchCaseProps> = ({ value, render, children }) => {
1822
if (value !== undefined) {
1923
if (children && !isEmptyChildren(children)) {

0 commit comments

Comments
 (0)