UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

80 lines 4.82 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * * Copyright (c) "Neo4j" * Neo4j Sweden AB [http://neo4j.com] * * This file is part of Neo4j. * * Neo4j is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import { ChevronDownIconOutline } from '@neo4j-ndl/react/icons'; import classNames from 'classnames'; import { createContext, forwardRef, useContext } from 'react'; const BreadcrumbsComponent = forwardRef(function BreadcrumbsComponent({ children, className, htmlAttributes, style }, ref) { const classes = classNames('ndl-breadcrumbs', className); return (_jsx("nav", Object.assign({ "aria-label": "breadcrumb", ref: ref, className: classes, style: style }, htmlAttributes, { children: _jsx("ol", { className: "ndl-breadcrumbs-list", children: children }) }))); }); const BreadcrumbsItemContext = createContext(null); export const useBreadcrumbsItemContext = () => { const context = useContext(BreadcrumbsItemContext); if (!context) { throw new Error('This component must be used within a <Breadcrumbs.Item>'); } return context; }; const BreadcrumbsItem = forwardRef(function BreadcrumbsItem({ children, className, style, htmlAttributes }, ref) { const classes = classNames('ndl-breadcrumbs-item', className); return (_jsx(BreadcrumbsItemContext.Provider, { value: { isInBreadcrumbsItem: true }, children: _jsx("li", Object.assign({ ref: ref, className: classes, style: style }, htmlAttributes, { children: _jsx("div", { className: "ndl-breadcrumbs-item-inner", children: children }) })) })); }); const BreadcrumbsButton = forwardRef(function BreadcrumbsButton(_a, ref) { var { children, as, className, style, htmlAttributes } = _a, restProps = __rest(_a, ["children", "as", "className", "style", "htmlAttributes"]); useBreadcrumbsItemContext(); const Component = as !== null && as !== void 0 ? as : 'button'; const classes = classNames('ndl-breadcrumbs-button ndl-breadcrumbs-sibling-hover', className); return (_jsx(Component, Object.assign({ ref: ref, className: classes, style: style }, restProps, htmlAttributes, { children: children }))); }); const BreadcrumbsSelectButton = forwardRef(function BreadcrumbsSelectButton({ onClick, children, className, style, htmlAttributes, ariaLabel, }, ref) { useBreadcrumbsItemContext(); const classes = classNames('ndl-breadcrumbs-select', className); return (_jsxs(BreadcrumbsButton, { ref: ref, as: "button", className: classes, style: style, onClick: onClick, htmlAttributes: Object.assign(Object.assign({}, htmlAttributes), { 'aria-label': ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : htmlAttributes === null || htmlAttributes === void 0 ? void 0 : htmlAttributes['aria-label'] }), children: [_jsx(ChevronDownIconOutline, {}), children] })); }); const BreadcrumbsLink = forwardRef(function BreadcrumbsLink(_a, ref) { var { children, as, className, style, htmlAttributes, ariaCurrent = false } = _a, restProps = __rest(_a, ["children", "as", "className", "style", "htmlAttributes", "ariaCurrent"]); useBreadcrumbsItemContext(); const Component = as !== null && as !== void 0 ? as : 'a'; const classes = classNames('ndl-breadcrumbs-link', { 'ndl-breadcrumbs-link-current': Boolean(ariaCurrent), }, className); return (_jsx(Component, Object.assign({ ref: ref, className: classes, style: style, "aria-current": ariaCurrent }, restProps, htmlAttributes, { children: children }))); }); const Breadcrumbs = Object.assign(BreadcrumbsComponent, { Button: BreadcrumbsButton, Item: BreadcrumbsItem, Link: BreadcrumbsLink, SelectButton: BreadcrumbsSelectButton, }); export { Breadcrumbs }; //# sourceMappingURL=Breadcrumbs.js.map