question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navigation: Add component

See original GitHub issue

I got a VERY early and rough prototype of a Navigation component during early development of G2: https://g2-components.xyz/iframe.html?id=components-navigator--default&viewMode=story#

Having a feature-rich<Navigation /> component would be a VERY welcomed addition in the world of web components. Some features would include:

  • Reactive to Route changes (e.g. React Router, Reach, Browser, etc… should be library agnostic)
  • Reactive to programatic changes
  • Nestable (in theory forever)
  • Animations
  • Persistent UI across screens (e.g. headers in iOS/Android)
  • Focus handling on screen changes

(The React Native world already has this ❤️)

I initially wrote about the requirements, mechanics, and breakdown in detail here: https://github.com/WordPress/gutenberg/pull/24107#issuecomment-662578255

Visual Prototype

An example of this experience can be seen in this CodePen (by @jameskoster) https://cdpn.io/jameskoster/debug/vYGEEpp#

Link to Figma file: https://www.figma.com/file/e4tLacmlPuZV47l7901FEs/WordPress-Design-Library?node-id=1456%3A72

Another Figma Prototype: https://www.figma.com/proto/QNNc834dBBNz1bL2qc9VZyq5/Navigation-experimental?node-id=1765%3A4323&viewport=517%2C73%2C0.14826907217502594&scaling=scale-down

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ItsJonQcommented, Aug 6, 2020

Updates! I have something working:

Demo: https://g2-components.xyz/iframe.html?id=components-navigator--sidebar

Nested screens work, along with “active” awareness, back/forward navigation awareness + animation sync.

The Navigation component code does work, however, I would not be comfortable using it outside of prototyping. The primary thing that needs to be fixed would be the (current) reliance on React Router Context. The current work-around to avoid app integration conflict is to use a namespace param (which isn’t ideal).

Anywhoo!! It looks + feels promising 😃

Check out the code needed to create this experience: https://github.com/ItsJonQ/g2/blob/master/packages/components/src/Navigator/__stories__/Navigator.Sidebar.stories.js

The components + markup is simple, and should feel very familiar to those who have used React Router (or any routing library). There’s room for improvement, but we should continue with this DX in mind!

Things to Improve

NavigationLink composition

One thing I’d like to improve is this:

<NavigatorLink to="Home">
    <MenuItem>My Home</MenuItem>
</NavigatorLink>

We should have to nest a component under <NavigatorLink />. Instead, it should be this:

<NavigatorLink as={MenuItem} to="Home">
    My Home
</NavigatorLink>

However, this appears to be a limitation with React Router (for the time being)

Animations

Right now, it’s being handled by react-transition-group. I’d like to refactor this in favour of components from the Animation system (@wp-g2/animations). It uses Framer Motion under the hood, which is VERY capable in seamlessly handling stateful mount/unmount transitions.

This will also give us core-level reducedMotion support for free ✌️

MenuItem

The example navigation uses another component for it’s item UI, MenuItem. MenuItem is based on List from Material UI:

https://material-ui.com/components/lists/

As such, it should be enhanced to enable (left aligned) Icon rendering, as well as other features that List offers - such as right aligned actions, a badge count, etc…

1reaction
sirrealcommented, Sep 17, 2021

I’d leave a strong vote for using a library and against implementing something when an OSS library (with a compatible license) already has the features we want.

The react / @wordpress/element situation is very painful at times, but I don’t think this is likely to be so relevant. Perhaps https://github.com/WordPress/gutenberg/pull/24107 is the most appropriate place to discuss whether or not to just use react-router?

It seems to me that the only argument against using react-router was the fact that it’s context don’t nest well:

Using a Router (e.g. React Router) for the a nav menu means that it will not be compatible with 3rd party apps using the same Router. (Router context cannot be gracefully shared, as the libraries are built to assume 1 single router instance).

Can we explore that space? That seems like a surmountable problem if its the only argument against react-router.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get started with the Navigation component - Android Developers
Add destinations to the navigation graph · In the Navigation Editor, click the New Destination icon , and then click Create new destination....
Read more >
Access the navigation prop from any component
useNavigation is a hook which gives access to the navigation object. It's useful when you cannot pass the navigation prop into the component...
Read more >
Navigating Between Screens - React Native
This guide covers the various navigation components available in React Native. If you are getting started with navigation, you will probably ...
Read more >
React Native Navigation: Tutorial with examples
In this React Native Navigation tutorial, we'll show you some examples of navigation patterns you can implement with React Navigation.
Read more >
React Native Navigation. How to add component to bottom ...
I want to add a component (let's say "Autobus") to bottom stack navigator so it will receive " navigation " argument, and I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found