UNPKG

@lobehub/ui

Version:

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

128 lines (127 loc) 7.31 kB
'use client'; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var _excluded = ["ref", "active", "avatar", "loading", "description", "date", "title", "onHoverChange", "actions", "className", "style", "showAction", "children", "classNames", "addon", "pin", "styles"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import { Loader2, MessageSquare } from 'lucide-react'; import { memo } from 'react'; import { Flexbox } from 'react-layout-kit'; import Icon from "../../Icon"; import Text from "../../Text"; import { useStyles } from "./style"; import { getChatItemTime } from "./time"; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; var ListItem = /*#__PURE__*/memo(function (_ref) { var ref = _ref.ref, active = _ref.active, avatar = _ref.avatar, loading = _ref.loading, description = _ref.description, date = _ref.date, title = _ref.title, onHoverChange = _ref.onHoverChange, actions = _ref.actions, className = _ref.className, style = _ref.style, showAction = _ref.showAction, children = _ref.children, classNames = _ref.classNames, addon = _ref.addon, pin = _ref.pin, customStyles = _ref.styles, rest = _objectWithoutProperties(_ref, _excluded); var _useStyles = useStyles(), styles = _useStyles.styles, cx = _useStyles.cx; var loadingNode = /*#__PURE__*/_jsx(Icon, { icon: Loader2, spin: true }); var pinNode = pin && /*#__PURE__*/_jsx("div", { className: cx(styles.pin, classNames === null || classNames === void 0 ? void 0 : classNames.pin), style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.pin, children: /*#__PURE__*/_jsx("div", { className: styles.triangle }) }); var actionsNode = actions && /*#__PURE__*/_jsx(Flexbox, { className: cx(styles.actions, classNames === null || classNames === void 0 ? void 0 : classNames.actions), gap: 4, horizontal: true, onClick: function onClick(e) { e.preventDefault(); e.stopPropagation(); }, style: _objectSpread({ display: showAction ? undefined : 'none' }, customStyles === null || customStyles === void 0 ? void 0 : customStyles.actions), children: actions }); var timeNode = date && /*#__PURE__*/_jsx("div", { className: cx(styles.date, classNames === null || classNames === void 0 ? void 0 : classNames.date), style: _objectSpread({ opacity: showAction ? 0 : undefined }, customStyles === null || customStyles === void 0 ? void 0 : customStyles.date), children: getChatItemTime(date) }); return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({ align: 'flex-start', className: cx(styles.root, active && styles.active, className), distribution: 'space-between', gap: 8, horizontal: true, onMouseEnter: function onMouseEnter() { onHoverChange === null || onHoverChange === void 0 || onHoverChange(true); }, onMouseLeave: function onMouseLeave() { onHoverChange === null || onHoverChange === void 0 || onHoverChange(false); }, padding: 12, ref: ref, style: style }, rest), {}, { children: [pinNode, /*#__PURE__*/_jsxs(Flexbox, { align: 'flex-start', className: classNames === null || classNames === void 0 ? void 0 : classNames.container, flex: 1, gap: 8, horizontal: true, style: _objectSpread({ overflow: 'hidden' }, customStyles === null || customStyles === void 0 ? void 0 : customStyles.container), children: [avatar !== null && avatar !== void 0 ? avatar : /*#__PURE__*/_jsx(Icon, { icon: MessageSquare, style: { marginTop: 4 } }), /*#__PURE__*/_jsxs(Flexbox, { className: cx(styles.content, classNames === null || classNames === void 0 ? void 0 : classNames.content), gap: 4, style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.content, children: [/*#__PURE__*/_jsx(Text, { as: 'h3', className: cx(styles.title, classNames === null || classNames === void 0 ? void 0 : classNames.title), ellipsis: true, style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.title, children: title }), description && /*#__PURE__*/_jsx(Text, { className: cx(styles.desc, classNames === null || classNames === void 0 ? void 0 : classNames.desc), ellipsis: true, style: customStyles === null || customStyles === void 0 ? void 0 : customStyles.desc, children: description }), addon] })] }), loading ? loadingNode : /*#__PURE__*/_jsxs(_Fragment, { children: [actionsNode, timeNode] }), children] })); }); ListItem.displayName = 'ListItem'; export default ListItem;