Code Monkey home page Code Monkey logo

global-nav's Introduction

Canonical Global Nav

This project contains the JavaScript and styles to display a banner across the top of a page.

This banner displays 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();

Options

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

  • maxWidth: The max-width of the global nav element (default: 68rem)

For example, to set the max-width to 80rem:

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

<script>
  canonicalGlobalNav.createNav({ maxWidth: '80rem' });
</script>
  • hiring: A URL for a hiring page which will display a link in the header to the job page (default: false)

For example, to set the hiring to https://boards.greenhouse.io/canonical/jobs/1586585

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

<script>
  canonicalGlobalNav.createNav({
    hiring: 'https://boards.greenhouse.io/canonical/jobs/1586585',
  });
</script>

If you're importing;

import { createNav } from '@canonical/global-nav';
createNav({ maxWidth: '80rem' });

Building the Global nav

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

##implest 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

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

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

anthonydillon avatar barrymcgee avatar renovate-bot avatar nottrobin avatar pmahnke avatar sowasred2012 avatar steverydz avatar renovate[bot] avatar dependabot[bot] avatar bethcollins92 avatar b-m-f avatar deadlight avatar caleb-ellis avatar bartaz avatar carkod avatar solazio avatar hatched avatar richmccartney avatar willmoggridge avatar fitojb avatar albertkol avatar jpmartinspt avatar mtruj013 avatar tbille avatar

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.