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 Breadcrumbs navigation component #9

Closed
wants to merge 1 commit into from

Conversation

edrpls
Copy link

@edrpls edrpls commented Apr 12, 2018

This PR will add the Breadcrumbs component, the prototype can be found here:

https://ds.gumgum.com/stable/

The component has optional submenus, please see the component's README for more details.

Make sure that the central panel in storybook has enough space (more than 991px) otherwise the component won't render (DS defaults)

@edrpls edrpls self-assigned this Apr 12, 2018
@edrpls edrpls added the new component Adding a new component to the library label Apr 12, 2018
@edrpls edrpls changed the base branch from master to develop April 12, 2018 00:57
@edrpls edrpls mentioned this pull request Apr 12, 2018
@edrpls edrpls removed the request for review from JMSantos94 April 12, 2018 01:13
@edrpls
Copy link
Author

edrpls commented Apr 12, 2018

#8

@edrpls
Copy link
Author

edrpls commented Apr 12, 2018

@mnicole found an issue where certain paths get repeated, I'll fix that asap

@edrpls
Copy link
Author

edrpls commented Apr 12, 2018

This is ready for review again.

@@ -0,0 +1,87 @@
import React, { Component } from 'react';
import { select, text, boolean } from '@storybook/addon-knobs';
import { action } from '@storybook/addon-actions';
Copy link
Contributor

Choose a reason for hiding this comment

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

action and text are unused imports

Copy link
Author

Choose a reason for hiding this comment

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

done

]
};

