-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
TableBatchAction.tsx
69 lines (60 loc) · 1.7 KB
/
TableBatchAction.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
/**
* Copyright IBM Corp. 2016, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import PropTypes from 'prop-types';
import React from 'react';
import { AddFilled as iconAddSolid } from '@carbon/icons-react';
import Button from '../Button';
export interface TableBatchActionProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
/**
* Specify if the button is an icon-only button
*/
hasIconOnly?: boolean;
/**
* If specifying the `renderIcon` prop, provide a description for that icon that can
* be read by screen readers
*/
iconDescription?: string;
/**
* Optional function to render your own icon in the underlying button
*/
renderIcon?: React.ElementType;
}
const TableBatchAction = ({
renderIcon = iconAddSolid,
iconDescription = 'Add',
...props
}: TableBatchActionProps) => (
<Button
renderIcon={renderIcon}
iconDescription={iconDescription}
{...props}
/>
);
TableBatchAction.propTypes = {
/**
* Specify if the button is an icon-only button
*/
hasIconOnly: PropTypes.bool,
/**
* If specifying the `renderIcon` prop, provide a description for that icon that can
* be read by screen readers
*/
iconDescription: (props) => {
if (props.renderIcon && !props.children && !props.iconDescription) {
return new Error(
'renderIcon property specified without also providing an iconDescription property.'
);
}
return undefined;
},
/**
* Optional function to render your own icon in the underlying button
*/
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};
export default TableBatchAction;