1
- /**
2
- * @flow
3
- * @file Footer list component
4
- * @author Box
5
- */
6
-
7
1
import * as React from 'react' ;
8
- import { injectIntl , FormattedMessage } from 'react-intl' ;
9
- import type { Node } from 'react' ;
10
-
2
+ import { FormattedMessage , useIntl } from 'react-intl' ;
11
3
import type { Collection , BoxItem } from '../../common/types/core' ;
12
- import Button from '../../components/button' ;
4
+ import Button , { ButtonType } from '../../components/button' ;
13
5
import ButtonGroup from '../../components/button-group' ;
14
6
import IconCheck from '../../icons/general/IconCheck' ;
15
7
import IconClose from '../../icons/general/IconClose' ;
16
8
import messages from '../common/messages' ;
17
-
18
9
import PrimaryButton from '../../components/primary-button' ;
19
10
import Tooltip from '../common/Tooltip' ;
20
11
import './Footer.scss' ;
21
12
22
- type Props = {
23
- cancelButtonLabel ?: string ,
24
- children ?: any ,
25
- chooseButtonLabel ?: string ,
26
- currentCollection : Collection ,
27
- hasHitSelectionLimit : boolean ,
28
- intl : any ,
29
- isSingleSelect : boolean ,
30
- onCancel : Function ,
31
- onChoose : Function ,
32
- onSelectedClick : Function ,
33
- renderCustomActionButtons ?: ( {
34
- onCancel : Function ,
35
- onChoose : Function ,
36
- selectedCount : number ,
37
- selectedItems : BoxItem [ ] ,
38
- } ) => Node ,
39
- selectedCount : number ,
40
- selectedItems : BoxItem [ ] ,
41
- showSelectedButton : boolean ,
42
- } ;
13
+ interface Props {
14
+ cancelButtonLabel ?: string ;
15
+ children ?: React . ReactNode ;
16
+ chooseButtonLabel ?: string ;
17
+ currentCollection : Collection ;
18
+ hasHitSelectionLimit : boolean ;
19
+ isSingleSelect : boolean ;
20
+ onCancel : ( ) => void ;
21
+ onChoose : ( ) => void ;
22
+ onSelectedClick : ( ) => void ;
23
+ renderCustomActionButtons ?: ( options : {
24
+ currentFolderId : string ;
25
+ currentFolderName : string ;
26
+ onCancel : ( ) => void ;
27
+ onChoose : ( ) => void ;
28
+ selectedCount : number ;
29
+ selectedItems : BoxItem [ ] ;
30
+ } ) => React . ReactNode ;
31
+ selectedCount : number ;
32
+ selectedItems : BoxItem [ ] ;
33
+ showSelectedButton : boolean ;
34
+ }
43
35
44
36
const Footer = ( {
45
37
currentCollection,
46
38
selectedCount,
47
39
selectedItems,
48
40
onSelectedClick,
49
41
hasHitSelectionLimit,
50
- intl,
51
42
isSingleSelect,
52
43
onCancel,
53
44
onChoose,
@@ -56,15 +47,17 @@ const Footer = ({
56
47
children,
57
48
renderCustomActionButtons,
58
49
showSelectedButton,
59
- } : Props ) => {
60
- const cancelMessage = intl . formatMessage ( messages . cancel ) ;
61
- const chooseMessage = intl . formatMessage ( messages . choose ) ;
50
+ } : Props ) : React . ReactElement => {
51
+ const { formatMessage } = useIntl ( ) ;
52
+ const cancelMessage = formatMessage ( messages . cancel ) ;
53
+ const chooseMessage = formatMessage ( messages . choose ) ;
62
54
const isChooseButtonDisabled = ! selectedCount ;
55
+
63
56
return (
64
57
< footer className = "bcp-footer" >
65
58
< div className = "bcp-footer-left" >
66
59
{ showSelectedButton && ! isSingleSelect && (
67
- < Button className = "bcp-selected" onClick = { onSelectedClick } type = "button" >
60
+ < Button className = "bcp-selected" onClick = { onSelectedClick } type = { ButtonType . BUTTON } >
68
61
< FormattedMessage
69
62
className = "bcp-selected-count"
70
63
{ ...messages . selected }
@@ -80,7 +73,6 @@ const Footer = ({
80
73
</ div >
81
74
< div className = "bcp-footer-right" >
82
75
{ children }
83
-
84
76
{ renderCustomActionButtons ? (
85
77
renderCustomActionButtons ( {
86
78
currentFolderId : currentCollection . id ,
@@ -93,17 +85,17 @@ const Footer = ({
93
85
) : (
94
86
< ButtonGroup className = "bcp-footer-actions" >
95
87
< Tooltip text = { cancelButtonLabel || cancelMessage } >
96
- < Button aria-label = { cancelMessage } onClick = { onCancel } type = "button" >
88
+ < Button aria-label = { cancelMessage } onClick = { onCancel } type = { ButtonType . BUTTON } >
97
89
< IconClose height = { 16 } width = { 16 } />
98
90
</ Button >
99
91
</ Tooltip >
100
92
< Tooltip isDisabled = { isChooseButtonDisabled } text = { chooseButtonLabel || chooseMessage } >
101
93
< PrimaryButton
102
94
aria-label = { chooseMessage }
103
- disabled = { isChooseButtonDisabled } // sets disabled attribute
104
- isDisabled = { isChooseButtonDisabled } // used in Button component
95
+ isDisabled = { isChooseButtonDisabled }
105
96
onClick = { onChoose }
106
- type = "button"
97
+ type = { ButtonType . BUTTON }
98
+ { ...{ disabled : isChooseButtonDisabled } } // sets disabled attribute for native HTML button
107
99
>
108
100
< IconCheck color = "#fff" height = { 16 } width = { 16 } />
109
101
</ PrimaryButton >
@@ -115,4 +107,4 @@ const Footer = ({
115
107
) ;
116
108
} ;
117
109
118
- export default injectIntl ( Footer ) ;
110
+ export default Footer ;
0 commit comments