UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

79 lines (78 loc) 4.67 kB
'use client'; var _templateObject, _templateObject2, _templateObject3; function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } import { Typography } from 'antd'; import { createStyles } from 'antd-style'; import { memo, useMemo } from 'react'; import { Flexbox } from 'react-layout-kit'; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var useStyles = createStyles(function (_ref) { var css = _ref.css, token = _ref.token; return { container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n min-width: 160px;\n max-width: 160px;\n height: 100%;\n padding: 8px;\n\n font-size: 12px;\n color: initial;\n\n background: ", ";\n border-radius: 8px;\n\n &:hover {\n background: ", ";\n }\n "])), token.colorFillQuaternary, token.colorFillTertiary), title: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n overflow: hidden;\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n\n text-overflow: ellipsis;\n "]))), url: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: hidden;\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 1;\n\n text-overflow: ellipsis;\n "]))) }; }); var SearchResultCard = /*#__PURE__*/memo(function (_ref2) { var url = _ref2.url, title = _ref2.title, alt = _ref2.alt; var _useStyles = useStyles(), styles = _useStyles.styles; var _useMemo = useMemo(function () { try { var urlObj = new URL(url); var _domain = urlObj.hostname.replace('www.', ''); var hostForUrl = urlObj.host; var _displayTitle = title; if (title === url) { _displayTitle = hostForUrl + urlObj.pathname; } return [_displayTitle, _domain, hostForUrl]; } catch (_unused) { return [title, url, url]; } }, [url, title]), _useMemo2 = _slicedToArray(_useMemo, 3), displayTitle = _useMemo2[0], domain = _useMemo2[1], host = _useMemo2[2]; return /*#__PURE__*/_jsx("a", { href: url, rel: "noreferrer", target: '_blank', children: /*#__PURE__*/_jsxs(Flexbox, { className: styles.container, gap: 2, justify: 'space-between', children: [/*#__PURE__*/_jsx("div", { className: styles.title, children: displayTitle }), /*#__PURE__*/_jsxs(Flexbox, { align: 'center', gap: 4, horizontal: true, children: [/*#__PURE__*/_jsx("img", { alt: alt || title || url, height: 14, src: "https://icons.duckduckgo.com/ip3/".concat(host, ".ico"), width: 14 }), /*#__PURE__*/_jsx(Typography.Text, { className: styles.url, type: 'secondary', children: domain })] })] }, url) }); }); export default SearchResultCard;