UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

87 lines 5.51 kB
"use strict"; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Breadcrumbs = exports.useBreadcrumbsItemContext = void 0; const jsx_runtime_1 = require("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/>. */ const icons_1 = require("@neo4j-ndl/react/icons"); const classnames_1 = __importDefault(require("classnames")); const react_1 = require("react"); const BreadcrumbsComponent = (0, react_1.forwardRef)(function BreadcrumbsComponent({ children, className, htmlAttributes, style }, ref) { const classes = (0, classnames_1.default)('ndl-breadcrumbs', className); return ((0, jsx_runtime_1.jsx)("nav", Object.assign({ "aria-label": "Breadcrumb", ref: ref, className: classes, style: style }, htmlAttributes, { children: (0, jsx_runtime_1.jsx)("ol", { className: "ndl-breadcrumbs-list", children: children }) }))); }); const BreadcrumbsItemContext = (0, react_1.createContext)(null); const useBreadcrumbsItemContext = () => { const context = (0, react_1.useContext)(BreadcrumbsItemContext); if (!context) { throw new Error('This component must be used within a <Breadcrumbs.Item>'); } return context; }; exports.useBreadcrumbsItemContext = useBreadcrumbsItemContext; const BreadcrumbsItem = (0, react_1.forwardRef)(function BreadcrumbsItem({ children, className, style, htmlAttributes }, ref) { const classes = (0, classnames_1.default)('ndl-breadcrumbs-item', className); return ((0, jsx_runtime_1.jsx)(BreadcrumbsItemContext.Provider, { value: { isInBreadcrumbsItem: true }, children: (0, jsx_runtime_1.jsx)("li", Object.assign({ ref: ref, className: classes, style: style }, htmlAttributes, { children: (0, jsx_runtime_1.jsx)("div", { className: "ndl-breadcrumbs-item-inner", children: children }) })) })); }); const BreadcrumbsButton = (0, react_1.forwardRef)(function BreadcrumbsButton(_a, ref) { var { children, as, className, style, htmlAttributes } = _a, restProps = __rest(_a, ["children", "as", "className", "style", "htmlAttributes"]); (0, exports.useBreadcrumbsItemContext)(); const Component = as !== null && as !== void 0 ? as : 'button'; const classes = (0, classnames_1.default)('ndl-breadcrumbs-button ndl-breadcrumbs-sibling-hover', className); return ((0, jsx_runtime_1.jsx)(Component, Object.assign({ ref: ref, className: classes, style: style }, restProps, htmlAttributes, { children: children }))); }); const BreadcrumbsSelectButton = (0, react_1.forwardRef)(function BreadcrumbsSelectButton({ onClick, children, className, style, htmlAttributes, ariaLabel, }, ref) { (0, exports.useBreadcrumbsItemContext)(); const classes = (0, classnames_1.default)('ndl-breadcrumbs-select', className); return ((0, jsx_runtime_1.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: [(0, jsx_runtime_1.jsx)(icons_1.ChevronDownIconOutline, {}), children] })); }); const BreadcrumbsLink = (0, react_1.forwardRef)(function BreadcrumbsLink(_a, ref) { var { children, as, className, style, htmlAttributes, ariaCurrent = false } = _a, restProps = __rest(_a, ["children", "as", "className", "style", "htmlAttributes", "ariaCurrent"]); (0, exports.useBreadcrumbsItemContext)(); const Component = as !== null && as !== void 0 ? as : 'a'; const classes = (0, classnames_1.default)('ndl-breadcrumbs-link', { 'ndl-breadcrumbs-link-current': Boolean(ariaCurrent), }, className); return ((0, jsx_runtime_1.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, }); exports.Breadcrumbs = Breadcrumbs; //# sourceMappingURL=Breadcrumbs.js.map