Skip to content
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

feat(v2): add icon to external navbar links #4949

Merged
merged 3 commits into from
Jun 15, 2021

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Jun 11, 2021

Motivation

For more consistency, we should probably add icon for external links in the navbar too. This was previously done for sidebar links (see #4261).

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Preview

image

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@lex111 lex111 added the pr: new feature This PR adds a new API or behavior. label Jun 11, 2021
@lex111 lex111 requested a review from slorber as a code owner June 11, 2021 07:56
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 11, 2021
@@ -32,6 +35,8 @@ function NavLink({
const toUrl = useBaseUrl(to);
const activeBaseUrl = useBaseUrl(activeBasePath);
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
const isExternalLink = label && href && href !== '#';
Copy link
Contributor Author

@lex111 lex111 Jun 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, if we should consider # as internal link? If so, we can use the built-in isInternalUrl function instead this condition.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable yes, just made the change

However I find this code a bit messy, don't really like that to/href are handled differently, we should try to make all this more uniform in the future (this is needed anyway for markdown as you can't precise if links are to or href)

@netlify
Copy link

netlify bot commented Jun 11, 2021

✔️ [V2]

🔨 Explore the source changes: 93dbe61

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/60c8950870a0230008d1563a

😎 Browse the preview: https://deploy-preview-4949--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jun 11, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 59
🟢 Accessibility 97
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4949--docusaurus-2.netlify.app/

@github-actions
Copy link

github-actions bot commented Jun 11, 2021

Size Change: +2.39 kB (0%)

Total Size: 623 kB

Filename Size Change
website/build/blog/2017/12/14/introducing-docusaurus/index.html 63.3 kB +1.22 kB (+2%)
website/build/index.html 28.2 kB +1.17 kB (+4%)
ℹ️ View Unchanged
Filename Size Change
website/build/assets/css/styles.********.css 87.8 kB 0 B
website/build/assets/js/main.********.js 444 kB +4 B (0%)
website/build/docs/introduction/index.html 235 B 0 B

compressed-size-action

Copy link
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Not sure all users will appreciate having an external link icon in their navbar, some sites have a lot of external links in navbar and having this icon multiple times in navbar does not look too good imho. + I don't think there's a clear API to disable this apart swizzling.

What about limiting this for dropdown items only and not top-level navbar items? (at least for desktop?)

@@ -32,6 +35,8 @@ function NavLink({
const toUrl = useBaseUrl(to);
const activeBaseUrl = useBaseUrl(activeBasePath);
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
const isExternalLink = label && href && href !== '#';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable yes, just made the change

However I find this code a bit messy, don't really like that to/href are handled differently, we should try to make all this more uniform in the future (this is needed anyway for markdown as you can't precise if links are to or href)

@lex111
Copy link
Contributor Author

lex111 commented Jun 14, 2021

I was inspired by VuePress as example that adds icon for external links to the navbar. Actually, end user can remove this icon via CSS attribute selector.

I suggest adding this icon without explicit customization for now, and just wait for feedback from users. As for me, it's not a big change, so I do not think that there will be a lot of dissatisfied with it.

@slorber
Copy link
Collaborator

slorber commented Jun 15, 2021

Hmm why not.

I think for now they can also disable it by using to instead of href (even if I don't like that "API" much)

Should we keep the release item in our own site? We don't seem to have enough width to make it fit:

image

@lex111
Copy link
Contributor Author

lex111 commented Jun 15, 2021

Yes, will remove this link, it was added just for demo purposes.

However, in Infima I previously opened PR that reduces current padding between navbar items. This seems to make sense to me, can you check this out?

@slorber slorber merged commit 57cf209 into master Jun 15, 2021
@slorber slorber deleted the lex111/external-link-navbar branch August 17, 2021 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants