11import React from 'react' ;
2- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3- import styles from './stylesheet.scss' ;
4- import { classes } from '/common/util' ;
52import { 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' ;
68
79class Button extends React . Component {
10+ constructor ( props ) {
11+ super ( props ) ;
12+
13+ this . state = {
14+ confirming : false ,
15+ } ;
16+ }
17+
818 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+ }
1038
1139 const iconOnly = ! children ;
1240 const props = {
1341 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 ,
1543 href : disabled ? null : href ,
44+ onClick : disabled ? null : onClick ,
1645 children : [
1746 icon && (
1847 typeof icon === 'string' ?
@@ -26,13 +55,9 @@ class Button extends React.Component {
2655 } ;
2756
2857 return to ? (
29- < Link to = { to } { ...props } />
58+ < Link { ...props } />
3059 ) : 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 } />
3661 ) : (
3762 < div { ...props } />
3863 ) ;
0 commit comments