-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor for simpliar api, deprecate SitemapCrumbs, will be removed in v7 BREAKING CHANGE: deprecate SitemapCrumbs component
- Loading branch information
Showing
11 changed files
with
217 additions
and
162 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 |
---|---|---|
@@ -1,102 +1,19 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
/* eslint-disable react/no-array-index-key */ | ||
import React from 'react' | ||
import Proptypes from 'prop-types' | ||
import { Link } from 'gatsby' | ||
import AutoGenCrumb from './auto-gen-crumb' | ||
import ClickTrackingCrumb from './click-tracking-crumb' | ||
import useBreadcrumb from './useBreadcrumb' | ||
|
||
const Breadcrumb = ({ | ||
title, | ||
location, | ||
crumbLabel, | ||
crumbSeparator, | ||
crumbWrapperStyle, | ||
crumbActiveStyle, | ||
crumbStyle, | ||
...rest | ||
}) => { | ||
const { crumbs = [], useClassNames } = useBreadcrumb({ | ||
location, | ||
crumbLabel, | ||
crumbSeparator, | ||
crumbStyle, | ||
crumbActiveStyle, | ||
}) | ||
const Breadcrumb = props => { | ||
const { useAutoGen } = useBreadcrumb({}) | ||
|
||
return ( | ||
<div> | ||
<span className="breadcrumb__title">{title}</span> | ||
{crumbs.map((c, i) => { | ||
return ( | ||
<div | ||
className="breadcrumb" | ||
style={ | ||
useClassNames ? null : { display: 'inline', ...crumbWrapperStyle } | ||
} | ||
key={i} | ||
> | ||
<Link | ||
to={c.pathname || ''} | ||
style={ | ||
useClassNames | ||
? null | ||
: { | ||
textDecoration: 'none', | ||
fontSize: '16pt', | ||
color: '#e1e1e1', | ||
...c.crumbStyle, | ||
} | ||
} | ||
activeStyle={ | ||
useClassNames | ||
? null | ||
: { | ||
color: 'white', | ||
...crumbActiveStyle, | ||
} | ||
} | ||
state={{ | ||
crumbClicked: true, | ||
}} | ||
className="breadcrumb__link" | ||
activeClassName={ | ||
useClassNames ? 'breadcrumb__link__active' : null | ||
} | ||
{...rest} | ||
> | ||
{c.crumbLabel} | ||
</Link> | ||
<span | ||
className="breadcrumb__separator" | ||
style={ | ||
useClassNames ? null : { fontSize: '16pt', ...c.crumbStyle } | ||
} | ||
> | ||
{i === crumbs.length - 1 ? null : c.crumbSeparator} | ||
</span> | ||
</div> | ||
) | ||
})} | ||
</div> | ||
<> | ||
{useAutoGen && <AutoGenCrumb {...props} />} | ||
{!useAutoGen && <ClickTrackingCrumb {...props} />} | ||
</> | ||
) | ||
} | ||
|
||
Breadcrumb.defaultProps = { | ||
title: '', | ||
crumbSeparator: ' / ', | ||
crumbWrapperStyle: {}, | ||
crumbStyle: {}, | ||
crumbActiveStyle: {}, | ||
} | ||
|
||
Breadcrumb.propTypes = { | ||
location: Proptypes.shape().isRequired, | ||
crumbLabel: Proptypes.string.isRequired, | ||
title: Proptypes.string, | ||
crumbSeparator: Proptypes.string, | ||
crumbWrapperStyle: Proptypes.shape(), | ||
crumbActiveStyle: Proptypes.shape(), | ||
crumbStyle: Proptypes.shape(), | ||
} | ||
|
||
export default 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
Oops, something went wrong.