import React from 'react';
import {storiesOf} from '@storybook/react';
import {confirm, ConfirmRoot, ConfirmNode} from '../src';
import BaseModal from 'react-modal';
class Modal extends React.Component {
render() {
return
}
}
storiesOf('Confirm', module)
.addDecorator(story => {
BaseModal.setAppElement('#root')
return
{story()}
})
.add('basic', () => {
class Basic extends React.Component {
render() {
return (
{({active, text, actions}) => (
)}
)
}
handleClick() {
confirm(`You haven't finished your post yet. Do you want to leave without finishing?`)
.then(() => {
console.log('Proceed')
}, () => {
console.log('Dismissed')
})
}
}
return
})
.add('hooks', () => {
class Basic extends React.Component {
render() {
return (
{({active, text, actions}) => (
)}
)
}
}
class SomewhereDeepDownInTheVDOMTree extends React.Component {
state = {
confirming: false
}
render() {
return (
)
}
handleClick = () => {
this.setState({ confirming: true })
confirm(`You haven't finished your post yet. Do you want to leave without finishing?`)
.then(() => {
console.log('Proceed')
this.setState({ confirming: false })
}, () => {
console.log('Dismissed')
this.setState({ confirming: false })
})
}
}
return
})
.add('custom title and buttons', () => {
class CustomTitle extends React.Component {
render() {
return (
{({active, text, actions, options}) => (
{options.title || 'Confirmation'}
{text}
{options.buttons && options.buttons.map((button, i) =>
)}
)}
)
}
handleClick() {
confirm({
title: 'Leave page?',
text:`You haven't finished your post yet. Do you want to leave without finishing?`,
buttons: [{
text: 'Extra',
onClick: () => console.log('Hello, meet the extra button!')
}]
}).then(() => {
console.log('Proceed')
}, () => {
console.log('Dismissed')
})
}
}
return
})