mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 02:08:55 +02:00
refactor: better external link icon positioning (#6994)
This commit is contained in:
parent
87592bca03
commit
e606e62a6a
3 changed files with 14 additions and 7 deletions
|
@ -250,6 +250,7 @@ function DocSidebarItemLink({
|
||||||
}: Props & {item: PropSidebarItemLink}) {
|
}: Props & {item: PropSidebarItemLink}) {
|
||||||
const {href, label, className} = item;
|
const {href, label, className} = item;
|
||||||
const isActive = isActiveSidebarItem(item, activePath);
|
const isActive = isActiveSidebarItem(item, activePath);
|
||||||
|
const isInternalLink = isInternalUrl(href);
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
className={clsx(
|
className={clsx(
|
||||||
|
@ -260,17 +261,21 @@ function DocSidebarItemLink({
|
||||||
)}
|
)}
|
||||||
key={label}>
|
key={label}>
|
||||||
<Link
|
<Link
|
||||||
className={clsx('menu__link', {
|
className={clsx(
|
||||||
'menu__link--active': isActive,
|
'menu__link',
|
||||||
})}
|
!isInternalLink && styles.menuExternalLink,
|
||||||
|
{
|
||||||
|
'menu__link--active': isActive,
|
||||||
|
},
|
||||||
|
)}
|
||||||
aria-current={isActive ? 'page' : undefined}
|
aria-current={isActive ? 'page' : undefined}
|
||||||
to={href}
|
to={href}
|
||||||
{...(isInternalUrl(href) && {
|
{...(isInternalLink && {
|
||||||
onClick: onItemClick ? () => onItemClick(item) : undefined,
|
onClick: onItemClick ? () => onItemClick(item) : undefined,
|
||||||
})}
|
})}
|
||||||
{...props}>
|
{...props}>
|
||||||
{label}
|
{label}
|
||||||
{!isInternalUrl(href) && <IconExternalLink />}
|
{!isInternalLink && <IconExternalLink />}
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
|
|
|
@ -11,3 +11,7 @@
|
||||||
var(--ifm-menu-link-padding-horizontal);
|
var(--ifm-menu-link-padding-horizontal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menuExternalLink {
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,4 @@
|
||||||
|
|
||||||
.iconExternalLink {
|
.iconExternalLink {
|
||||||
margin-left: 0.3rem;
|
margin-left: 0.3rem;
|
||||||
position: relative;
|
|
||||||
top: 1px;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue