Skip to content

[docs-infra] Fix TOC RTL padding regression #44535

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

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Changes from all commits
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
27 changes: 11 additions & 16 deletions docs/src/modules/components/AppTableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ const NavList = styled(Typography)({
});

const NavItem = styled(Link, {
shouldForwardProp: (prop) =>
prop !== 'active' && prop !== 'secondary' && prop !== 'secondarySubItem',
shouldForwardProp: (prop) => prop !== 'active' && prop !== 'level',
})(({ theme }) => {
const activeStyles = {
borderLeftColor: (theme.vars || theme).palette.primary[200],
Expand All @@ -67,9 +66,8 @@ const NavItem = styled(Link, {

return [
{
'--_padding-left': '12px',
boxSizing: 'border-box',
padding: theme.spacing('6px', 0, '6px', 'var(--_padding-left)'),
padding: '6px 0 6px 12px',
borderLeft: `1px solid transparent`,
display: 'block',
fontSize: theme.typography.pxToRem(13),
Expand All @@ -93,15 +91,15 @@ const NavItem = styled(Link, {
},
},
{
props: ({ secondary }) => secondary,
props: ({ level }) => level === 2,
style: {
'--_padding-left': theme.spacing(3),
padding: `6px 0 6px ${theme.spacing(3)}`,
},
},
{
props: ({ secondarySubItem }) => secondarySubItem,
props: ({ level }) => level === 3,
style: {
'--_padding-left': theme.spacing(4.5),
padding: `6px 0 6px ${theme.spacing(4.5)}`,
},
},
],
Expand Down Expand Up @@ -250,15 +248,14 @@ export default function AppTableOfContents(props) {
[],
);

const itemLink = (item, secondary, secondarySubItem) => (
const itemLink = (item, level) => (
<NavItem
display="block"
href={`#${item.hash}`}
underline="none"
onClick={handleClick(item.hash)}
active={activeState === item.hash}
secondary={secondary}
secondarySubItem={secondarySubItem}
level={level}
>
<span dangerouslySetInnerHTML={{ __html: item.text }} />
</NavItem>
Expand Down Expand Up @@ -324,18 +321,16 @@ export default function AppTableOfContents(props) {
<NavList component="ul">
{toc.map((item) => (
<li key={item.text}>
{itemLink(item)}
{itemLink(item, 1)}
{item.children.length > 0 ? (
<NavList as="ul">
{item.children.map((subitem) => (
<li key={subitem.text}>
{itemLink(subitem, true)}
{itemLink(subitem, 2)}
{subitem.children?.length > 0 ? (
<NavList as="ul">
{subitem.children.map((nestedSubItem) => (
<li key={nestedSubItem.text}>
{itemLink(nestedSubItem, false, true)}
</li>
<li key={nestedSubItem.text}>{itemLink(nestedSubItem, 3)}</li>
))}
</NavList>
) : null}
Expand Down
Loading