pre-installations and preparations

This commit is contained in:
MuhammadKhalilzadeh committed 2024-05-05 11:21:00 +03:30
1 parent 3e5a0329cb
commit 201d621ac3
6977 files changed
+742826

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
import * as React from 'react';
import { ListContextValue } from '../useList/ListContext';
import { TabMetadata } from '../useTabs';
import { CompoundComponentContextValue } from '../useCompound';
export type TabsListProviderValue = CompoundComponentContextValue<string | number, TabMetadata> & ListContextValue<string | number>;
export interface TabsListProviderProps {
value: TabsListProviderValue;
children: React.ReactNode;
}
/**
* Sets up the contexts for the underlying Tab components.
*
* @ignore - do not document.
*/
export declare function TabsListProvider(props: TabsListProviderProps): React.JSX.Element;
+41
View File
@@ -0,0 +1,41 @@
'use client';
import * as React from 'react';
import { ListContext } from '../useList/ListContext';
import { CompoundComponentContext } from '../useCompound';
import { jsx as _jsx } from "react/jsx-runtime";
/**
* Sets up the contexts for the underlying Tab components.
*
* @ignore - do not document.
*/
export function TabsListProvider(props) {
const {
value,
children
} = props;
const {
dispatch,
getItemIndex,
getItemState,
registerItem,
totalSubitemCount
} = value;
const listContextValue = React.useMemo(() => ({
dispatch,
getItemState,
getItemIndex
}), [dispatch, getItemIndex, getItemState]);
const compoundComponentContextValue = React.useMemo(() => ({
getItemIndex,
registerItem,
totalSubitemCount
}), [registerItem, getItemIndex, totalSubitemCount]);
return /*#__PURE__*/_jsx(CompoundComponentContext.Provider, {
value: compoundComponentContextValue,
children: /*#__PURE__*/_jsx(ListContext.Provider, {
value: listContextValue,
children: children
})
});
}
+3
View File
@@ -0,0 +1,3 @@
export { useTabsList } from './useTabsList';
export * from './useTabsList.types';
export * from './TabsListProvider';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export { useTabsList } from './useTabsList';
export * from './useTabsList.types';
export * from './TabsListProvider';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/useTabsList/index.js",
"types": "./index.d.ts"
}
+7
View File
@@ -0,0 +1,7 @@
import { ListState, ListAction, ListActionContext } from '../useList';
import { ActionWithContext } from '../utils/useControllableReducer.types';
import { ValueChangeAction } from './useTabsList.types';
export type TabsListActionContext = ListActionContext<string | number> & {
selectionFollowsFocus: boolean;
};
export declare function tabsListReducer(state: ListState<string | number>, action: ActionWithContext<ListAction<string | number> | ValueChangeAction, TabsListActionContext>): ListState<string | number>;
+30
View File
@@ -0,0 +1,30 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import { listReducer, ListActionTypes, moveHighlight } from '../useList';
import { TabsListActionTypes } from './useTabsList.types';
export function tabsListReducer(state, action) {
if (action.type === TabsListActionTypes.valueChange) {
return _extends({}, state, {
highlightedValue: action.value
});
}
const newState = listReducer(state, action);
const {
context: {
selectionFollowsFocus
}
} = action;
if (action.type === ListActionTypes.itemsChange) {
if (newState.selectedValues.length > 0) {
return _extends({}, newState, {
highlightedValue: newState.selectedValues[0]
});
}
moveHighlight(null, 'reset', action.context);
}
if (selectionFollowsFocus && newState.highlightedValue != null) {
return _extends({}, newState, {
selectedValues: [newState.highlightedValue]
});
}
return newState;
}
+13
View File
@@ -0,0 +1,13 @@
import { UseTabsListParameters, UseTabsListReturnValue } from './useTabsList.types';
/**
*
* Demos:
*
* - [Tabs](https://mui.com/base-ui/react-tabs/#hooks)
*
* API:
*
* - [useTabsList API](https://mui.com/base-ui/react-tabs/hooks-api/#use-tabs-list)
*/
declare function useTabsList(parameters: UseTabsListParameters): UseTabsListReturnValue;
export { useTabsList };
+132
View File
@@ -0,0 +1,132 @@
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import { useTabsContext } from '../Tabs';
import { TabsListActionTypes } from './useTabsList.types';
import { useCompoundParent } from '../useCompound';
import { useList } from '../useList';
import { tabsListReducer } from './tabsListReducer';
/**
*
* Demos:
*
* - [Tabs](https://mui.com/base-ui/react-tabs/#hooks)
*
* API:
*
* - [useTabsList API](https://mui.com/base-ui/react-tabs/hooks-api/#use-tabs-list)
*/
function useTabsList(parameters) {
var _selectedValues$;
const {
rootRef: externalRef
} = parameters;
const {
direction = 'ltr',
onSelected,
orientation = 'horizontal',
value,
registerTabIdLookup,
selectionFollowsFocus
} = useTabsContext();
const {
subitems,
contextValue: compoundComponentContextValue
} = useCompoundParent();
const tabIdLookup = React.useCallback(tabValue => {
var _subitems$get;
return (_subitems$get = subitems.get(tabValue)) == null ? void 0 : _subitems$get.id;
}, [subitems]);
registerTabIdLookup(tabIdLookup);
const subitemKeys = React.useMemo(() => Array.from(subitems.keys()), [subitems]);
const getTabElement = React.useCallback(tabValue => {
var _subitems$get$ref$cur, _subitems$get2;
if (tabValue == null) {
return null;
}
return (_subitems$get$ref$cur = (_subitems$get2 = subitems.get(tabValue)) == null ? void 0 : _subitems$get2.ref.current) != null ? _subitems$get$ref$cur : null;
}, [subitems]);
const isRtl = direction === 'rtl';
let listOrientation;
if (orientation === 'vertical') {
listOrientation = 'vertical';
} else {
listOrientation = isRtl ? 'horizontal-rtl' : 'horizontal-ltr';
}
const handleChange = React.useCallback((event, newValue) => {
var _newValue$;
onSelected(event, (_newValue$ = newValue[0]) != null ? _newValue$ : null);
}, [onSelected]);
const controlledProps = React.useMemo(() => {
if (value === undefined) {
return {};
}
return value != null ? {
selectedValues: [value]
} : {
selectedValues: []
};
}, [value]);
const isItemDisabled = React.useCallback(item => {
var _subitems$get$disable, _subitems$get3;
return (_subitems$get$disable = (_subitems$get3 = subitems.get(item)) == null ? void 0 : _subitems$get3.disabled) != null ? _subitems$get$disable : false;
}, [subitems]);
const {
contextValue: listContextValue,
dispatch,
getRootProps: getListboxRootProps,
state: {
highlightedValue,
selectedValues
},
rootRef: mergedRootRef
} = useList({
controlledProps,
disabledItemsFocusable: !selectionFollowsFocus,
focusManagement: 'DOM',
getItemDomElement: getTabElement,
isItemDisabled,
items: subitemKeys,
rootRef: externalRef,
onChange: handleChange,
orientation: listOrientation,
reducerActionContext: React.useMemo(() => ({
selectionFollowsFocus: selectionFollowsFocus || false
}), [selectionFollowsFocus]),
selectionMode: 'single',
stateReducer: tabsListReducer
});
React.useEffect(() => {
if (value === undefined) {
return;
}
// when a value changes externally, the highlighted value should be synced to it
if (value != null) {
dispatch({
type: TabsListActionTypes.valueChange,
value
});
}
}, [dispatch, value]);
const getRootProps = (externalProps = {}) => {
return _extends({}, externalProps, getListboxRootProps(externalProps), {
'aria-orientation': orientation === 'vertical' ? 'vertical' : undefined,
role: 'tablist'
});
};
const contextValue = React.useMemo(() => _extends({}, compoundComponentContextValue, listContextValue), [compoundComponentContextValue, listContextValue]);
return {
contextValue,
dispatch,
getRootProps,
highlightedValue,
isRtl,
orientation,
rootRef: mergedRootRef,
selectedValue: (_selectedValues$ = selectedValues[0]) != null ? _selectedValues$ : null
};
}
export { useTabsList };
+58
View File
@@ -0,0 +1,58 @@
import * as React from 'react';
import { TabsListProviderValue } from './TabsListProvider';
import { ListAction } from '../useList';
export interface UseTabsListParameters {
/**
* Ref to the root element.
*/
rootRef: React.Ref<Element>;
}
export type UseTabsListRootSlotProps<ExternalProps = {}> = ExternalProps & {
'aria-label'?: React.AriaAttributes['aria-label'];
'aria-labelledby'?: React.AriaAttributes['aria-labelledby'];
'aria-orientation'?: React.AriaAttributes['aria-orientation'];
role: React.AriaRole;
ref: React.RefCallback<Element> | null;
onKeyDown?: React.KeyboardEventHandler<HTMLElement>;
};
export interface UseTabsListReturnValue {
/**
* The value to be passed to the TabListProvider above all the tabs.
*/
contextValue: TabsListProviderValue;
/**
* Action dispatcher for the tabs list component.
* Allows to programmatically control the tabs list.
*/
dispatch: (action: ListAction<string | number>) => void;
/**
* Resolver for the root slot's props.
* @param externalProps props for the root slot
* @returns props that should be spread on the root slot
*/
getRootProps: <ExternalProps extends Record<string, unknown> = {}>(externalProps?: ExternalProps) => UseTabsListRootSlotProps<ExternalProps>;
/**
* The value of the currently highlighted tab.
*/
highlightedValue: string | number | null;
/**
* If `true`, it will indicate that the text's direction in right-to-left.
*/
isRtl: boolean;
/**
* The component orientation (layout flow direction).
*/
orientation: 'horizontal' | 'vertical';
rootRef: React.RefCallback<Element> | null;
/**
* The value of the currently selected tab.
*/
selectedValue: string | number | null;
}
export declare const TabsListActionTypes: {
readonly valueChange: "valueChange";
};
export interface ValueChangeAction {
type: typeof TabsListActionTypes.valueChange;
value: string | number | null;
}
+3
View File
@@ -0,0 +1,3 @@
export const TabsListActionTypes = {
valueChange: 'valueChange'
};