UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

60 lines 2.29 kB
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, { useCallback } from 'react'; import { classNames } from '../_common/defaultImports'; import { needleWarningMessage } from '../_common/utils'; import { XMarkIconOutline } from '../icons'; /** * * * Helpers * * */ /** Add any helper functions here. */ /** * * * Tag Component * * */ export const Tag = React.forwardRef(function Tag(props, ref) { const { children, type = 'default', size = 'medium', isRemovable, onRemove, className, htmlAttributes, } = props; if (isRemovable && typeof onRemove !== 'function') { needleWarningMessage('Tag element is removable but onRemove prop is not a function or provided'); } const classes = classNames(`ndl-tag`, className, { 'ndl-destructive': type === 'destructive', 'ndl-removeable': isRemovable, 'ndl-small': size === 'small', 'ndl-medium': size === 'medium', 'ndl-large': size === 'large', }); const keyDownHandler = useCallback((e) => { if (e.key === 'Enter') { onRemove === null || onRemove === void 0 ? void 0 : onRemove(e); } }, [onRemove]); return (_jsxs("div", Object.assign({ className: classes, ref: ref }, htmlAttributes, { children: [children, isRemovable && (_jsx("button", { type: "button", className: "ndl-remove-icon", onKeyDown: keyDownHandler, onClick: onRemove, "aria-label": "Remove tag", children: _jsx(XMarkIconOutline, {}) }))] }))); }); //# sourceMappingURL=Tag.js.map