pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
'use client';
|
||||
|
||||
import _extends from "@babel/runtime/helpers/esm/extends";
|
||||
import * as React from 'react';
|
||||
import { unstable_useControlled as useControlled } from '@mui/utils';
|
||||
import { useCompoundParent } from '../useCompound';
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Tabs](https://mui.com/base-ui/react-tabs/#hooks)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [useTabs API](https://mui.com/base-ui/react-tabs/hooks-api/#use-tabs)
|
||||
*/
|
||||
function useTabs(parameters) {
|
||||
const {
|
||||
value: valueProp,
|
||||
defaultValue,
|
||||
onChange,
|
||||
orientation = 'horizontal',
|
||||
direction = 'ltr',
|
||||
selectionFollowsFocus = false
|
||||
} = parameters;
|
||||
const [value, setValue] = useControlled({
|
||||
controlled: valueProp,
|
||||
default: defaultValue,
|
||||
name: 'Tabs',
|
||||
state: 'value'
|
||||
});
|
||||
const onSelected = React.useCallback((event, newValue) => {
|
||||
setValue(newValue);
|
||||
onChange == null || onChange(event, newValue);
|
||||
}, [onChange, setValue]);
|
||||
const {
|
||||
subitems: tabPanels,
|
||||
contextValue: compoundComponentContextValue
|
||||
} = useCompoundParent();
|
||||
const tabIdLookup = React.useRef(() => undefined);
|
||||
const getTabPanelId = React.useCallback(tabValue => {
|
||||
var _tabPanels$get;
|
||||
return (_tabPanels$get = tabPanels.get(tabValue)) == null ? void 0 : _tabPanels$get.id;
|
||||
}, [tabPanels]);
|
||||
const getTabId = React.useCallback(tabPanelId => {
|
||||
return tabIdLookup.current(tabPanelId);
|
||||
}, []);
|
||||
const registerTabIdLookup = React.useCallback(lookupFunction => {
|
||||
tabIdLookup.current = lookupFunction;
|
||||
}, []);
|
||||
return {
|
||||
contextValue: _extends({
|
||||
direction,
|
||||
getTabId,
|
||||
getTabPanelId,
|
||||
onSelected,
|
||||
orientation,
|
||||
registerTabIdLookup,
|
||||
selectionFollowsFocus,
|
||||
value
|
||||
}, compoundComponentContextValue)
|
||||
};
|
||||
}
|
||||
export { useTabs };
|
||||
Reference in new issue
Block a user