mirror of https://github.com/sgoudham/carbon.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
491 B
JavaScript
23 lines
491 B
JavaScript
5 years ago
|
import React from 'react'
|
||
|
import Button from './Button'
|
||
|
|
||
|
export default function ConfirmButton(props) {
|
||
|
const [confirmed, setConfirmed] = React.useState(false)
|
||
|
return (
|
||
|
<Button
|
||
|
{...props}
|
||
|
onClick={e => {
|
||
|
if (confirmed) {
|
||
|
props.onClick(e)
|
||
|
setConfirmed(false)
|
||
|
} else {
|
||
|
setConfirmed(true)
|
||
|
}
|
||
|
}}
|
||
|
onBlur={() => setConfirmed(false)}
|
||
|
>
|
||
|
{confirmed ? 'Are you sure?' : props.children}
|
||
|
</Button>
|
||
|
)
|
||
|
}
|