import React from 'react'; import {Renderer, RendererProps} from '../factory'; import {Api, SchemaNode, Schema, Action} from '../types'; import cx from 'classnames'; import TooltipWrapper from '../components/TooltipWrapper'; import {filter} from '../utils/tpl'; import {themeable} from '../theme'; import {hasIcon, Icon} from '../components/icons'; import {BaseSchema, SchemaClassName, SchemaIcon, SchemaTpl} from '../Schema'; /** * 提示渲染器,默认会显示个小图标,鼠标放上来的时候显示配置的内容。 */ export interface RemarkSchema extends BaseSchema { /** * 指定为提示类型 */ type: 'remark'; label?: string; icon?: SchemaIcon; tooltipClassName?: SchemaClassName; /** * 触发规则 */ trigger?: Array<'click' | 'hover' | 'focus'>; /** * 提示标题 */ title?: string; /** * 提示内容 */ content: SchemaTpl; /** * 显示位置 */ placement?: 'top' | 'right' | 'bottom' | 'left'; /** * 点击其他内容时是否关闭弹框信息 */ rootClose?: boolean; } export type SchemaRemark = string | Omit; export function filterContents( tooltip: | string | undefined | {title?: string; render?: any; content?: string; body?: string}, data: any ) { if (typeof tooltip === 'string') { return filter(tooltip, data); } else if (tooltip) { return tooltip.title ? { render: tooltip.render ? () => tooltip.render(data) : undefined, title: filter(tooltip.title, data), content: tooltip.content || tooltip.body ? filter(tooltip.content || tooltip.body || '', data) : undefined } : tooltip.content || tooltip.body ? filter(tooltip.content || tooltip.body || '', data) : undefined; } return tooltip; } export interface RemarkProps extends RendererProps, Omit { icon: string; trigger: Array<'hover' | 'click' | 'focus'>; } class Remark extends React.Component { static propsList: Array = []; static defaultProps = { icon: '', trigger: ['hover', 'focus'] as Array<'hover' | 'click' | 'focus'> }; render() { const { className, icon, label, tooltip, placement, rootClose, trigger, container, classPrefix: ns, classnames: cx, content, data, env, tooltipClassName } = this.props; const finalIcon = tooltip?.icon ?? icon; const finalLabel = tooltip?.label ?? label; return (
{finalLabel ? {finalLabel} : null} {finalIcon ? ( hasIcon(finalIcon) ? ( ) : ( ) ) : finalIcon === false && finalLabel ? null : ( )}
); } } export default themeable(Remark); @Renderer({ type: 'remark', name: 'remark' }) export class RemarkRenderer extends Remark {}