UNPKG

ndla-ui

Version:

UI component library for NDLA.

56 lines (51 loc) 1.34 kB
/** * Copyright (c) 2016-present, NDLA. * * This source code is licensed under the GPLv3 license found in the * LICENSE file in the root directory of this source tree. * */ import React from 'react'; import PropTypes from 'prop-types'; import BEMHelper from 'react-bem-helper'; import { uuid } from 'ndla-util'; import { Home } from 'ndla-icons/common'; import BreadcrumbItem from './BreadcrumbItem'; var classes = BEMHelper({ name: 'breadcrumb', prefix: 'c-' }); var Breadcrumb = function Breadcrumb(_ref) { var children = _ref.children, items = _ref.items; return React.createElement( 'div', classes(), children, React.createElement( 'ol', classes('list'), items.map(function (item, i) { return React.createElement( BreadcrumbItem, { classes: classes, home: i === 0, key: uuid(), isCurrent: i === items.length - 1, to: item.to, name: item.name }, i === 0 ? React.createElement(Home, { className: 'c-icon--20' }) : item.name ); }) ) ); }; Breadcrumb.propTypes = { children: PropTypes.node, items: PropTypes.arrayOf(PropTypes.shape({ to: PropTypes.string.isRequired, name: PropTypes.string.isRequired })) }; export default Breadcrumb;