-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
row_expansion_button.tsx
44 lines (39 loc) · 1.14 KB
/
row_expansion_button.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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { EuiButtonIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useCallback } from 'react';
export const RowExpansionButton = <Item extends any>({
isExpanded,
item,
onCollapse,
onExpand,
}: {
isExpanded: boolean;
item: Item;
onCollapse: (item: Item) => void;
onExpand: (item: Item) => void;
}) => {
const handleClick = useCallback(() => (isExpanded ? onCollapse(item) : onExpand(item)), [
isExpanded,
item,
onCollapse,
onExpand,
]);
return (
<EuiButtonIcon
onClick={handleClick}
aria-label={isExpanded ? collapseAriaLabel : expandAriaLabel}
iconType={isExpanded ? 'arrowUp' : 'arrowDown'}
/>
);
};
const collapseAriaLabel = i18n.translate('xpack.infra.table.collapseRowLabel', {
defaultMessage: 'Collapse',
});
const expandAriaLabel = i18n.translate('xpack.infra.table.expandRowLabel', {
defaultMessage: 'Expand',
});