Skip to content

Living style guide for SEEK, powered by React, webpack, CSS Modules and Less.

License

Notifications You must be signed in to change notification settings

brian-captain-crosby/seek-style-guide

 
 

Repository files navigation

Build Status npm Greenkeeper David David David semantic-release Commitizen friendly

seek-style-guide

Living style guide for SEEK, powered by React, webpack, CSS Modules and Less.

If you're creating a new project from scratch, consider using sku, our officially supported front-end development toolkit. It's specially designed to get your project up and running as quickly as possible, while simplifying the process of keeping your development environment up to date.

If you'd instead like to work on a custom webpack project, you can use seek-style-guide-webpack to streamline the integration process.

Installation

$ npm install --save seek-style-guide react react-dom react-helmet

Optionally, if not making use of the React components, you can install seek-style-guide by itself:

$ npm install --save seek-style-guide

Upgrading

Consumers can stay up to date by following our release notes, which are published automatically whenever a new release is published to npm.

Setup

Wrap your app with the StyleGuideProvider component to use any of the style guide components. For example:

import React, { Component } from 'react';
import { StyleGuideProvider } from 'seek-style-guide/react';

export default class App extends Component {
  render() {
    const locale = 'AU';
    const title = '...';
    const meta = [
      { name: 'description', content: '...' }
    ];
    const link = [
      { rel: 'canonical', href: 'https://www.seek.com.au/' }
    ];

    return (
      <StyleGuideProvider locale={locale} title={title} meta={meta} link={link}>
        ...
      </StyleGuideProvider>
    );
  }
};

StyleGuideProvider's props are used to set the page head properties using Helmet.

Applying the Standard Header and Footer

The standard header and footer are provided as React components:

import { Header, Footer } from 'seek-style-guide/react';

The <Header> component accepts the following props:

  • locale: 'AU' (default) or 'NZ'
  • authenticated: null/undefined (default, authentication pending), true or false
  • userName: User's display name, when authenticated
  • activeTab: Text of the active tab, e.g. 'Job Search'
  • divider: true (default, renders a blue divider below the navigation tabs) or false
  • linkRenderer: Function to allow custom rendering of links. The default implementation simply renders a standard link, spreading all props: props => <a {...props} />

The <Footer> component accepts the following props:

  • locale: See above.
  • linkRenderer: See above.

High Level Components

As much as possible, you should aim to minimise the amount of custom CSS you need to write. This is achieved by leveraging our suite of high level components, which are demonstrated on our style guide documentation site.

Low Level Styling

For more advanced pages, if you need to drop down into Less, the style guide provides a set of mixins and variables to make it easier to stay on brand.

In any style sheet that depends on the style guide, first import the Less theme by reference.

@import (reference) "~seek-style-guide/theme";

Responsive Breakpoint

The style guide exposes one responsive breakpoint:

@responsive-breakpoint: 740px;

Content should otherwise be responsive within its container. The set of included components follow this model internally if you'd like to get a sense of what this looks like in practice.

Color Variables

As much as possible, colors should be directly imported from the style guide.

The following colors are provided:

// Brand colors
@sk-blue
@sk-pink
@sk-green
@sk-purple
@sk-teal

// Partner brand colors
@sk-business
@sk-volunteer
@sk-learning-light
@sk-learning-medium
@sk-learning-dark

// Grays
@sk-black
@sk-charcoal
@sk-mid-gray-dark
@sk-mid-gray-medium
@sk-mid-gray
@sk-mid-gray-light
@sk-gray-light
@sk-gray-lightest
@sk-off-white
@sk-white

// Element colors
@sk-link
@sk-link-visited
@sk-focus
@sk-highlight
@sk-green-light
@sk-yellow
@sk-yellow-light
@sk-footer
@sk-background
@sk-yellow

Z-Indexes

To ensure correct relative elements stacking order, z-index variables are provided:

@z-index-header-overlay
@z-index-header
@z-index-page-overlay
@z-index-inline-overlay
@z-index-negative

Accessible Color Variants

