1
1
import React from 'react' ;
2
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3
- import styles from './stylesheet.scss' ;
4
- import { classes } from '/common/util' ;
5
2
import { Link } from 'react-router-dom' ;
3
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
4
+ import faExclamationCircle from '@fortawesome/fontawesome-free-solid/faExclamationCircle' ;
5
+ import { classes } from '/common/util' ;
6
+ import { Ellipsis } from '/components' ;
7
+ import styles from './stylesheet.scss' ;
6
8
7
9
class Button extends React . Component {
10
+ constructor ( props ) {
11
+ super ( props ) ;
12
+
13
+ this . state = {
14
+ confirming : false ,
15
+ } ;
16
+ }
17
+
8
18
render ( ) {
9
- const { className, children, onClick, to, href, icon, reverse, selected, disabled, primary, active, ...rest } = this . props ;
19
+ let { className, children, to, href, onClick, icon, reverse, selected, disabled, primary, active, confirmNeeded, ...rest } = this . props ;
20
+ const { confirming } = this . state ;
21
+
22
+ if ( confirmNeeded ) {
23
+ if ( confirming ) {
24
+ className = classes ( styles . confirming , className ) ;
25
+ icon = faExclamationCircle ;
26
+ children = < Ellipsis key = "text" > Click to Confirm</ Ellipsis > ;
27
+ } else {
28
+ to = null ;
29
+ href = null ;
30
+ onClick = ( ) => {
31
+ this . setState ( { confirming : true } ) ;
32
+ window . setTimeout ( ( ) => {
33
+ this . setState ( { confirming : false } ) ;
34
+ } , 2000 ) ;
35
+ } ;
36
+ }
37
+ }
10
38
11
39
const iconOnly = ! children ;
12
40
const props = {
13
41
className : classes ( styles . button , reverse && styles . reverse , selected && styles . selected , disabled && styles . disabled , primary && styles . primary , active && styles . active , iconOnly && styles . icon_only , className ) ,
14
- onClick : disabled ? null : onClick ,
42
+ to : disabled ? null : to ,
15
43
href : disabled ? null : href ,
44
+ onClick : disabled ? null : onClick ,
16
45
children : [
17
46
icon && (
18
47
typeof icon === 'string' ?
@@ -26,13 +55,9 @@ class Button extends React.Component {
26
55
} ;
27
56
28
57
return to ? (
29
- < Link to = { to } { ...props } />
58
+ < Link { ...props } />
30
59
) : href ? (
31
- / ^ h t t p s ? : \/ \/ / i. test ( href ) ? (
32
- < a href = { href } rel = "noopener" target = "_blank" { ...props } />
33
- ) : (
34
- < a href = { href } { ...props } />
35
- )
60
+ < a rel = "noopener" target = "_blank" { ...props } />
36
61
) : (
37
62
< div { ...props } />
38
63
) ;
0 commit comments