1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/open-hand-choerodon-ui

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
index.tsx 3.7 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
HughHzWu Отправлено 4 лет назад 69fae6b
import React, { Component, MouseEventHandler, ReactNode } from 'react';
import Tooltip, { AbstractTooltipProps, RenderFunction } from '../tooltip';
import Icon from '../icon';
import Button from '../button';
import { ButtonType } from '../button/Button';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale-provider/default';
import { Size } from '../_util/enum';
import { getPrefixCls } from '../configure';
export interface PopconfirmProps extends AbstractTooltipProps {
title: ReactNode | RenderFunction;
onConfirm?: MouseEventHandler<any>;
onCancel?: MouseEventHandler<any>;
okText?: ReactNode;
okType?: ButtonType;
cancelText?: ReactNode;
}
export interface PopconfirmState {
visible?: boolean;
}
export interface PopconfirmLocale {
okText: string;
cancelText: string;
}
export default class Popconfirm extends Component<PopconfirmProps, PopconfirmState> {
static displayName = 'Popconfirm';
static defaultProps = {
transitionName: 'zoom-big',
placement: 'top',
trigger: 'click',
okType: 'primary',
};
private tooltip: any;
constructor(props: PopconfirmProps) {
super(props);
this.state = {
visible: props.visible,
};
}
componentWillReceiveProps(nextProps: PopconfirmProps) {
if ('visible' in nextProps) {
this.setState({ visible: nextProps.visible });
}
}
getPopupDomNode() {
return this.tooltip.getPopupDomNode();
}
onConfirm: MouseEventHandler<HTMLButtonElement> = e => {
this.setVisible(false);
const { onConfirm } = this.props;
if (onConfirm) {
onConfirm.call(this, e);
}
};
onCancel: MouseEventHandler<HTMLButtonElement> = e => {
this.setVisible(false);
const { onCancel } = this.props;
if (onCancel) {
onCancel.call(this, e);
}
};
onVisibleChange = (visible: boolean) => {
this.setVisible(visible);
};
setVisible(visible: boolean) {
const props = this.props;
if (!('visible' in props)) {
this.setState({ visible });
}
const { onVisibleChange } = props;
if (onVisibleChange) {
onVisibleChange(visible);
}
}
saveTooltip = (node: any) => {
this.tooltip = node;
};
renderOverlayWithLocale = (popconfirmLocale: PopconfirmLocale) => {
const { title, cancelText, okText, okType } = this.props;
const prefixCls = this.getPrefixCls();
return (
<div>
<div className={`${prefixCls}-inner-content`}>
<div className={`${prefixCls}-message`}>
<Icon type="warning" />
<div className={`${prefixCls}-message-title`}>{typeof title === 'function' ? title() : title}</div>
</div>
<div className={`${prefixCls}-buttons`}>
<Button onClick={this.onCancel} size={Size.small}>
{cancelText || popconfirmLocale.cancelText}
</Button>
<Button onClick={this.onConfirm} type={okType} size={Size.small}>
{okText || popconfirmLocale.okText}
</Button>
</div>
</div>
</div>
);
};
renderLocale = () => {
return (
<LocaleReceiver componentName="Popconfirm" defaultLocale={defaultLocale.Popconfirm}>
{this.renderOverlayWithLocale}
</LocaleReceiver>
);
};
getPrefixCls() {
const { prefixCls } = this.props;
return getPrefixCls('popover', prefixCls);
}
render() {
const { placement, ...restProps } = this.props;
const { visible } = this.state;
return (
<Tooltip
{...restProps}
prefixCls={this.getPrefixCls()}
placement={placement}
onVisibleChange={this.onVisibleChange}
visible={visible}
overlay={this.renderLocale}
ref={this.saveTooltip}
/>
);
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/open-hand-choerodon-ui.git
git@gitlife.ru:oschina-mirror/open-hand-choerodon-ui.git
oschina-mirror
open-hand-choerodon-ui
open-hand-choerodon-ui
1.5.0-beta.0