The contrast ratio of certain foreground/background color combinations don't meet the AA accessibility standards that we aim for. As a result, a suite of accessible variants have been provided:

@sk-mid-gray-on-white
@sk-pink-on-gray-light
@sk-learning-dark-on-gray-light
@sk-business-on-gray-light
@sk-link-on-mid-gray-light
@sk-mid-gray-dark-on-gray-light

Please note that this list is not exhaustive, so contributions are encouraged. To validate color combinations, we recommend the use of the web-based tool Accessible Colors by @moroshko.

Grid Variables

In order to ensure elements correctly follow the grid, element sizing should always be controlled by the following variables:

@grid-row-height
@grid-gutter-width
@grid-column-width
@grid-container-width

When defining a document content container:

.element {
  max-width: @grid-container-width;
}

When defining heights and vertical padding/margins:

.element {
  height: (@grid-row-height * 3);
  padding-bottom: @grid-row-height;
  margin-bottom: @grid-row-height;
}

When defining widths and horizontal padding/margins:

.element {
  width: (@grid-column-width * 3);
  padding-right: @grid-gutter-width;
  margin-right: @grid-column-width;
}

It's important to note that any additions to these values (e.g. borders) will need to be negated to maintain rhythm:

.element {
  @border-width: 1px;
  border-bottom: @border-width solid @sk-charcoal;
  padding-bottom: @grid-row-height - @border-width;
}

Standalone Header and Footer

If you're maintaining or updating a non-React app, a standalone JS + CSS package is provided when installing from npm. The bundled JavaScript is provided as a UMD package, providing a global SeekHeaderFooter object as a fallback for older apps without a proper module system.

First, include the following files in your app:

  • seek-style-guide/dist/header-footer/styles.css
  • seek-style-guide/dist/header-footer/client.js

Then, add placeholder elements to your page:

  • <div id="header"></div>
  • <div id="footer"></div>

When the document is ready, render the header:

var header = SeekHeaderFooter.renderHeader(document.getElementById('header'), {
  ...initialProps
});

// Update props later, if needed:
header.updateProps({
  ...newProps
});

Finally, render the footer following a similar pattern:

var footer = SeekHeaderFooter.renderFooter(document.getElementById('footer'), {
  ...initialProps
});

// Update props later, if needed:
footer.updateProps({
  ...newProps
});

If you need to create React elements (e.g. when providing a linkRenderer function), the standalone bundle also exports React's createElement function so you don't need to install React separately to gain access to it:

var link = SeekHeaderFooter.createElement('a', { href: '/jobs' }, 'Jobs');

For more detail on accepted props, read the React documentation for applying the standard header and footer.

Advanced Usage

Optimising Imports

Note: If you're using sku, this optimisation is already enabled.

When importing from the style guide, while it might appear that you are only importing what's needed, it's highly likely that you're actually including the entire style guide in your application bundle (even when using tree shaking in webpack 2).

In order to help you optimise your bundle size, all components can be imported directly from their individual source files. For example, take a look at standard import statement:

import { Header, Footer } from 'seek-style-guide/react';

This can also be expressed as separate, file-level imports:

import Header from 'seek-style-guide/react/Header/Header.js';
import Footer from 'seek-style-guide/react/Footer/Footer.js';

Rather than transforming this manually, it's recommended that you leverage Babel instead, with babel-plugin-transform-imports configured to match the pattern used in this style guide.

To set this up, assuming you're already using Babel, first install the plugin:

npm install --save-dev babel-plugin-transform-imports

Then, include the following in your Babel config:

"plugins": [
  ["babel-plugin-transform-imports", {
    "seek-style-guide/react": {
      "transform": "seek-style-guide/react/${member}/${member}",
      "preventFullImport": true
    }
  }]
]

Contributing

Refer to CONTRIBUTING.md.

If you're planning to change the public API, please open a new issue and follow the provided RFC template in the GitHub issue template.

License

MIT.

About

Living style guide for SEEK, powered by React, webpack, CSS Modules and Less.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 81.9%
  • CSS 18.1%