UNPKG

@alilc/lowcode-plugin-components-pane

Version:
69 lines 2.21 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import React from 'react'; import cls from 'classnames/bind'; import Svg from '../../Icon/Component'; import style from './index.module.scss'; var cx = cls.bind(style); var Component = /*#__PURE__*/function (_React$Component) { _inheritsLoose(Component, _React$Component); Component.getDerivedStateFromProps = function getDerivedStateFromProps(props) { var _snippet$screenshot; var data = props.data; var icon = data.icon, _data$snippets = data.snippets, snippets = _data$snippets === void 0 ? [] : _data$snippets; var snippet = snippets[0]; var screenshot = (_snippet$screenshot = snippet === null || snippet === void 0 ? void 0 : snippet.screenshot) !== null && _snippet$screenshot !== void 0 ? _snippet$screenshot : icon; return { icon: screenshot, snippet: snippet }; }; function Component(props) { var _this; _this = _React$Component.call(this, props) || this; _this.state = { icon: '', snippet: null }; _this.t = void 0; _this.t = props.t; return _this; } var _proto = Component.prototype; _proto.renderIcon = function renderIcon() { var icon = this.state.icon; if (!icon) { return /*#__PURE__*/React.createElement(Svg, { className: cx('no-icon') }); } if (typeof icon === 'string') { return /*#__PURE__*/React.createElement("img", { src: icon, alt: "" }); } if (typeof icon === 'function') { var X = icon; return /*#__PURE__*/React.createElement(X, null); } return icon; }; _proto.render = function render() { var data = this.props.data; var title = data.title; var snippet = this.state.snippet; return /*#__PURE__*/React.createElement("div", { className: cls('snippet', cx('card')), "data-id": snippet.id, title: this.t(title) }, /*#__PURE__*/React.createElement("div", { className: cx('icon') }, this.renderIcon()), /*#__PURE__*/React.createElement("div", { className: cx('name') }, this.t(title))); }; return Component; }(React.Component); export { Component as default };