A wrapper for the Confirm component. Allows showing the confirmation dialog
without mounting the Confirm component first. Can be used outside React.
A wrapper for the Confirm component. Allows showing the confirmation dialog
without mounting the Confirm component first. Can be used outside React.
<div id="confirm"></div>
button {
margin-right: 8px !important;
}
import {render} from 'react-dom';
import React from 'react';
import confirm from '@jetbrains/ring-ui/components/confirm-service/confirm-service';
import Button from '@jetbrains/ring-ui/components/button/button';
class ConfirmDemo extends React.Component {
componentDidMount() {
this.showConfirm();
}
showConfirm = () => {
return confirm({text: 'Do you really wish to proceed?'}).
then(() => console.info('Confirmed')).
catch(() => console.warn('Rejected'));
}
showWithAnotherText = () => {
return confirm({
text: 'There is another confirmation',
description: 'Confirmation description',
confirmLabel: 'OK',
rejectLabel: 'Cancel',
cancelIsDefault: true,
onBeforeConfirm: () => new Promise(resolve => setTimeout(resolve, 1000))
}).
then(() => console.info('Confirmed')).
catch(() => console.warn('Rejected'));
}
render() {
return (
<div>
<Button onClick={this.showConfirm}>Show confirm</Button>
<Button onClick={this.showWithAnotherText}>Show another message</Button>
</div>
);
}
}
render(<ConfirmDemo/>, document.getElementById('confirm'));