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

+18
View File
@@ -0,0 +1,18 @@
import * as React from 'react';
import { TabsContextValue } from '../Tabs/TabsContext';
import { CompoundComponentContextValue } from '../useCompound';
export type TabPanelMetadata = {
id: string | undefined;
ref: React.RefObject<HTMLElement>;
};
export type TabsProviderValue = CompoundComponentContextValue<string | number, TabPanelMetadata> & TabsContextValue;
export interface TabsProviderProps {
value: TabsProviderValue;
children: React.ReactNode;
}
/**
* Sets up the contexts for the underlying Tab and TabPanel components.
*
* @ignore - do not document.
*/
export declare function TabsProvider(props: TabsProviderProps): React.JSX.Element;
+52
View File
@@ -0,0 +1,52 @@
'use client';
import * as React from 'react';
import { TabsContext } from '../Tabs/TabsContext';
import { CompoundComponentContext } from '../useCompound';
import { jsx as _jsx } from "react/jsx-runtime";
/**
* Sets up the contexts for the underlying Tab and TabPanel components.
*
* @ignore - do not document.
*/
export function TabsProvider(props) {
const {
value: valueProp,
children
} = props;
const {
direction,
getItemIndex,
onSelected,
orientation,
registerItem,
registerTabIdLookup,
selectionFollowsFocus,
totalSubitemCount,
value,
getTabId,
getTabPanelId
} = valueProp;
const compoundComponentContextValue = React.useMemo(() => ({
getItemIndex,
registerItem,
totalSubitemCount
}), [registerItem, getItemIndex, totalSubitemCount]);
const tabsContextValue = React.useMemo(() => ({
direction,
getTabId,
getTabPanelId,
onSelected,
orientation,
registerTabIdLookup,
selectionFollowsFocus,
value
}), [direction, getTabId, getTabPanelId, onSelected, orientation, registerTabIdLookup, selectionFollowsFocus, value]);
return /*#__PURE__*/_jsx(CompoundComponentContext.Provider, {
value: compoundComponentContextValue,
children: /*#__PURE__*/_jsx(TabsContext.Provider, {
value: tabsContextValue,
children: children
})
});
}
+3
View File
@@ -0,0 +1,3 @@
export * from './useTabs';
export * from './useTabs.types';
export * from './TabsProvider';
+5
View File
@@ -0,0 +1,5 @@
'use client';
export * from './useTabs';
export * from './useTabs.types';
export * from './TabsProvider';
+6
View File
@@ -0,0 +1,6 @@
{
"sideEffects": false,
"module": "./index.js",
"main": "../node/useTabs/index.js",
"types": "./index.d.ts"
}
+19
View File
@@ -0,0 +1,19 @@
import * as React from 'react';
import { UseTabsParameters, UseTabsReturnValue } from './useTabs.types';
export interface TabMetadata {
disabled: boolean;
id: string | undefined;
ref: React.RefObject<HTMLElement>;
}
/**
*
* Demos:
*
* - [Tabs](https://mui.com/base-ui/react-tabs/#hooks)
*
* API:
*
* - [useTabs API](https://mui.com/base-ui/react-tabs/hooks-api/#use-tabs)
*/
declare function useTabs(parameters: UseTabsParameters): UseTabsReturnValue;
export { useTabs };
+64
View File
@@ -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 };
+38
View File
@@ -0,0 +1,38 @@
/// <reference types="react" />
import { TabsProviderValue } from './TabsProvider';
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 | null;
/**
* The default value. Use when the component is not controlled.
*/
defaultValue?: string | number | null;
/**
* 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 | null, value: number | string | null) => void;
/**
* If `true` the selected tab changes on focus. Otherwise it only
* changes on activation.
*/
selectionFollowsFocus?: boolean;
}
export interface UseTabsReturnValue {
/**
* Returns the values to be passed to the tabs provider.
*/
contextValue: TabsProviderValue;
}
+1
View File
@@ -0,0 +1 @@
export {};