forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitButton.jsx
More file actions
49 lines (42 loc) · 1.23 KB
/
UnitButton.jsx
File metadata and controls
49 lines (42 loc) · 1.23 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
import PropTypes from 'prop-types';
import { useSelector } from 'react-redux';
import { Button } from '@openedx/paragon';
import { Link } from 'react-router-dom';
import UnitIcon from './UnitIcon';
import { getCourseId, getSequenceId } from '../../data/selectors';
const UnitButton = ({
unitId,
className,
showTitle,
isActive, // passed from parent (SequenceNavigationTabs)
}) => {
const courseId = useSelector(getCourseId);
const sequenceId = useSelector(getSequenceId);
const unit = useSelector((state) => state.models.units[unitId]);
const { title, contentType } = unit || {};
return (
<Button
className={className}
variant={isActive ? 'primary' : 'outline-primary'}
as={Link}
title={title}
to={`/course/${courseId}/container/${unitId}/${sequenceId}/`}
data-testid="course-unit-btn"
>
<UnitIcon type={contentType} />
{showTitle && <span className="unit-title">{title}</span>}
</Button>
);
};
UnitButton.propTypes = {
className: PropTypes.string,
showTitle: PropTypes.bool,
unitId: PropTypes.string.isRequired,
isActive: PropTypes.bool,
};
UnitButton.defaultProps = {
className: undefined,
showTitle: false,
isActive: false,
};
export default UnitButton;