forked from folio-org/stripes-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutHeader.js
81 lines (69 loc) · 1.75 KB
/
LayoutHeader.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React from 'react';
import PropTypes from 'prop-types';
import Button from '../Button';
import Icon from '../Icon';
import css from './LayoutHeader.css';
const propTypes = {
actions: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
icon: PropTypes.string,
handler: PropTypes.func,
}),
),
level: PropTypes.number,
noActions: PropTypes.bool,
onDelete: PropTypes.func,
title: PropTypes.oneOfType([
PropTypes.string,
PropTypes.node,
]),
};
const defaultProps = {
level: 3,
};
const LayoutHeader = ({ title, level, actions, onDelete, noActions }) => {
const getHeader = () => React.createElement(`h${level}`, { style: { margin: 0 } }, title);
const renderActions = () => {
const renderedActions = [];
if (noActions) {
return [(<span key={`${title.toString()}-noAction`}> </span>)];
}
let actionList;
if (!actions) {
actionList = [
{ title: 'Delete',
icon: 'trashBin',
handler: onDelete },
];
} else {
actionList = actions;
}
actionList.forEach((a, i) => {
renderedActions.push(
<Button
key={`${a.name}-${i}`}
buttonStyle="link slim"
style={{ margin: 0, padding: 0 }}
onClick={a.handler}
>
<Icon icon={a.icon} width="24px" height="24px" /> <span className="sr-only">{a.name}</span>
</Button>,
);
});
return renderedActions;
};
return (
<div className={css.sectionHeader}>
<div>
{getHeader()}
</div>
<div className={css.sectionActions}>
{renderActions()}
</div>
</div>
);
};
LayoutHeader.propTypes = propTypes;
LayoutHeader.defaultProps = defaultProps;
export default LayoutHeader;