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(theme-classic): allow specifying width/height in logo #5770

Merged
merged 10 commits into from Nov 1, 2021

Conversation

cerkiewny
Copy link
Contributor

Motivation

Fixes #5724

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

Check manually if new config works,
snapshot tests for website should not change with new config

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Oct 22, 2021
@netlify
Copy link

netlify bot commented Oct 22, 2021

✔️ [V2]
Built without sensitive environment variables

🔨 Explore the source changes: 55c68e3

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

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

@github-actions
Copy link

github-actions bot commented Oct 22, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟢 Performance 99
🟢 Accessibility 98
🟠 Best practices 86
🟢 SEO 100
🟢 PWA 91

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

@cerkiewny
Copy link
Contributor Author

Let me know what you think about code change I will follow it up with doc change if the code changes are in the right direction.

@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Oct 27, 2021
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.

Thanks

In any case, we don't want to change the current API and avoid any breaking change.

Using a string remains the simple option for the end user, and Docusaurus should later handle it automatically by transforming it to an ImageObject: it should not be done by the user (or at least it should not be mandatory).

I suggest we could just forward additional props to the img element directly, and write in our own website config:

module.exports = {
  themeConfig: {
    navbar: {
      title: 'Site Title',
      logo: {
        src: 'img/logo.png',
        width: 50,
        height: 50,
        className: "my-custom-logo"
      },
    },
  },
};

We'll figure out later how to automatically infer a good default width/height for the referenced FS image

@cerkiewny
Copy link
Contributor Author

Thanks

In any case, we don't want to change the current API and avoid any breaking change.

Using a string remains the simple option for the end user, and Docusaurus should later handle it automatically by transforming it to an ImageObject: it should not be done by the user (or at least it should not be mandatory).

I suggest we could just forward additional props to the img element directly, and write in our own website config:

module.exports = {
  themeConfig: {
    navbar: {
      title: 'Site Title',
      logo: {
        src: 'img/logo.png',
        width: 50,
        height: 50,
        className: "my-custom-logo"
      },
    },
  },
};

We'll figure out later how to automatically infer a good default width/height for the referenced FS image

Not sure if it is/isn't a problem but in this case width/height would be shared between logo from src and srcDark.

@slorber
Copy link
Collaborator

slorber commented Oct 27, 2021

Not sure if it is/isn't a problem but in this case width/height would be shared between logo from src and srcDark.

That does not seem like a big deal: users should use logos of same size to avoid layout shifts anyway, and has the responsibility to not mess things up: we just pass through, no additional logic

@cerkiewny
Copy link
Contributor Author

Not sure if it is/isn't a problem but in this case width/height would be shared between logo from src and srcDark.

That does not seem like a big deal: users should use logos of same size to avoid layout shifts anyway, and has the responsibility to not mess things up: we just pass through, no additional logic

Well had more of responsive logo idea in mind then src/srcDark really, but I guess if there is no plan for it, it can be added later

@slorber
Copy link
Collaborator

slorber commented Oct 27, 2021

Well had more of responsive logo idea in mind then src/srcDark really, but I guess if there is no plan for it, it can be added later

Not sure what you mean, but 2 logos with different widths means clicking on the theme switch will shift navbar items: bad UX

@Josh-Cena Josh-Cena changed the title feat: changed the logo properties to allow width/height specification feat: alow specifying width/height in logo Nov 1, 2021
@Josh-Cena Josh-Cena changed the title feat: alow specifying width/height in logo feat: allow specifying width/height in logo Nov 1, 2021
@cerkiewny
Copy link
Contributor Author

One missing thing in this PR is the documentation change to describe config for width/height @Josh-Cena

@Josh-Cena
Copy link
Collaborator

Sure, thanks :)

@Josh-Cena Josh-Cena changed the title feat: allow specifying width/height in logo feat(theme-classic): allow specifying width/height in logo Nov 1, 2021
@Josh-Cena
Copy link
Collaborator

I think this is good enough for now. We can try:

  • Allow passing arbitrary props to logo images, just like for navbar links;
  • Infer image sizes from files

But those can be in follow-ups. This solution is fine.

@Josh-Cena Josh-Cena merged commit 41ef9da into facebook:main Nov 1, 2021
@cerkiewny
Copy link
Contributor Author

I still think there is usecase for responsive logos, I would wait for the "PlatformSpecific" feature to be implemented, and then we could add platform specific to the logo setting to support responsive logo usecase if theme supports platforms like high DPI phones. Here are examples of "responsive logos":

obraz

@Josh-Cena
Copy link
Collaborator

I still think there is usecase for responsive logos, I would wait for the "PlatformSpecific" feature to be implemented, and then we could add platform specific to the logo setting to support responsive logo usecase if theme supports platforms like high DPI phones. Here are examples of "responsive logos":

Ah, yes, we could look into that. We don't want logos to be responsive to light/dark, but screen sizes sound fine. Beware though that currently all logo usages are scaled so that their sizes are invariant on all screen sizes.

@cerkiewny cerkiewny deleted the feature/logo_size branch November 1, 2021 11:00
@slorber
Copy link
Collaborator

slorber commented Nov 3, 2021

Maybe we could allow passing a className so that you can handle the responsiveness yourself with CSS?

I think lighthouse might still report an error though, and you'll need to keep the width/height

@Josh-Cena
Copy link
Collaborator

I think lighthouse might still report an error though, and you'll need to keep the width/height

width and height are needed for minimizing layout shifts (while we still have many layout shifts with other images), and I do think we should allow any props passed to the rendered image. From @cerkiewny's demo I think they actually want different images being rendered, which IMO is not necessary for now

@alex-drocks
Copy link

Logo is broken when updating from beta8 to beta9 on header and footer. I tried adding width and height but it still cannot find the image that was already working in beta8.

image

@Josh-Cena
Copy link
Collaborator

@alex-drocks this is a different issue. If you are using a base URL you are probably experiencing #5863, which has been fixed in a canary release.

@alex-drocks
Copy link

@alex-drocks this is a different issue. If you are using a base URL you are probably experiencing #5863, which has been fixed in a canary release.

Thanks Josh, yes in fact I am using a baseUrl.

For reference to other readers, it means i am not using the default localhost:port/ base but something like localhost:port/my-base-path/...

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.

NavbarLogo doesn't have width and height attribute
5 participants