UNPKG

@lobehub/ui

Version:

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

119 lines (118 loc) 6.34 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", "style", "preview", "isLoading", "maxHeight", "maxWidth", "minHeight", "minWidth", "actions", "className", "alwaysShowActions", "variant", "objectFit", "classNames", "styles", "onClick", "width", "height"]; 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 { Image as AntImage, Skeleton } from 'antd'; import { cva } from 'class-variance-authority'; import { memo, useMemo } from 'react'; import { Flexbox } from 'react-layout-kit'; import usePreview from "./components/usePreview"; import { FALLBACK, useStyles } from "./style"; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var Image = /*#__PURE__*/memo(function (_ref) { var ref = _ref.ref, style = _ref.style, preview = _ref.preview, isLoading = _ref.isLoading, _ref$maxHeight = _ref.maxHeight, maxHeight = _ref$maxHeight === void 0 ? '100%' : _ref$maxHeight, _ref$maxWidth = _ref.maxWidth, maxWidth = _ref$maxWidth === void 0 ? '100%' : _ref$maxWidth, minHeight = _ref.minHeight, minWidth = _ref.minWidth, actions = _ref.actions, className = _ref.className, alwaysShowActions = _ref.alwaysShowActions, _ref$variant = _ref.variant, variant = _ref$variant === void 0 ? 'filled' : _ref$variant, _ref$objectFit = _ref.objectFit, objectFit = _ref$objectFit === void 0 ? 'cover' : _ref$objectFit, classNames = _ref.classNames, customStyles = _ref.styles, onClick = _ref.onClick, width = _ref.width, height = _ref.height, rest = _objectWithoutProperties(_ref, _excluded); var _useStyles = useStyles({ alwaysShowActions: alwaysShowActions, maxHeight: maxHeight, maxWidth: maxWidth, minHeight: minHeight, minWidth: minWidth, objectFit: objectFit }), styles = _useStyles.styles, cx = _useStyles.cx, theme = _useStyles.theme; var mergePreivew = usePreview(preview); var variants = useMemo(function () { return cva(styles.root, { defaultVariants: { variant: 'filled' }, /* eslint-disable sort-keys-fix/sort-keys-fix */ variants: { variant: { filled: styles.filled, outlined: styles.outlined, borderless: styles.borderless } } /* eslint-enable sort-keys-fix/sort-keys-fix */ }); }, [styles]); if (isLoading) return /*#__PURE__*/_jsx("div", { onClick: onClick, children: /*#__PURE__*/_jsx(Skeleton.Avatar, { active: true, style: { borderRadius: theme.borderRadius, height: height, maxHeight: maxHeight, maxWidth: maxWidth, minHeight: minHeight, minWidth: minWidth, width: width } }) }); return /*#__PURE__*/_jsxs(Flexbox, { className: cx(variants({ variant: variant }), className), ref: ref, style: style, children: [actions && /*#__PURE__*/_jsx("div", { className: styles.actions, children: actions }), /*#__PURE__*/_jsx(AntImage, _objectSpread({ className: classNames === null || classNames === void 0 ? void 0 : classNames.image, fallback: FALLBACK, height: height, loading: 'lazy', onClick: onClick, preview: preview === false ? false : _objectSpread({ mask: false }, mergePreivew), style: _objectSpread({ height: 'auto', width: '100%' }, customStyles === null || customStyles === void 0 ? void 0 : customStyles.image), width: width, wrapperClassName: cx(styles.image, classNames === null || classNames === void 0 ? void 0 : classNames.wrapper), wrapperStyle: _objectSpread({ height: 'auto', width: '100%' }, customStyles === null || customStyles === void 0 ? void 0 : customStyles.wrapper) }, rest))] }); }); Image.displayName = 'Image'; export default Image;