1+ import React , { ReactNode , FunctionComponent } from 'react' ;
2+ export type Callback = ( instance : Instance ) => void ;
3+ /**
4+ * - ready function accepts a callback as its parameter and executes it as soon as Tabs get mounted.
5+
6+ * - If ready function is called after the Tabs has been mounted, the callback passed in will be executed immediately.
7+
8+ * - ready function can be executed multiple times and its identity is stable and won’t change on re-renders.
9+ */
10+ export type Ready = ( callback : Callback ) => void ;
11+ export interface Options {
12+ /** * default value is "ltr" */
13+ direction ?: 'rtl' | 'ltr' ;
14+ defaultPanelComponent ?: ( ) => ReactNode | null ;
15+ tabComponent ?: ( props : any ) => ReactNode ;
16+ selectedTabID ?: string ; tabs ?: Array < TabData > ;
17+ /** * default value is true */
18+ accessibility ?: boolean ;
19+ /** * default value is false */
20+ isVertical ?: boolean ;
21+ onLoad ?: ( ) => void ;
22+ onInit ?: ( ) => void ;
23+ onChange ?: ( { currentData, previousData, closedTabIDs, openedTabIDs } : { currentData : any , previousData : any , closedTabIDs : Array < string > , openedTabIDs : Array < string > } ) => void ;
24+ /** * defautl value function returns true */
25+ beforeSelect ?: ( e : React . MouseEvent < HTMLInputElement > , id : string ) => boolean ; onFirstSelect ?: ( { currentSelectedTabId, previousSelectedTabId } : { currentSelectedTabId : string , previousSelectedTabId : string } ) => void ;
26+ onSelect ?: ( { currentSelectedTabId, previousSelectedTabId } : { currentSelectedTabId : string , previousSelectedTabId : string } ) => void ;
27+ onOpen ?: ( openedTabIDs : Array < string > ) => void ;
28+ /** * defautl value function returns true */
29+ beforeClose ?: ( e : React . MouseEvent < HTMLInputElement > , id : string ) => boolean ;
30+ onClose ?: ( closedTabIDs : Array < string > ) => void ; onDestroy ?: ( ) => void ;
31+ }
32+ export interface TabData {
33+ id ?: string ;
34+ title ?: string ;
35+ tooltip ?: string ;
36+ /** * default value is true */
37+ closable ?: boolean ;
38+ /** * default value is false */
39+ lazy ?: boolean ;
40+ iconClass ?: string ;
41+ /** * default value is false */
42+ disable ?: boolean ;
43+ panelComponent ?: React . ReactNode | React . ReactElement | React . FunctionComponent ;
44+ [ x : string ] : unknown ;
45+ }
46+ export interface CurrentData {
47+ openTabIDs : Array < string > ;
48+ selectedTabID : string ;
49+ }
50+ export interface Instance {
51+ isOpen : ( tabID : string ) => boolean ;
52+ open : ( tabData : TabData ) => Promise < { currentData : CurrentData , instance : Instance } > ;
53+ isSelected : ( tabID : string ) => boolean ;
54+ select : ( tabID : string ) => Promise < { currentData : CurrentData , instance : Instance } > ;
55+ /**
56+ * - When switching parameter is true, it switches to previous selected tab
57+ */
58+ close : ( tabID : string , switching ?: boolean ) => Promise < { currentData : CurrentData , instance : Instance } > ;
59+ refresh : ( ) => Promise < { currentData : CurrentData , instance : Instance } > ;
60+ getOption : ( optionName : string ) => any ;
61+ setOption : ( optionName : string , optionValue : any ) => Instance ;
62+ getTab : ( tabID : string ) => TabData ;
63+ setTab : ( tabID : string , sourceObject : TabData ) => Instance ;
64+ on : ( eventName : string , handler : Function ) => Instance ;
65+ one : ( eventName : string , handler : Function ) => Instance ;
66+ off : ( eventName : string , handler : Function ) => Instance ;
67+ getData : ( ) => TabData ;
68+ getPreviousData : ( ) => TabData ;
69+ sort : ( tabIDs : Array < string > ) => Promise < { currentData : CurrentData , instance : Instance } > ;
70+ }
71+ export const TabList : FunctionComponent < { } > ;
72+ export const PanelList : FunctionComponent < { } > ;
73+ function useDynTabs ( options ?: Options ) : [ TabList , PanelList , Ready ] ;
74+ export default useDynTabs ;
0 commit comments