UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

113 lines 6.1 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 React, { useEffect } from 'react'; import { classNames } from '../_common/defaultImports'; import { needleWarningMessage } from '../_common/utils'; import { Button } from '../button'; import { IconButton } from '../icon-button'; import { CheckCircleIconSolid, ExclamationCircleIconSolid, ExclamationTriangleIconSolid, InformationCircleIconSolid, XMarkIconOutline, } from '../icons'; import { Typography } from '../typography'; /** * * * Helpers * * */ const StatusIcon = ({ type }) => { if (type === 'neutral') { return null; } const iconComponent = (() => { switch (type) { case 'success': return _jsx(CheckCircleIconSolid, {}); case 'warning': return _jsx(ExclamationTriangleIconSolid, {}); case 'danger': return _jsx(ExclamationCircleIconSolid, {}); case 'info': return _jsx(InformationCircleIconSolid, {}); default: return null; } })(); return (_jsx("div", { className: "ndl-banner-icon ndl-banner-status-icon", children: iconComponent })); }; const BannerActions = React.forwardRef(function BannerActions(_a, ref) { var { label, disabled, fill = 'text', as, htmlAttributes, style, className } = _a, restProps = __rest(_a, ["label", "disabled", "fill", "as", "htmlAttributes", "style", "className"]); // If statement used because typescript doesn't like the combination of the as and fill properties if (fill === 'text') { return (_jsx(Button, Object.assign({}, restProps, { fill: "text", isDisabled: disabled, size: "small", as: as || 'a', ref: ref, style: style, className: className, htmlAttributes: htmlAttributes, children: label }))); } else { return (_jsx(Button, Object.assign({}, restProps, { fill: "outlined", isDisabled: disabled, size: "small", as: as || 'a', ref: ref, style: style, className: className, htmlAttributes: htmlAttributes, children: label }))); } }); const Banner = React.forwardRef(function Banner({ as, type = 'info', hasIcon = false, title, name, actions = [], description = null, onClose, className = '', children = null, isCloseable = false, usage = 'inline', htmlAttributes, // TODO v4: Change default to false for isAlert isAlert = true, }, ref) { const Element = as || 'div'; useEffect(() => { if (typeof title !== 'string' && !name && isCloseable) { needleWarningMessage('Banner Component expected `name` prop when title is not a string: https://dequeuniversity.com/rules/axe/4.2/aria-dialog-name?application=axeAPI'); } }, [title, name, isCloseable]); if (typeof title === 'string' && !name) { name = title; } const classes = classNames('ndl-banner', { 'ndl-with-description': description, 'ndl-with-title': title, 'ndl-neutral': type === 'neutral', 'ndl-info': type === 'info', 'ndl-success': type === 'success', 'ndl-warning': type === 'warning', 'ndl-danger': type === 'danger', 'ndl-global': usage === 'global', 'ndl-inline': usage === 'inline', 'ndl-full-width': usage === 'full-width', [className]: className && className !== '', }); const handleClose = (e) => { if (onClose && typeof onClose === 'function') { onClose(e); } }; return (_jsxs(Element, Object.assign({ className: classes, role: isAlert ? (isCloseable ? 'alertdialog' : 'alert') : undefined, title: name, ref: ref }, htmlAttributes, { children: [hasIcon && _jsx(StatusIcon, { type: type }), _jsxs("div", { className: "ndl-banner-content", children: [_jsxs("div", { className: "ndl-banner-title-description", children: [title && (_jsx(Typography, { variant: "h6", as: "span", className: "ndl-banner-title", children: title })), (description || children) && (_jsx(Typography, { variant: "body-medium", as: "div", className: "ndl-banner-description", children: children || description }))] }), actions && actions.length > 0 && (_jsx("div", { className: "ndl-banner-actions", children: actions.map((action, index) => (_jsx(BannerActions, Object.assign({}, action), index))) }))] }), isCloseable && (_jsx(IconButton, { isClean: true, size: "small", onKeyDown: handleClose, onClick: handleClose, ariaLabel: "close banner", className: "ndl-banner-icon ndl-close-icon", children: _jsx(XMarkIconOutline, {}) }))] }))); }); // Issue with TypeScript forwardRef and subcomponents: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34757#issuecomment-894053907 const BannerNamespace = Object.assign(Banner, { Actions: BannerActions }); BannerNamespace.displayName = 'Banner'; export { BannerNamespace as Banner }; //# sourceMappingURL=Banner.js.map