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

Allow custom components to be rendered in EuiSideNav #310

Merged
merged 4 commits into from
Jan 19, 2018

Conversation

pugnascotia
Copy link
Contributor

In EuiSideNav, allow a component prop to be passed that will be used to render the individual items in the navigation. This makes interoperability with e.g. react-router easier. The current implementation is difficult to use in Cloud's UI. To make the implementation clean, I refactored the current link / button rendering into a component, and use it by default.

Other changes:

  • Fix test name typo in side_nav.test.js

@pugnascotia pugnascotia requested a review from cjcenizal January 17, 2018 10:42
Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Nice improvement Rory! I have one idea to pass by you.

</div>);

const component = render(
<EuiSideNav items={sideNav} component={MyNavButton} />
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm on the fence on this idea but I'd like to know what you think. Would it be better, worse, or neutral if we passed in a renderItem callback instead? From an interface standpoint, I think this is slightly better because then there's cohesion between the items prop and the renderItem prop. It wouldn't change anything structurally:

const renderItem = ({ href, className, children }) => (
  <div data-test-id="my-custom-element" href={href} className={className}>
    {children}
  </div>
);

const component = render(
  <EuiSideNav items={sideNav} renderItem={renderItem} />
);

Internally, the implementation would have to change somewhat. I don't think we'd want to set EuiSideNavButton as the default prop value any more, since the way that's consumed would be different than consuming the callback. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjcenizal I've pushed a change, let me know what you think.

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

🏹 Nice! LGTM!

@pugnascotia pugnascotia merged commit 538d941 into elastic:master Jan 19, 2018
@pugnascotia pugnascotia deleted the side-nav-custom-component branch January 19, 2018 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants