Skip to content

Commit

Permalink
feat: add hard-coded course tabs (openedx#6)
Browse files Browse the repository at this point in the history
* feat: add hard-coded course tabs

* fix: add key to course nav tabs

* refactor: split NavTab from CourseTabsNavigation

* refactor: alphabetize props
  • Loading branch information
Adam Butterworth authored and davidjoy committed Jan 10, 2020
1 parent 1f79bea commit 0db7cab
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/components/CourseTabsNavigation.jsx
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);
30 changes: 30 additions & 0 deletions src/components/NavTab.jsx
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,
};
11 changes: 11 additions & 0 deletions src/components/messages.js
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;
4 changes: 4 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Header, { messages as headerMessages } from '@edx/frontend-component-head
import Footer, { messages as footerMessages } from '@edx/frontend-component-footer';

import appMessages from './i18n';
import CourseTabsNavigation from './components/CourseTabsNavigation';
import LearningSequencePage from './learning-sequence/LearningSequencePage';

import './index.scss';
Expand All @@ -19,6 +20,9 @@ subscribe(APP_READY, () => {
ReactDOM.render(
<AppProvider>
<Header />
<div className="container pt-2">
<CourseTabsNavigation activeTabSlug="course" />
</div>
<Switch>
{/* Staging: course-v1:UBCx+Water201x_2+2T2015 */}
<Route
Expand Down
15 changes: 15 additions & 0 deletions src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@
flex: 0;
}
}

.nav-underline-tabs {
.nav-link {
border-bottom: 4px solid transparent;
color: theme-color('gray', 700);

&:hover,
&:focus,
&.active {
font-weight: $font-weight-normal;
color: theme-color('primary', 500);
border-color: theme-color('primary', 500);
}
}
}

0 comments on commit 0db7cab

Please sign in to comment.