npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@financial-times/dotcom-ui-layout

v9.3.4

Published

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

Downloads

7,770

Readme

@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

| PROP | TYPE | OPTIONAL | DEFAULT | DESCRIPTION | |-----------------|-------------------------------------------------|----------|-------------|----------------------------------------------------------------------------------------------| | navigationData | TNavigationData | true* | undefined | Required if using the built in header and/or footer components. See note below. | | headerVariant | 'simple' | 'large-logo' | 'logo-only'| 'no-outbound-links'| false | true | "simple" | The type of built in header to display | | headerBefore | string | ReactElement | true | undefined | A slot for content to appear before Header | | headerAfter | string | ReactElement | true | undefined | A slot for content to appear after Header | | headerOptions | THeaderProps | true | undefined | Pass options to the header component | | headerComponent | ReactElement | true | undefined | Pass a custom header | | footerVariant | 'simple' | 'legal' | false | true | "simple" | The type of built in footer to display | | footerBefore | string | ReactElement | true | undefined | A slot for content to appear before Footer | | footerAfter | string | ReactElement | true | undefined | A slot for content to appear after Footer | | footerOptions | TFooterProps | true | undefined | Pass options to the footer component | | footerComponent | ReactElement | true | undefined | Pass a custom footer | | contents | string | true | undefined | A 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 />}
/>