@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
86 lines • 5.56 kB
JavaScript
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, useContext } from 'react';
const BreadcrumbsComponent = (_a) => {
var { children, className, htmlAttributes, style, ref, shouldWrap = true } = _a, restProps = __rest(_a, ["children", "className", "htmlAttributes", "style", "ref", "shouldWrap"]);
const classes = classNames('ndl-breadcrumbs', className);
const listClasses = classNames('ndl-breadcrumbs-list', {
'ndl-breadcrumbs-wrap': shouldWrap,
});
return (_jsx("nav", Object.assign({ "aria-label": "Breadcrumb", ref: ref, className: classes, style: style }, restProps, htmlAttributes, { children: _jsx("ol", { className: listClasses, 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 = (_a) => {
var { children, className, style, htmlAttributes, ref } = _a, restProps = __rest(_a, ["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, restProps, { children: _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"]);
useBreadcrumbsItemContext();
const Component = as !== null && as !== void 0 ? as : 'button';
const classes = classNames('ndl-breadcrumbs-button ndl-breadcrumbs-sibling-hover', className);
return (_jsxs(Component, Object.assign({ ref: ref, className: classes, style: style }, htmlAttributes, restProps, { children: [Boolean(leadingElement) && (_jsx("div", { className: "ndl-breadcrumbs-button-leading-element", children: leadingElement })), _jsx("div", { className: "ndl-breadcrumbs-button-content", children: children }), Boolean(trailingElement) && (_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"]);
useBreadcrumbsItemContext();
const classes = classNames('ndl-breadcrumbs-select', className);
return (_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: _jsx(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"]);
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