UNPKG

tntd

Version:

tntd是基于 TNT Design 设计体系的 React UI 组件库,主要用于研发企业级中后台产品。

73 lines (72 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _classnames = _interopRequireDefault(require("classnames")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } var __rest = void 0 && (void 0).__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var _default = exports["default"] = function _default(props) { var alt = props.alt, title = props.title, src = props.src, width = props.width, height = props.height, _props$style = props.style, style = _props$style === void 0 ? {} : _props$style, className = props.className, onError = props.onError, shape = props.shape, errorImgSrc = props.errorImgSrc, type = props.type, others = __rest(props, ["alt", "title", "src", "width", "height", "style", "className", "onError", "shape", "errorImgSrc", "type"]); var styles = Object.assign(Object.assign({}, style), { display: 'inline-block', width: width, height: height, overflow: 'hidden' }); if (shape === 'rounded') { styles.borderRadius = '5px'; } else if (shape === 'circle') { styles.borderRadius = '50%'; } var centerStyles = { width: width, height: height, display: 'table-cell', verticalAlign: 'middle', textAlign: 'center' }; var imgStyles = { width: 'auto', height: 'auto', maxWidth: width, maxHeight: height }; var cls = (0, _classnames["default"])('tntd-img', shape, className); return _react["default"].createElement("div", Object.assign({ className: cls, style: styles }, others), _react["default"].createElement("div", { style: centerStyles }, _react["default"].createElement("img", { style: imgStyles, onError: onError, src: src, alt: alt, title: title }))); };