@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
93 lines • 6.27 kB
JavaScript
"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 = (_a) => {
var { children, className, htmlAttributes, style, ref, shouldWrap = true } = _a, restProps = __rest(_a, ["children", "className", "htmlAttributes", "style", "ref", "shouldWrap"]);
const classes = (0, classnames_1.default)('ndl-breadcrumbs', className);
const listClasses = (0, classnames_1.default)('ndl-breadcrumbs-list', {
'ndl-breadcrumbs-wrap': shouldWrap,
});
return ((0, jsx_runtime_1.jsx)("nav", Object.assign({ "aria-label": "Breadcrumb", ref: ref, className: classes, style: style }, restProps, htmlAttributes, { children: (0, jsx_runtime_1.jsx)("ol", { className: listClasses, 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 = (_a) => {
var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["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, restProps, { children: (0, jsx_runtime_1.jsx)("div", { className: "ndl-breadcrumbs-item-inner", children: children }) })) }));
};
const BreadcrumbsButton = (_a) => {
var { children, as, className, style, htmlAttributes, ref, leadingElement, trailingElement } = _a, restProps = __rest(_a, ["children", "as", "className", "style", "htmlAttributes", "ref", "leadingElement", "trailingElement"]);
(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.jsxs)(Component, Object.assign({ ref: ref, className: classes, style: style }, htmlAttributes, restProps, { children: [Boolean(leadingElement) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-breadcrumbs-button-leading-element", children: leadingElement })), (0, jsx_runtime_1.jsx)("div", { className: "ndl-breadcrumbs-button-content", children: children }), Boolean(trailingElement) && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-breadcrumbs-button-trailing-element", children: trailingElement }))] })));
};
const BreadcrumbsSelectButton = (_a) => {
var { onClick, children, className, style, htmlAttributes, ariaLabel, ref } = _a, restProps = __rest(_a, ["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.jsx)(BreadcrumbsButton, Object.assign({ 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'] }), leadingElement: (0, jsx_runtime_1.jsx)(icons_1.ChevronDownIconOutline, {}) }, restProps, { children: children })));
};
const BreadcrumbsLink = (_a) => {
var { children, as, className, style, htmlAttributes, ariaCurrent = false, ref } = _a, restProps = __rest(_a, ["children", "as", "className", "style", "htmlAttributes", "ariaCurrent", "ref"]);
(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