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