2
2
3
3
React Dynamic Tabs with full API
4
4
5
- ### [ document ] ( https://github.com/ dev-javascript/react-dyn-tabs/ )
5
+ ### [ Demo ] ( https://dev-javascript.github.io /react-dyn-tabs/ )
6
6
7
7
## Features
8
8
@@ -85,7 +85,7 @@ $ yarn add react-dyn-tabs
85
85
import React , {useEffect } from ' react' ;
86
86
import useDynTabs from ' react-dyn-tabs' ;
87
87
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' ;
89
89
import ContactComponent from ' ./contact-component' ;
90
90
91
91
export default () => {
@@ -255,15 +255,6 @@ const [TabList, PanelList, ready] = useDynTabs({
255
255
const [TabList , PanelList , ready ] = useDynTabs ({direction: ' rtl' });
256
256
```
257
257
258
- or
259
-
260
- ``` js
261
- if (instance .getOption (' direction' ) !== ' ltr' ) {
262
- instance .setOption (' direction' , ' ltr' );
263
- instance .refresh ();
264
- }
265
- ```
266
-
267
258
### tabComponent
268
259
269
260
<table >
@@ -297,22 +288,6 @@ const [TabList, PanelList, ready] = useDynTabs({
297
288
});
298
289
```
299
290
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
-
316
291
### defaultPanelComponent
317
292
318
293
Default value for panelComponent option.
@@ -343,13 +318,6 @@ const [TabList, PanelList, ready] = useDynTabs({
343
318
});
344
319
```
345
320
346
- or
347
-
348
- ``` js
349
- instance .setOption (' defaultPanelComponent' , (props ) => < p>< / p> );
350
- instance .refresh ();
351
- ```
352
-
353
321
### accessibility
354
322
355
323
<table >
@@ -375,14 +343,6 @@ instance.refresh();
375
343
const [TabList , PanelList , ready ] = useDynTabs ({accessibility: false });
376
344
```
377
345
378
- or
379
-
380
- ``` js
381
- if (instance .getOption (' accessibility' ) == true ) {
382
- instance .setOption (' accessibility' , false ).refresh ();
383
- }
384
- ```
385
-
386
346
** NOTE :**
387
347
388
348
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({
464
424
// you can use 'this' here which refers to the instance
465
425
},
466
426
});
467
- // or
468
- instance .setOption (' onInit' , () => {}).refresh ();
469
- // or
470
- instance .on (' onInit' , () => {});
471
427
```
472
428
473
429
### onChange
@@ -495,8 +451,6 @@ const [TabList, PanelList, ready] = useDynTabs({
495
451
// you can use 'this' here which refers to the instance
496
452
},
497
453
});
498
- // or
499
- instance .setOption (' onChange' , ({currentData, previousData, closedTabIDs, openedTabIDs}) => {}).refresh ();
500
454
```
501
455
502
456
### beforeSelect
@@ -528,12 +482,6 @@ const [TabList, PanelList, ready] = useDynTabs({
528
482
return true ;
529
483
},
530
484
});
531
- // or
532
- instance
533
- .setOption (' beforeSelect' , (e , id ) => {
534
- return true ;
535
- })
536
- .refresh ();
537
485
```
538
486
539
487
### onSelect
@@ -561,8 +509,6 @@ const [TabList, PanelList, ready] = useDynTabs({
561
509
// you can use 'this' here which refers to the instance
562
510
},
563
511
});
564
- // or
565
- instance .setOption (' onSelect' , ({currentSelectedTabId, previousSelectedTabId}) => {}).refresh ();
566
512
```
567
513
568
514
### onOpen
@@ -590,8 +536,6 @@ const [TabList, PanelList, ready] = useDynTabs({
590
536
// you can use 'this' here which refers to the instance
591
537
},
592
538
});
593
- // or
594
- instance .setOption (' onOpen' , (openedTabIDs ) => {}).refresh ();
595
539
```
596
540
597
541
### beforeClose
@@ -623,12 +567,6 @@ const [TabList, PanelList, ready] = useDynTabs({
623
567
return true ;
624
568
},
625
569
});
626
- // or
627
- instance
628
- .setOption (' beforeClose' , (e , id ) => {
629
- return true ;
630
- })
631
- .refresh ();
632
570
```
633
571
634
572
### onClose
@@ -656,8 +594,6 @@ const [TabList, PanelList, ready] = useDynTabs({
656
594
// you can use 'this' here which refers to the instance
657
595
},
658
596
});
659
- // or
660
- instance .setOption (' onClose' , (closedTabIDs ) => {}).refresh ();
661
597
```
662
598
663
599
### onDestroy
@@ -685,8 +621,6 @@ const [TabList, PanelList, ready] = useDynTabs({
685
621
// you can use 'this' here which refers to the instance
686
622
},
687
623
});
688
- // or
689
- instance .setOption (' onDestroy' , () => {}).refresh ();
690
624
```
691
625
692
626
## Methods
@@ -718,10 +652,10 @@ Parameters:
718
652
** Example**
719
653
720
654
``` js
721
- if (instance .isOpen (' 2 ' ) == false ) {
655
+ if (instance .isOpen (' contact ' ) == false ) {
722
656
instance
723
657
.open ({
724
- id: ' 2 ' ,
658
+ id: ' contact ' ,
725
659
title: ' contact' ,
726
660
tooltip: ' contact' ,
727
661
disable: false ,
@@ -730,7 +664,7 @@ if (instance.isOpen('2') == false) {
730
664
panelComponent: < ContactPanel>< / ContactPanel> ,
731
665
})
732
666
.then (({currentData, instance}) => {
733
- // do sth here
667
+ console . log ( ' contact tab is open ' );
734
668
});
735
669
}
736
670
```
@@ -766,9 +700,9 @@ Parameters:
766
700
** Example**
767
701
768
702
``` 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 ' );
772
706
});
773
707
}
774
708
```
@@ -795,7 +729,7 @@ Parameters:
795
729
``` js
796
730
if (instance .isOpen (' 2' ) == true ) {
797
731
instance .close (' 2' ).then (({currentData, instance}) => {
798
- // do sth here
732
+ console . log ( ' tab 2 is closed ' );
799
733
});
800
734
}
801
735
```
@@ -831,9 +765,11 @@ const onSelect = instance.getOption('onSelect');
831
765
832
766
### setOption
833
767
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 .
835
769
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
837
773
838
774
Parameters:
839
775
@@ -845,6 +781,7 @@ Parameters:
845
781
``` js
846
782
instance .setOption (' direction' , ' rtl' );
847
783
instance .setOption (' onSelect' , () => {});
784
+ instance .setOption (' beforeSelect' , () => false );
848
785
```
849
786
850
787
### getTab
@@ -872,14 +809,14 @@ Return value : instance
872
809
873
810
Parameters:
874
811
875
- - ` optionName : String`
876
- - ` optionValue : string|boolean|object|function `
812
+ - ` tab id : String`
813
+ - ` source object : containing the properties you want to apply `
877
814
878
815
** Example**
879
816
880
817
``` 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 > } );
883
820
```
884
821
885
822
### on
@@ -1058,13 +995,21 @@ upcoming...
1058
995
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.
1059
996
1060
997
``` 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';
1063
1002
```
1064
1003
1004
+ ** NOTE :**
1005
+
1006
+ You can find other themes at src/themes folder.
1007
+
1065
1008
## Caveats
1066
1009
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.
1068
1013
1069
1014
## Deprecated features
1070
1015
0 commit comments