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

react-layout-views

v0.4.0

Published

Easy layouts for React & React Native

Downloads

20

Readme

React Layout Views

Easy layouts for React & React Native

See live examples

Why

Creating UI layouts should be simple and declarative.

The aim of this library is to provide an intuitive API for composing layouts by abstracting away certain flex concepts like axis alignment and replacing these with more intuitive terms like horizontal, bottom, right, and center.

Another goal of this library is to provide consistent spacing between layout elements.

Examples

See live examples

Horizontal

// This example produces a horizontal layout where 
// each section is spaced by 20px and the first section is 
// pushing its siblings to the right.

<Layout horizontal spacing='20px'>
  <Section grow>Content 1</Section>
  <Section>Content 2</Section>
  <Section>Content 3</Section>
</Layout>

Nested Layouts

// This example shows the previous example with
// the addition of a nested layout contained
// by the last section in the parent layout.

<Layout horizontal spacing='20px'>
  <Section grow>Content 1</Section>
  <Section>Content 2</Section>
  <Section>
    <Layout spacing='10px'>
      <Section>Content 1</Section>
      <Section>Content 2</Section>
      <Section>Content 3</Section>
    </Layout>
  </Section>
</Layout>

Styling

// This example shows how styles may be applied
// directly to `Layout` and `Section`.

<Layout horizontal spacing='20px' style={{background: 'red'}}> // does not produce inline styles
  <Section grow>Content 1</Section>
  <Section>Content 2</Section>
  <Section style={{padding: '1em'}}>Content 3</Section> // does not produce inline styles
</Layout>

Setup

Install

$ npm install react-layout-views

Import

import { Layout, Section } from 'react-layout-views' // web

// OR

import { Layout, Section } from 'react-layout-views/native' // native

...

API

<Layout />

A Layout wraps one or many Section components. By default child Sections are arranged vertically. Adding the horizontal prop arranges children across the X axis.

Spacing between child Sections is set via the spacing prop as a CSS length for web or number for React Native.

The grow prop is used to define how a Section fills available space inside a Layout. Alignment props (e.g. top, right, etc.) may be combined to position content.

Props

  • ideal width (flex-basis) of child Sections

By default, Layout will wrap Sections according to this value. On web, this can be any CSS length. Native accepts a number or percentage string.

  • align child Sections to bottom of available Layout area
  • combine with center, centerHorizontal, left, right
  • align child Sections to center X and Y of available Layout area
  • combine with top, right, bottom, left
  • align child Sections on the X axis
  • combine with top, bottom
  • align child Sections on the Y axis
  • combine with left, right

fill available space of parent Section or other flex element

align child Sections horizontally

  • align child Sections to the left
  • combine with top, bottom, center, centerVertical

prevent default wrapping of horizontal Layout

reverse order of child Sections

  • align child Sections to the right
  • combine with top, bottom, center, centerVertical
  • align child Sections to the right
  • combine with top, bottom, center, centerVertical
  • align child Sections to the top
  • combine with left, right, center, centerHorizontal
  • horizontal Layout's wrapped orphan Sections maintain their basis-defined widths and remain aligned with preceding row columns
  • useful for "card" layouts.

<Section />

The Section component subdivides a Layout and contains other components or another Layout. The grow prop is used to define how a Section fills available space inside a Layout. Alignment props (e.g. top, right, etc.) may be combined to position content.

Props

ideal width (flex-basis)

  • align content to bottom of available Section area
  • combine with center, centerHorizontal, left, right
  • align content to center X and Y axis of available Section area
  • combine with top, right, bottom, left
  • align content on the X axis of available Section area
  • combine with top, bottom
  • align content on the Y axis of available Section area
  • combine with left, right
  • fill available space in parent Layout
  • boolean sets value to 1
  • may be specified as a number (e.g. 0.5, 2, 50)
  • align content to the left of available Section area
  • combine with top, bottom, center, centerVertical
  • align content to the right of available Section area
  • combine with top, bottom, center, centerVertical
  • align content to the top of available Section area
  • combine with left, right, center, centerHorizontal

Develop

  • npm run setup install project and test app deps
  • npm run dist or npm run dist:watch - build
  • npm run apps:run - start storybook for web and native
  • npm run apps:test - run visual regression tests with loki