GithubHelp home page GithubHelp logo

canonical / global-nav Goto Github PK

View Code? Open in Web Editor NEW
5.0 14.0 23.0 1.63 MB

A script and stylesheet that displays the Canonical global nav across the top of a site

Home Page: https://www.npmjs.com/package/@canonical/global-nav

HTML 24.81% JavaScript 37.74% Shell 27.04% Dockerfile 0.92% SCSS 9.49%
navigation npm banner javascript package npm-package web-and-design

global-nav's Introduction

Canonical Global Nav

This project contains the JavaScript and styles to add an "All Canonical" navigation dropdown item to the Vanilla navigation pattern.

The dropdown contains a list of Canonical eco-system websites, giving a user the ability to jump around the core sites easily.

Usage

Use a node package manager to install this component and then link the JS file into the head of your site, with optional settings.

The styles will automatically be injected into the page's <head>.

  1. Install via yarn or npm
yarn add @canonical/global-nav

...or...

npm install @canonical/global-nav --save
  1. You can then install the library either by directly linking to it or via ES6 imports.

To consume the library directly, add a link to the JS file containing an IIFE and run the canonicalGlobalNav.createNav() function;

<script src="/node_modules/@canonical/global-nav/dist/iife.js"></script>
<script>
  canonicalGlobalNav.createNav();
</script>

To import it, simply call it from your site-wide JS file;

import { createNav } from '@canonical/global-nav';
createNav();
  1. You will then need to add the .global-nav class to a ul.p-navigation__items element within the navigation pattern. The module will look for this class and add the dropdown as the first item in the list.

Options

