general-assistant
Version:
General Assistant components
35 lines (34 loc) • 2.51 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { robotName as zh_robotName, userName as zh_userName } from '../i18n/zh-cn.json';
import { robotName as en_robotName, userName as en_userName } from '../i18n/en-us.json';
import { useTranslation } from 'react-i18next';
import { useEffect, useState, useContext } from 'react';
import classNames from 'classnames';
import { useStore } from 'zustand';
import StoreContext from '../_store/StoreContext';
import Tooltip from '../Tooltips';
export default function IconRender({ Tem, def }) {
const { i18n: i18nContext } = useTranslation();
const dataStore = useContext(StoreContext);
const { GlobalCtxs } = useStore(dataStore, (state) => ({
GlobalCtxs: state.GlobalCtxs
}));
useEffect(() => {
if (name === zh_robotName || name === en_robotName) {
if (i18nContext.language === 'zh')
setMyName(zh_robotName);
if (i18nContext.language === 'en')
setMyName(en_robotName);
}
if (name === zh_userName || name === en_userName) {
if (i18nContext.language === 'zh')
setMyName(zh_userName);
if (i18nContext.language === 'en')
setMyName(en_userName);
}
}, [i18nContext.language]);
const { Render, onClick, name, title, className, posi = 'left' } = Tem;
const isCustom = typeof Render === 'function' ? '01' : typeof Render === 'boolean' && Render && def ? '02' : '03';
const [myName, setMyName] = useState(name);
return (_jsxs(_Fragment, { children: [isCustom === '01' && GlobalCtxs && _jsx(Render, { ctx: GlobalCtxs, onClick: onClick }), isCustom === '02' && (_jsxs("div", { className: 'DS-GA-flex DS-GA-justify-center DS-GA-items-center DS-GA-flex-shrink-0 DS-GA-cursor-pointer', onClick: onClick, children: [_jsx(Tooltip, { title: title, place: posi, children: _jsx("div", { className: classNames('DS-GA-w-12 DS-GA-h-12 DS-GA-p-2', className, 'DS-GA-rounded-full DS-GA-flex DS-GA-justify-center DS-GA-items-center DS-GA-flex-shrink-0', 'DS-GA-transition DS-GA-ease-in-out DS-GA-delay-150 hover:DS-GA-shadow-lg'), children: typeof def === 'string' ? (def.startsWith('http') ? (_jsx("img", { src: def })) : (_jsx("i", { className: classNames('iconfont-assistant DS-GA-text-theme-shal-7', def) }))) : (def) }) }), name && _jsx("div", { className: 'DS-GA-max-w-36 o-text DS-GA-pl-2 DS-GA-text-text-deep-10', children: myName })] }))] }));
}