diff --git a/code/ui/manager/src/components/sidebar/TreeNode.tsx b/code/ui/manager/src/components/sidebar/TreeNode.tsx index 9768c0cf10a7..dc837accee6d 100644 --- a/code/ui/manager/src/components/sidebar/TreeNode.tsx +++ b/code/ui/manager/src/components/sidebar/TreeNode.tsx @@ -2,14 +2,13 @@ import { styled } from '@storybook/theming'; import type { Color, Theme } from '@storybook/theming'; import { Icons } from '@storybook/components'; import { transparentize } from 'polished'; -import type { FunctionComponent, ComponentProps } from 'react'; +import type { FC, ComponentProps } from 'react'; import React from 'react'; export const CollapseIcon = styled.span<{ isExpanded: boolean }>(({ theme, isExpanded }) => ({ display: 'inline-block', width: 0, height: 0, - marginTop: 6, marginLeft: 8, marginRight: 5, color: transparentize(0.4, theme.textMutedColor), @@ -41,8 +40,6 @@ const TypeIcon = styled(Icons)<{ docsMode?: boolean }>( { width: 12, height: 12, - padding: 1, - marginTop: 3, marginRight: 5, flex: '0 0 auto', }, @@ -132,7 +129,27 @@ export const RootNode = styled.div(({ theme }) => ({ color: theme.textMutedColor, })); -export const GroupNode: FunctionComponent< +const Wrapper = styled.div({ + display: 'flex', + alignItems: 'center', +}); + +const InvisibleText = styled.p({ + margin: 0, + width: 0, +}); + +// Make the content have a min-height equal to one line of text +export const IconsWrapper: FC<{ children?: React.ReactNode }> = ({ children }) => { + return ( + +   + {children} + + ); +}; + +export const GroupNode: FC< ComponentProps & { isExpanded?: boolean; isExpandable?: boolean } > = React.memo(function GroupNode({ children, @@ -142,43 +159,53 @@ export const GroupNode: FunctionComponent< }) { return ( - {isExpandable ? : null} - + + {isExpandable ? : null} + + {children} ); }); -export const ComponentNode: FunctionComponent> = React.memo( +export const ComponentNode: FC> = React.memo( function ComponentNode({ theme, children, isExpanded, isExpandable, isSelected, ...props }) { return ( - {isExpandable && } - + + {isExpandable && } + + {children} ); } ); -export const DocumentNode: FunctionComponent< - ComponentProps & { docsMode: boolean } -> = React.memo(function DocumentNode({ theme, children, docsMode, ...props }) { - return ( - - - {children} - - ); -}); - -export const StoryNode: FunctionComponent> = React.memo( - function StoryNode({ theme, children, ...props }) { +export const DocumentNode: FC & { docsMode: boolean }> = React.memo( + function DocumentNode({ theme, children, docsMode, ...props }) { return ( - + + + {children} ); } ); + +export const StoryNode: FC> = React.memo(function StoryNode({ + theme, + children, + ...props +}) { + return ( + + + + + {children} + + ); +});