Skip to content

Commit

Permalink
TabsListUnstyled types
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed May 27, 2022
1 parent 4f4fc54 commit b4bc1f3
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from 'react';
import TabsListUnstyled, { TabsListUnstyledRootSlotProps } from '@mui/base/TabsListUnstyled';

function Root(props: TabsListUnstyledRootSlotProps) {
const { ownerState, ...other } = props;
return <div data-orientation={ownerState.orientation} {...other} />;
}

const styledTabsList = <TabsListUnstyled components={{ Root }} />;
27 changes: 14 additions & 13 deletions packages/mui-base/src/TabsListUnstyled/TabsListUnstyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import PropTypes from 'prop-types';
import clsx from 'clsx';
import { OverridableComponent } from '@mui/types';
import composeClasses from '../composeClasses';
import { appendOwnerState } from '../utils';
import { appendOwnerState, WithOptionalOwnerState } from '../utils';
import { getTabsListUnstyledUtilityClass } from './tabsListUnstyledClasses';
import TabsListUnstyledProps, { TabsListUnstyledTypeMap } from './TabsListUnstyledProps';
import {
TabsListUnstyledProps,
TabsListUnstyledRootSlotProps,
TabsListUnstyledTypeMap,
} from './TabsListUnstyled.types';
import useTabsList from './useTabsList';

const useUtilityClasses = (ownerState: { orientation: 'horizontal' | 'vertical' }) => {
Expand Down Expand Up @@ -42,23 +46,20 @@ const TabsListUnstyled = React.forwardRef<unknown, TabsListUnstyledProps>((props
const classes = useUtilityClasses(ownerState);

const TabsListRoot: React.ElementType = component ?? components.Root ?? 'div';
const tabsListRootProps = appendOwnerState(
const tabsListRootProps: WithOptionalOwnerState<TabsListUnstyledRootSlotProps> = appendOwnerState(
TabsListRoot,
{ ...other, ...componentsProps.root },
{
...getRootProps(),
...other,
...componentsProps.root,
className: clsx(className, componentsProps.root?.className, classes.root),
},
ownerState,
);

const processedChildren = processChildren();

return (
<TabsListRoot
{...getRootProps()}
{...tabsListRootProps}
className={clsx(className, componentsProps.root?.className, classes.root)}
>
{processedChildren}
</TabsListRoot>
);
return <TabsListRoot {...tabsListRootProps}>{processedChildren}</TabsListRoot>;
}) as OverridableComponent<TabsListUnstyledTypeMap>;

TabsListUnstyled.propTypes /* remove-proptypes */ = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { OverrideProps } from '@mui/types';
import { UseTabsListRootSlotProps } from './useTabsList.types';

interface TabsListUnstyledComponentsPropsOverrides {}

Expand Down Expand Up @@ -31,7 +32,7 @@ export interface TabsListUnstyledTypeMap<P = {}, D extends React.ElementType = '
defaultComponent: D;
}

type TabsListUnstyledProps<
export type TabsListUnstyledProps<
D extends React.ElementType = TabsListUnstyledTypeMap['defaultComponent'],
P = {},
> = OverrideProps<TabsListUnstyledTypeMap<P, D>, D> & {
Expand All @@ -43,4 +44,12 @@ type TabsListUnstyledProps<
component?: D;
};

export default TabsListUnstyledProps;
export type TabsListUnstyledOwnerState = TabsListUnstyledProps & {
isRtl: boolean;
orientation: 'horizontal' | 'vertical';
};

export type TabsListUnstyledRootSlotProps = UseTabsListRootSlotProps & {
className?: string;
ownerState: TabsListUnstyledOwnerState;
};
2 changes: 1 addition & 1 deletion packages/mui-base/src/TabsListUnstyled/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { default } from './TabsListUnstyled';
export type { default as TabsListUnstyledProps } from './TabsListUnstyledProps';
export * from './TabsListUnstyled.types';

export { default as tabsListUnstyledClasses } from './tabsListUnstyledClasses';
export * from './tabsListUnstyledClasses';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export type UseTabsListRootSlotProps<TOther = {}> = TOther & {
'aria-labelledby'?: React.AriaAttributes['aria-labelledby'];
'aria-orientation'?: React.AriaAttributes['aria-orientation'];
role: React.AriaRole;
ref: React.Ref<unknown>;
ref: React.Ref<any>;
onKeyDown?: React.KeyboardEventHandler<HTMLElement>;
};

0 comments on commit b4bc1f3

Please sign in to comment.