-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
UI: Fix TreeNode alignment when using a different font #22221
Changes from 1 commit
645c7cd
f562120
222e687
1de752e
2bc038b
0978fdc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ export const CollapseIcon = styled.span<{ isExpanded: boolean }>(({ theme, isExp | |
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', | ||
}, | ||
|
@@ -145,6 +142,26 @@ export const RootNode = styled.div(({ theme }) => ({ | |
color: theme.textMutedColor, | ||
})); | ||
|
||
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: FunctionComponent<{ children?: React.ReactNode }> = ({ children }) => { | ||
return ( | ||
<Wrapper> | ||
<InvisibleText> </InvisibleText> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need this InvisibleText? It should automatically center it in the middle without this line, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason is that when the text for the TreeNode breaks in multiple lines the icon needs to be centered with the first line of text on the right side not with the whole container, like the first example here: To achieve this the only way I found is to wrap the Icon within an element that has a height of just one line of text and align the icon vertically inside it, so it will be aligned with the first line of text of the TreeNode. We can't use a fixed value that represents the height of one line of text because each font can have a different height, to deal with it I used this trick of placing an invisible character to set a height for the container of the icon to be exactly the same as one line of a text. Just for visualization |
||
{children} | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export const GroupNode: FunctionComponent< | ||
ComponentProps<typeof BranchNode> & { isExpanded?: boolean; isExpandable?: boolean } | ||
> = React.memo(function GroupNode({ | ||
|
@@ -155,8 +172,10 @@ export const GroupNode: FunctionComponent< | |
}) { | ||
return ( | ||
<BranchNode isExpandable={isExpandable} tabIndex={-1} {...props}> | ||
{isExpandable ? <CollapseIcon isExpanded={isExpanded} /> : null} | ||
<TypeIcon icon="folder" useSymbol color="primary" /> | ||
<IconsWrapper> | ||
{isExpandable ? <CollapseIcon isExpanded={isExpanded} /> : null} | ||
<TypeIcon icon="folder" useSymbol color="primary" /> | ||
</IconsWrapper> | ||
{children} | ||
</BranchNode> | ||
); | ||
|
@@ -166,8 +185,10 @@ export const ComponentNode: FunctionComponent<ComponentProps<typeof BranchNode>> | |
function ComponentNode({ theme, children, isExpanded, isExpandable, isSelected, ...props }) { | ||
return ( | ||
<BranchNode isExpandable={isExpandable} tabIndex={-1} {...props}> | ||
{isExpandable && <CollapseIcon isExpanded={isExpanded} />} | ||
<TypeIcon icon="component" useSymbol color="secondary" /> | ||
<IconsWrapper> | ||
{isExpandable && <CollapseIcon isExpanded={isExpanded} />} | ||
<TypeIcon icon="component" useSymbol color="secondary" /> | ||
</IconsWrapper> | ||
{children} | ||
</BranchNode> | ||
); | ||
|
@@ -179,7 +200,9 @@ export const DocumentNode: FunctionComponent< | |
> = React.memo(function DocumentNode({ theme, children, docsMode, ...props }) { | ||
return ( | ||
<LeafNode tabIndex={-1} {...props}> | ||
<TypeIcon icon="document" useSymbol docsMode={docsMode} /> | ||
<IconsWrapper> | ||
<TypeIcon icon="document" useSymbol docsMode={docsMode} /> | ||
</IconsWrapper> | ||
{children} | ||
</LeafNode> | ||
); | ||
|
@@ -189,7 +212,9 @@ export const StoryNode: FunctionComponent<ComponentProps<typeof LeafNode>> = Rea | |
function StoryNode({ theme, children, ...props }) { | ||
return ( | ||
<LeafNode tabIndex={-1} {...props}> | ||
<TypeIcon icon="bookmarkhollow" useSymbol /> | ||
<IconsWrapper> | ||
<TypeIcon icon="bookmarkhollow" useSymbol /> | ||
</IconsWrapper> | ||
{children} | ||
</LeafNode> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use
FC
instead ofFunctionComponent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, this is better 😄
I changed it here: f562120