diff --git a/code/ui/components/src/bar/bar.tsx b/code/ui/components/src/bar/bar.tsx index 08c67aededf..bdbb60757f3 100644 --- a/code/ui/components/src/bar/bar.tsx +++ b/code/ui/components/src/bar/bar.tsx @@ -7,6 +7,7 @@ import { ScrollArea } from '../ScrollArea/ScrollArea'; export interface SideProps { left?: boolean; right?: boolean; + scrollable?: boolean; } export const Side = styled.div( @@ -14,10 +15,10 @@ export const Side = styled.div( display: 'flex', whiteSpace: 'nowrap', flexBasis: 'auto', - flexShrink: 0, marginLeft: 3, marginRight: 3, }, + ({ scrollable }) => (scrollable ? { flexShrink: 0 } : {}), ({ left }) => left ? { @@ -38,18 +39,25 @@ export const Side = styled.div( ); Side.displayName = 'Side'; -const UnstyledBar: FC> = ({ children, className }) => ( - - {children} - -); -export const Bar = styled(UnstyledBar)<{ border?: boolean }>( - ({ theme }) => ({ +const UnstyledBar: FC & { scrollable?: boolean }> = ({ + children, + className, + scrollable, +}) => + scrollable ? ( + + {children} + + ) : ( +
{children}
+ ); +export const Bar = styled(UnstyledBar)<{ border?: boolean; scrollable?: boolean }>( + ({ theme, scrollable = true }) => ({ color: theme.barTextColor, width: '100%', height: 40, flexShrink: 0, - overflow: 'auto', + overflow: scrollable ? 'auto' : 'hidden', overflowY: 'hidden', }), ({ theme, border = false }) => @@ -72,9 +80,8 @@ const BarInner = styled.div<{ bgColor: string }>(({ bgColor }) => ({ backgroundColor: bgColor || '', })); -export interface FlexBarProps { +export interface FlexBarProps extends ComponentProps { border?: boolean; - children?: any; backgroundColor?: string; } @@ -83,7 +90,9 @@ export const FlexBar: FC = ({ children, backgroundColor, ...rest } return ( - {left} + + {left} + {right ? {right} : null} diff --git a/code/ui/components/src/tabs/tabs.tsx b/code/ui/components/src/tabs/tabs.tsx index 683e8456478..80cf528aa90 100644 --- a/code/ui/components/src/tabs/tabs.tsx +++ b/code/ui/components/src/tabs/tabs.tsx @@ -5,7 +5,7 @@ import { sanitize } from '@storybook/csf'; import { Placeholder } from '../placeholder/placeholder'; import { TabButton } from '../bar/button'; -import { Side } from '../bar/bar'; +import { FlexBar, Side } from '../bar/bar'; import type { ChildrenList } from './tabs.helpers'; import { childrenToList, VisuallyHidden } from './tabs.helpers'; import { useList } from './tabs.hooks'; @@ -40,15 +40,6 @@ const Wrapper = styled.div( } ); -const WrapperChildren = styled.div<{ backgroundColor: string }>(({ theme, backgroundColor }) => ({ - color: theme.barTextColor, - display: 'flex', - width: '100%', - height: 40, - boxShadow: `${theme.appBorderColor} 0 -1px 0 0 inset`, - background: backgroundColor ?? theme.barBg, -})); - export const TabBar = styled.div({ overflow: 'hidden', @@ -60,12 +51,6 @@ export const TabBar = styled.div({ flexGrow: 1, }); -const TabBarSide = styled(Side)({ - flexGrow: 1, - flexShrink: 1, - maxWidth: '100%', -}); - TabBar.displayName = 'TabBar'; export interface ContentProps { @@ -159,36 +144,34 @@ export const Tabs: FC = memo( return list.length ? ( - - - - {visibleList.map(({ title, id, active, color }) => { - return ( - { - tabRefs.current.set(id, ref); - }} - className={`tabbutton ${active ? 'tabbutton-active' : ''}`} - type="button" - key={id} - active={active} - textColor={color} - onClick={(e: MouseEvent) => { - e.preventDefault(); - actions.onSelect(id); - }} - role="tab" - > - {title} - - ); - })} - - - + + + {visibleList.map(({ title, id, active, color }) => { + return ( + { + tabRefs.current.set(id, ref); + }} + className={`tabbutton ${active ? 'tabbutton-active' : ''}`} + type="button" + key={id} + active={active} + textColor={color} + onClick={(e: MouseEvent) => { + e.preventDefault(); + actions.onSelect(id); + }} + role="tab" + > + {title} + + ); + })} + + {tools ? {tools} : null} - + {list.map(({ id, active, render }) => render({ key: id, active }))}