9.4.1 • Published 2 days ago

@financial-times/dotcom-ui-layout v9.4.1

Weekly downloads
613
License
MIT
Repository
-
Last release
2 days ago

@financial-times/dotcom-ui-layout

This package composes the basic page layout, including selection of the header and footer variants, and insertion of elements that prepend/append them.

Getting started

This package is compatible with Node 12+ and is distributed on npm.

npm install --save @financial-times/dotcom-ui-layout

After installing the package you can use it to wrap your application views and pages. The layout includes the global UI elements so you can focus on the contents of your pages.

Usage with JSX

If you're using React and JSX you can use the <Layout /> component to wrap your existing component tree.

import React from 'react'
import Home from './pages/Home'
import { Layout } from '@financial-times/dotcom-ui-layout'

const page = <Layout {...options}><App /></Layout>

Please note that the layout component is designed to be used on the server-side. It can be rendered on the client-side but there is not usually a good reason to do so. If possible you should consider <App /> as your application root and client-side mounting point.

Usage without JSX

If your application is not using React or JSX then you can still use the Layout component via React's createElement() function to wrap your existing HTML. In this case the contents option is used to pass in a pre-rendered string of HTML.

const React = require('react')
const renderApp = require('./lib/render-app')
const { Layout } = require('@financial-times/dotcom-ui-layout')

const html = renderApp()
const page = React.createElement(Layout, { contents: html, ...options })

Rendering to a string

However you are integrating the layout component with your application you will need to convert the output from a React element to a string or stream of HTML to send to your application's users. You need to use the react-dom package for this:

const ReactDOM = require('react-dom/server')
const outputHTML = ReactDOM.renderToStaticMarkup(document)

For a full example for how to use this component please refer to the FT UI example app.

Styles

This component includes styles written in Sass which includes the styles for n-ui-foundations and the header and footer components. It can be imported into your application's main Sass stylesheet:

@import '@financial-times/dotcom-ui-layout/styles';

It is also possible to build the layout styles individually, for example to improve long-term caching. If you integrate the layout styles this way then you may need to add a dependency on n-ui-foundations and import its mixins into your app's main Sass stylesheet:

@import 'n-ui-foundations/mixins';

Please note that the exact usage will depend on how you configure your Sass compiler and whether or not you are using Bower to install dependencies.

Options

Props

PROPTYPEOPTIONALDEFAULTDESCRIPTION
navigationDataTNavigationDatatrue*undefinedRequired if using the built in header and/or footer components. See note below.
headerVariant'simple' | 'large-logo' | 'logo-only'| 'no-outbound-links'| falsetrue"simple"The type of built in header to display
headerBeforestring | ReactElementtrueundefinedA slot for content to appear before Header
headerAfterstring | ReactElementtrueundefinedA slot for content to appear after Header
headerOptionsTHeaderPropstrueundefinedPass options to the header component
headerComponentReactElementtrueundefinedPass a custom header
footerVariant'simple' | 'legal' | falsetrue"simple"The type of built in footer to display
footerBeforestring | ReactElementtrueundefinedA slot for content to appear before Footer
footerAfterstring | ReactElementtrueundefinedA slot for content to appear after Footer
footerOptionsTFooterPropstrueundefinedPass options to the footer component
footerComponentReactElementtrueundefinedPass a custom footer
contentsstringtrueundefinedA prerendered string of HTML used to insert the page contents when not using JSX composition

* Navigation data is required to render all header variants except for "logo-only". Navigation data is required to render all built in footer components. It is recommended to integrate the navigation package with your application to get navigation data.

Custom components

All slots accept both custom React components or a string of HTML.

import { Layout } from '@financial-times/dotcom-ui-layout'

const adBannerHTML = getAdBanner(id) // => <iframe>...<iframe>

<Layout
  headerBefore={adBannerHTML}
  headerComponent={<CustomHeader />}
  headerAfter={adBannerHTML}
  footerComponent={<CustomFooter />}
/>
9.4.1

2 days ago

9.4.0

23 days ago

9.3.4

3 months ago

8.2.6

3 months ago

9.3.3

3 months ago

9.3.2

4 months ago

9.3.1

4 months ago

9.3.0

4 months ago

9.2.1

4 months ago

9.2.0

4 months ago

9.1.1

4 months ago

9.1.0

5 months ago

9.0.3

5 months ago

8.2.3

7 months ago

8.2.2

7 months ago

8.2.5

7 months ago

9.0.0-beta.5

9 months ago

9.0.0-beta.4

9 months ago

9.0.0-beta.3

9 months ago

9.0.0-beta.2

9 months ago

9.0.0-beta.1

9 months ago

9.0.0-beta.9

8 months ago

9.0.0-beta.8

8 months ago

9.0.0-beta.7

8 months ago

9.0.0-beta.6

8 months ago

8.2.1

8 months ago

8.2.0

8 months ago

9.0.2

6 months ago

9.0.1

7 months ago

9.0.0-beta.15

7 months ago

9.0.0-beta.16

7 months ago

9.0.0-beta.13

8 months ago

9.0.0-beta.14

8 months ago

9.0.0-beta.11

8 months ago

9.0.0-beta.12

8 months ago

9.0.0-beta.10

8 months ago

8.1.0

11 months ago

7.3.5

1 year ago

7.3.4

1 year ago

8.0.0

1 year ago

7.3.3

1 year ago

7.3.2

1 year ago

7.3.1

1 year ago

7.3.0

1 year ago

7.2.6

1 year ago

7.2.7

1 year ago

7.1.3

2 years ago

7.2.5

1 year ago

7.2.4

2 years ago

7.1.4

2 years ago

7.1.1

2 years ago

7.1.0

2 years ago

7.0.0

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.2

2 years ago

5.1.0

2 years ago

4.2.0

2 years ago

5.0.0

2 years ago

4.0.0

2 years ago

4.1.0

2 years ago

3.0.0

2 years ago

2.6.1

3 years ago

2.6.2

3 years ago

2.6.0

3 years ago

2.5.2

3 years ago

2.5.1

3 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0-pre.1

4 years ago

2.1.0

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.6.5

4 years ago

0.7.0-beta.1

4 years ago

0.7.0-beta.2

4 years ago

0.7.0

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.8

4 years ago

0.5.7

4 years ago

0.5.6

4 years ago

0.5.5

4 years ago

0.4.5

4 years ago

0.5.4

4 years ago

0.4.4

4 years ago

0.5.3

4 years ago

0.5.2

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.5.0-beta.3

4 years ago

0.5.0-beta.1

4 years ago

0.5.0-beta.2

4 years ago

0.4.1

4 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.1-test.2

5 years ago

0.0.1-test.1

5 years ago