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

Expose dynamically setting the topLevelNavbarItems in v4 #3620

Open
Firgrep opened this issue Oct 31, 2024 · 8 comments
Open

Expose dynamically setting the topLevelNavbarItems in v4 #3620

Firgrep opened this issue Oct 31, 2024 · 8 comments
Labels
enhancement New feature or request

Comments

@Firgrep
Copy link

Firgrep commented Oct 31, 2024

Is your feature request related to a problem? Please describe.
In v3, you could alter the navbar items by filtering what was passed to its props, such that you could dynamically change the navbar based on the path (the old turbo.build page used to do this). In v4, the navbar retrieves the items internally through a hook, preventing feeding it the modified list of items.

Describe the solution you'd like A clear and concise description of what you
want to happen.
Want to be able to modify the navbar items.

Describe alternatives you've considered A clear and concise description of
any alternative solutions or features you've considered.
Not sure what other workarounds are possible here. I want to be able to modify that list since that list also goes into the mobile navbar etc.

Additional context Add any other context or screenshots about the feature
request here.

@Firgrep Firgrep added the enhancement New feature or request label Oct 31, 2024
@Firgrep Firgrep mentioned this issue Oct 31, 2024
1 task
@Firgrep
Copy link
Author

Firgrep commented Oct 31, 2024

Trying to come up with a solution in the referenced PR above. It's not working though, so if anyone can spot the issue or suggest a better way, or if there's a workaround, I'm all ears.

@dimaMachina
Copy link
Collaborator

I think I had a similar problem when I did a migration of graphql.org

https://github.com/graphql/graphql.github.io/blob/f7bfbd177f1f7a13109bb370ad401151428444e8/src/globals.css#L78-L82

maybe we can add the possibility to set className in _meta files?

@Firgrep
Copy link
Author

Firgrep commented Nov 1, 2024

Would this also add new links? Not just hide existing ones?

@dimaMachina
Copy link
Collaborator

dimaMachina commented Nov 1, 2024

Would this also add new links? Not just hide existing ones?

of course not

the navbar retrieves the items internally through a hook, preventing feeding it the modified list of items.

we cannot pass functions from server components into client components

Not sure what other workarounds are possible here. I want to be able to modify that list since that list also goes into the mobile navbar etc.

show me an example with screenshots of what you want to achieve

@Firgrep
Copy link
Author

Firgrep commented Nov 1, 2024

we cannot pass functions from server components into client components

Yes, I understand that, but the config.tsx in nextra-theme-docs is a client component that uses a zustand store that lives on the client? I'm not familiar with zustand but I reckon there must be a way to manipulate the store (scoped to the relevant field) and expose that in a hook?

show me an example with screenshots of what you want to achieve

I can do better, I can show you a live example, using nextra v3. Based on the URL, the navbar has items added based on route.

Root page:
image

More specific page (notice Guides and Reference added to the navbar that are based on the route):
image

You can see it here https://sphil.xyz

@dimaMachina
Copy link
Collaborator

The problem with your PR is that even if you make work the setTopLevelNavbarItems function, it will not work as you expected.

When you will visit the root page you'll get a flash of Guide and Reference nav links present on initial loading, and after they will be removed.

I am not interested and not convinced in this feature for now

@Firgrep
Copy link
Author

Firgrep commented Nov 2, 2024

Ok, fair enough. I'll just have to get creative then :) thank you for your time and attention! Feel free to close this issue.

@dimaMachina
Copy link
Collaborator

Thank you 🙏 let’s keep it open if anybody wants to have a similar feature or has an idea of proof of concept that could be easily integrated into Nextra

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants