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

@schlagerkhan/styled-components-layout

v0.2.4

Published

Simple layout components for styled-components

Downloads

3

Readme

Styled Components Media

This is an addon to styled-components to facilitate the layout of normal, centered websites. More specifically it mainly eases the management of the responsiveness and padding of the main content of the page.

OBS!

  • This package is closely related to @schlagerkhan/styled-components-media. You might want to read it's documentation before getting into this.
  • This package injects some properties into the styled-components default export. See more below.

Installation

npm install @schlagerkhan/styled-components-layout

or

yarn add @schlagerkhan/styled-components-layout

Usage

import styled from 'styled-components';
import { LayoutThemeProvider } from '@schlagerkhan/styled-components-layout';

const Layout = styled.Layout``;

const Header = styled.header``;

const Main = styled.Main``;

const Content = styled.Content``;

const Footer = styled.footer``;

export const App = () => (
    <LayoutThemeProvider>
        <Layout>
            <Header>
                <Content>
                    Header
                </Content>
            </Header>
            <Main>
                <Content>
                    This is the content
                </Content>
            </Main>
            <Footer>
                <Content>
                    Footer
                </Content>
        </Layout>
    </LayoutThemeProvider>
);

Components

The components have to be used in a specific hiearchy in order to work correctly. A model of them can be seen in the image below:

  1. Layout
    • Fills the entire page
  2. Header, Main, Footer
    • Header and Footer are not provided by this library
    • Main fills the space that is not occupied by header of footer.
  3. Content
    • Is centered by margin-left/right: auto
    • Has a responsive max width defined by the `LayoutThemeProvider``
    • Has a responsive padding defined in the same way.

Every level-2-component (Header, Main, Footer) that needs centered content can use the Content as a direct child (as in the code example above).

API

The package exposes the following modules/components:

LayoutThemeProvider

Extends the MediaThemeProvider from @schlagerkhan/styled-components-media which adds a default theme containing:

  • media - The object which upon which the responsiveness is based.
  • contentMediaMaxWidths - An object of max-widths corresponding to the (or some of the) media-widths.
  • contentMediaPaddings- The object of paddings corresponding to the (or some of the) media-widths

DEFAULT_CONTENT_MAX_WIDTHS

  • initial: 425

  • tablet: 600

  • laptop: 1024

Gives a the following max-widths for the specified viewports:

  • viewport < tablet: max-width: 425px
  • tablet <= viewport < laptop: max-width: 600px
  • laptop <= viewport: max-width: 1024px

DEFAULT_CONTENT_MEDIA_PADDINGS

  • initial: 16px
  • tablet: 24px
  • laptop: 48px

Give paddings in the same manner as for the max-widths

Layout

This component should be as close to the root as possible. Fills up the entire page.

It renders as a article html tag.

Layout, as all the react components exposed by this package, are injected into the styled-components default export object. This means that you don't have to explicitly import the components when you want to use them, you can use them such as:

const Layout = styled.Layout`...`;
const Main = styled.Main`...`;
const Content = styled.Content`...`;

Main

This component should be siblings with the header and the footer. It also have to be a child of the Layout component.

It fills up the space not occupied by any other sibling component.

It renders as a main html tag.

Content

This component is where the magic happens. It is centered using the margin-left/right: auto. Also, with the help of max/minWidth from the @schlagerkhan/styled-component-media project and the objects defined by the LayoutThemeProvider it creates a responsive component that updates it's max-width and horizontal paddings depending on the current viewport.

In this way you can always use the Content tag to center your content in the same way all across your application.

It renders as a div tag.

Contribute

Pull requests are welcome.

License

MIT