-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat(theme-common): Get desktopThresholdWidth from docusaurus config #9261
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
Conversation
… fall back to 996
This reverts commit c629834.
Hi @jgarrow! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
Hi @jgarrow I'm sorry but unfortunately we can't do this. The value 996 is not arbitrary, and is hardcoded in many more places notably Infima (https://infima.dev/), the design system that Docusaurus theme classic uses. Changing the value on the JS side, and not taking into consideration the CSS side, is going to lead to weird unexpected behaviors. For example you'll notice that on your preview, for a 755px width, if you click on the mobile drawer (which is still displayed despite your breakpoint), the drawer overlay will be applied but the drawer will not render: ![]() This is just one edge case, there are probably others. If you want to have configurable breakpoints, it needs to be implemented "full-stack", including CSS and Infima. Afaik there's no CSS variable support for mediaqueries: https://bholmes.dev/blog/alternative-to-css-variable-media-queries/ Infima uses PostCSS: @custom-media --ifm-narrow-window (max-width: 996px);
@media (--ifm-narrow-window) {
padding: 0;
} Which currently compiles to: @media (max-width: 996px) {
padding: 0;
} The value is hardcoded also in the Infima distributed CSS file. It would require a few changes to our infrastructure (and probably apply https://github.com/csstools/postcss-custom-media at the Docusaurus side) to support configurable breakpoints. Overall I'm not even sure all this is a good idea. There might be some design system components that wouldn't render well under a different viewport size. If you want to customize things, you'd rather do that on a case-by-case basis instead of changing the global breakpoint. If your goal is to only affect the navbar, then you should swizzle the navbar and reconfigure the CSS/JS according to your new breakpoint. And maybe all the rest should keep behaving exactly as before? |
@slorber The issue is that there's no way to change that hardcoded breakpoint while still maintaining all of the same underlying logic. All I would like to do is change the navbar breakpoint (I need it larger), but unless there's a way to swizzle hooks and other non-component |
@jgarrow we enable you to fork the navbar entrypoint component, which gives you the opportunity to not use our own Copy/pasting is fine, as well as using any alternative implementation that suits your custom goal. Similarly if you find a React behavior that annoys you, React is a deps of our code, and you can't patch React by simply swizzling Docusaurus code. You'd need to fork it, use patch-package, vendor it or any other solution. You can consider "theme-common" that way too: it's an utility lib not necessarily meant to be overriden. If you agree with the code in it, use it, otherwise, don't use it for it on your own. The best I could concede here is to allow you passing breakpoints to the hook as parameters so that it becomes a bit more flexible and you can avoid copy/pasting, but I don't want this to be part of the public config API of Docusaurus. useWindowSize({breakpoints = defaultBreakpoints})` But keep in mind that by adding this we are slighly increasing bundle size for all users, despite maybe only you will ever use it. The goal of theme-common is not to support every possible use case you might have by swizzling. |
@slorber I understand that the primary purpose of the A small change to allow for an optional If you’re open to it, I’d like to open a PR for this addition. |
I wouldn't call copy pasting a relatively small function an extensive fork 😅 But OK 👍accepting a small pr |
Just finding thread, I would love to have this built in plz <3 |
@slorber I simplified the implementation to just be function params vs a sizing config in the |
Pre-flight checklist
Motivation
The
desktopThresholdWidth
in theuseWindowSize
hook is currently hardcoded at 996px. This makes it impossible to customize the breakpoint for the navbar, which creates inconsistencies when other CSS media query breakpoints are customized for the rest of the site.This change allows for customization of that value by looking for a
breakpoints.desktop
value in thethemeConfig
in thedocusaurus.config.js
file. If none is present, it will default to the original 996 value.Test Plan
An additional theme config has been added to
website/_dogfooding/dogfooding.config.js
:The
website/docusaurus.config.js
config has been updated to add this newdogfoodingThemeConfig
to its existingthemeConfig
. Spin up that site and change the viewport width to observe that the navbar hamburger menu icon is visible below and hidden above 744px.Test links
Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/
Related issues/PRs