Skip to content

Commit f01a532

Browse files
adding types
1 parent c4b6707 commit f01a532

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

index.d.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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;

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "dev-javascript",
77
"email": "javascript.code.dev@gmail.com"
88
},
9+
"types": "./index.d.ts",
910
"description": "React dynamic tabs with full API",
1011
"main": "lib/cjs/index.js",
1112
"module": "lib/esm/index.js",
@@ -84,7 +85,10 @@
8485
"themes",
8586
"src",
8687
"!*.test.js",
87-
"!*.test.js.snap"
88+
"!*.test.js.snap",
89+
"index.d.ts",
90+
"react-dyn-tabs.ts",
91+
"index.ts"
8892
],
8993
"keywords": [
9094
"react",
@@ -113,4 +117,4 @@
113117
"dependencies": {
114118
"prop-types": "^15.7.2"
115119
}
116-
}
120+
}

0 commit comments

Comments
 (0)