forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTitleButton.jsx
More file actions
100 lines (94 loc) · 2.65 KB
/
TitleButton.jsx
File metadata and controls
100 lines (94 loc) · 2.65 KB
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
import PropTypes from 'prop-types';
import { useIntl } from '@edx/frontend-platform/i18n';
import {
Button, Stack, Badge, Truncate,
} from '@openedx/paragon';
import {
ArrowDropDown as ArrowDownIcon,
ArrowRight as ArrowRightIcon,
} from '@openedx/paragon/icons';
import { getCombinedBadgeList } from '../utils';
import messages from './messages';
const TitleButton = ({
group, isExpanded, isExperiment, onTitleClick,
}) => {
const { formatMessage } = useIntl();
const { id, name, usage } = group;
return (
<Button
iconBefore={isExpanded ? ArrowDownIcon : ArrowRightIcon}
variant="tertiary"
className="configuration-card-header__button"
data-testid="configuration-card-header-button"
onClick={onTitleClick}
>
<div className="configuration-card-header__title">
<h3>
<Truncate.Deprecated lines={1}>{name}</Truncate.Deprecated>
</h3>
<span className="x-small text-gray-500">
{formatMessage(messages.titleId, { id })}
</span>
</div>
{!isExpanded && (
<Stack
gap={2.5}
direction="horizontal"
data-testid="configuration-card-header-button-usage"
>
{getCombinedBadgeList(usage, group, isExperiment, formatMessage).map(
(badge) => (
<Badge
key={badge}
className="configuration-card-header__badge"
data-testid="configuration-card-header__badge"
>
<span className="small">{badge}</span>
</Badge>
),
)}
</Stack>
)}
</Button>
);
};
TitleButton.defaultProps = {
isExperiment: false,
};
TitleButton.propTypes = {
group: PropTypes.shape({
id: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
usage: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string,
url: PropTypes.string,
}),
),
version: PropTypes.number.isRequired,
active: PropTypes.bool,
description: PropTypes.string,
groups: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number,
name: PropTypes.string,
usage: PropTypes.arrayOf(
PropTypes.shape({
label: PropTypes.string,
url: PropTypes.string,
}),
),
version: PropTypes.number,
}),
),
parameters: PropTypes.shape({
courseId: PropTypes.string,
}),
readOnly: PropTypes.bool,
scheme: PropTypes.string,
}).isRequired,
isExpanded: PropTypes.bool.isRequired,
isExperiment: PropTypes.bool,
onTitleClick: PropTypes.func.isRequired,
};
export default TitleButton;