pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+2
@@ -0,0 +1,2 @@
|
||||
export { useTabPanel } from './useTabPanel';
|
||||
export * from './useTabPanel.types';
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use client';
|
||||
|
||||
export { useTabPanel } from './useTabPanel';
|
||||
export * from './useTabPanel.types';
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "./index.js",
|
||||
"main": "../node/useTabPanel/index.js",
|
||||
"types": "./index.d.ts"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import { UseTabPanelParameters, UseTabPanelReturnValue } from './useTabPanel.types';
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Tabs](https://mui.com/base-ui/react-tabs/#hooks)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [useTabPanel API](https://mui.com/base-ui/react-tabs/hooks-api/#use-tab-panel)
|
||||
*/
|
||||
declare function useTabPanel(parameters: UseTabPanelParameters): UseTabPanelReturnValue;
|
||||
export { useTabPanel };
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import * as React from 'react';
|
||||
import { unstable_useId as useId, unstable_useForkRef as useForkRef } from '@mui/utils';
|
||||
import { useTabsContext } from '../Tabs';
|
||||
import { useCompoundItem } from '../useCompound';
|
||||
function tabPanelValueGenerator(otherTabPanelValues) {
|
||||
return otherTabPanelValues.size;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Tabs](https://mui.com/base-ui/react-tabs/#hooks)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [useTabPanel API](https://mui.com/base-ui/react-tabs/hooks-api/#use-tab-panel)
|
||||
*/
|
||||
function useTabPanel(parameters) {
|
||||
const {
|
||||
value: valueParam,
|
||||
id: idParam,
|
||||
rootRef: externalRef
|
||||
} = parameters;
|
||||
const context = useTabsContext();
|
||||
if (context === null) {
|
||||
throw new Error('No TabContext provided');
|
||||
}
|
||||
const {
|
||||
value: selectedTabValue,
|
||||
getTabId
|
||||
} = context;
|
||||
const id = useId(idParam);
|
||||
const ref = React.useRef(null);
|
||||
const handleRef = useForkRef(ref, externalRef);
|
||||
const metadata = React.useMemo(() => ({
|
||||
id,
|
||||
ref
|
||||
}), [id]);
|
||||
const {
|
||||
id: value
|
||||
} = useCompoundItem(valueParam != null ? valueParam : tabPanelValueGenerator, metadata);
|
||||
const hidden = value !== selectedTabValue;
|
||||
const correspondingTabId = value !== undefined ? getTabId(value) : undefined;
|
||||
const getRootProps = (externalProps = {}) => {
|
||||
return _extends({
|
||||
'aria-labelledby': correspondingTabId != null ? correspondingTabId : undefined,
|
||||
hidden,
|
||||
id: id != null ? id : undefined
|
||||
}, externalProps, {
|
||||
ref: handleRef
|
||||
});
|
||||
};
|
||||
return {
|
||||
hidden,
|
||||
getRootProps,
|
||||
rootRef: handleRef
|
||||
};
|
||||
}
|
||||
export { useTabPanel };
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/// <reference types="react" />
|
||||
export interface UseTabPanelParameters {
|
||||
/**
|
||||
* The id of the TabPanel.
|
||||
*/
|
||||
id?: string;
|
||||
/**
|
||||
* The ref of the TabPanel.
|
||||
*/
|
||||
rootRef?: React.Ref<HTMLElement>;
|
||||
/**
|
||||
* The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected.
|
||||
*/
|
||||
value?: number | string;
|
||||
}
|
||||
interface UseTabPanelRootSlotOwnProps {
|
||||
'aria-labelledby'?: string;
|
||||
hidden?: boolean;
|
||||
id?: string;
|
||||
ref: React.Ref<HTMLElement>;
|
||||
}
|
||||
export type UseTabPanelRootSlotProps<ExternalProps = {}> = ExternalProps & UseTabPanelRootSlotOwnProps;
|
||||
export interface UseTabPanelReturnValue {
|
||||
/**
|
||||
* If `true`, it indicates that the tab panel will be hidden.
|
||||
*/
|
||||
hidden: boolean;
|
||||
/**
|
||||
* Resolver for the root slot's props.
|
||||
* @param externalProps additional props for the root slot
|
||||
* @returns props that should be spread on the root slot
|
||||
*/
|
||||
getRootProps: <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseTabPanelRootSlotProps<ExternalProps>;
|
||||
rootRef: React.Ref<HTMLElement>;
|
||||
}
|
||||
export {};
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in new issue
Block a user