-
Notifications
You must be signed in to change notification settings - Fork 38
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
Conversation
@mnicole found an issue where certain paths get repeated, I'll fix that asap |
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'; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More on that:
storybookjs/storybook#993
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
components/molecules/Breadcrumb.jsx
Outdated
Breadcrumb.displayName = 'Breadcrumb'; | ||
|
||
Breadcrumb.propTypes = { | ||
LinkElt: PropTypes.oneOfType([PropTypes.element, PropTypes.func]).isRequired, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
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.
components/molecules/Breadcrumb.jsx
Outdated
const Breadcrumb = props => { | ||
const { | ||
config: { title, path, subpaths }, | ||
LinkElt, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to linkComponent
components/molecules/Breadcrumb.jsx
Outdated
@@ -0,0 +1,54 @@ | |||
import React, { Component } from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Component
is unused
components/molecules/Breadcrumb.jsx
Outdated
pathname, | ||
hideMenus, | ||
isLast, | ||
className = '' |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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>{' '} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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. |
components/molecules/Breadcrumb.jsx
Outdated
|
||
Breadcrumb.defaultProps = { | ||
className: '' | ||
}; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
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. |
@jscottsmith that's a good idea, but won't be possible to implement on this PR due to time constraints. |
I refactored the findTrail function a bit to better handle some cases where the root path may not be specified. |
Added an optional boolean prop (hideRoot) to hide the root element. |
There was a problem hiding this 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.
@@ -0,0 +1,136 @@ | |||
# Breadcrumbs | |||
|
|||
**NOTE**: The component will only render with a minimun width of **991px** |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
components/molecules/Breadcrumbs.jsx
Outdated
config={path} | ||
pathname={pathname} | ||
isLast={arr.length - 1 === index} | ||
isLast={arr.length - 1 === index} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this prop is duplicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
components/molecules/Breadcrumbs.jsx
Outdated
// Set initial data if necessary | ||
const initialData = config.path === '/' ? [initialBreadcrumb] : []; | ||
// Set index difference between breadcrumbs and path | ||
const pathToBreadcrumbsDiff = initialData.length ? 2 : 1; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@mnicole took me a while, but I think the issues with duplicate breadcrumbs are fixed now. I may be a little woozy tomorrow. |
There was a problem hiding this 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!
components/molecules/Breadcrumbs.jsx
Outdated
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; |
There was a problem hiding this comment.
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
6938083
to
7a14cd1
Compare
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)