UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

139 lines 7.58 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Banner = 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 react_1 = __importStar(require("react")); const defaultImports_1 = require("../_common/defaultImports"); const utils_1 = require("../_common/utils"); const button_1 = require("../button"); const icon_button_1 = require("../icon-button"); const icons_1 = require("../icons"); const typography_1 = require("../typography"); /** * * * Helpers * * */ const StatusIcon = ({ type }) => { if (type === 'neutral') { return null; } const iconComponent = (() => { switch (type) { case 'success': return (0, jsx_runtime_1.jsx)(icons_1.CheckCircleIconSolid, {}); case 'warning': return (0, jsx_runtime_1.jsx)(icons_1.ExclamationTriangleIconSolid, {}); case 'danger': return (0, jsx_runtime_1.jsx)(icons_1.ExclamationCircleIconSolid, {}); case 'info': return (0, jsx_runtime_1.jsx)(icons_1.InformationCircleIconSolid, {}); default: return null; } })(); return ((0, jsx_runtime_1.jsx)("div", { className: "ndl-banner-icon ndl-banner-status-icon", children: iconComponent })); }; const BannerActions = react_1.default.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 ((0, jsx_runtime_1.jsx)(button_1.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 ((0, jsx_runtime_1.jsx)(button_1.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_1.default.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'; (0, react_1.useEffect)(() => { if (typeof title !== 'string' && !name && isCloseable) { (0, utils_1.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 = (0, defaultImports_1.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 ((0, jsx_runtime_1.jsxs)(Element, Object.assign({ className: classes, role: isAlert ? (isCloseable ? 'alertdialog' : 'alert') : undefined, title: name, ref: ref }, htmlAttributes, { children: [hasIcon && (0, jsx_runtime_1.jsx)(StatusIcon, { type: type }), (0, jsx_runtime_1.jsxs)("div", { className: "ndl-banner-content", children: [(0, jsx_runtime_1.jsxs)("div", { className: "ndl-banner-title-description", children: [title && ((0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: "h6", as: "span", className: "ndl-banner-title", children: title })), (description || children) && ((0, jsx_runtime_1.jsx)(typography_1.Typography, { variant: "body-medium", as: "div", className: "ndl-banner-description", children: children || description }))] }), actions && actions.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "ndl-banner-actions", children: actions.map((action, index) => ((0, jsx_runtime_1.jsx)(BannerActions, Object.assign({}, action), index))) }))] }), isCloseable && ((0, jsx_runtime_1.jsx)(icon_button_1.IconButton, { isClean: true, size: "small", onKeyDown: handleClose, onClick: handleClose, ariaLabel: "close banner", className: "ndl-banner-icon ndl-close-icon", children: (0, jsx_runtime_1.jsx)(icons_1.XMarkIconOutline, {}) }))] }))); }); // Issue with TypeScript forwardRef and subcomponents: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34757#issuecomment-894053907 const BannerNamespace = Object.assign(Banner, { Actions: BannerActions }); exports.Banner = BannerNamespace; BannerNamespace.displayName = 'Banner'; //# sourceMappingURL=Banner.js.map