-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(breadcrumb): Add the breadcrumb widget (#2451)
* feat(breadcrumb): kick-off connectBreadcrumb * chore(dev): add breadcrumb into storybook * feat(connectBreadcrumb): remove view logic * feat(widgets): export breadcrumb widget * feat(widget): breadcrumb * feat(component): kick-off breadcrumb component * feat(Breadcrumb): WIP * feat(Breadcrumb): modified separator * feat(Breadcrumb): display breadcrumb (without any links) * feat(Breadcrumb): WIP * feat(Breadcrumb): add css classes * feat(Breadcrumb): working on styling * feat(Breadcrumb): modified onClick prop * feat(Breadcrumb): Add headerFooter + autoHideContainer * feat(Breadcrumb): documentation * feat(Breadcrumb): remove cssClass root * enable use as a standalone widget * add template to widget * add custom label story * first series of tests * add logic for the onclick on "Home" * add templates for home and separator * warn the user if there's already a Breadcrumb used with the same facet * add cssClasses * add lifecycle test * modify template so it re renders when rootProps are modified * modify css classes applied to the home label * change the separator in the theme * more tests for connectBreadcrumb * add documentation * add createUrl + some refactoring * add default selected item story * WIP * WIP - fixing response data for hierarchical values * add createUrl + rootPath * add default selected item story * WIP * chore(test): test on second value * feat(Breadcrumb): update API of the connector * fix(dep): use same casing for isEqual * chore(doc): fix misc. errors * chore(breadcrumb): add more docs and validation * various code improvements Review fixes. Fix #2299
- Loading branch information
1 parent
0c987c1
commit 11d78f0
Showing
15 changed files
with
1,209 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Template from '../Template.js'; | ||
import autoHideContainerHOC from '../../decorators/autoHideContainer.js'; | ||
|
||
const itemsPropType = PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
name: PropTypes.string, | ||
value: PropTypes.string, | ||
}) | ||
); | ||
|
||
class Breadcrumb extends PureComponent { | ||
static propTypes = { | ||
createURL: PropTypes.func, | ||
cssClasses: PropTypes.objectOf(PropTypes.string), | ||
items: itemsPropType, | ||
refine: PropTypes.func.isRequired, | ||
separator: PropTypes.oneOfType([PropTypes.string, PropTypes.element]), | ||
templateProps: PropTypes.object.isRequired, | ||
translate: PropTypes.func, | ||
}; | ||
|
||
render() { | ||
const { createURL, items, refine, cssClasses } = this.props; | ||
|
||
const breadcrumb = items.map((item, idx) => { | ||
const isLast = idx === items.length - 1; | ||
const label = isLast | ||
? <a className={`${cssClasses.disabledLabel} ${cssClasses.label}`}> | ||
{item.name} | ||
</a> | ||
: <a | ||
className={cssClasses.label} | ||
href={createURL(item.value)} | ||
onClick={e => { | ||
e.preventDefault(); | ||
refine(item.value); | ||
}} | ||
> | ||
{item.name} | ||
</a>; | ||
|
||
return [ | ||
<Template | ||
key={item.name + idx} | ||
rootProps={{ className: cssClasses.separator }} | ||
templateKey="separator" | ||
{...this.props.templateProps} | ||
/>, | ||
label, | ||
]; | ||
}); | ||
|
||
const homeClassNames = | ||
items.length > 0 | ||
? [cssClasses.home, cssClasses.label] | ||
: [cssClasses.disabledLabel, cssClasses.home, cssClasses.label]; | ||
|
||
const homeOnClickHandler = e => { | ||
e.preventDefault(); | ||
refine(null); | ||
}; | ||
|
||
const homeUrl = createURL(null); | ||
|
||
return ( | ||
<div className={cssClasses.root}> | ||
<a | ||
className={homeClassNames.join(' ')} | ||
href={homeUrl} | ||
onClick={homeOnClickHandler} | ||
> | ||
<Template templateKey="home" {...this.props.templateProps} /> | ||
</a> | ||
{breadcrumb} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default autoHideContainerHOC(Breadcrumb); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.