Skip to content

Commit 5c91853

Browse files
update readme
1 parent a9ae0ba commit 5c91853

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

README.md

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,48 +983,66 @@ const {selectedTabID, openTabIDs} = instance.getPreviousData();
983983
<th>type</th>
984984
<th>default value</th>
985985
<th>required</th>
986+
<th>description</th>
986987
</tr>
987988
<tr>
988989
<td>id</td>
989990
<td>string</td>
990991
<td></td>
991992
<td>false</td>
993+
<td>a unique identifier for each tab</td>
992994
</tr>
993995
<tr>
994996
<td>title</td>
995997
<td>string</td>
996998
<td>' '</td>
997999
<td>false</td>
1000+
<td></td>
9981001
</tr>
9991002
<tr>
10001003
<td>tooltip</td>
10011004
<td>string</td>
10021005
<td>' '</td>
10031006
<td>false</td>
1007+
<td></td>
10041008
</tr>
10051009
<tr>
10061010
<td>panelComponent</td>
10071011
<td>React Element | React Component | null</td>
10081012
<td>A function component which returns empty div</td>
10091013
<td>false</td>
1014+
<td></td>
1015+
</tr>
1016+
<tr>
1017+
<td>lazy</td>
1018+
<td>boolean</td>
1019+
<td>false</td>
1020+
<td>false</td>
1021+
<td>
1022+
If set to false the panel will be rendered initially.
1023+
if set to true the panel will not be rendered until the tab is activated
1024+
</td>
10101025
</tr>
10111026
<tr>
10121027
<td>closable</td>
10131028
<td>boolean</td>
10141029
<td>true</td>
10151030
<td>false</td>
1031+
<td></td>
10161032
</tr>
10171033
<tr>
10181034
<td>iconClass</td>
10191035
<td>string</td>
10201036
<td>' '</td>
10211037
<td>false</td>
1038+
<td>class name for the icon</td>
10221039
</tr>
10231040
<tr>
10241041
<td>disable</td>
10251042
<td>boolean</td>
10261043
<td>false</td>
10271044
<td>false</td>
1045+
<td></td>
10281046
</tr>
10291047
</tbody>
10301048
</table>
@@ -1037,6 +1055,7 @@ const tabData = {
10371055
title: 'contactTitle',
10381056
tooltip: 'contactTooltip',
10391057
disable: true,
1058+
lazy: true,
10401059
iconClass: 'fa fa-home',
10411060
closable: false,
10421061
panelComponent: (porps) => <p> contact content </p>,
@@ -1050,7 +1069,57 @@ if (instance.isOpen(tabData.id) == false) {
10501069

10511070
## Lazy Loading
10521071

1053-
upcoming...
1072+
Defer loading of tab content until the tab is activated
1073+
1074+
Example 1
1075+
1076+
```js
1077+
const Panel3 = React.lazy(() => import('./components/panel3.js'));
1078+
function LazyLoadingPanel3(porps) {
1079+
return (
1080+
<Suspense fallback={<div>Loading...</div>}>
1081+
<Panel3 {...porps}></Panel3>
1082+
</Suspense>
1083+
);
1084+
}
1085+
useDynTabs({
1086+
tabs: [
1087+
{id: '1', title: 'eager loading tab 1', panelComponent: <p>panel 1</p>},
1088+
{id: '2', title: 'eager loading tab 2', lazy: true, panelComponent: <p>panel 2</p>},
1089+
{id: '3', title: 'lazy loading tab 3', lazy: true, panelComponent: LazyLoadingPanel3},
1090+
],
1091+
selectedTabID: '1',
1092+
});
1093+
```
1094+
1095+
**NOTE :**
1096+
1097+
- panel 1 is eagerly loaded and rendered.
1098+
- panel 2 is eagerly loaded but will not be rendered until tab 2 is activated.
1099+
- panel 3 will not be loaded and rendered until tab 3 is activated.
1100+
1101+
Example 2 ( using onFirstSelect event )
1102+
1103+
```js
1104+
useDynTabs({
1105+
tabs: [
1106+
{id: '1', title: 'eager loading tab 1', panelComponent: <p>panel 1</p>},
1107+
{id: '2', title: 'eager loading tab 2', lazy: true, panelComponent: <p>panel 2</p>},
1108+
{id: '3', title: 'lazy loading tab 3', lazy: true, panelComponent: <div>Loading...</div>},
1109+
],
1110+
onFirstSelect: function ({currentSelectedTabId, previousSelectedTabId}) {
1111+
const instance = this;
1112+
if (currentSelectedTabId === '3') {
1113+
import('./components/panel3.js').then((defaultExportedModule) => {
1114+
const Panel3 = defaultExportedModule.default;
1115+
instance.setTab('3', {panelComponent: Panel3});
1116+
instance.refresh();
1117+
});
1118+
}
1119+
},
1120+
selectedTabID: '1',
1121+
});
1122+
```
10541123

10551124
## Styling
10561125

@@ -1065,7 +1134,7 @@ import 'react-dyn-tabs/themes/react-dyn-tabs-card.min.css';
10651134

10661135
**NOTE :**
10671136

1068-
You can find other themes at themes folder.
1137+
You can find other themes at themes folder and multiple themes example at example/multi-themes-example folder.
10691138

10701139
## Caveats
10711140

0 commit comments

Comments
 (0)