general-assistant
Version:
General Assistant components
28 lines (27 loc) • 1.95 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { uiCreateChat as zh_uiCreateChat } from '../i18n/zh-cn.json';
import { uiCreateChat as en_uiCreateChat } 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';
export default function BtnRender({ Tem, def }) {
const { i18n: i18nContext } = useTranslation();
const dataStore = useContext(StoreContext);
const { GlobalCtxs } = useStore(dataStore, (state) => ({
GlobalCtxs: state.GlobalCtxs
}));
useEffect(() => {
if (name === zh_uiCreateChat || name === en_uiCreateChat) {
if (i18nContext.language === 'zh')
setMyName(zh_uiCreateChat);
if (i18nContext.language === 'en')
setMyName(en_uiCreateChat);
}
}, [i18nContext.language]);
const { Render, onClick, name, className } = Tem;
const isCustom = typeof Render === 'function' ? '01' : typeof Render === 'boolean' && Render && def ? '02' : '03';
const [myName, setMyName] = useState(name);
return (_jsxs("div", { className: `DS-GA-h-10 ${className} DS-GA-rounded-3xl DS-GA-text-text-reverse-9 DS-GA-bg-theme-deep-9 hover:DS-GA-shadow-lg DS-GA-flex DS-GA-justify-center DS-GA-items-center DS-GA-cursor-pointer`, onClick: onClick, children: [isCustom === '01' && GlobalCtxs && _jsx(Render, { ctx: GlobalCtxs }), isCustom === '02' && (_jsxs(_Fragment, { children: [typeof def === 'string' ? (def.startsWith('http') ? (_jsx("img", { src: def, onClick: onClick })) : (_jsx("i", { className: classNames('iconfont-assistant DS-GA-text-text-reverse-10', def) }))) : (def), name && _jsx("div", { className: 'DS-GA-pl-3 DS-GA-text-base DS-GA-text-text-reverse-10', children: myName })] }))] }));
}