class BreadcrumbsStory extends Component {
Copy link
Contributor

@jscottsmith jscottsmith Apr 13, 2018

Choose a reason for hiding this comment

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

Can we improve this story somehow? I don't even see the breadcrumbs displaying in the storybook.

Oh, it's because of the screen size. Any way to make sure breadcrumbs display on smaller screens?

Copy link
Author

Choose a reason for hiding this comment

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

I spent like an hour yesterday trying to move the sidebar to give it more space, you'll have to make them smaller for now for it to show. (Are the notes about the width noticeable and clear enough?).

We'd have to switch either to Storybook v4 or change how we import the components.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I completely missed the note in the README. (ohdog). I think that should be fine for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

btw i still need to finish moving the readme to the center section so that will be more noticeable!

Copy link
Author

Choose a reason for hiding this comment

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

Btw, I made the notification larger on the readme

Breadcrumb.displayName = 'Breadcrumb';

Breadcrumb.propTypes = {
LinkElt: PropTypes.oneOfType([PropTypes.element, PropTypes.func]).isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, but I don't like this prop name ;). I think I prefer linkComponent or even just component. Or other options?

Copy link
Author

Choose a reason for hiding this comment

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

linkComponent sounds great, haha I didn't like it either but didn't have time to think about it.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, ya i think that's at least more clear. I was confused by the name at first.

const Breadcrumb = props => {
const {
config: { title, path, subpaths },
LinkElt,
Copy link
Contributor

Choose a reason for hiding this comment

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

also feels weird to have a capitalized prop. I'd prefer it renamed when destructured.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

| config | Object that defines the app routes. See below for details. | true |
| pathname | Current pathname either from react-router or window.location.pathname | true |
| hideMenus | Boolean attribute to prevent displaying subpath submenus | false |
| linkElt | Optional component to display as the breadcrumbs. Receives prop "to" as its href | false |
Copy link
Contributor

Choose a reason for hiding this comment

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

linkElt is actually LinkElt. Though I suggest changing it. See comment

Copy link
Author

Choose a reason for hiding this comment

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

It is only LinkElt on the Breadcrumb component, not on the main component. But I will apply the suggestion.

Copy link
Author

Choose a reason for hiding this comment

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

Updated to linkComponent

@@ -0,0 +1,54 @@
import React, { Component } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Component is unused

pathname,
hideMenus,
isLast,
className = ''
Copy link
Contributor

@jscottsmith jscottsmith Apr 13, 2018

Choose a reason for hiding this comment

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

need className in prop types. Also, I don't think it's necessary to provide the default value ''. I think classnames will exclude it if the value is undefined.

Copy link
Author

Choose a reason for hiding this comment

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

Added proptype and default

</li>
))}
</ul>
</div>{' '}
Copy link
Contributor

Choose a reason for hiding this comment

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

is this {' '} dingleberry intentional? if so, maybe we should wrap it in a <span> so it at least feels intentional.

Copy link
Author

Choose a reason for hiding this comment

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

it is intentional, It was added by prettier... maybe? Good idea, the span works just fine. I'll push it.

Copy link
Author

Choose a reason for hiding this comment

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

done

@edrpls
Copy link
Author

edrpls commented Apr 13, 2018

I'm going to make a quick change to make the config an array instead of an object, I think it makes more sense that way.


Breadcrumb.defaultProps = {
className: ''
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is necessary when using classnames/cx. undefined values should be omitted.

Copy link
Author

Choose a reason for hiding this comment

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

done

@jscottsmith
Copy link
Contributor

Not critical for merge, but a nice-to-have would be would be to make this more keyboard accessible. Specifically for breadcrumbs with sub categories. Currently focus can't trigger the pop-up menu. Seems that's the only limitation though. Might also be good to do an ARIA pass, though I don't expect it will need much since we're probably using semantic markup.

@edrpls
Copy link
Author

edrpls commented Apr 13, 2018

@jscottsmith that's a good idea, but won't be possible to implement on this PR due to time constraints.

@edrpls
Copy link
Author

edrpls commented Apr 13, 2018

I refactored the findTrail function a bit to better handle some cases where the root path may not be specified.

@edrpls
Copy link
Author

edrpls commented Apr 13, 2018

Added an optional boolean prop (hideRoot) to hide the root element.

Copy link
Contributor

@jscottsmith jscottsmith left a comment

Choose a reason for hiding this comment

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

No more comments from me. Would like to address some keyboard accessibility in the future.

:shipit:

@@ -0,0 +1,136 @@
# Breadcrumbs

**NOTE**: The component will only render with a minimun width of **991px**
Copy link
Collaborator

Choose a reason for hiding this comment

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

tiny detail but minimun -> minimum

Copy link
Author

Choose a reason for hiding this comment

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

fixed

config={path}
pathname={pathname}
isLast={arr.length - 1 === index}
isLast={arr.length - 1 === index}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this prop is duplicated

Copy link
Author

Choose a reason for hiding this comment

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

fixed

// Set initial data if necessary
const initialData = config.path === '/' ? [initialBreadcrumb] : [];
// Set index difference between breadcrumbs and path
const pathToBreadcrumbsDiff = initialData.length ? 2 : 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think the issue is here, it works with 1 : 0

Copy link
Author

Choose a reason for hiding this comment

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

I didn't see this before, I ended up changing some of the logic a bit but it should be fixed now.

@edrpls
Copy link
Author

edrpls commented Apr 13, 2018

@mnicole took me a while, but I think the issues with duplicate breadcrumbs are fixed now. I may be a little woozy tomorrow.

Copy link
Collaborator

@mnicole mnicole left a comment

Choose a reason for hiding this comment

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

everything looks good now!

const initialSections = duplicateRoot ? parts.slice(1) : parts;
const maxLength = duplicateRoot ? initialSections.length + 1 : initialSections.length;
// Set index difference between breadcrumbs and path
//const pathToBreadcrumbsDiff = 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this got left in here! you probably want to remove line 99 too.

Add Breadcrumbs children components

Add working breadcrumbs component

Handle parameters and react-router integration

Document breadcrumbs component

Allow optional titleDecorator prop

Add optional prop to hide root breadcrumb
@edrpls edrpls force-pushed the feature/8-breadcrumbs-nav-component branch from 6938083 to 7a14cd1 Compare April 13, 2018 16:15
@edrpls edrpls closed this Apr 13, 2018
@edrpls edrpls deleted the feature/8-breadcrumbs-nav-component branch April 13, 2018 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new component Adding a new component to the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants