/
ActionableDetail.js
64 lines (58 loc) · 1.72 KB
/
ActionableDetail.js
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
import React from 'react';
import {
TextListItem,
TextListItemVariants,
Tooltip,
TooltipPosition,
} from '@patternfly/react-core';
import { OutlinedQuestionCircleIcon } from '@patternfly/react-icons';
import PropTypes from 'prop-types';
import EditableTextInput from './EditableTextInput';
import EditableSwitch from './EditableSwitch';
// To be used within a TextList
const ActionableDetail = ({
attribute, label, value, textArea, boolean, tooltip, onEdit,
}) => {
const displayProps = { attribute, value, onEdit };
return (
<React.Fragment key={label}>
<TextListItem component={TextListItemVariants.dt}>
{label}
{tooltip &&
<span className="foreman-spaced-icon">
<Tooltip
position={TooltipPosition.top}
content={tooltip}
>
<OutlinedQuestionCircleIcon />
</Tooltip>
</span>
}
</TextListItem>
<TextListItem component={TextListItemVariants.dd} className="foreman-spaced-list">
{boolean ?
<EditableSwitch {...displayProps} /> :
<EditableTextInput {...{ ...displayProps, textArea, onEdit }} />}
</TextListItem>
</React.Fragment>
);
};
ActionableDetail.propTypes = {
attribute: PropTypes.string.isRequired, // back-end name for API call
label: PropTypes.string.isRequired, // displayed label
value: PropTypes.oneOfType([ // displayed value
PropTypes.string,
PropTypes.bool,
]),
onEdit: PropTypes.func.isRequired,
textArea: PropTypes.bool,
boolean: PropTypes.bool,
tooltip: PropTypes.string,
};
ActionableDetail.defaultProps = {
textArea: false,
boolean: false,
tooltip: null,
value: null,
};
export default ActionableDetail;