The createNav function takes an object of options with the following property:

  • breakpoint: The point, in pixels, at which the navigation switches between desktop and mobile layouts. The default is 620px, which is meant to reflect the default value of $breakpoint-navigation-threshold in Vanilla (see Vanilla's breakpoint documentation).

  • mobileContainerSelector and desktopContainerSelector: Selectors (can be 'id' or 'class') of where to attach the mobile and desktop views of the global-nav. This will also circumvent the default eventListeners being attached as they are dependent on the default structure, so custom JS will be nessacary. Also in this case, the class global-nav should still be used to indicate the position of the 'All Canonical' tab button. If ony one is used it will render the default global nav.

If the $breakpoint-navigation-threshold Vanilla variable is overridden in your project, you will need to set this option on the global nav.

For example, to set the breakpoint to 1036:

<script src="/node_modules/@canonical/global-nav/dist/index.js"></script>

<script>
  canonicalGlobalNav.createNav({
    breakpoint: 1036,
    mobileContainerSelector: 'global-nav-mobile',
    desktopContainerSelector: 'global-nav-desktop',
  });
</script>

If you're importing;

import { createNav } from '@canonical/global-nav';
createNav({ breakpoint: 1036 });

Building the Global nav

To build the JS into the /dist folder, run:

./run build

Running the project locally

The simplest way to run the site locally is to first install Docker (on Linux you may need to add your user to the docker group), and then use the ./run script:

./run

You can also use the dotrun snap, by running:

dotrun

Once the containers are setup, you can visit http://127.0.0.1:8300 in your browser.

Watching changed files

For working on Sass files and JS files , you may want to dynamically watch for changes to rebuild the dist files whenever something changes.

To setup the watcher, open a new terminal window and run:

./run watch

Before submitting your pull request, run the tests - which checks both the JS and Sass for errors.

./run test

How to add inline svgs

Just because this was a bit of a pain, here is what I did.

  1. Shrink the svg as much as possible
  2. Upload it to the asset server for others - OPTIONAL
  3. View it in a browser and grab the source code.
  4. Convert the quotes from double " to single ' - CRITICAL
  5. Encode the svg
  6. Add this with data:image/svg+xml, in the right place in product-details.js

Vanilla updates

This project uses the Vanilla framework as a dependency in two ways: the SCSS files are imported directly to build the styles of the global-nav itself (via the vanilla-framework npm package, as defined in dependencied in package.json) and for styling the demo page (via direct link in the index.html file).

When updating Vanilla to latest version both dependencies should be updated.

Release process

The package is versioned using semantic versioning and published to the NPM registry.

To cut a new release run:

npm version [patch|minor|major]

This will trigger the prepublishonly script which will ensure requisite artefacts are built before publishing.

Code licensed LGPLv3 by Canonical Ltd.

With ♥ from Canonical

global-nav's People

Contributors

albertkol avatar anthonydillon avatar b-m-f avatar barrymcgee avatar bartaz avatar bethcollins92 avatar caleb-ellis avatar carkod avatar deadlight avatar dependabot[bot] avatar edlerd avatar fitojb avatar goulinkh avatar hatched avatar jkfran avatar jpmartinspt avatar juanruitina avatar minkyngkm avatar mtruj013 avatar nottrobin avatar pedoch avatar petesfrench avatar pmahnke avatar renovate-bot avatar renovate[bot] avatar richmccartney avatar solazio avatar sowasred2012 avatar steverydz avatar willmoggridge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

global-nav's Issues

Lint the Scss

Currently there are some lint issues in the Scss. These should pass.

Make "login" section optional

The "login" section in the global nav is problematic - it doesn't do what you expect, effectively duplicates content from "products", and makes it difficult to put the global nav on sites with their own login, like snapcraft.io.

I believe the simplest solution is to simply remove it as I don't think it adds anything.

Could we do this?

Investigate other methods of building HTML elements with JS

At the moment, the global-nav builds a huge amount of markup from strings using a simple string-to-HTML-element helper function. We should investigate better methods of building HTML elements with JS, because at the moment it feels a little bit hacky.

Options include:

  • Javascript templates
  • JSX (without React)
  • Web components

Allow injection of additional links

On snapcraft.io we want to add a "We're hiring" link, seems it would ideally be injected into the global nav. Other sites may also have use for this in the future.

screenshot_2018-09-13 the leading operating system for pcs iot devices servers and the cloud ubuntu

It's possible to focus on nav items when the nav is closed

From accessibility workshop:

To reproduce:

  • Tab to "Products"
  • Press Enter
  • Tab through the links
  • Tab backwards to "Products" and press Enter to close the nav
  • Press tab several times, focus state will be lost because focus has moved to items within the closed nav (doesn't seem to happen before the nav is opened for the first time)

Would be good to include a MOTD as part of the global navigation

To announce important releases, features, products or new job positions available might be a good idea to have a link as part of the global navigation:

image

Obviously this will be compromised on mobile but we can either show a short form of it or just hide it completely.

Mobile view
image

BEM is component

This should be a BEM component. For example:

.global-nav
  ....
  .global-nav__list
  ...
  .global-nav__list--more
  ...

Add CI

With each PR created it should trigger a CI of the lint and test.

Retire the “Login” menu

Summary: The “Login” menu in the global nav should be retired, to make way for account UI on ubuntu.com Ubuntu Advantage pages (requested by Mark), as well as solving other IA problems.


The Canonical global nav currently includes a “Login” menu at top right, containing links to Ubuntu Advantage, Landscape, Livepatch, Launchpad.net, Snapcraft.io, and JAAS. Unfortunately:

  • Unlike almost every other site with a “Login” control, this menu never lets you “Login” to the site you’re on. Only one of those six sites — snapcraft.io — uses the global nav itself, and even it hides the “Login” menu because if it was present it would suggest that you were not signed in when really you were.
  • Three of the six items are duplicates of items in the “Products” menu right next door — “Landscape”/“Landscape”, “Juju”/“JAAS”, and “Snaps”/“Snapcraft.io” — indicating that something is wrong with the IA.
  • The menu is titled “CUSTOMER PORTALS”, which, marketing jargon aside, covers only four of the six items. Launchpad.net is used mainly by Ubuntu contributors rather than customers, and snapcraft.io is used by app developers who often aren’t customers either.

The work for ubuntu.com to show your Ubuntu Advantage tokens — and later, other details of your paid Ubuntu Advantage subscriptions (Ubuntu-design#133) — involves showing whether you are signed in, and if so as who. My current design puts this info in the body of the page, because if it was anywhere near the header, the global nav’s “Login” would become even more confusing.

Mark would like to “have your username in the header” on these Ubuntu Advantage pages. One way to do this would be for ubuntu.com to follow the lead of snapcraft.io, in hiding the global nav’s “Login”. But this would obscure access to the three items in the menu that aren’t duplicates of items in the Products menu. A simpler solution is to move those non-duplicate items to the “Products” menu, and to retire the “Login” menu altogether.

Rendered link is missing text

<a class="global-nav__header-logo-anchor" href="https://www.canonical.com"> 
  <img src="https://assets.ubuntu.com/v1/9c74eb2d-logo-canonical-white.svg" width="74px"> 
</a>

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined

Add JS tests

We should have full unit tests for the function in the JS.

NodeList.forEach doesn't always exist.

We have been getting a number of errors on jaas.ai because NodeList does not have a forEach method in older browsers. In the following line headerLinks therefore does not return an object which has a forEach function.

https://github.com/canonical-web-and-design/global-nav/blob/af963ffc4ac1e34c138d31715744421d3a220a56/src/js/global-nav.js#L261

Even though these browsers are outside of our supported matrix we should make it more resilient. The fix here is rather trivial by modifying the iterator we use to loop over the collection.

MacOS - closed nav visible on scroll

MacOS has 'elastic scroll' allowing you to scroll over the top or bottom of the page.
This makes global-nav dropdown visible.

  1. Go to page with global nav on MacOS (https://ubuntu.com, https://microk8s.io, https://mir-server.io)
  2. Scroll up (over the edge of the page) - white backround will appear over the global nav
  3. Open global nav Products
  4. Close global nav Products
  5. Scroll up again over the top edge

The bottom of "Products" menu is visible. If you scroll fast you can see quite a bunch of it:
screen shot 2018-12-14 at 11 55 38

Discovered when QAing canonical/snapcraft.io#1449

Top margin on .global-nav__list

On the .global-nav__list element, webkit browsers are adding a 1em top margin.

This can be fixed by giving the class 0 top margin.

Make global-nav an NPM package

And change the README to suggest installing via NPM.

This is because (as far as I remember) we agreed to no longer use Bower packages.

Considering Careers on the global nav

As part of the global navigation, it will be good to consider other sections that might be of interesting when you are visiting a product from Canonical. For example, careers.

Just thinking out loud here but at Europython we had many developers asking for who was behind snapcraft as it is a nebulous term looking through the site. When we mentioned Canonical being the company behind snaps, then the Canonical brand and the ubuntu one lifted our pitch with positive resonance related to these brands in the dev community.

In regards to Careers, a big percentage of our new positions available are for engineers. Taking into account that the main audience for snapcraft are developers, it will be easier to find prospective candidates within users of the platform rather than looking outside. Since Canonical is ultimately the company hiring, it will make sense to find some space in the global nav for careers.

Might be good to find some time to discuss as a WG initiative at some point.

Global nav login links followed by empty <ul>'s

@lyubomir-popov commented on Fri May 01 2020

Summary

Spacing in the global nav is uneven due to empty uls image

Process

Open the global nav, inspect the Login > links, look for empty uls after them

Current and expected result

Current:
image

Taking the uls out and (optionally) adding a .u-no-padding--bottom on .global-nav__inline-list element (the parent .global-nav__matrix-item already provides enough padding):

image

Design review changes

  • It shouldn't be dark on small screens. Can we keep the same colour across breakpoints?
  • The links should align left with the external icon - in small screens
  • It looks like there are rounded corners top left/right corners
  • In large screens when More is selected can we remove the borders around More?

Injecting the global nav into top of page flow causes jarring jump

After the page is rendered and painted, the global nav injection script fires, pushes all page content down by 32px and causes the page render and paint process to refire meaning the whole process is intensive and feels slow.

See on Ubuntu: https://cl.ly/8eb99b16eb16

See on demo page: https://cl.ly/dfed49e5b80c

By adding a placeholder div into the page, 32px high with a black background, this jump disappears and the whole process becomes indecipherable: https://cl.ly/9d00c55b8aab

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.


  • Check this box to trigger a request for Renovate to run again on this repository

Create deployment system

Once this project hits v1 we should create a button push releasing and updating the project on the asset server.

Small screen positioning on the bottom doesn't work with sticky footer

Global nav on small screens currently positions itself on the bottom of the page using absolute positioning.

It's a tricky thing by itself, as it requires additional margin on the bottom and assumes no other styles on body will affect it.

One of the things that does affect it is a sticky footer. Snapcraft.io uses one, Vanilla has it as utility (vf-u-sticky-footer). They set html and body height to 100% (to make sticky footer work) and this causes global nav to appear in the bottom of the browser screen rather bottom of the page. And global nav (absolutely positioned) keeps it's position when scrolled making it appear in the middle of the page.

screen shot 2018-12-14 at 12 01 46

Discovered when QAing canonical/snapcraft.io#1449

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.