Skip to content

Commit

Permalink
feat: Add typescript typings to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Apr 8, 2023
1 parent 58caf6a commit 0cb15ff
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
49 changes: 49 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { FunctionComponent, HTMLProps } from 'react';

export interface TabsProps
extends Omit<HTMLProps<HTMLDivElement>, 'className' | 'onSelect' | 'ref'> {
className?: string | string[] | { [name: string]: boolean } | undefined;
defaultFocus?: boolean | undefined;
defaultIndex?: number | undefined;
direction?: 'rtl' | 'ltr' | undefined;
disabledTabClassName?: string | undefined;
disableUpDownKeys?: boolean | undefined;
domRef?: ((node?: HTMLElement) => void) | undefined;
environment?: Window | undefined;
focusTabOnClick?: boolean | undefined;
forceRenderTabPanel?: boolean | undefined;
onSelect?:
| ((index: number, last: number, event: Event) => boolean | void)
| undefined;
selectedIndex?: number | undefined;
selectedTabClassName?: string | undefined;
selectedTabPanelClassName?: string | undefined;
}

export interface TabListProps
extends Omit<HTMLProps<HTMLUListElement>, 'className'> {
className?: string | string[] | { [name: string]: boolean } | undefined;
}

export interface TabProps
extends Omit<HTMLProps<HTMLLIElement>, 'className' | 'tabIndex'> {
className?: string | string[] | { [name: string]: boolean } | undefined;
disabled?: boolean | undefined;
disabledClassName?: string | undefined;
selectedClassName?: string | undefined;
tabIndex?: string | undefined;
}

export interface TabPanelProps
extends Omit<HTMLProps<HTMLDivElement>, 'className'> {
className?: string | string[] | { [name: string]: boolean } | undefined;
forceRender?: boolean | undefined;
selectedClassName?: string | undefined;
}

export const Tabs: FunctionComponent<TabsProps>;
export const TabList: FunctionComponent<TabListProps>;
export const Tab: FunctionComponent<TabProps>;
export const TabPanel: FunctionComponent<TabPanelProps>;

export declare function resetIdCounter(): void;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "An accessible and easy tab component for ReactJS",
"main": "lib/index.js",
"module": "esm/index.js",
"typings": "index.d.ts",
"scripts": {
"clean:commonjs": "rimraf lib",
"clean:umd": "rimraf dist",
Expand Down Expand Up @@ -36,7 +37,8 @@
"esm",
"lib",
"style",
"src"
"src",
"index.d.ts"
],
"homepage": "https://github.com/reactjs/react-tabs",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const propTypes = {
PropTypes.object,
]),
disabled: PropTypes.bool,
tabIndex: PropTypes.string,
disabledClassName: PropTypes.string,
focus: PropTypes.bool, // private
id: PropTypes.string, // private
panelId: PropTypes.string, // private
selected: PropTypes.bool, // private
selectedClassName: PropTypes.string,
tabRef: PropTypes.func,
tabIndex: PropTypes.string,
tabRef: PropTypes.func, // private
};

const Tab = (props) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ const MODE_CONTROLLED = 0;
const MODE_UNCONTROLLED = 1;
const propTypes = {
children: childrenPropType,
direction: PropTypes.oneOf(['rtl', 'ltr']),
className: PropTypes.oneOfType([
PropTypes.string,
PropTypes.array,
PropTypes.object,
]),
defaultFocus: PropTypes.bool,
defaultIndex: PropTypes.number,
direction: PropTypes.oneOf(['rtl', 'ltr']),
disabledTabClassName: PropTypes.string,
disableUpDownKeys: PropTypes.bool,
domRef: PropTypes.func,
environment: PropTypes.object,
focusTabOnClick: PropTypes.bool,
forceRenderTabPanel: PropTypes.bool,
onSelect: onSelectPropType,
selectedIndex: selectedIndexPropType,
selectedTabClassName: PropTypes.string,
selectedTabPanelClassName: PropTypes.string,
environment: PropTypes.object,
};
const defaultProps = {
defaultFocus: false,
Expand Down

0 comments on commit 0cb15ff

Please sign in to comment.