From 4fd651d21eca10139f524da102aa83cfd6355977 Mon Sep 17 00:00:00 2001 From: Leonid Tolli Date: Fri, 17 Jan 2020 17:48:21 +0200 Subject: [PATCH 1/2] feat: Add Breadcrumbs component --- src/Breadcrumbs.js | 75 ++++++++++++++++++++++++++++++++++++++++ test/BreadCrumbs.test.js | 36 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/Breadcrumbs.js create mode 100644 test/BreadCrumbs.test.js diff --git a/src/Breadcrumbs.js b/src/Breadcrumbs.js new file mode 100644 index 00000000..1dd210a6 --- /dev/null +++ b/src/Breadcrumbs.js @@ -0,0 +1,75 @@ +import React from 'react' +import { KeyboardArrowRight as ArrowRight } from '@material-ui/icons' +import Link from './link/Link' +import clsx from 'clsx' +import { Typography, Container } from '@material-ui/core' +import { makeStyles } from '@material-ui/core/styles' +import PropTypes from 'prop-types' + +export const styles = theme => ({ + breadcrumbs: { + backgroundColor: '#F4F2F1', + padding: '12px 0', + + '& a': { + color: theme.palette.text.primary, + textDecoration: 'none', + }, + }, + + separator: { + height: '12px', + position: 'relative', + top: '2px', + width: '16px', + }, + + current: { + fontWeight: 'bold', + color: theme.palette.text.primary, + }, +}) + +const useStyles = makeStyles(styles, 'RSFBreadcrumbs') + +export default function Breadcrumbs({ items, classes }) { + classes = useStyles({ classes }) + + return ( + + + {items && + items.map((item, i) => { + const arrow = i > 0 ? : null + const isLastItem = items.length - 1 === i + + if (item.href) { + return ( + + {arrow} + + {item.text} + + + ) + } else { + return ( + + {arrow} + {item.text} + + ) + } + })} +   + + + ) +} + +Breadcrumbs.propTypes = { + /** + * The items to display, each with url, text, and state. + */ + items: PropTypes.arrayOf(PropTypes.objectOf), +} diff --git a/test/BreadCrumbs.test.js b/test/BreadCrumbs.test.js new file mode 100644 index 00000000..d9fee1c8 --- /dev/null +++ b/test/BreadCrumbs.test.js @@ -0,0 +1,36 @@ +import React from 'react' +import { mount } from 'enzyme' +import Breadcrumbs from 'react-storefront/Breadcrumbs' +import { Typography, Container } from '@material-ui/core' + +describe('Breadcrumbs', () => { + let wrapper + + afterEach(() => { + wrapper.unmount() + }) + + it('should render empty span when no items provided', () => { + wrapper = mount() + + expect(wrapper.find(Container).children.length).toBe(1) + }) + + it('should apply bold style to last item', () => { + const items = [{ text: 'test1' }, { text: 'test2' }] + wrapper = mount() + + expect( + wrapper + .findWhere(item => item.type() === 'span' && item.text() === 'test2') + .prop('className'), + ).toContain('current') + }) + + it('should render items with href as a link', () => { + const items = [{ text: 'test1', href: '/test' }] + wrapper = mount() + + expect(wrapper.find('a').text()).toBe('test1') + }) +}) From c065dc1213f6fc58925da908651f3b7d4dc32747 Mon Sep 17 00:00:00 2001 From: Mark Brocato Date: Fri, 17 Jan 2020 18:15:01 +0200 Subject: [PATCH 2/2] bump to 7.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b8fa882e..0293e314 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-storefront", - "version": "7.0.0-alpha.8", + "version": "7.0.0", "description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.", "module": "./index.js", "license": "Apache-2.0",