1- /**
2- * @flow
3- * @file Footer list component
4- * @author Box
5- */
6-
71import * 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' ;
113import type { Collection , BoxItem } from '../../common/types/core' ;
12- import Button from '../../components/button' ;
4+ import Button , { ButtonType } from '../../components/button' ;
135import ButtonGroup from '../../components/button-group' ;
146import IconCheck from '../../icons/general/IconCheck' ;
157import IconClose from '../../icons/general/IconClose' ;
168import messages from '../common/messages' ;
17-
189import PrimaryButton from '../../components/primary-button' ;
1910import Tooltip from '../common/Tooltip' ;
2011import './Footer.scss' ;
2112
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+ }
4335
4436const Footer = ( {
4537 currentCollection,
4638 selectedCount,
4739 selectedItems,
4840 onSelectedClick,
4941 hasHitSelectionLimit,
50- intl,
5142 isSingleSelect,
5243 onCancel,
5344 onChoose,
@@ -56,15 +47,17 @@ const Footer = ({
5647 children,
5748 renderCustomActionButtons,
5849 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 ) ;
6254 const isChooseButtonDisabled = ! selectedCount ;
55+
6356 return (
6457 < footer className = "bcp-footer" >
6558 < div className = "bcp-footer-left" >
6659 { showSelectedButton && ! isSingleSelect && (
67- < Button className = "bcp-selected" onClick = { onSelectedClick } type = "button" >
60+ < Button className = "bcp-selected" onClick = { onSelectedClick } type = { ButtonType . BUTTON } >
6861 < FormattedMessage
6962 className = "bcp-selected-count"
7063 { ...messages . selected }
@@ -80,7 +73,6 @@ const Footer = ({
8073 </ div >
8174 < div className = "bcp-footer-right" >
8275 { children }
83-
8476 { renderCustomActionButtons ? (
8577 renderCustomActionButtons ( {
8678 currentFolderId : currentCollection . id ,
@@ -93,17 +85,17 @@ const Footer = ({
9385 ) : (
9486 < ButtonGroup className = "bcp-footer-actions" >
9587 < Tooltip text = { cancelButtonLabel || cancelMessage } >
96- < Button aria-label = { cancelMessage } onClick = { onCancel } type = "button" >
88+ < Button aria-label = { cancelMessage } onClick = { onCancel } type = { ButtonType . BUTTON } >
9789 < IconClose height = { 16 } width = { 16 } />
9890 </ Button >
9991 </ Tooltip >
10092 < Tooltip isDisabled = { isChooseButtonDisabled } text = { chooseButtonLabel || chooseMessage } >
10193 < PrimaryButton
10294 aria-label = { chooseMessage }
103- disabled = { isChooseButtonDisabled } // sets disabled attribute
104- isDisabled = { isChooseButtonDisabled } // used in Button component
95+ isDisabled = { isChooseButtonDisabled }
10596 onClick = { onChoose }
106- type = "button"
97+ type = { ButtonType . BUTTON }
98+ { ...{ disabled : isChooseButtonDisabled } } // sets disabled attribute for native HTML button
10799 >
108100 < IconCheck color = "#fff" height = { 16 } width = { 16 } />
109101 </ PrimaryButton >
@@ -115,4 +107,4 @@ const Footer = ({
115107 ) ;
116108} ;
117109
118- export default injectIntl ( Footer ) ;
110+ export default Footer ;
0 commit comments