Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7de6ba4381 | ||
|
|
14fe2d9bc6 | ||
|
|
78573e30f1 | ||
|
|
ae014d2f24 | ||
|
|
726aff9f8d | ||
|
|
bb7c5cb39f | ||
|
|
90df9feb87 | ||
|
|
a86cde04bd | ||
|
|
afc03b2253 | ||
|
|
01cee41441 | ||
|
|
307669cf9f | ||
|
|
265f3be635 | ||
|
|
7742de1609 | ||
|
|
1778b78f0a | ||
|
|
36ced5252f | ||
|
|
00ca9197d5 | ||
|
|
adf6f71c05 | ||
|
|
fee5d11aec | ||
|
|
5772de187f | ||
|
|
4c033a655a | ||
|
|
e75043dd2b | ||
|
|
97a15f5059 | ||
|
|
0b882173eb | ||
|
|
ebaa9ea32e | ||
|
|
07faa1290a | ||
|
|
61b68fdd80 | ||
|
|
2b244c71b9 | ||
|
|
490edabf11 | ||
|
|
b503643603 | ||
|
|
227c754c48 | ||
|
|
57e05c4d88 | ||
|
|
5d77fab8f3 | ||
|
|
2a8793d4ac |
33
.env
33
.env
@@ -1,33 +0,0 @@
|
|||||||
BASE_URL=localhost:1995
|
|
||||||
SITE_NAME=Open edX
|
|
||||||
LMS_BASE_URL=http://localhost:18000
|
|
||||||
CREDENTIALS_BASE_URL=http://localhost:18150
|
|
||||||
ECOMMERCE_BASE_URL=http://localhost:18130
|
|
||||||
LOGIN_URL=http://localhost:18000/login
|
|
||||||
LOGOUT_URL=http://localhost:18000/login
|
|
||||||
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
|
|
||||||
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
|
|
||||||
SEGMENT_KEY=ul
|
|
||||||
ACCESS_TOKEN_COOKIE_NAME=edx-jwt-cookie-header-payload
|
|
||||||
USER_INFO_COOKIE_NAME=edx-user-info
|
|
||||||
CSRF_COOKIE_NAME=csrftoken
|
|
||||||
LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference
|
|
||||||
SITE_NAME=edX
|
|
||||||
MARKETING_SITE_BASE_URL=http://localhost:18000
|
|
||||||
ENTERPRISE_MARKETING_URL=http://example.com
|
|
||||||
ENTERPRISE_MARKETING_UTM_CAMPAIGN=my_campaign
|
|
||||||
ENTERPRISE_MARKETING_UTM_SOURCE=edX profile
|
|
||||||
ENTERPRISE_MARKETING_FOOTER_UTM_MEDIUM=Footer
|
|
||||||
SUPPORT_URL=http://localhost:18000/support
|
|
||||||
CONTACT_URL=http://localhost:18000/contact
|
|
||||||
OPEN_SOURCE_URL=http://localhost:18000/openedx
|
|
||||||
TERMS_OF_SERVICE_URL=http://localhost:18000/terms-of-service
|
|
||||||
PRIVACY_POLICY_URL=http://localhost:18000/privacy-policy
|
|
||||||
FACEBOOK_URL=https://www.facebook.com
|
|
||||||
TWITTER_URL=https://twitter.com
|
|
||||||
YOU_TUBE_URL=https://www.youtube.com
|
|
||||||
LINKED_IN_URL=https://www.linkedin.com
|
|
||||||
REDDIT_URL=https://www.reddit.com
|
|
||||||
APPLE_APP_STORE_URL=https://www.apple.com/ios/app-store/
|
|
||||||
GOOGLE_PLAY_URL=https://play.google.com/store
|
|
||||||
ORDER_HISTORY_URL=localhost:1996/orders
|
|
||||||
19
.env.development
Normal file
19
.env.development
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
ACCESS_TOKEN_COOKIE_NAME=edx-jwt-cookie-header-payload
|
||||||
|
BASE_URL=localhost:8080
|
||||||
|
CREDENTIALS_BASE_URL=http://localhost:18150
|
||||||
|
CSRF_TOKEN_API_PATH=/csrf/api/v1/token
|
||||||
|
ECOMMERCE_BASE_URL=http://localhost:18130
|
||||||
|
LANGUAGE_PREFERENCE_COOKIE_NAME=openedx-language-preference
|
||||||
|
LMS_BASE_URL=http://localhost:18000
|
||||||
|
LOGIN_URL=http://localhost:18000/login
|
||||||
|
LOGOUT_URL=http://localhost:18000/login
|
||||||
|
MARKETING_SITE_BASE_URL=http://localhost:18000
|
||||||
|
ORDER_HISTORY_URL=localhost:1996/orders
|
||||||
|
REFRESH_ACCESS_TOKEN_ENDPOINT=http://localhost:18000/login_refresh
|
||||||
|
SEGMENT_KEY=null
|
||||||
|
SITE_NAME=Open edX
|
||||||
|
USER_INFO_COOKIE_NAME=edx-user-info
|
||||||
|
LOGO_URL=https://edx-cdn.org/v3/default/logo.svg
|
||||||
|
LOGO_TRADEMARK_URL=https://edx-cdn.org/v3/default/logo-trademark.svg
|
||||||
|
LOGO_WHITE_URL=https://edx-cdn.org/v3/default/logo-white.svg
|
||||||
|
FAVICON_URL=https://edx-cdn.org/v3/default/favicon.ico
|
||||||
3
.eslintrc.js
Normal file
3
.eslintrc.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
|
|
||||||
|
module.exports = createConfig('eslint');
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "eslint-config-edx",
|
|
||||||
"parser": "babel-eslint",
|
|
||||||
"rules": {
|
|
||||||
"import/no-extraneous-dependencies": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
"devDependencies": [
|
|
||||||
"webpack.config.js",
|
|
||||||
"**/*.test.jsx",
|
|
||||||
"**/*.test.js"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"env": {
|
|
||||||
"jest": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
26
.github/workflows/ci.yml
vendored
Normal file
26
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
name: Default CI
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Setup Nodejs
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Validate package-lock.json changes
|
||||||
|
run: make validate-no-uncommitted-package-lock-changes
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
- name: Test
|
||||||
|
run: npm run test
|
||||||
|
- name: i18n_extract
|
||||||
|
run: npm run i18n_extract
|
||||||
|
- name: Coverage
|
||||||
|
uses: codecov/codecov-action@v1
|
||||||
37
.github/workflows/release.yml
vendored
Normal file
37
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: Release CI
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Validate package-lock.json changes
|
||||||
|
run: make validate-no-uncommitted-package-lock-changes
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
- name: Test
|
||||||
|
run: npm run test
|
||||||
|
- name: i18n_extract
|
||||||
|
run: npm run i18n_extract
|
||||||
|
- name: Coverage
|
||||||
|
uses: codecov/codecov-action@v1
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
- name: Release
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
|
||||||
|
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
|
||||||
|
run: npx semantic-release
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ dist
|
|||||||
node_modules
|
node_modules
|
||||||
temp
|
temp
|
||||||
src/i18n/transifex_input.json
|
src/i18n/transifex_input.json
|
||||||
|
module.config.js
|
||||||
|
|||||||
17
.travis.yml
17
.travis.yml
@@ -1,17 +0,0 @@
|
|||||||
language: node_js
|
|
||||||
node_js: 12
|
|
||||||
install:
|
|
||||||
- npm install
|
|
||||||
script:
|
|
||||||
- npm run lint
|
|
||||||
- npm run test
|
|
||||||
- npm run build
|
|
||||||
after_success:
|
|
||||||
- npm run semantic-release
|
|
||||||
- codecov
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
# GH_TOKEN
|
|
||||||
- secure: CFN/uOByWC+7S+AAXECLQ0mNgoiyCDl1ZB5AT5+/qP+xEVs0ysFKDWrD9W8KeQqHqCMPUKNt23nrgxwvFCkSx+n1MAnxZmOdVJWbzGbUB9TsqrwVUALkqof1MrRB8UFVEzIRaO60iRN/L3zVXML+4GsycYX6rHyptbAypxplpljDyKrY8tc/mM7AGZ9eVFGSq+7CXXmdvkhP9kLkH1tIYvR7wjTKvZHbHf6YRjIVCiyzxM4S/E9l8JRnbERp02XosRD62PUJXXk6EJVn6Qoub6CaPnpew5crW0iRF1UJs54U29zWd/S+LuW66WkLfJu7rDq6AFJNMtMNusJxwVkOv4X+p0oJDWZEhojW+/Wm10UAu8/g5oAqeePZEGiSbT3Hp1VqOc4FY/kmOLiM+L6oq/AA2XX6iiE8lA64IH5R8ApQamF4GTUYTvKHeLPgXnGJH7A95Xy9/+jmX9I9wJREMrHrkyPjoX/NTRdG+RrebB1+An9Bt9vAbG862gbOZfgTcuWHDOlG5gcA964Fr7RqR5a62yr45Gw+Q0lTrLj5mGAjjSpMRIAQzi9e7oXmoMZnvenu/WJAe5M+u+/gv82HeXcMwLvNNGSvz+0i1xNUOoX1zHG046oGKiX0Zu+l0JfNwihJTO7vJlaITmjhfOyufwpk74xEyrhf8nLF9e5Frec=
|
|
||||||
# NPM_TOKEN
|
|
||||||
- secure: fuV04Ctf0mgbw6nTJhsTzGZ6dyafZtGVj30ZkvSWsB9hUU8KDtl7wWVW9EayCQsSyyFgPY9RVav5olgC/zljAjDGg0nfF7n8uKIABA0TXdP683WZd06bVOmDXfL26B3yM83aW2xgHZN6VCCvCE8bLP1V6eV8nsr38gDgxVbHa0YasDMmvtYrog+IjxwjcJx7fD0RbYyi7iJC++pdw9kcFqOad28Us7L/jCn+rC3CmUT4kOwPjP5g1v5sB2FA7ouN5s1hUUTKuttV32VJgRP7wbZzoHeHX5BRGSqijdXNSaK5UwzqRnM1sGZkuNDZhJbSB3q90SQrPRgV+fRizwN8zs8Htb+Kk8+wGY6zNhmi9C+lUIv7UpDYbstMWYIf39+P/24Oj+vJBjMY30M9NWB8gt1OQ0dJUoK53v1+BMVmDB0doL6I53xwzUjQetvqOF0Wm3E3OrqJP00OJdzIcAeh2DzcIRW1SrBhI4HAsl7QJZNpRw11QzJ3K2iQSiWNd8qIuX+XJjzQdn1v09gCstvbP33Vn8tP1x0XTSi8wIhTDqE0bII/Sc80Jh76nu0ItQ8pmX4lGsER4C0N3Dp7Zz51yW7E70AWWLsUrMNdF0oHoP437ZRGPhYs5OI6x5AM2jlU8fJ5aUroEsYFCwkH0OO37THohpAQpApe9zL10miTEbw=
|
|
||||||
2
Makefile
2
Makefile
@@ -12,7 +12,7 @@ transifex_temp = ./temp/babel-plugin-react-intl
|
|||||||
|
|
||||||
build:
|
build:
|
||||||
rm -rf ./dist
|
rm -rf ./dist
|
||||||
./node_modules/.bin/babel src --out-dir dist --source-maps --ignore **/*.test.jsx,**/__mocks__,**/__snapshots__,**/setupTest.js --copy-files
|
./node_modules/.bin/fedx-scripts babel src --out-dir dist --source-maps --ignore **/*.test.jsx,**/__mocks__,**/__snapshots__,**/setupTest.js --copy-files
|
||||||
@# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want.
|
@# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want.
|
||||||
@rm -rf dist/**/*.test.jsx
|
@rm -rf dist/**/*.test.jsx
|
||||||
@rm -rf dist/**/__snapshots__
|
@rm -rf dist/**/__snapshots__
|
||||||
|
|||||||
@@ -1,33 +1,3 @@
|
|||||||
module.exports = {
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
presets: [
|
|
||||||
[
|
module.exports = createConfig('babel-preserve-modules');
|
||||||
'@babel/preset-env',
|
|
||||||
{
|
|
||||||
modules: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
'@babel/preset-react',
|
|
||||||
],
|
|
||||||
plugins: [
|
|
||||||
'@babel/plugin-proposal-object-rest-spread',
|
|
||||||
'@babel/plugin-proposal-class-properties',
|
|
||||||
],
|
|
||||||
env: {
|
|
||||||
i18n: {
|
|
||||||
plugins: [
|
|
||||||
[
|
|
||||||
'react-intl',
|
|
||||||
{
|
|
||||||
messagesDir: './temp/babel-plugin-react-intl',
|
|
||||||
moduleSourceName: '@edx/frontend-i18n',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
test: {
|
|
||||||
presets: [
|
|
||||||
'@babel/preset-env',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
const path = require('path');
|
|
||||||
|
|
||||||
// Resolve ~tilda paths used in paragon to
|
|
||||||
// node_modules. This is used to reference
|
|
||||||
// bootstrap specifically.
|
|
||||||
module.exports = {
|
|
||||||
includePaths: [
|
|
||||||
path.resolve(__dirname, '../node_modules'),
|
|
||||||
],
|
|
||||||
};
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en-us">
|
|
||||||
<head>
|
|
||||||
<title>Example</title>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script src="./index.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -2,39 +2,35 @@ import 'babel-polyfill';
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { App, AppContext, APP_READY, AppProvider } from '@edx/frontend-base';
|
import { initialize, getConfig, subscribe, APP_READY } from '@edx/frontend-platform';
|
||||||
import { NewRelicLoggingService } from '@edx/frontend-logging';
|
import { AppContext, AppProvider } from '@edx/frontend-platform/react';
|
||||||
import './index.scss';
|
import Header from '@edx/frontend-component-header';
|
||||||
import SiteHeader from '../src/';
|
|
||||||
|
|
||||||
App.subscribe(APP_READY, () => {
|
import './index.scss';
|
||||||
|
|
||||||
|
subscribe(APP_READY, () => {
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<AppProvider>
|
<AppProvider>
|
||||||
{/* We can fake out authentication by including another provider here with the data we want */}
|
{/* We can fake out authentication by including another provider here with the data we want */}
|
||||||
<AppContext.Provider value={{
|
<AppContext.Provider value={{
|
||||||
authenticatedUser: {
|
authenticatedUser: null,
|
||||||
userId: null,
|
config: getConfig(),
|
||||||
username: null,
|
|
||||||
roles: [],
|
|
||||||
administrator: false,
|
|
||||||
},
|
|
||||||
config: App.config
|
|
||||||
}}>
|
}}>
|
||||||
<SiteHeader />
|
<Header />
|
||||||
</AppContext.Provider>
|
</AppContext.Provider>
|
||||||
<h5 className="mt-2 mb-5">Logged out state</h5>
|
<h5 className="mt-2 mb-5">Logged out state</h5>
|
||||||
|
|
||||||
{/* We can fake out authentication by including another provider here with the data we want */}
|
{/* We can fake out authentication by including another provider here with the data we want */}
|
||||||
<AppContext.Provider value={{
|
<AppContext.Provider value={{
|
||||||
authenticatedUser: {
|
authenticatedUser: {
|
||||||
userId: null,
|
userId: '123abc',
|
||||||
username: 'testuser',
|
username: 'testuser',
|
||||||
roles: [],
|
roles: [],
|
||||||
administrator: false,
|
administrator: false,
|
||||||
},
|
},
|
||||||
config: App.config
|
config: getConfig(),
|
||||||
}}>
|
}}>
|
||||||
<SiteHeader />
|
<Header />
|
||||||
</AppContext.Provider>
|
</AppContext.Provider>
|
||||||
<h5 className="mt-2">Logged in state</h5>
|
<h5 className="mt-2">Logged in state</h5>
|
||||||
</AppProvider>,
|
</AppProvider>,
|
||||||
@@ -42,4 +38,6 @@ App.subscribe(APP_READY, () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
App.initialize({ messages: [], loggingService: NewRelicLoggingService });
|
initialize({
|
||||||
|
messages: []
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
@import "~@edx/paragon/scss/core/core.scss";
|
@import "@edx/brand/paragon/fonts";
|
||||||
@import '../src/index.scss';
|
@import "@edx/brand/paragon/variables";
|
||||||
|
@import "@edx/paragon/scss/core/core";
|
||||||
|
@import "@edx/brand/paragon/overrides";
|
||||||
|
|
||||||
|
@import "@edx/frontend-component-header/index";
|
||||||
|
|||||||
7
jest.config.js
Normal file
7
jest.config.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
|
|
||||||
|
module.exports = createConfig('jest', {
|
||||||
|
setupFiles: [
|
||||||
|
'<rootDir>/src/setupTest.js',
|
||||||
|
],
|
||||||
|
});
|
||||||
25939
package-lock.json
generated
25939
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
108
package.json
108
package.json
@@ -2,22 +2,27 @@
|
|||||||
"name": "@edx/frontend-component-header",
|
"name": "@edx/frontend-component-header",
|
||||||
"version": "1.0.0-semantically-released",
|
"version": "1.0.0-semantically-released",
|
||||||
"description": "The standard header for Open edX",
|
"description": "The standard header for Open edX",
|
||||||
|
"main": "dist/index.js",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
"main": "dist/index.js",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "make build",
|
"build": "make build",
|
||||||
"i18n_extract": "BABEL_ENV=i18n babel src --quiet > /dev/null",
|
"i18n_extract": "BABEL_ENV=i18n fedx-scripts babel src --quiet > /dev/null",
|
||||||
"lint": "eslint --ext .js --ext .jsx .",
|
"lint": "fedx-scripts eslint --ext .js --ext .jsx .",
|
||||||
"semantic-release": "semantic-release",
|
"snapshot": "fedx-scripts jest --updateSnapshot",
|
||||||
"start": "parcel ./example/index.html --no-source-maps --out-dir example/dist",
|
"start": "fedx-scripts webpack-dev-server --progress",
|
||||||
"test": "jest --coverage --passWithNoTests"
|
"test": "fedx-scripts jest --coverage"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"/dist",
|
"/dist"
|
||||||
"/src"
|
|
||||||
],
|
],
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "npm run lint",
|
||||||
|
"commit-msg": "commitlint -e $GIT_PARAMS"
|
||||||
|
}
|
||||||
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/edx/frontend-component-header.git"
|
"url": "git+https://github.com/edx/frontend-component-header.git"
|
||||||
@@ -29,69 +34,38 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/edx/frontend-component-header#readme",
|
"homepage": "https://github.com/edx/frontend-component-header#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.6.0",
|
"@commitlint/cli": "8.2.0",
|
||||||
"@babel/core": "^7.6.0",
|
"@commitlint/config-angular": "8.2.0",
|
||||||
"@babel/plugin-proposal-class-properties": "^7.5.5",
|
"@commitlint/prompt": "8.2.0",
|
||||||
"@babel/plugin-proposal-object-rest-spread": "^7.5.5",
|
"@commitlint/prompt-cli": "8.2.0",
|
||||||
"@babel/preset-env": "^7.6.0",
|
"@edx/brand": "npm:@edx/brand-openedx@1.1.0",
|
||||||
"@babel/preset-react": "^7.0.0",
|
"@edx/frontend-build": "5.4.0",
|
||||||
"@edx/frontend-analytics": "^2.0.0",
|
"@edx/frontend-platform": "1.8.0",
|
||||||
"@edx/frontend-auth": "^6.0.1",
|
"@edx/paragon": "12.0.5",
|
||||||
"@edx/frontend-base": "^2.0.0",
|
"codecov": "3.7.2",
|
||||||
"@edx/frontend-i18n": "^3.0.2",
|
|
||||||
"@edx/frontend-logging": "^3.0.1",
|
|
||||||
"@edx/paragon": "^7.1.2",
|
|
||||||
"babel-eslint": "^10.0.3",
|
|
||||||
"babel-plugin-react-intl": "^4.1.18",
|
|
||||||
"dotenv": "^8.1.0",
|
|
||||||
"enzyme": "3.10.0",
|
"enzyme": "3.10.0",
|
||||||
"enzyme-adapter-react-16": "1.14.0",
|
"enzyme-adapter-react-16": "1.14.0",
|
||||||
"eslint": "^6.3.0",
|
"husky": "3.0.9",
|
||||||
"eslint-config-edx": "^4.0.4",
|
"prop-types": "15.7.2",
|
||||||
"jest": "^24.9.0",
|
"react": "16.9.0",
|
||||||
"parcel-bundler": "^1.12.3",
|
"react-dom": "16.9.0",
|
||||||
"prop-types": "^15.7.2",
|
"react-redux": "7.1.1",
|
||||||
"react": "^16.9.0",
|
"react-router-dom": "5.1.2",
|
||||||
"react-dom": "^16.9.0",
|
"react-test-renderer": "16.9.0",
|
||||||
"react-redux": "^7.1.1",
|
"reactifex": "1.1.1",
|
||||||
"react-router-dom": "^5.0.1",
|
"redux": "4.0.4",
|
||||||
"react-test-renderer": "^16.9.0",
|
"redux-saga": "1.1.1"
|
||||||
"reactifex": "^1.1.1",
|
|
||||||
"redux": "^4.0.4",
|
|
||||||
"redux-saga": "^1.0.5",
|
|
||||||
"sass": "^1.22.12",
|
|
||||||
"semantic-release": "^15.13.24"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@edx/frontend-analytics": "^2.0.0",
|
|
||||||
"@edx/frontend-base": "^2.0.0",
|
|
||||||
"@edx/frontend-i18n": "^3.0.2",
|
|
||||||
"prop-types": "^15.7.2",
|
|
||||||
"react": "^16.9.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-polyfill": "^6.26.0",
|
"babel-polyfill": "6.26.0",
|
||||||
"react-responsive": "^8.0.1",
|
"react-responsive": "8.0.3",
|
||||||
"react-transition-group": "^4.3.0"
|
"react-transition-group": "4.3.0"
|
||||||
},
|
},
|
||||||
"jest": {
|
"peerDependencies": {
|
||||||
"transform": {
|
"@edx/frontend-platform": "^1.8.0",
|
||||||
"^.+\\.jsx?$": "babel-jest"
|
"@edx/paragon": "^7.0.0",
|
||||||
},
|
"prop-types": "^15.5.10",
|
||||||
"collectCoverageFrom": [
|
"react": "^16.9.0",
|
||||||
"src/**/*.{js,jsx}",
|
"react-dom": "^16.9.0"
|
||||||
"!**/node_modules/**",
|
|
||||||
"!**/dist/**"
|
|
||||||
],
|
|
||||||
"moduleNameMapper": {
|
|
||||||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/src/__mocks__/fileMock.js"
|
|
||||||
},
|
|
||||||
"transformIgnorePatterns": [
|
|
||||||
"/node_modules/(?!@edx)"
|
|
||||||
],
|
|
||||||
"setupFiles": [
|
|
||||||
"./src/setupTest.js",
|
|
||||||
"dotenv/config"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
public/index.html
Executable file
11
public/index.html
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en-us" dir="ltr">
|
||||||
|
<head>
|
||||||
|
<title>Header</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"extends": [
|
||||||
"config:base"
|
"config:base"
|
||||||
]
|
],
|
||||||
|
"patch": {
|
||||||
|
"automerge": true
|
||||||
|
},
|
||||||
|
"rebaseStalePrs": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ function Avatar({
|
|||||||
const avatar = src ? (
|
const avatar = src ? (
|
||||||
<img className="d-block w-100 h-100" src={src} alt={alt} />
|
<img className="d-block w-100 h-100" src={src} alt={alt} />
|
||||||
) : (
|
) : (
|
||||||
<AvatarIcon className="text-muted" style={{ width: size, height: size }} role="img" aria-hidden focusable="false" />
|
<AvatarIcon style={{ width: size, height: size }} role="img" aria-hidden focusable="false" />
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { injectIntl, intlShape } from '@edx/frontend-i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
// Local Components
|
// Local Components
|
||||||
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
||||||
@@ -8,7 +8,7 @@ import Avatar from './Avatar';
|
|||||||
import { LinkedLogo, Logo } from './Logo';
|
import { LinkedLogo, Logo } from './Logo';
|
||||||
|
|
||||||
// i18n
|
// i18n
|
||||||
import messages from './SiteHeader.messages';
|
import messages from './Header.messages';
|
||||||
|
|
||||||
// Assets
|
// Assets
|
||||||
import { CaretIcon } from './Icons';
|
import { CaretIcon } from './Icons';
|
||||||
@@ -22,7 +22,9 @@ class DesktopHeader extends React.Component {
|
|||||||
const { mainMenu } = this.props;
|
const { mainMenu } = this.props;
|
||||||
|
|
||||||
// Nodes are accepted as a prop
|
// Nodes are accepted as a prop
|
||||||
if (!Array.isArray(mainMenu)) return mainMenu;
|
if (!Array.isArray(mainMenu)) {
|
||||||
|
return mainMenu;
|
||||||
|
}
|
||||||
|
|
||||||
return mainMenu.map((menuItem) => {
|
return mainMenu.map((menuItem) => {
|
||||||
const {
|
const {
|
||||||
@@ -64,7 +66,7 @@ class DesktopHeader extends React.Component {
|
|||||||
<MenuTrigger
|
<MenuTrigger
|
||||||
tag="button"
|
tag="button"
|
||||||
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { username })}
|
aria-label={intl.formatMessage(messages['header.label.account.menu.for'], { username })}
|
||||||
className="btn btn-light d-inline-flex align-items-center pl-2 pr-3"
|
className="btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||||
>
|
>
|
||||||
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
|
<Avatar size="1.5em" src={avatar} alt="" className="mr-2" />
|
||||||
{username} <CaretIcon role="img" aria-hidden focusable="false" />
|
{username} <CaretIcon role="img" aria-hidden focusable="false" />
|
||||||
@@ -106,7 +108,7 @@ class DesktopHeader extends React.Component {
|
|||||||
<header className="site-header-desktop">
|
<header className="site-header-desktop">
|
||||||
<div className="container-fluid">
|
<div className="container-fluid">
|
||||||
<div className="nav-container position-relative d-flex align-items-center">
|
<div className="nav-container position-relative d-flex align-items-center">
|
||||||
{ logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} />}
|
{logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} />}
|
||||||
<nav
|
<nav
|
||||||
aria-label={intl.formatMessage(messages['header.label.main.nav'])}
|
aria-label={intl.formatMessage(messages['header.label.main.nav'])}
|
||||||
className="nav main-nav"
|
className="nav main-nav"
|
||||||
|
|||||||
@@ -1,25 +1,35 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import Responsive from 'react-responsive';
|
import Responsive from 'react-responsive';
|
||||||
import { injectIntl, intlShape } from '@edx/frontend-i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
import { App, AppContext, APP_CONFIGURED } from '@edx/frontend-base';
|
import { AppContext } from '@edx/frontend-platform/react';
|
||||||
|
import {
|
||||||
|
APP_CONFIG_INITIALIZED,
|
||||||
|
ensureConfig,
|
||||||
|
mergeConfig,
|
||||||
|
getConfig,
|
||||||
|
subscribe,
|
||||||
|
} from '@edx/frontend-platform';
|
||||||
|
|
||||||
import DesktopHeader from './DesktopHeader';
|
import DesktopHeader from './DesktopHeader';
|
||||||
import MobileHeader from './MobileHeader';
|
import MobileHeader from './MobileHeader';
|
||||||
|
|
||||||
import LogoSVG from './logo.svg';
|
import messages from './Header.messages';
|
||||||
|
|
||||||
import messages from './SiteHeader.messages';
|
ensureConfig([
|
||||||
|
'LMS_BASE_URL',
|
||||||
|
'LOGOUT_URL',
|
||||||
|
'LOGIN_URL',
|
||||||
|
'SITE_NAME',
|
||||||
|
'LOGO_URL',
|
||||||
|
], 'Header component');
|
||||||
|
|
||||||
App.subscribe(APP_CONFIGURED, () => {
|
subscribe(APP_CONFIG_INITIALIZED, () => {
|
||||||
App.requireConfig([
|
mergeConfig({
|
||||||
'LMS_BASE_URL',
|
LOGISTRATION_MINIMAL_HEADER: !!process.env.LOGISTRATION_MINIMAL_HEADER,
|
||||||
'LOGOUT_URL',
|
}, 'Header additional config');
|
||||||
'LOGIN_URL',
|
|
||||||
'SITE_NAME',
|
|
||||||
], 'Header component');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function SiteHeader({ intl }) {
|
function Header({ intl }) {
|
||||||
const { authenticatedUser, config } = useContext(AppContext);
|
const { authenticatedUser, config } = useContext(AppContext);
|
||||||
|
|
||||||
const mainMenu = [
|
const mainMenu = [
|
||||||
@@ -30,7 +40,7 @@ function SiteHeader({ intl }) {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const userMenu = [
|
const userMenu = authenticatedUser === null ? [] : [
|
||||||
{
|
{
|
||||||
type: 'item',
|
type: 'item',
|
||||||
href: `${config.LMS_BASE_URL}/dashboard`,
|
href: `${config.LMS_BASE_URL}/dashboard`,
|
||||||
@@ -67,32 +77,32 @@ function SiteHeader({ intl }) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
logo: LogoSVG,
|
logo: config.LOGO_URL,
|
||||||
logoAltText: config.SITE_NAME,
|
logoAltText: config.SITE_NAME,
|
||||||
siteName: config.SITE_NAME,
|
siteName: config.SITE_NAME,
|
||||||
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
|
logoDestination: `${config.LMS_BASE_URL}/dashboard`,
|
||||||
loggedIn: !!authenticatedUser.username,
|
loggedIn: authenticatedUser !== null,
|
||||||
username: authenticatedUser.username,
|
username: authenticatedUser !== null ? authenticatedUser.username : null,
|
||||||
avatar: authenticatedUser.avatar,
|
avatar: authenticatedUser !== null ? authenticatedUser.avatar : null,
|
||||||
mainMenu,
|
mainMenu: getConfig().LOGISTRATION_MINIMAL_HEADER ? [] : mainMenu,
|
||||||
userMenu,
|
userMenu: getConfig().LOGISTRATION_MINIMAL_HEADER ? [] : userMenu,
|
||||||
loggedOutItems,
|
loggedOutItems: getConfig().LOGISTRATION_MINIMAL_HEADER ? [] : loggedOutItems,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<>
|
||||||
<Responsive maxWidth={768}>
|
<Responsive maxWidth={768}>
|
||||||
<MobileHeader {...props} />
|
<MobileHeader {...props} />
|
||||||
</Responsive>
|
</Responsive>
|
||||||
<Responsive minWidth={769}>
|
<Responsive minWidth={769}>
|
||||||
<DesktopHeader {...props} />
|
<DesktopHeader {...props} />
|
||||||
</Responsive>
|
</Responsive>
|
||||||
</React.Fragment>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
SiteHeader.propTypes = {
|
Header.propTypes = {
|
||||||
intl: intlShape.isRequired,
|
intl: intlShape.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default injectIntl(SiteHeader);
|
export default injectIntl(Header);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { defineMessages } from '@edx/frontend-i18n';
|
import { defineMessages } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
'header.links.courses': {
|
'header.links.courses': {
|
||||||
@@ -67,7 +67,7 @@ const messages = defineMessages({
|
|||||||
description: 'The aria label for the account menu trigger',
|
description: 'The aria label for the account menu trigger',
|
||||||
},
|
},
|
||||||
'header.label.account.menu.for': {
|
'header.label.account.menu.for': {
|
||||||
id: 'header.label.account.menu',
|
id: 'header.label.account.menu.for',
|
||||||
defaultMessage: 'Account menu for {username}',
|
defaultMessage: 'Account menu for {username}',
|
||||||
description: 'The aria label for the account menu trigger when the username is displayed in it',
|
description: 'The aria label for the account menu trigger when the username is displayed in it',
|
||||||
},
|
},
|
||||||
127
src/Header.test.jsx
Normal file
127
src/Header.test.jsx
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { IntlProvider } from '@edx/frontend-platform/i18n';
|
||||||
|
import TestRenderer from 'react-test-renderer';
|
||||||
|
import { AppContext } from '@edx/frontend-platform/react';
|
||||||
|
import { Context as ResponsiveContext } from 'react-responsive';
|
||||||
|
|
||||||
|
import Header from './index';
|
||||||
|
|
||||||
|
describe('<Header />', () => {
|
||||||
|
it('renders correctly for anonymous desktop', () => {
|
||||||
|
const component = (
|
||||||
|
<ResponsiveContext.Provider value={{ width: 1280 }}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={{
|
||||||
|
authenticatedUser: null,
|
||||||
|
config: {
|
||||||
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Header />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
</ResponsiveContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly for authenticated desktop', () => {
|
||||||
|
const component = (
|
||||||
|
<ResponsiveContext.Provider value={{ width: 1280 }}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={{
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: 'abc123',
|
||||||
|
username: 'edX',
|
||||||
|
roles: [],
|
||||||
|
administrator: false,
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Header />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
</ResponsiveContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly for anonymous mobile', () => {
|
||||||
|
const component = (
|
||||||
|
<ResponsiveContext.Provider value={{ width: 500 }}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={{
|
||||||
|
authenticatedUser: null,
|
||||||
|
config: {
|
||||||
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Header />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
</ResponsiveContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders correctly for authenticated mobile', () => {
|
||||||
|
const component = (
|
||||||
|
<ResponsiveContext.Provider value={{ width: 500 }}>
|
||||||
|
<IntlProvider locale="en" messages={{}}>
|
||||||
|
<AppContext.Provider
|
||||||
|
value={{
|
||||||
|
authenticatedUser: {
|
||||||
|
userId: 'abc123',
|
||||||
|
username: 'edX',
|
||||||
|
roles: [],
|
||||||
|
administrator: false,
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
||||||
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
|
LOGIN_URL: process.env.LOGIN_URL,
|
||||||
|
LOGOUT_URL: process.env.LOGOUT_URL,
|
||||||
|
LOGO_URL: process.env.LOGO_URL,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Header />
|
||||||
|
</AppContext.Provider>
|
||||||
|
</IntlProvider>
|
||||||
|
</ResponsiveContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
|
const wrapper = TestRenderer.create(component);
|
||||||
|
|
||||||
|
expect(wrapper.toJSON()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
|
||||||
function Logo({ src, alt, ...attributes }) {
|
function Logo({ src, alt, ...attributes }) {
|
||||||
return (
|
return (
|
||||||
<img src={src} alt={alt} {...attributes} />
|
<img src={src} alt={alt} {...attributes} />
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React from 'react';
|
|||||||
import { CSSTransition } from 'react-transition-group';
|
import { CSSTransition } from 'react-transition-group';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
|
||||||
function MenuTrigger({ tag, className, ...attributes }) {
|
function MenuTrigger({ tag, className, ...attributes }) {
|
||||||
return React.createElement(tag, {
|
return React.createElement(tag, {
|
||||||
className: `menu-trigger ${className}`,
|
className: `menu-trigger ${className}`,
|
||||||
@@ -19,7 +18,6 @@ MenuTrigger.defaultProps = {
|
|||||||
};
|
};
|
||||||
const MenuTriggerType = <MenuTrigger />.type;
|
const MenuTriggerType = <MenuTrigger />.type;
|
||||||
|
|
||||||
|
|
||||||
function MenuContent({ tag, className, ...attributes }) {
|
function MenuContent({ tag, className, ...attributes }) {
|
||||||
return React.createElement(tag, {
|
return React.createElement(tag, {
|
||||||
className: ['menu-content', className].join(' '),
|
className: ['menu-content', className].join(' '),
|
||||||
@@ -35,6 +33,17 @@ MenuContent.defaultProps = {
|
|||||||
className: null,
|
className: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const menuPropTypes = {
|
||||||
|
tag: PropTypes.string,
|
||||||
|
onClose: PropTypes.func,
|
||||||
|
onOpen: PropTypes.func,
|
||||||
|
closeOnDocumentClick: PropTypes.bool,
|
||||||
|
respondToPointerEvents: PropTypes.bool,
|
||||||
|
className: PropTypes.string,
|
||||||
|
transitionTimeout: PropTypes.number,
|
||||||
|
transitionClassName: PropTypes.string,
|
||||||
|
children: PropTypes.arrayOf(PropTypes.node).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
class Menu extends React.Component {
|
class Menu extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -66,10 +75,14 @@ class Menu extends React.Component {
|
|||||||
|
|
||||||
// Event handlers
|
// Event handlers
|
||||||
onDocumentClick(e) {
|
onDocumentClick(e) {
|
||||||
if (!this.props.closeOnDocumentClick) return;
|
if (!this.props.closeOnDocumentClick) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const clickIsInMenu = this.menu.current === e.target || this.menu.current.contains(e.target);
|
const clickIsInMenu = this.menu.current === e.target || this.menu.current.contains(e.target);
|
||||||
if (clickIsInMenu) return;
|
if (clickIsInMenu) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
@@ -77,7 +90,9 @@ class Menu extends React.Component {
|
|||||||
onTriggerClick(e) {
|
onTriggerClick(e) {
|
||||||
// Let the browser follow the link of the trigger if the menu
|
// Let the browser follow the link of the trigger if the menu
|
||||||
// is already expanded and the trigger has an href attribute
|
// is already expanded and the trigger has an href attribute
|
||||||
if (this.state.expanded && e.target.getAttribute('href')) return;
|
if (this.state.expanded && e.target.getAttribute('href')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.toggle();
|
this.toggle();
|
||||||
@@ -89,7 +104,9 @@ class Menu extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onKeyDown(e) {
|
onKeyDown(e) {
|
||||||
if (!this.state.expanded) return;
|
if (!this.state.expanded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case 'Escape': {
|
case 'Escape': {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -131,16 +148,19 @@ class Menu extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnter() {
|
onMouseEnter() {
|
||||||
if (!this.props.respondToPointerEvents) return;
|
if (!this.props.respondToPointerEvents) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.open();
|
this.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseLeave() {
|
onMouseLeave() {
|
||||||
if (!this.props.respondToPointerEvents) return;
|
if (!this.props.respondToPointerEvents) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Internal functions
|
// Internal functions
|
||||||
|
|
||||||
getFocusableElements() {
|
getFocusableElements() {
|
||||||
@@ -151,7 +171,7 @@ class Menu extends React.Component {
|
|||||||
// Any extra props are attributes for the menu
|
// Any extra props are attributes for the menu
|
||||||
const attributes = {};
|
const attributes = {};
|
||||||
Object.keys(this.props)
|
Object.keys(this.props)
|
||||||
.filter(property => Menu.propTypes[property] === undefined)
|
.filter(property => menuPropTypes[property] === undefined)
|
||||||
.forEach((property) => {
|
.forEach((property) => {
|
||||||
attributes[property] = this.props[property];
|
attributes[property] = this.props[property];
|
||||||
});
|
});
|
||||||
@@ -173,7 +193,9 @@ class Menu extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
if (this.props.onOpen) this.props.onOpen();
|
if (this.props.onOpen) {
|
||||||
|
this.props.onOpen();
|
||||||
|
}
|
||||||
this.setState({ expanded: true });
|
this.setState({ expanded: true });
|
||||||
// Listen to touchend and click events to ensure the menu
|
// Listen to touchend and click events to ensure the menu
|
||||||
// can be closed on mobile, pointer, and mixed input devices
|
// can be closed on mobile, pointer, and mixed input devices
|
||||||
@@ -182,7 +204,9 @@ class Menu extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
if (this.props.onClose) this.props.onClose();
|
if (this.props.onClose) {
|
||||||
|
this.props.onClose();
|
||||||
|
}
|
||||||
this.setState({ expanded: false });
|
this.setState({ expanded: false });
|
||||||
document.removeEventListener('touchend', this.onDocumentClick, true);
|
document.removeEventListener('touchend', this.onDocumentClick, true);
|
||||||
document.removeEventListener('click', this.onDocumentClick, true);
|
document.removeEventListener('click', this.onDocumentClick, true);
|
||||||
@@ -240,18 +264,7 @@ class Menu extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Menu.propTypes = menuPropTypes;
|
||||||
Menu.propTypes = {
|
|
||||||
tag: PropTypes.string,
|
|
||||||
onClose: PropTypes.func,
|
|
||||||
onOpen: PropTypes.func,
|
|
||||||
closeOnDocumentClick: PropTypes.bool,
|
|
||||||
respondToPointerEvents: PropTypes.bool,
|
|
||||||
className: PropTypes.string,
|
|
||||||
transitionTimeout: PropTypes.number,
|
|
||||||
transitionClassName: PropTypes.string,
|
|
||||||
children: PropTypes.arrayOf(PropTypes.node).isRequired,
|
|
||||||
};
|
|
||||||
Menu.defaultProps = {
|
Menu.defaultProps = {
|
||||||
tag: 'div',
|
tag: 'div',
|
||||||
className: null,
|
className: null,
|
||||||
@@ -263,5 +276,4 @@ Menu.defaultProps = {
|
|||||||
transitionClassName: 'menu-content',
|
transitionClassName: 'menu-content',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export { Menu, MenuTrigger, MenuContent };
|
export { Menu, MenuTrigger, MenuContent };
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { injectIntl, intlShape } from '@edx/frontend-i18n';
|
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||||
|
|
||||||
// Local Components
|
// Local Components
|
||||||
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
import { Menu, MenuTrigger, MenuContent } from './Menu';
|
||||||
@@ -8,7 +8,7 @@ import Avatar from './Avatar';
|
|||||||
import { LinkedLogo, Logo } from './Logo';
|
import { LinkedLogo, Logo } from './Logo';
|
||||||
|
|
||||||
// i18n
|
// i18n
|
||||||
import messages from './SiteHeader.messages';
|
import messages from './Header.messages';
|
||||||
|
|
||||||
// Assets
|
// Assets
|
||||||
import { MenuIcon } from './Icons';
|
import { MenuIcon } from './Icons';
|
||||||
@@ -22,7 +22,9 @@ class MobileHeader extends React.Component {
|
|||||||
const { mainMenu } = this.props;
|
const { mainMenu } = this.props;
|
||||||
|
|
||||||
// Nodes are accepted as a prop
|
// Nodes are accepted as a prop
|
||||||
if (!Array.isArray(mainMenu)) return mainMenu;
|
if (!Array.isArray(mainMenu)) {
|
||||||
|
return mainMenu;
|
||||||
|
}
|
||||||
|
|
||||||
return mainMenu.map((menuItem) => {
|
return mainMenu.map((menuItem) => {
|
||||||
const {
|
const {
|
||||||
@@ -89,6 +91,8 @@ class MobileHeader extends React.Component {
|
|||||||
stickyOnMobile,
|
stickyOnMobile,
|
||||||
intl,
|
intl,
|
||||||
mainMenu,
|
mainMenu,
|
||||||
|
userMenu,
|
||||||
|
loggedOutItems,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
const logoProps = { src: logo, alt: logoAltText, href: logoDestination };
|
||||||
const stickyClassName = stickyOnMobile ? 'sticky-top' : '';
|
const stickyClassName = stickyOnMobile ? 'sticky-top' : '';
|
||||||
@@ -99,7 +103,7 @@ class MobileHeader extends React.Component {
|
|||||||
className={`site-header-mobile d-flex justify-content-between align-items-center shadow ${stickyClassName}`}
|
className={`site-header-mobile d-flex justify-content-between align-items-center shadow ${stickyClassName}`}
|
||||||
>
|
>
|
||||||
<div className="w-100 d-flex justify-content-start">
|
<div className="w-100 d-flex justify-content-start">
|
||||||
{mainMenu.length > 0 ?
|
{mainMenu.length > 0 ? (
|
||||||
<Menu className="position-static">
|
<Menu className="position-static">
|
||||||
<MenuTrigger
|
<MenuTrigger
|
||||||
tag="button"
|
tag="button"
|
||||||
@@ -116,25 +120,28 @@ class MobileHeader extends React.Component {
|
|||||||
>
|
>
|
||||||
{this.renderMainMenu()}
|
{this.renderMainMenu()}
|
||||||
</MenuContent>
|
</MenuContent>
|
||||||
</Menu> : null }
|
</Menu>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-100 d-flex justify-content-center">
|
<div className="w-100 d-flex justify-content-center">
|
||||||
{ logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} itemType="http://schema.org/Organization" />}
|
{ logoDestination === null ? <Logo className="logo" src={logo} alt={logoAltText} /> : <LinkedLogo className="logo" {...logoProps} itemType="http://schema.org/Organization" />}
|
||||||
</div>
|
</div>
|
||||||
<div className="w-100 d-flex justify-content-end align-items-center">
|
<div className="w-100 d-flex justify-content-end align-items-center">
|
||||||
<Menu tag="nav" aria-label={intl.formatMessage(messages['header.label.secondary.nav'])} className="position-static">
|
{userMenu.length > 0 || loggedOutItems.length > 0 ? (
|
||||||
<MenuTrigger
|
<Menu tag="nav" aria-label={intl.formatMessage(messages['header.label.secondary.nav'])} className="position-static">
|
||||||
tag="button"
|
<MenuTrigger
|
||||||
className="icon-button"
|
tag="button"
|
||||||
aria-label={intl.formatMessage(messages['header.label.account.menu'])}
|
className="icon-button"
|
||||||
title={intl.formatMessage(messages['header.label.account.menu'])}
|
aria-label={intl.formatMessage(messages['header.label.account.menu'])}
|
||||||
>
|
title={intl.formatMessage(messages['header.label.account.menu'])}
|
||||||
<Avatar size="1.5rem" src={avatar} alt={username} />
|
>
|
||||||
</MenuTrigger>
|
<Avatar size="1.5rem" src={avatar} alt={username} />
|
||||||
<MenuContent tag="ul" className="nav flex-column pin-left pin-right border-top shadow py-2">
|
</MenuTrigger>
|
||||||
{loggedIn ? this.renderUserMenuItems() : this.renderLoggedOutItems()}
|
<MenuContent tag="ul" className="nav flex-column pin-left pin-right border-top shadow py-2">
|
||||||
</MenuContent>
|
{loggedIn ? this.renderUserMenuItems() : this.renderLoggedOutItems()}
|
||||||
</Menu>
|
</MenuContent>
|
||||||
|
</Menu>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
|
|
||||||
import React from 'react';
|
|
||||||
import { IntlProvider } from '@edx/frontend-i18n';
|
|
||||||
import TestRenderer from 'react-test-renderer';
|
|
||||||
import { AppContext } from '@edx/frontend-base';
|
|
||||||
import { Context as ResponsiveContext } from 'react-responsive';
|
|
||||||
|
|
||||||
import SiteHeader from './index';
|
|
||||||
|
|
||||||
describe('<SiteHeader />', () => {
|
|
||||||
it('renders correctly for desktop', () => {
|
|
||||||
const component = (
|
|
||||||
<ResponsiveContext.Provider value={{ width: 1280 }}>
|
|
||||||
<IntlProvider locale="en" messages={{}}>
|
|
||||||
<AppContext.Provider value={{
|
|
||||||
authenticatedUser: {
|
|
||||||
userId: null,
|
|
||||||
username: null,
|
|
||||||
roles: [],
|
|
||||||
administrator: false,
|
|
||||||
},
|
|
||||||
config: {
|
|
||||||
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
|
||||||
SITE_NAME: process.env.SITE_NAME,
|
|
||||||
LOGIN_URL: process.env.LOGIN_URL,
|
|
||||||
LOGOUT_URL: process.env.LOGOUT_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SiteHeader />
|
|
||||||
</AppContext.Provider>
|
|
||||||
</IntlProvider>
|
|
||||||
</ResponsiveContext.Provider>
|
|
||||||
);
|
|
||||||
|
|
||||||
const wrapper = TestRenderer.create(component);
|
|
||||||
|
|
||||||
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders correctly for mobile', () => {
|
|
||||||
const component = (
|
|
||||||
<ResponsiveContext.Provider value={{ width: 500 }}>
|
|
||||||
<IntlProvider locale="en" messages={{}}>
|
|
||||||
<AppContext.Provider value={{
|
|
||||||
authenticatedUser: {
|
|
||||||
userId: null,
|
|
||||||
username: null,
|
|
||||||
roles: [],
|
|
||||||
administrator: false,
|
|
||||||
},
|
|
||||||
config: {
|
|
||||||
LMS_BASE_URL: process.env.LMS_BASE_URL,
|
|
||||||
SITE_NAME: process.env.SITE_NAME,
|
|
||||||
LOGIN_URL: process.env.LOGIN_URL,
|
|
||||||
LOGOUT_URL: process.env.LOGOUT_URL,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SiteHeader />
|
|
||||||
</AppContext.Provider>
|
|
||||||
</IntlProvider>
|
|
||||||
</ResponsiveContext.Provider>
|
|
||||||
);
|
|
||||||
|
|
||||||
const wrapper = TestRenderer.create(component);
|
|
||||||
|
|
||||||
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
// __mocks__/fileMock.js
|
|
||||||
|
|
||||||
module.exports = 'test-file-stub';
|
|
||||||
419
src/__snapshots__/Header.test.jsx.snap
Normal file
419
src/__snapshots__/Header.test.jsx.snap
Normal file
@@ -0,0 +1,419 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`<Header /> renders correctly for anonymous desktop 1`] = `
|
||||||
|
<header
|
||||||
|
className="site-header-desktop"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="container-fluid"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="nav-container position-relative d-flex align-items-center"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="logo"
|
||||||
|
href="http://localhost:18000/dashboard"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="edX"
|
||||||
|
className="d-block"
|
||||||
|
src="https://edx-cdn.org/v3/default/logo.svg"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
<nav
|
||||||
|
aria-label="Main"
|
||||||
|
className="nav main-nav"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="nav-link"
|
||||||
|
href="http://localhost:18000/dashboard"
|
||||||
|
>
|
||||||
|
Courses
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
<nav
|
||||||
|
aria-label="Secondary"
|
||||||
|
className="nav secondary-menu-container align-items-center ml-auto"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="btn mr-2 btn-link"
|
||||||
|
href="http://localhost:18000/login"
|
||||||
|
>
|
||||||
|
Login
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
className="btn mr-2 btn-outline-primary"
|
||||||
|
href="http://localhost:18000/register"
|
||||||
|
>
|
||||||
|
Sign Up
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`<Header /> renders correctly for anonymous mobile 1`] = `
|
||||||
|
<header
|
||||||
|
aria-label="Main"
|
||||||
|
className="site-header-mobile d-flex justify-content-between align-items-center shadow sticky-top"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="w-100 d-flex justify-content-start"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu position-static"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Main Menu"
|
||||||
|
className="menu-trigger icon-button"
|
||||||
|
onClick={[Function]}
|
||||||
|
title="Main Menu"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5rem",
|
||||||
|
"width": "1.5rem",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<rect
|
||||||
|
fill="currentColor"
|
||||||
|
height="2"
|
||||||
|
width="20"
|
||||||
|
x="2"
|
||||||
|
y="5"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
fill="currentColor"
|
||||||
|
height="2"
|
||||||
|
width="20"
|
||||||
|
x="2"
|
||||||
|
y="11"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
fill="currentColor"
|
||||||
|
height="2"
|
||||||
|
width="20"
|
||||||
|
x="2"
|
||||||
|
y="17"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="w-100 d-flex justify-content-center"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="logo"
|
||||||
|
href="http://localhost:18000/dashboard"
|
||||||
|
itemType="http://schema.org/Organization"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="edX"
|
||||||
|
className="d-block"
|
||||||
|
src="https://edx-cdn.org/v3/default/logo.svg"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="w-100 d-flex justify-content-end align-items-center"
|
||||||
|
>
|
||||||
|
<nav
|
||||||
|
aria-label="Secondary"
|
||||||
|
className="menu position-static"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Account Menu"
|
||||||
|
className="menu-trigger icon-button"
|
||||||
|
onClick={[Function]}
|
||||||
|
title="Account Menu"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="avatar overflow-hidden d-inline-flex rounded-circle null"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5rem",
|
||||||
|
"width": "1.5rem",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5rem",
|
||||||
|
"width": "1.5rem",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M4.10255106,18.1351061 C4.7170266,16.0581859 8.01891846,14.4720277 12,14.4720277 C15.9810815,14.4720277 19.2829734,16.0581859 19.8974489,18.1351061 C21.215206,16.4412566 22,14.3122775 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,14.3122775 2.78479405,16.4412566 4.10255106,18.1351061 Z M12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 Z M12,13 C9.790861,13 8,11.209139 8,9 C8,6.790861 9.790861,5 12,5 C14.209139,5 16,6.790861 16,9 C16,11.209139 14.209139,13 12,13 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`<Header /> renders correctly for authenticated desktop 1`] = `
|
||||||
|
<header
|
||||||
|
className="site-header-desktop"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="container-fluid"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="nav-container position-relative d-flex align-items-center"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="logo"
|
||||||
|
href="http://localhost:18000/dashboard"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="edX"
|
||||||
|
className="d-block"
|
||||||
|
src="https://edx-cdn.org/v3/default/logo.svg"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
<nav
|
||||||
|
aria-label="Main"
|
||||||
|
className="nav main-nav"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="nav-link"
|
||||||
|
href="http://localhost:18000/dashboard"
|
||||||
|
>
|
||||||
|
Courses
|
||||||
|
</a>
|
||||||
|
</nav>
|
||||||
|
<nav
|
||||||
|
aria-label="Secondary"
|
||||||
|
className="nav secondary-menu-container align-items-center ml-auto"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu null"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Account menu for edX"
|
||||||
|
className="menu-trigger btn btn-outline-primary d-inline-flex align-items-center pl-2 pr-3"
|
||||||
|
onClick={[Function]}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="avatar overflow-hidden d-inline-flex rounded-circle mr-2"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5em",
|
||||||
|
"width": "1.5em",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M4.10255106,18.1351061 C4.7170266,16.0581859 8.01891846,14.4720277 12,14.4720277 C15.9810815,14.4720277 19.2829734,16.0581859 19.8974489,18.1351061 C21.215206,16.4412566 22,14.3122775 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,14.3122775 2.78479405,16.4412566 4.10255106,18.1351061 Z M12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 Z M12,13 C9.790861,13 8,11.209139 8,9 C8,6.790861 9.790861,5 12,5 C14.209139,5 16,6.790861 16,9 C16,11.209139 14.209139,13 12,13 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
edX
|
||||||
|
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="16px"
|
||||||
|
role="img"
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
width="16px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M7,4 L7,8 L11,8 L11,10 L5,10 L5,4 L7,4 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
transform="translate(8.000000, 7.000000) rotate(-45.000000) translate(-8.000000, -7.000000) "
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`<Header /> renders correctly for authenticated mobile 1`] = `
|
||||||
|
<header
|
||||||
|
aria-label="Main"
|
||||||
|
className="site-header-mobile d-flex justify-content-between align-items-center shadow sticky-top"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="w-100 d-flex justify-content-start"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="menu position-static"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Main Menu"
|
||||||
|
className="menu-trigger icon-button"
|
||||||
|
onClick={[Function]}
|
||||||
|
title="Main Menu"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5rem",
|
||||||
|
"width": "1.5rem",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<rect
|
||||||
|
fill="currentColor"
|
||||||
|
height="2"
|
||||||
|
width="20"
|
||||||
|
x="2"
|
||||||
|
y="5"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
fill="currentColor"
|
||||||
|
height="2"
|
||||||
|
width="20"
|
||||||
|
x="2"
|
||||||
|
y="11"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
fill="currentColor"
|
||||||
|
height="2"
|
||||||
|
width="20"
|
||||||
|
x="2"
|
||||||
|
y="17"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="w-100 d-flex justify-content-center"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="logo"
|
||||||
|
href="http://localhost:18000/dashboard"
|
||||||
|
itemType="http://schema.org/Organization"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
alt="edX"
|
||||||
|
className="d-block"
|
||||||
|
src="https://edx-cdn.org/v3/default/logo.svg"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="w-100 d-flex justify-content-end align-items-center"
|
||||||
|
>
|
||||||
|
<nav
|
||||||
|
aria-label="Secondary"
|
||||||
|
className="menu position-static"
|
||||||
|
onKeyDown={[Function]}
|
||||||
|
onMouseEnter={[Function]}
|
||||||
|
onMouseLeave={[Function]}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
aria-expanded={false}
|
||||||
|
aria-haspopup="menu"
|
||||||
|
aria-label="Account Menu"
|
||||||
|
className="menu-trigger icon-button"
|
||||||
|
onClick={[Function]}
|
||||||
|
title="Account Menu"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="avatar overflow-hidden d-inline-flex rounded-circle null"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5rem",
|
||||||
|
"width": "1.5rem",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
aria-hidden={true}
|
||||||
|
focusable="false"
|
||||||
|
height="24px"
|
||||||
|
role="img"
|
||||||
|
style={
|
||||||
|
Object {
|
||||||
|
"height": "1.5rem",
|
||||||
|
"width": "1.5rem",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version="1.1"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24px"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M4.10255106,18.1351061 C4.7170266,16.0581859 8.01891846,14.4720277 12,14.4720277 C15.9810815,14.4720277 19.2829734,16.0581859 19.8974489,18.1351061 C21.215206,16.4412566 22,14.3122775 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,14.3122775 2.78479405,16.4412566 4.10255106,18.1351061 Z M12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 Z M12,13 C9.790861,13 8,11.209139 8,9 C8,6.790861 9.790861,5 12,5 C14.209139,5 16,6.790861 16,9 C16,11.209139 14.209139,13 12,13 Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
`;
|
||||||
@@ -1,186 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`<SiteHeader /> renders correctly for desktop 1`] = `
|
|
||||||
<header
|
|
||||||
className="site-header-desktop"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="container-fluid"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="nav-container position-relative d-flex align-items-center"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
className="logo"
|
|
||||||
href="http://localhost:18000/dashboard"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
alt="edX"
|
|
||||||
className="d-block"
|
|
||||||
src="test-file-stub"
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
<nav
|
|
||||||
aria-label="Main"
|
|
||||||
className="nav main-nav"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
className="nav-link"
|
|
||||||
href="http://localhost:18000/dashboard"
|
|
||||||
>
|
|
||||||
Courses
|
|
||||||
</a>
|
|
||||||
</nav>
|
|
||||||
<nav
|
|
||||||
aria-label="Secondary"
|
|
||||||
className="nav secondary-menu-container align-items-center ml-auto"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
className="btn mr-2 btn-link"
|
|
||||||
href="http://localhost:18000/login"
|
|
||||||
>
|
|
||||||
Login
|
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
className="btn mr-2 btn-outline-primary"
|
|
||||||
href="http://localhost:18000/register"
|
|
||||||
>
|
|
||||||
Sign Up
|
|
||||||
</a>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`<SiteHeader /> renders correctly for mobile 1`] = `
|
|
||||||
<header
|
|
||||||
aria-label="Main"
|
|
||||||
className="site-header-mobile d-flex justify-content-between align-items-center shadow sticky-top"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="w-100 d-flex justify-content-start"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="menu position-static"
|
|
||||||
onKeyDown={[Function]}
|
|
||||||
onMouseEnter={[Function]}
|
|
||||||
onMouseLeave={[Function]}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
aria-expanded={false}
|
|
||||||
aria-haspopup="menu"
|
|
||||||
aria-label="Main Menu"
|
|
||||||
className="menu-trigger icon-button"
|
|
||||||
onClick={[Function]}
|
|
||||||
title="Main Menu"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
aria-hidden={true}
|
|
||||||
focusable="false"
|
|
||||||
height="24px"
|
|
||||||
role="img"
|
|
||||||
style={
|
|
||||||
Object {
|
|
||||||
"height": "1.5rem",
|
|
||||||
"width": "1.5rem",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
version="1.1"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
width="24px"
|
|
||||||
>
|
|
||||||
<rect
|
|
||||||
fill="currentColor"
|
|
||||||
height="2"
|
|
||||||
width="20"
|
|
||||||
x="2"
|
|
||||||
y="5"
|
|
||||||
/>
|
|
||||||
<rect
|
|
||||||
fill="currentColor"
|
|
||||||
height="2"
|
|
||||||
width="20"
|
|
||||||
x="2"
|
|
||||||
y="11"
|
|
||||||
/>
|
|
||||||
<rect
|
|
||||||
fill="currentColor"
|
|
||||||
height="2"
|
|
||||||
width="20"
|
|
||||||
x="2"
|
|
||||||
y="17"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className="w-100 d-flex justify-content-center"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
className="logo"
|
|
||||||
href="http://localhost:18000/dashboard"
|
|
||||||
itemType="http://schema.org/Organization"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
alt="edX"
|
|
||||||
className="d-block"
|
|
||||||
src="test-file-stub"
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className="w-100 d-flex justify-content-end align-items-center"
|
|
||||||
>
|
|
||||||
<nav
|
|
||||||
aria-label="Secondary"
|
|
||||||
className="menu position-static"
|
|
||||||
onKeyDown={[Function]}
|
|
||||||
onMouseEnter={[Function]}
|
|
||||||
onMouseLeave={[Function]}
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
aria-expanded={false}
|
|
||||||
aria-haspopup="menu"
|
|
||||||
aria-label="Account Menu"
|
|
||||||
className="menu-trigger icon-button"
|
|
||||||
onClick={[Function]}
|
|
||||||
title="Account Menu"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className="avatar overflow-hidden d-inline-flex rounded-circle null"
|
|
||||||
style={
|
|
||||||
Object {
|
|
||||||
"height": "1.5rem",
|
|
||||||
"width": "1.5rem",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
aria-hidden={true}
|
|
||||||
className="text-muted"
|
|
||||||
focusable="false"
|
|
||||||
height="24px"
|
|
||||||
role="img"
|
|
||||||
style={
|
|
||||||
Object {
|
|
||||||
"height": "1.5rem",
|
|
||||||
"width": "1.5rem",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
version="1.1"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
width="24px"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M4.10255106,18.1351061 C4.7170266,16.0581859 8.01891846,14.4720277 12,14.4720277 C15.9810815,14.4720277 19.2829734,16.0581859 19.8974489,18.1351061 C21.215206,16.4412566 22,14.3122775 22,12 C22,6.4771525 17.5228475,2 12,2 C6.4771525,2 2,6.4771525 2,12 C2,14.3122775 2.78479405,16.4412566 4.10255106,18.1351061 Z M12,24 C5.372583,24 0,18.627417 0,12 C0,5.372583 5.372583,0 12,0 C18.627417,0 24,5.372583 24,12 C24,18.627417 18.627417,24 12,24 Z M12,13 C9.790861,13 8,11.209139 8,9 C8,6.790861 9.790861,5 12,5 C14.209139,5 16,6.790861 16,9 C16,11.209139 14.209139,13 12,13 Z"
|
|
||||||
fill="currentColor"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</nav>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
`;
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import SiteHeader from './SiteHeader';
|
import Header from './Header';
|
||||||
import messages from './i18n/index';
|
import messages from './i18n/index';
|
||||||
|
|
||||||
export { messages };
|
export { messages };
|
||||||
|
|
||||||
export default SiteHeader;
|
export default Header;
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ $white: #fff;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.site-header-mobile {
|
.site-header-mobile {
|
||||||
|
height: 3rem;
|
||||||
|
|
||||||
.nav-link {
|
.nav-link {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -43,7 +45,6 @@ $white: #fff;
|
|||||||
|
|
||||||
|
|
||||||
.site-header-desktop {
|
.site-header-desktop {
|
||||||
height: 3.75rem;
|
|
||||||
box-shadow: 0 1px 0 0 rgba(0,0,0,.1);
|
box-shadow: 0 1px 0 0 rgba(0,0,0,.1);
|
||||||
background: $white;
|
background: $white;
|
||||||
.nav-link {
|
.nav-link {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 17 KiB |
@@ -11,7 +11,6 @@ Enzyme.configure({ adapter: new Adapter() });
|
|||||||
process.env.ACCESS_TOKEN_COOKIE_NAME = 'edx-jwt-cookie-header-payload';
|
process.env.ACCESS_TOKEN_COOKIE_NAME = 'edx-jwt-cookie-header-payload';
|
||||||
process.env.BASE_URL = 'localhost:1995';
|
process.env.BASE_URL = 'localhost:1995';
|
||||||
process.env.CREDENTIALS_BASE_URL = 'http://localhost:18150';
|
process.env.CREDENTIALS_BASE_URL = 'http://localhost:18150';
|
||||||
process.env.CSRF_COOKIE_NAME = 'csrftoken';
|
|
||||||
process.env.CSRF_TOKEN_API_PATH = '/csrf/api/v1/token';
|
process.env.CSRF_TOKEN_API_PATH = '/csrf/api/v1/token';
|
||||||
process.env.ECOMMERCE_BASE_URL = 'http://localhost:18130';
|
process.env.ECOMMERCE_BASE_URL = 'http://localhost:18130';
|
||||||
process.env.LANGUAGE_PREFERENCE_COOKIE_NAME = 'openedx-language-preference';
|
process.env.LANGUAGE_PREFERENCE_COOKIE_NAME = 'openedx-language-preference';
|
||||||
@@ -24,3 +23,7 @@ process.env.REFRESH_ACCESS_TOKEN_ENDPOINT = 'http://localhost:18000/login_refres
|
|||||||
process.env.SEGMENT_KEY = 'segment_whoa';
|
process.env.SEGMENT_KEY = 'segment_whoa';
|
||||||
process.env.SITE_NAME = 'edX';
|
process.env.SITE_NAME = 'edX';
|
||||||
process.env.USER_INFO_COOKIE_NAME = 'edx-user-info';
|
process.env.USER_INFO_COOKIE_NAME = 'edx-user-info';
|
||||||
|
process.env.LOGO_URL = 'https://edx-cdn.org/v3/default/logo.svg';
|
||||||
|
process.env.LOGO_TRADEMARK_URL = 'https://edx-cdn.org/v3/default/logo-trademark.svg';
|
||||||
|
process.env.LOGO_WHITE_URL = 'https://edx-cdn.org/v3/default/logo-white.svg';
|
||||||
|
process.env.FAVICON_URL = 'https://edx-cdn.org/v3/default/favicon.ico';
|
||||||
|
|||||||
15
webpack.dev.config.js
Normal file
15
webpack.dev.config.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const { createConfig } = require('@edx/frontend-build');
|
||||||
|
|
||||||
|
module.exports = createConfig('webpack-dev', {
|
||||||
|
entry: path.resolve(__dirname, 'example'),
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'example/dist'),
|
||||||
|
publicPath: '/',
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'@edx/frontend-component-header': path.resolve(__dirname, 'src'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user