UNPKG

6.14 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverridableStringUnion } from '@mui/types';
4import { SlotComponentProps } from '../utils/types';
5import { Theme } from '../styles';
6import { TabScrollButtonProps } from '../TabScrollButton';
7import { OverridableComponent, OverrideProps } from '../OverridableComponent';
8import { TabsClasses } from './tabsClasses';
9import SvgIcon from '../SvgIcon';
10
11export interface TabsPropsIndicatorColorOverrides {}
12
13export interface TabsStartScrollButtonIconSlotPropsOverrides {}
14export interface TabsEndScrollButtonIconSlotPropsOverrides {}
15
16export interface TabsOwnerState extends TabsProps {
17 vertical: boolean;
18 fixed: boolean;
19 hideScrollbar: boolean;
20 scrollableX: boolean;
21 scrollableY: boolean;
22 centered: boolean;
23 scrollButtonsHideMobile: boolean;
24}
25
26export interface TabsOwnProps {
27 /**
28 * Callback fired when the component mounts.
29 * This is useful when you want to trigger an action programmatically.
30 * It supports two actions: `updateIndicator()` and `updateScrollButtons()`
31 *
32 * @param {object} actions This object contains all possible actions
33 * that can be triggered programmatically.
34 */
35 action?: React.Ref<TabsActions>;
36 /**
37 * If `true`, the scroll buttons aren't forced hidden on mobile.
38 * By default the scroll buttons are hidden on mobile and takes precedence over `scrollButtons`.
39 * @default false
40 */
41 allowScrollButtonsMobile?: boolean;
42 /**
43 * The label for the Tabs as a string.
44 */
45 'aria-label'?: string;
46 /**
47 * An id or list of ids separated by a space that label the Tabs.
48 */
49 'aria-labelledby'?: string;
50 /**
51 * If `true`, the tabs are centered.
52 * This prop is intended for large views.
53 * @default false
54 */
55 centered?: boolean;
56 /**
57 * The content of the component.
58 */
59 children?: React.ReactNode;
60 /**
61 * Override or extend the styles applied to the component.
62 */
63 classes?: Partial<TabsClasses>;
64 /**
65 * The components used for each slot inside.
66 * @default {}
67 */
68 slots?: {
69 StartScrollButtonIcon?: React.ElementType;
70 EndScrollButtonIcon?: React.ElementType;
71 };
72 /**
73 * The extra props for the slot components.
74 * You can override the existing props or add new ones.
75 * @default {}
76 */
77 slotProps?: {
78 startScrollButtonIcon?: SlotComponentProps<
79 typeof SvgIcon,
80 TabsStartScrollButtonIconSlotPropsOverrides,
81 TabsOwnerState
82 >;
83 endScrollButtonIcon?: SlotComponentProps<
84 typeof SvgIcon,
85 TabsEndScrollButtonIconSlotPropsOverrides,
86 TabsOwnerState
87 >;
88 };
89 /**
90 * Determines the color of the indicator.
91 * @default 'primary'
92 */
93 indicatorColor?: OverridableStringUnion<
94 'secondary' | 'primary',
95 TabsPropsIndicatorColorOverrides
96 >;
97 /**
98 * Callback fired when the value changes.
99 *
100 * @param {React.SyntheticEvent} event The event source of the callback. **Warning**: This is a generic event not a change event.
101 * @param {any} value We default to the index of the child (number)
102 */
103 onChange?: (event: React.SyntheticEvent, value: any) => void;
104 /**
105 * The component orientation (layout flow direction).
106 * @default 'horizontal'
107 */
108 orientation?: 'horizontal' | 'vertical';
109 /**
110 * The component used to render the scroll buttons.
111 * @default TabScrollButton
112 */
113 ScrollButtonComponent?: React.ElementType;
114 /**
115 * Determine behavior of scroll buttons when tabs are set to scroll:
116 *
117 * - `auto` will only present them when not all the items are visible.
118 * - `true` will always present them.
119 * - `false` will never present them.
120 *
121 * By default the scroll buttons are hidden on mobile.
122 * This behavior can be disabled with `allowScrollButtonsMobile`.
123 * @default 'auto'
124 */
125 scrollButtons?: 'auto' | true | false;
126 /**
127 * If `true` the selected tab changes on focus. Otherwise it only
128 * changes on activation.
129 */
130 selectionFollowsFocus?: boolean;
131 /**
132 * Props applied to the tab indicator element.
133 * @default {}
134 */
135 TabIndicatorProps?: React.HTMLAttributes<HTMLDivElement> & {
136 sx?: SxProps<Theme>;
137 };
138 /**
139 * Props applied to the [`TabScrollButton`](https://mui.com/material-ui/api/tab-scroll-button/) element.
140 * @default {}
141 */
142 TabScrollButtonProps?: Partial<TabScrollButtonProps>;
143 /**
144 * Determines the color of the `Tab`.
145 * @default 'primary'
146 */
147 textColor?: 'secondary' | 'primary' | 'inherit';
148 /**
149 * The value of the currently selected `Tab`.
150 * If you don't want any selected `Tab`, you can set this prop to `false`.
151 */
152 value?: any;
153 /**
154 * Determines additional display behavior of the tabs:
155 *
156 * - `scrollable` will invoke scrolling properties and allow for horizontally
157 * scrolling (or swiping) of the tab bar.
158 * - `fullWidth` will make the tabs grow to use all the available space,
159 * which should be used for small views, like on mobile.
160 * - `standard` will render the default state.
161 * @default 'standard'
162 */
163 variant?: 'standard' | 'scrollable' | 'fullWidth';
164 /**
165 * If `true`, the scrollbar is visible. It can be useful when displaying
166 * a long vertical list of tabs.
167 * @default false
168 */
169 visibleScrollbar?: boolean;
170 /**
171 * The system prop that allows defining system overrides as well as additional CSS styles.
172 */
173 sx?: SxProps<Theme>;
174}
175
176export interface TabsTypeMap<
177 AdditionalProps = {},
178 RootComponent extends React.ElementType = 'div',
179> {
180 props: AdditionalProps & TabsOwnProps;
181 defaultComponent: RootComponent;
182}
183
184/**
185 *
186 * Demos:
187 *
188 * - [Tabs](https://mui.com/material-ui/react-tabs/)
189 *
190 * API:
191 *
192 * - [Tabs API](https://mui.com/material-ui/api/tabs/)
193 */
194declare const Tabs: OverridableComponent<TabsTypeMap>;
195
196export interface TabsActions {
197 updateIndicator(): void;
198 updateScrollButtons(): void;
199}
200
201export type TabsProps<
202 RootComponent extends React.ElementType = TabsTypeMap['defaultComponent'],
203 AdditionalProps = {},
204> = OverrideProps<TabsTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
205 component?: React.ElementType;
206};
207
208export default Tabs;