UNPKG

@neo4j-ndl/react

Version:

React implementation of Neo4j Design System

46 lines 2.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClickableUrls = 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 = __importDefault(require("react")); // credits to https://www.regextester.com/96504, modified though const URL_REGEX = // eslint-disable-next-line /(?:https?|s?ftp|bolt):\/\/(?:(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))?\))+(?:\((?:[^\s()<>]+|(?:\(?:[^\s()<>]+\)))?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))?/gi; const ClickableUrlsComponent = ({ text }) => { var _a; const definedText = text !== null && text !== void 0 ? text : ''; const urls = (_a = definedText.match(URL_REGEX)) !== null && _a !== void 0 ? _a : []; return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: definedText.split(URL_REGEX).map((t, index) => { /* since we never move these components this key should be fine */ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [t, urls[index] && ( // Should be safe from XSS. // Ref: https://mathiasbynens.github.io/rel-noopener/ (0, jsx_runtime_1.jsx)("a", { href: urls[index], target: "_blank", rel: "noopener noreferrer", className: "hover:underline", children: urls[index] }))] }, `clickable-url-${index}`)); }) })); }; exports.ClickableUrls = react_1.default.memo(ClickableUrlsComponent); //# sourceMappingURL=clickable-urls.js.map