Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[useTabs] Add explicit return type #36047

Merged
merged 11 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/pages/base/api/use-tabs.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@
}
}
},
"returnValue": {},
"returnValue": {
"tabsContextValue": {
"type": {
"name": "{\n /**\n * Id used as a prefix for the current Tabs.\n */\n idPrefix: string | undefined\n /**\n * The value of the currently selected `Tab`.\n * If you don't want any selected `Tab`, you can set this prop to `false`.\n */\n value: string | number | false\n /**\n * Callback for setting new value.\n */\n onSelected: (e: React.SyntheticEvent, newValue: string | number | false) => void\n /**\n * The component orientation (layout flow direction).\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The direction of the text.\n */\n direction: 'ltr' | 'rtl' | undefined\n /**\n * If `true` the selected tab changes on focus. Otherwise it only\n * changes on activation.\n */\n selectionFollowsFocus: boolean | undefined\n}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to extract descriptions from nested objects

"description": ""
},
"required": true
}
},
"name": "useTabs",
"filename": "/packages/mui-base/src/TabsUnstyled/useTabs.ts",
"demos": "<ul><li><a href=\"/base/react-tabs/#hooks\">Unstyled Tabs</a></li></ul>"
Expand Down
3 changes: 2 additions & 1 deletion packages/mui-base/src/TabsUnstyled/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export * from './tabsUnstyledClasses';
export * from './TabsUnstyled.types';

export { default as useTabs } from './useTabs';
export * from './useTabs';

export * from './useTabs.types';
33 changes: 2 additions & 31 deletions packages/mui-base/src/TabsUnstyled/useTabs.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
import * as React from 'react';
import { unstable_useControlled as useControlled, unstable_useId as useId } from '@mui/utils';
import { UseTabsParameters, UseTabsReturnValue } from './useTabs.types';

export interface UseTabsParameters {
/**
* The value of the currently selected `Tab`.
* If you don't want any selected `Tab`, you can set this prop to `false`.
*/
value?: string | number | false;
/**
* The default value. Use when the component is not controlled.
*/
defaultValue?: string | number | false;
/**
* The component orientation (layout flow direction).
* @default 'horizontal'
*/
orientation?: 'horizontal' | 'vertical';
/**
* The direction of the text.
* @default 'ltr'
*/
direction?: 'ltr' | 'rtl';
/**
* Callback invoked when new value is being set.
*/
onChange?: (event: React.SyntheticEvent, value: number | string | boolean) => void;
/**
* If `true` the selected tab changes on focus. Otherwise it only
* changes on activation.
*/
selectionFollowsFocus?: boolean;
}
/**
*
* Demos:
Expand All @@ -41,7 +12,7 @@ export interface UseTabsParameters {
*
* - [useTabs API](https://mui.com/base/api/use-tabs/)
*/
function useTabs(parameters: UseTabsParameters) {
function useTabs(parameters: UseTabsParameters): UseTabsReturnValue {
const {
value: valueProp,
defaultValue,
Expand Down
61 changes: 61 additions & 0 deletions packages/mui-base/src/TabsUnstyled/useTabs.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
export interface UseTabsParameters {
/**
* The value of the currently selected `Tab`.
* If you don't want any selected `Tab`, you can set this prop to `false`.
*/
value?: string | number | false;
/**
* The default value. Use when the component is not controlled.
*/
defaultValue?: string | number | false;
/**
* The component orientation (layout flow direction).
* @default 'horizontal'
*/
orientation?: 'horizontal' | 'vertical';
/**
* The direction of the text.
* @default 'ltr'
*/
direction?: 'ltr' | 'rtl';
/**
* Callback invoked when new value is being set.
*/
onChange?: (event: React.SyntheticEvent, value: number | string | boolean) => void;
/**
* If `true` the selected tab changes on focus. Otherwise it only
* changes on activation.
*/
selectionFollowsFocus?: boolean;
}

export interface UseTabsReturnValue {
tabsContextValue: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a JSDocs description please.

/**
* Id used as a prefix for the current Tabs.
*/
idPrefix: string | undefined;
/**
* The value of the currently selected `Tab`.
* If you don't want any selected `Tab`, you can set this prop to `false`.
*/
value: string | number | false;
/**
* Callback for setting new value.
*/
onSelected: (e: React.SyntheticEvent, newValue: string | number | false) => void;
/**
* The component orientation (layout flow direction).
*/
orientation?: 'horizontal' | 'vertical';
/**
* The direction of the text.
*/
direction: 'ltr' | 'rtl' | undefined;
/**
* If `true` the selected tab changes on focus. Otherwise it only
* changes on activation.
*/
selectionFollowsFocus: boolean | undefined;
};
}