|
1 | 1 | import PropTypes from 'prop-types' |
2 | 2 |
|
| 3 | +import Slide from 'components/transitions/Slide' |
| 4 | + |
3 | 5 | export default function ConfirmationBar({ |
4 | 6 | message = 'Are you sure?', |
| 7 | + show, |
| 8 | + setShow, |
5 | 9 | onCancel, |
6 | 10 | onConfirm, |
| 11 | + hideOnCancel = true, |
| 12 | + hideOnConfirm = false, |
7 | 13 | }) { |
8 | 14 | return ( |
9 | | - <div className="notified"> |
10 | | - <div className="notification warning"> |
11 | | - <div className="message">{message}</div> |
12 | | - <div className="controls compact"> |
13 | | - <button |
14 | | - onClick={() => { |
15 | | - onConfirm() |
16 | | - }} |
17 | | - className="control square success" |
18 | | - > |
19 | | - <span className="icon"> |
20 | | - <i className="las la-check"></i> |
21 | | - </span> |
22 | | - </button> |
23 | | - <button |
24 | | - onClick={() => { |
25 | | - onCancel() |
26 | | - }} |
27 | | - className="control square danger" |
28 | | - > |
29 | | - <span className="icon"> |
30 | | - <i className="las la-times"></i> |
31 | | - </span> |
32 | | - </button> |
| 15 | + <Slide in={show}> |
| 16 | + <div className="confirmation-bar notified transition"> |
| 17 | + <div className="notification warning"> |
| 18 | + <div className="message">{message}</div> |
| 19 | + <div className="controls compact"> |
| 20 | + <button |
| 21 | + onClick={() => { |
| 22 | + if (hideOnConfirm) { |
| 23 | + setShow(false) |
| 24 | + } |
| 25 | + if (typeof onConfirm === 'function') { |
| 26 | + onConfirm() |
| 27 | + } |
| 28 | + }} |
| 29 | + className="control square success" |
| 30 | + > |
| 31 | + <span className="icon"> |
| 32 | + <i className="las la-check"></i> |
| 33 | + </span> |
| 34 | + </button> |
| 35 | + <button |
| 36 | + onClick={() => { |
| 37 | + if (hideOnCancel) { |
| 38 | + setShow(false) |
| 39 | + } |
| 40 | + if (typeof onCancel === 'function') { |
| 41 | + onCancel() |
| 42 | + } |
| 43 | + }} |
| 44 | + className="control square danger" |
| 45 | + > |
| 46 | + <span className="icon"> |
| 47 | + <i className="las la-times"></i> |
| 48 | + </span> |
| 49 | + </button> |
| 50 | + </div> |
33 | 51 | </div> |
34 | 52 | </div> |
35 | | - </div> |
| 53 | + </Slide> |
36 | 54 | ) |
37 | 55 | } |
38 | 56 |
|
39 | 57 | ConfirmationBar.propTypes = { |
40 | 58 | message: PropTypes.string, |
41 | | - onCancel: PropTypes.func.isRequired, |
42 | | - onConfirm: PropTypes.func.isRequired, |
| 59 | + show: PropTypes.bool, |
| 60 | + setShow: PropTypes.func.isRequired, |
| 61 | + onCancel: PropTypes.func, |
| 62 | + onConfirm: PropTypes.func, |
| 63 | + hideOnCancel: PropTypes.bool, |
| 64 | + hideOnConfirm: PropTypes.bool, |
43 | 65 | } |
0 commit comments