UNPKG

@primer/components

Version:
63 lines (58 loc) 2.69 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } import classnames from 'classnames'; // eslint-disable-next-line import/no-namespace import React from 'react'; import styled from 'styled-components'; import Box from './Box'; import { COMMON, FLEX, get } from './constants'; import sx from './sx'; const SELECTED_CLASS = 'selected'; const Wrapper = styled.li.withConfig({ displayName: "Breadcrumbs__Wrapper", componentId: "hwwoo0-0" })(["display:inline-block;white-space:nowrap;list-style:none;&::after{padding-right:0.5em;padding-left:0.5em;color:", ";font-size:", ";content:'/';}&:first-child{margin-left:0;}&:last-child{&::after{content:none;}}"], get('colors.fg.muted'), get('fontSizes.1')); const BreadcrumbsBase = styled.nav.withConfig({ displayName: "Breadcrumbs__BreadcrumbsBase", componentId: "hwwoo0-1" })(["display:flex;justify-content:space-between;", ";", ";", ";"], COMMON, FLEX, sx); function Breadcrumbs({ className, children, theme, ...rest }) { const wrappedChildren = React.Children.map(children, child => /*#__PURE__*/React.createElement(Wrapper, { theme: theme }, child)); return /*#__PURE__*/React.createElement(BreadcrumbsBase, _extends({ className: className, "aria-label": "Breadcrumbs", theme: theme }, rest), /*#__PURE__*/React.createElement(Box, { as: "ol", my: 0, pl: 0 }, wrappedChildren)); } Breadcrumbs.displayName = "Breadcrumbs"; const BreadcrumbsItem = styled.a.attrs(props => ({ activeClassName: typeof props.to === 'string' ? 'selected' : '', className: classnames(props.selected && SELECTED_CLASS, props.className), 'aria-current': props.selected ? 'page' : null })).withConfig({ displayName: "Breadcrumbs__BreadcrumbsItem", componentId: "hwwoo0-2" })(["color:", ";display:inline-block;font-size:", ";text-decoration:none;&:hover{text-decoration:underline;}&.selected{color:", ";pointer-events:none;}", " ", ";"], get('colors.accent.fg'), get('fontSizes.1'), get('colors.fg.default'), COMMON, sx); Breadcrumbs.displayName = 'Breadcrumbs'; BreadcrumbsItem.displayName = 'Breadcrumbs.Item'; export default Object.assign(Breadcrumbs, { Item: BreadcrumbsItem }); /** * @deprecated Use the `Breadcrumbs` component instead (i.e. `<Breadcrumb>` → `<Breadcrumbs>`) */ export const Breadcrumb = Object.assign(Breadcrumbs, { Item: BreadcrumbsItem }); /** * @deprecated Use the `BreadcrumbsProps` type instead */