forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add hard-coded course tabs (openedx#6)
* feat: add hard-coded course tabs * fix: add key to course nav tabs * refactor: split NavTab from CourseTabsNavigation * refactor: alphabetize props
- Loading branch information
Showing
5 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import messages from './messages'; | ||
import NavTab from './NavTab'; | ||
|
||
function CourseTabsNavigation({ activeTabSlug, courseTabs, intl }) { | ||
const courseNavTabs = courseTabs.map(({ slug, ...courseTab }) => ( | ||
<NavTab | ||
isActive={slug === activeTabSlug} | ||
key={slug} | ||
{...courseTab} | ||
/> | ||
)); | ||
|
||
return ( | ||
<nav | ||
aria-label={intl.formatMessage(messages['learn.navigation.course.tabs.label'])} | ||
className="nav nav-underline-tabs" | ||
> | ||
{courseNavTabs} | ||
</nav> | ||
); | ||
} | ||
|
||
CourseTabsNavigation.propTypes = { | ||
activeTabSlug: PropTypes.string, | ||
courseTabs: PropTypes.arrayOf(PropTypes.shape({ | ||
title: PropTypes.string.isRequired, | ||
priority: PropTypes.number.isRequired, | ||
slug: PropTypes.string.isRequired, | ||
url: PropTypes.string.isRequired, | ||
})), | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
CourseTabsNavigation.defaultProps = { | ||
activeTabSlug: undefined, | ||
courseTabs: [ | ||
{ | ||
title: 'Course', | ||
slug: 'course', | ||
priority: 1, | ||
url: 'http://localhost:18000/courses/course-v1:edX+DemoX+Demo_Course/course/', | ||
}, | ||
|
||
{ | ||
title: 'Discussion', | ||
slug: 'discussion', | ||
priority: 2, | ||
url: 'http://localhost:18000/courses/course-v1:edX+DemoX+Demo_Course/discussion/forum/', | ||
}, | ||
{ | ||
title: 'Wiki', | ||
slug: 'wiki', | ||
priority: 3, | ||
url: 'http://localhost:18000/courses/course-v1:edX+DemoX+Demo_Course/course_wiki', | ||
}, | ||
{ | ||
title: 'Progress', | ||
slug: 'progress', | ||
priority: 4, | ||
url: 'http://localhost:18000/courses/course-v1:edX+DemoX+Demo_Course/progress', | ||
}, | ||
{ | ||
title: 'Instructor', | ||
slug: 'instructor', | ||
priority: 5, | ||
url: 'http://localhost:18000/courses/course-v1:edX+DemoX+Demo_Course/instructor', | ||
}, | ||
], | ||
}; | ||
|
||
export default injectIntl(CourseTabsNavigation); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
|
||
export default function NavTab(props) { | ||
const { | ||
isActive, url, title, ...attrs | ||
} = props; | ||
|
||
const className = classNames( | ||
'nav-item nav-link', | ||
{ active: isActive }, | ||
attrs.className, | ||
); | ||
|
||
return <a {...attrs} className={className} href={url}>{title}</a>; | ||
} | ||
|
||
NavTab.propTypes = { | ||
className: PropTypes.string, | ||
isActive: PropTypes.bool, | ||
title: PropTypes.string.isRequired, | ||
url: PropTypes.string.isRequired, | ||
}; | ||
|
||
NavTab.defaultProps = { | ||
className: undefined, | ||
isActive: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
'learn.navigation.course.tabs.label': { | ||
id: 'learn.navigation.course.tabs.label', | ||
defaultMessage: 'Course Material', | ||
description: 'The accessible label for course tabs navigation', | ||
}, | ||
}); | ||
|
||
export default messages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters