ICE 气泡确认框
npm install @icedesign/balloon-confirm
气泡确认框
Balloon
组件。Balloon
组件,所以对于子元素是自定义React Component
的情况,需要主动传递onMouseEnter
、onMouseLeave
、onClick
事件。props
可参考Balloon
组件,其中triggerType
默认为click
。参数名 | 说明 | 必填 | 类型 | 默认值 | 备注 |
---|---|---|---|---|---|
className | 样式名 | 否 | string | - | |
title | 确认框描述 | 否 | string | - | |
confirmText | 确认按钮文本 | 否 | string | '确认' | |
cancelText | 取消按钮文本 | 否 | string | '取消' | |
onConfirm | 点击确认的回调 | 否 | function(e) | - | |
onCanel | 点击取消的回调 | 否 | function(e) | - | |
Icon | 自定义气泡图标 | 否 | ReactNode | <Icon type="warning" style={{ color: '#FFA003' }} /> |
使用BalloonConfirm生成一个简单的确认弹窗
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import BalloonConfirm from '@icedesign/balloon-confirm';
import { Button, Message } from '@alifd/next';
class App extends Component {
onConfirm = (e) => {
console.log('ok');
Message.success('click on ok')
}
onCancel = (e) => {
console.log('cancel');
Message.error('click on cancel')
}
render() {
return (
<BalloonConfirm
onConfirm={this.onConfirm}
onCancel={this.onCancel}
title="真的要删除吗亲"
>
<Button>删除</Button>
</BalloonConfirm>
);
}
}
class Test extends Component {
render() {
return (
<div {...this.props}>测试</div>
);
}
}
ReactDOM.render((
<App />
), mountNode);
当子元素为自定义组件时,主动传递上层事件
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import BalloonConfirm from '@icedesign/balloon-confirm';
import { Button, Message } from '@alifd/next';
class App extends Component {
onConfirm = (e) => {
console.log('ok');
Message.success('click on ok')
}
onCancel = (e) => {
console.log('cancel');
Message.error('click on cancel')
}
render() {
return (
<BalloonConfirm
onConfirm={this.onConfirm}
onCancel={this.onCancel}
title="真的要删除吗亲"
>
<DeleteText />
</BalloonConfirm>
);
}
}
class DeleteText extends Component {
render() {
return (
<span
{...this.props}
style={{
color: '#f00',
}}
>
删除
</span>
);
}
}
ReactDOM.render((
<App />
), mountNode);