Skip to content

Commit 9e7b2c3

Browse files
author
Alexandr Kozhevnikov
committed
docs
1 parent b8acf25 commit 9e7b2c3

File tree

1 file changed

+52
-68
lines changed

1 file changed

+52
-68
lines changed

README.md

Lines changed: 52 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,23 @@ All the actions are api based. It means there is `no state` in the component. De
8585
### Minimal setup
8686

8787
```js
88-
import React, { Component } from 'react';
89-
import ReactDOM from 'react-dom';
90-
import { Tabs, TabList, Tab, PanelList, Panel } from '@react-tabtab-next/tabtab';
91-
92-
class Basic extends Component {
93-
render() {
94-
return (
95-
<Tabs>
96-
<TabList>
97-
<Tab>Tab1</Tab>
98-
<Tab>Tab2</Tab>
99-
</TabList>
100-
<PanelList>
101-
<Panel>Content1</Panel>
102-
<Panel>Content2</Panel>
103-
</PanelList>
104-
</Tabs>
105-
);
106-
}
107-
}
108-
109-
ReactDOM.render(<Basic />, document.getElementById('root'));
88+
import React from 'react';
89+
import { Tabs, Panel, Tab, TabList, PanelList } from '@react-tabtab-next/tabtab';
90+
91+
export const Example = () => {
92+
return (
93+
<Tabs>
94+
<TabList>
95+
<Tab>Tab1</Tab>
96+
<Tab>Tab2</Tab>
97+
</TabList>
98+
<PanelList>
99+
<Panel>Content1</Panel>
100+
<Panel>Content2</Panel>
101+
</PanelList>
102+
</Tabs>
103+
);
104+
};
110105
```
111106

112107
It's simple to use. Zero configuration!
@@ -115,7 +110,7 @@ It's simple to use. Zero configuration!
115110

116111
```js
117112
import React, { Component } from 'react';
118-
import { Tabs, DragTabList, PanelList, Panel, helpers } from '@react-tabtab-next/tabtab';
113+
import { Tabs, DragTabList, PanelList, Panel, Tab, helpers } from '@react-tabtab-next/tabtab';
119114

120115
const makeData = (number, titlePrefix = 'Tab') => {
121116
const data = [];
@@ -155,7 +150,7 @@ export default class Drag extends Component {
155150
const tabsTemplate = [];
156151
const panelTemplate = [];
157152
tabs.forEach((tab, index) => {
158-
tabsTemplate.push(<DragTab key={index}>{tab.title}</DragTab>);
153+
tabsTemplate.push(<Tab key={index}>{tab.title}</Tab>);
159154
panelTemplate.push(<Panel key={index}>{tab.content}</Panel>);
160155
});
161156
return (
@@ -179,7 +174,7 @@ Based on above example, the different to implement `normal tab` or `drag tab` is
179174

180175
And all the actions are controllable. You can customize your switch action. But if you don't want to write customized switch logic, you can directly use `import {simpleSwitch} from 'react-tabtab/lib/helpers/move'` this built-in function.
181176

182-
**normal tab**
177+
### normal tab
183178

184179
```js
185180
<Tabs>
@@ -194,7 +189,7 @@ And all the actions are controllable. You can customize your switch action. But
194189
</Tabs>
195190
```
196191

197-
**Sortable tabs**
192+
### Sortable tabs (+ ExtraButton)
198193

199194
```js
200195
<Tabs
@@ -229,46 +224,35 @@ In some case, if the data is large or we want to save the bandwidth, lazy loadin
229224
Moreover, you can mix lazy load panel with normal panel!
230225

231226
```js
232-
import React, { Component } from 'react';
233-
import ReactDOM from 'react-dom';
234-
import { Tabs, TabList, Tab, PanelList, AsyncPanel, Panel } from '@react-tabtab-next/tabtab';
235-
236-
function loadContentFunc(callback) {
237-
setTimeout(() => {
238-
callback(null, 'some content');
239-
}, 1000);
240-
}
241-
242-
// You also can provide promise as return function:
243-
// function loadContentFunc() {
244-
// return fetch('/products')
245-
// .then(resp => resp.json())
246-
// .then(data => data);
247-
// }
248-
249-
class AsyncTab extends Component {
250-
render() {
251-
return (
252-
<Tabs>
253-
<TabList>
254-
<Tab>Tab1</Tab>
255-
<Tab>Tab2</Tab>
256-
</TabList>
257-
<PanelList>
258-
<Panel>Content1</Panel>
259-
<AsyncPanel
260-
loadContent={loadContentFunc}
261-
render={(data) => <div>{JSON.stringify(data)}</div>}
262-
renderLoading={() => <div>Loading...</div>}
263-
cache={true}
264-
/>
265-
</PanelList>
266-
</Tabs>
267-
);
268-
}
269-
}
227+
import React from 'react';
228+
import { Tabs, Panel, Tab, TabList, PanelList, AsyncPanel } from '@react-tabtab-next/tabtab';
229+
230+
const AsyncTabsExmple = () => {
231+
const loadContentFunc = (callback) => {
232+
setTimeout(() => {
233+
callback(null, 'some content');
234+
}, 1000);
235+
};
236+
return (
237+
<Tabs>
238+
<TabList>
239+
<Tab>Tab1</Tab>
240+
<Tab>Tab2</Tab>
241+
</TabList>
242+
<PanelList>
243+
<Panel>Content1</Panel>
244+
<AsyncPanel
245+
loadContent={loadContentFunc}
246+
render={(data) => <div>{JSON.stringify(data)}</div>}
247+
renderLoading={() => <div>Loading...</div>}
248+
cache={true}
249+
/>
250+
</PanelList>
251+
</Tabs>
252+
);
253+
};
270254

271-
ReactDOM.render(<AsyncTab />, document.getElementById('root'));
255+
export default AsyncTabsExmple;
272256
```
273257

274258
To implement lazy loading, use `AsyncPanel` to wrap your panel content. Remember to provide `loadContent`, `render`, `renderLoading` these 3 props.
@@ -532,7 +516,7 @@ And now your tab is material design style!
532516

533517
If current theme doesn't meet your demand, follow this three steps and create a new one.
534518

535-
**First step: import current style**
519+
- First step: import current style
536520

537521
```js
538522
import styled from 'styled-components';
@@ -541,7 +525,7 @@ import { styled as styledTabTab } from '@react-tabtab-next/tabtab';
541525
let { TabListStyle, ActionButtonStyle, TabStyle, PanelStyle } = styledTabTab;
542526
```
543527

544-
**Second: extend style and export it**
528+
- Second: extend style and export it
545529

546530
```js
547531
import styled from 'styled-components';
@@ -598,7 +582,7 @@ Panel = styled(Panel)``;
598582
export { TabList, ActionButton, Tab, Panel };
599583
```
600584

601-
**Last: import your style and use it!**
585+
- Last: import your style and use it!
602586

603587
When you finish the new `@react-tabtab-next/theme` style, feel free to add it to `theme/` folder and send PR!
604588

0 commit comments

Comments
 (0)