-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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 custom props for consumption by swizzled sidebar #3888
Conversation
Hi @oriooctopus! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, 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. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Size Change: +16 B (0%) Total Size: 154 kB ℹ️ View Unchanged
|
✔️ Deploy preview for docusaurus-2 ready! 🔨 Explore the source changes: 708b9da 🔍 Inspect the deploy logs: https://app.netlify.com/sites/docusaurus-2/deploys/5fd264ae8c351500070b0a2a 😎 Browse the preview: https://deploy-preview-3888--docusaurus-2.netlify.app |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks fine, but please avoid refactoring types unnecessarily, that's outside the scope of this feature request and should rather be decided separately
@@ -39,6 +39,7 @@ Available document ids= | |||
type: 'link', | |||
label: sidebar_label || title, | |||
href: permalink, | |||
extra: item.extra, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I like "data" more for the name of this attribute, but no strong opinion
@ReginaLiang what's your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slorber,
Actually, I think any one will be fine. ^v^, a little little thought, How about customFields
? It is consistent with DocusaurusConfig object, I guess customFields
more meaningful. But any one is OK for me.
@slorber, @oriooctopus ,
Thanks for your guys great work! I believe docusaurus is getting better and better.
website/docs/docs.md
Outdated
@@ -165,6 +165,8 @@ As the name implies, `SidebarItem` is an item defined in a Sidebar. There are a | |||
- [Ref](#ref) | |||
- [Category](#category) | |||
|
|||
**Note**: If you would like to pass in custom props to a swizzled sidebar, an optional object called `extra` can be added to any of the items: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does not seem good enough to me, it looks like you forgot to add an example after the :
?
@slorber would you like an additional commit with the changes or would you prefer them squashed/amended? |
@oriooctopus it's not needed to squash because we squash all prs when merging, so we don't care about your local history 😉 |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-3888--docusaurus-2.netlify.app/classic/ |
@slorber does this look good to you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still some type->interface refactorings
- "extra" still there after the renaming.
Otherwise LGTM.
Not sure customProps
is the best name, but let's merge this. We'll see later if anyone can come with a better name 😅
@@ -20,7 +21,7 @@ import { | |||
import {mapValues, flatten, difference} from 'lodash'; | |||
import {getElementsAround} from '@docusaurus/utils'; | |||
|
|||
type SidebarItemCategoryJSON = { | |||
export type SidebarItemCategoryJSON = SidebarItemBase & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it need an export? I don't see it imported anywhere, why this change?
|
||
export type SidebarItemLink = { | ||
export interface SidebarItemLink extends SidebarItemBase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before: use type aliases instead of refactoring to interface
@@ -21,13 +21,17 @@ declare module '@docusaurus/plugin-content-docs-types' { | |||
permalinkToSidebar: PermalinkToSidebar; | |||
}; | |||
|
|||
export type PropSidebarItemLink = { | |||
export type PropsSidebarItemBase = { | |||
extra?: object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now renamed to customProps?
2ee80a3
to
708b9da
Compare
Just updated it, sorry about the changes I missed last time. |
thanks, LGTM 👍 @oriooctopus the TS setup is a bit messy currently, not sure to have a good answer for that, but we'll try to improve it over time :) |
Motivation
-I want to pass in custom props for consumption by my swizzled DocSidebar component
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
I modified a test within
docusaurus-plugin-content/src/__tests__/sidebars.test.ts
Related PRs
#3868