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

Add animations to navigation component #24771

Merged
merged 9 commits into from
Aug 26, 2020

Conversation

joshuatf
Copy link
Contributor

@joshuatf joshuatf commented Aug 24, 2020

Fixes #24258

Description

  • Adds left and right sliding animations for navigation levels.
  • Refactors the item mapping to be significantly more performant.

Testing

  1. Make sure the navigation component items and children still work as expected.
  2. Make sure that navigation down in items or up (using the back button) results in the expected animation.
  3. Optionally, add more levels of depth in the story to see this continue working.

@psealock psealock added the [Feature] Navigation Component A navigational waterfall component for hierarchy of items. label Aug 24, 2020
@psealock psealock force-pushed the feature/navigation branch from 1c2111b to aa9d063 Compare August 25, 2020 04:04
@joshuatf
Copy link
Contributor Author

As a heads up, the animation here technically hides the level that is being animated out immediately and then slides in the new level, which is subtly different than sliding out the old level and sliding in the new level.

If we want to switch to the latter, we can do so but I think the best way to do this is iterate over all the levels.

/cc @jameskoster for your thoughts on this animation. (Don't worry too much about the other design as we'll be styling more within the wc nav repo.)

Copy link
Contributor

@psealock psealock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! I'm glad the in-house animation works well.

Just a question about memoization, otherwise this is good to go.

@@ -84,7 +84,7 @@ function Example() {

return (
<Navigation activeItemId={ active } data={ data } rootTitle="Home">
{ ( { level, levelItems, parentLevel, NavigationBackButton } ) => {
{ ( { level, parentLevel, NavigationBackButton } ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More simplification, nice!

@@ -35,7 +35,7 @@ const NavigationMenuItem = ( props ) => {

const handleClick = () => {
if ( children.length ) {
setActiveLevel( id );
setActiveLevelId( id );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

level.id === 'root'
? null
: items.find( ( item ) => item.id === level.parent );
const items = mapItems( data );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calculation happens on every render. How about adding useMemo here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! Added in e687266.

I think there are some further optimizations that we could tackle here so a full update doesn't occur whenever the activeItemId is changed, but may need to handle in a follow-up.

@psealock
Copy link
Contributor

I made a mistake when trying to rebase the feature branch and deleted the changes from #24706. Those changes now are included in this PR.

Otherwise, its all looking good and ready to merge. The only issue is a failed check because npm install produces a package-lock.json.

There are local uncommitted changes after one or both of 'npm install' or 'npm run docs:build'!

@psealock psealock merged commit b5508b4 into WordPress:feature/navigation Aug 26, 2020
psealock added a commit that referenced this pull request Aug 31, 2020
* Navigation Component: Remove setActiveLevel child function arg (#24704)

* remove setActiveLevel from public api

* change to NavigationBackButton

* return null for backButton if no parentLevel

* Navigation Component: Expose __experimentalNavigation component (#24706)

* Expose __experimentalNavigation component

* fix typo

* expose menut and menu-item as well

* Loop over navigation levels and wrap with animate

* Use map and set to organize items and levels

* Simplify level and item logic

* Remove unnecessary key prop

* Fix parent level assignment

* Add back in key prop to force animation

* Use useMemo to map item data

Co-authored-by: Paul Sealock <psealock@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Navigation Component A navigational waterfall component for hierarchy of items.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants