Skip to content

Commit 1d5bd1a

Browse files
update readme : correct description of setTab
function
1 parent 19c3443 commit 1d5bd1a

File tree

1 file changed

+29
-84
lines changed

1 file changed

+29
-84
lines changed

README.md

Lines changed: 29 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
React Dynamic Tabs with full API
44

5-
### [document](https://github.com/dev-javascript/react-dyn-tabs/)
5+
### [Demo](https://dev-javascript.github.io/react-dyn-tabs/)
66

77
## Features
88

@@ -85,7 +85,7 @@ $ yarn add react-dyn-tabs
8585
import React, {useEffect} from 'react';
8686
import useDynTabs from 'react-dyn-tabs';
8787
import 'react-dyn-tabs/style/react-dyn-tabs.css';
88-
import 'react-dyn-tabs/themes/default.css';
88+
import 'react-dyn-tabs/themes/react-dyn-tabs-card.css';
8989
import ContactComponent from './contact-component';
9090

9191
export default () => {
@@ -255,15 +255,6 @@ const [TabList, PanelList, ready] = useDynTabs({
255255
const [TabList, PanelList, ready] = useDynTabs({direction: 'rtl'});
256256
```
257257

258-
or
259-
260-
```js
261-
if (instance.getOption('direction') !== 'ltr') {
262-
instance.setOption('direction', 'ltr');
263-
instance.refresh();
264-
}
265-
```
266-
267258
### tabComponent
268259

269260
<table>
@@ -297,22 +288,6 @@ const [TabList, PanelList, ready] = useDynTabs({
297288
});
298289
```
299290

300-
or
301-
302-
```js
303-
const CustomTabComponent = (props) => {
304-
const {id, isSelected, api: instance} = props;
305-
return (
306-
<button {...props.tabProps}>
307-
{props.children}
308-
{props.iconProps && <span {...props.iconProps}></span>}
309-
</button>
310-
);
311-
};
312-
instance.setOption('tabComponent', CustomTabComponent);
313-
instance.refresh();
314-
```
315-
316291
### defaultPanelComponent
317292

318293
Default value for panelComponent option.
@@ -343,13 +318,6 @@ const [TabList, PanelList, ready] = useDynTabs({
343318
});
344319
```
345320

346-
or
347-
348-
```js
349-
instance.setOption('defaultPanelComponent', (props) => <p></p>);
350-
instance.refresh();
351-
```
352-
353321
### accessibility
354322

355323
<table>
@@ -375,14 +343,6 @@ instance.refresh();
375343
const [TabList, PanelList, ready] = useDynTabs({accessibility: false});
376344
```
377345

378-
or
379-
380-
```js
381-
if (instance.getOption('accessibility') == true) {
382-
instance.setOption('accessibility', false).refresh();
383-
}
384-
```
385-
386346
**NOTE :**
387347

388348
This option assigns id attribute on panel element and button element inside the tab. for having elements without id attribute, set this option to false.
@@ -464,10 +424,6 @@ const [TabList, PanelList, ready] = useDynTabs({
464424
// you can use 'this' here which refers to the instance
465425
},
466426
});
467-
// or
468-
instance.setOption('onInit', () => {}).refresh();
469-
// or
470-
instance.on('onInit', () => {});
471427
```
472428

473429
### onChange
@@ -495,8 +451,6 @@ const [TabList, PanelList, ready] = useDynTabs({
495451
// you can use 'this' here which refers to the instance
496452
},
497453
});
498-
// or
499-
instance.setOption('onChange', ({currentData, previousData, closedTabIDs, openedTabIDs}) => {}).refresh();
500454
```
501455

502456
### beforeSelect
@@ -528,12 +482,6 @@ const [TabList, PanelList, ready] = useDynTabs({
528482
return true;
529483
},
530484
});
531-
// or
532-
instance
533-
.setOption('beforeSelect', (e, id) => {
534-
return true;
535-
})
536-
.refresh();
537485
```
538486

539487
### onSelect
@@ -561,8 +509,6 @@ const [TabList, PanelList, ready] = useDynTabs({
561509
// you can use 'this' here which refers to the instance
562510
},
563511
});
564-
// or
565-
instance.setOption('onSelect', ({currentSelectedTabId, previousSelectedTabId}) => {}).refresh();
566512
```
567513

568514
### onOpen
@@ -590,8 +536,6 @@ const [TabList, PanelList, ready] = useDynTabs({
590536
// you can use 'this' here which refers to the instance
591537
},
592538
});
593-
// or
594-
instance.setOption('onOpen', (openedTabIDs) => {}).refresh();
595539
```
596540

597541
### beforeClose
@@ -623,12 +567,6 @@ const [TabList, PanelList, ready] = useDynTabs({
623567
return true;
624568
},
625569
});
626-
// or
627-
instance
628-
.setOption('beforeClose', (e, id) => {
629-
return true;
630-
})
631-
.refresh();
632570
```
633571

