Skip to content

Commit c69b291

Browse files
author
Brandon Hsiao
committed
Merge branch 'feat/anchor-headers' of git.streamlit.io:streamlit/streamlit into feat/anchor-headers
2 parents 1d68738 + 282fbf1 commit c69b291

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

frontend/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
StyledStreamlitMarkdown,
4040
StyledLinkIconContainer,
4141
StyledLinkIcon,
42+
StyledHeaderContent,
4243
} from "./styled-components"
4344

4445
import "katex/dist/katex.min.css"
@@ -147,10 +148,10 @@ function HeadingWithAnchor({
147148
<StyledLinkIconContainer>
148149
{elementId && (
149150
<StyledLinkIcon href={`#${elementId}`}>
150-
<LinkIcon size="20" color="#ccc" />
151+
<LinkIcon size="18" />
151152
</StyledLinkIcon>
152153
)}
153-
{children}
154+
<StyledHeaderContent>{children}</StyledHeaderContent>
154155
</StyledLinkIconContainer>
155156
)
156157
}

frontend/src/components/shared/StreamlitMarkdown/styled-components.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,46 @@ export const StyledStreamlitMarkdown = styled.div(({ theme }) => ({
4141
},
4242
}))
4343

44-
export const StyledLinkIconContainer = styled.div(({ theme }) => ({
44+
export const StyledLinkIconContainer = styled.div(() => ({
4545
position: "relative",
46-
left: "-30px",
47-
paddingLeft: "30px",
48-
a: {
49-
display: "none",
50-
},
46+
left: "calc(-2.5rem - 0.5rem)",
47+
width: "calc(100% + 2.5rem + 0.5rem)",
48+
display: "flex",
49+
alignItems: "flex-start",
5150
":hover": {
5251
a: {
53-
display: "inline-block",
52+
opacity: 0.75,
5453
},
5554
},
5655
}))
5756

5857
export const StyledLinkIcon = styled.a(({ theme }) => ({
59-
position: "absolute",
60-
top: "-2px",
58+
position: "relative",
59+
top: "calc(-1.25rem + 0.5em)",
6160
left: 0,
61+
marginRight: "0.5rem",
62+
63+
// center icon
64+
lineHeight: 0,
65+
display: "inline-flex",
66+
alignItems: "center",
67+
justifyContent: "center",
68+
69+
// copied from full screen button
70+
transition: "opacity 300ms",
71+
opacity: 0,
72+
height: "2.5rem",
73+
width: "2.5rem",
74+
zIndex: theme.zIndices.sidebar + 1,
75+
border: "none",
76+
backgroundColor: theme.colors.white,
77+
borderRadius: theme.radii.xl,
78+
79+
svg: {
80+
stroke: theme.colors.bodyText,
81+
},
82+
}))
83+
84+
export const StyledHeaderContent = styled.span(() => ({
85+
position: "relative",
6286
}))

0 commit comments

Comments
 (0)