Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DST-111]: enhance styling tabs #3250

Merged
merged 9 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/components/src/Tabs/TabPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { TabListState } from '@react-stately/tabs';

export interface TabPanelProps extends AriaTabPanelProps {
state: TabListState<object>;
className?: string;
}

export const TabPanel = ({ state, ...props }: TabPanelProps) => {
export const TabPanel = ({ state, className, ...props }: TabPanelProps) => {
const ref = useRef(null);
const { tabPanelProps } = useTabPanel(props, state, ref);
return (
<div {...tabPanelProps} ref={ref}>
<div className={className} ref={ref} {...tabPanelProps}>
{state.selectedItem?.props.children}
</div>
);
Expand Down
52 changes: 34 additions & 18 deletions packages/components/src/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@ import { Tab } from './Tab';
import { TabPanel } from './TabPanel';
import { Item } from '@react-stately/collections';
import { TabContext } from './Context';
import { ItemProps } from '@react-types/shared';

interface TabsProps
extends Omit<AriaTabListProps<object>, 'orientation' | 'isDisabled'>,
GapSpaceProp {
size?: 'small' | 'medium' | 'large';
disabled?: boolean;
variant?: string;
}
export const Tabs = ({
export const Tabs: Tabs = ({
space = 2,
size = 'medium',
sarahgm marked this conversation as resolved.
Show resolved Hide resolved
disabled,
variant,
className,
...rest
}: TabsProps) => {
const ref = useRef(null);
Expand All @@ -38,21 +33,42 @@ export const Tabs = ({
size,
variant,
});

return (
<TabContext.Provider value={{ classNames }}>
<div
className={cn('flex', gapSpace[space], classNames.tabs)}
{...tabListProps}
ref={ref}
>
{[...state.collection].map(item => {
return <Tab key={item.key} item={item} state={state} />;
})}
{/* tabs container */}
<div className={className}>
OsamaAbdellateef marked this conversation as resolved.
Show resolved Hide resolved
<div
className={cn('flex', gapSpace[space], classNames.tabs)}
{...tabListProps}
ref={ref}
>
{[...state.collection].map(item => {
return <Tab key={item.key} item={item} state={state} />;
})}
</div>
<TabPanel
key={state.selectedItem?.key}
state={state}
className={state.selectedItem?.props?.className}
OsamaAbdellateef marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
<TabPanel key={state.selectedItem?.key} state={state} />
</TabContext.Provider>
);
};

Tabs.Item = Item;

interface TabsProps
extends Omit<AriaTabListProps<object>, 'orientation' | 'isDisabled'>,
GapSpaceProp {
size?: 'small' | 'medium' | 'large';
OsamaAbdellateef marked this conversation as resolved.
Show resolved Hide resolved
disabled?: boolean;
variant?: string;
className?: string;
}

interface Tabs {
(props: TabsProps): JSX.Element;
// to add className to <Tabs.Item>
Item: (props: ItemProps<any> & { className?: string }) => JSX.Element;
}