634572
### onClose
@@ -656,8 +594,6 @@ const [TabList, PanelList, ready] = useDynTabs({
656594
// you can use 'this' here which refers to the instance
657595
},
658596
});
659-
// or
660-
instance.setOption('onClose', (closedTabIDs) => {}).refresh();
661597
```
662598

663599
### onDestroy
@@ -685,8 +621,6 @@ const [TabList, PanelList, ready] = useDynTabs({
685621
// you can use 'this' here which refers to the instance
686622
},
687623
});
688-
// or
689-
instance.setOption('onDestroy', () => {}).refresh();
690624
```
691625

692626
## Methods
@@ -718,10 +652,10 @@ Parameters:
718652
**Example**
719653

720654
```js
721-
if (instance.isOpen('2') == false) {
655+
if (instance.isOpen('contact') == false) {
722656
instance
723657
.open({
724-
id: '2',
658+
id: 'contact',
725659
title: 'contact',
726660
tooltip: 'contact',
727661
disable: false,
@@ -730,7 +664,7 @@ if (instance.isOpen('2') == false) {
730664
panelComponent: <ContactPanel></ContactPanel>,
731665
})
732666
.then(({currentData, instance}) => {
733-
//do sth here
667+
console.log('contact tab is open');
734668
});
735669
}
736670
```
@@ -766,9 +700,9 @@ Parameters:
766700
**Example**
767701

768702
```js
769-
if (instance.isSelected('your tab id') == false) {
770-
instance.select('your tab id').then(({currentData, instance}) => {
771-
//do sth here
703+
if (instance.isSelected('1') == false) {
704+
instance.select('1').then(({currentData, instance}) => {
705+
console.log('tab 1 is selected');
772706
});
773707
}
774708
```
@@ -795,7 +729,7 @@ Parameters:
795729
```js
796730
if (instance.isOpen('2') == true) {
797731
instance.close('2').then(({currentData, instance}) => {
798-
//do sth here
732+
console.log('tab 2 is closed');
799733
});
800734
}
801735
```
@@ -831,9 +765,11 @@ const onSelect = instance.getOption('onSelect');
831765

832766
### setOption
833767

834-
for re-rendering immediately after this function, you should call refresh method after it.
768+
You can use this method for setting all options except selectedTabID and tabs options.
835769

836-
Return value : instance
770+
For re-rendering immediately after this function, you should call refresh method after it.
771+
772+
Return value : instance object
837773

838774
Parameters:
839775

@@ -845,6 +781,7 @@ Parameters:
845781
```js
846782
instance.setOption('direction', 'rtl');
847783
instance.setOption('onSelect', () => {});
784+
instance.setOption('beforeSelect', () => false);
848785
```
849786

850787
### getTab
@@ -872,14 +809,14 @@ Return value : instance
872809

873810
Parameters:
874811

875-
- `optionName : String`
876-
- `optionValue : string|boolean|object|function`
812+
- `tab id : String`
813+
- `source object : containing the properties you want to apply`
877814

878815
**Example**
879816

880817
```js
881-
instance.setTab('disable', true);
882-
instance.setTab('panelComponent', (props) => <p />);
818+
instance.setTab('home', {disable: true});
819+
instance.setTab('contact', {closable: false, panelComponent: (props) => <p>contact panel</p>});
883820
```
884821

885822
### on
@@ -1058,13 +995,21 @@ upcoming...
1058995
react-dyn-tabs does not include any style loading by default. Default stylesheets and themes are provided and can be included in your application if desired.
1059996

1060997
```js
1061-
import 'react-dyn-tabs/style/react-dyn-tabs.css';
1062-
import 'react-dyn-tabs/themes/default.css';
998+
import 'react-dyn-tabs/style/react-dyn-tabs.min.css';
999+
// or import 'react-dyn-tabs/style/scss/react-dyn-tabs.scss';
1000+
import 'react-dyn-tabs/themes/react-dyn-tabs-card.min.css';
1001+
// or import 'react-dyn-tabs/themes/scss/react-dyn-tabs-card.scss';
10631002
```
10641003

1004+
**NOTE :**
1005+
1006+
You can find other themes at src/themes folder.
1007+
10651008
## Caveats
10661009

1067-
Some actions like open, select, close and refresh cause re-rendering, and using them immediately after calling useDynTabs hook will create an infinite loop and other bugs that most likely you don't want to cause. you should use them inside event listeners or subscriptions.
1010+
- Some actions like open, select, close and refresh cause re-rendering, and using them immediately after calling useDynTabs hook will create an infinite loop and other bugs that most likely you don't want to cause. you should use them inside event listeners or subscriptions.
1011+
1012+
- Do not use setState inside the onInit callback because it leads to an infinite loop.
10681013

10691014
## Deprecated features
10701015

0 commit comments

Comments
 (0)