react-linear-layout

    3.0.0 • Public • Published

    react-linear-layout NPM Package

    ISC License

    A layout component that arranges children in a single row or column using CSS flexbox.

    At it's core, this component is basically a CSS flexbox. As such, all CSS flexbox properties are valid when styling a LinearLayout. The component consists of some sensible CSS defaults as well as a few CSS custom properties (see the documented CSS custom properties below for more details) that make styling item gaps (I.E. margins) and sizing of elements quite a bit easier.

    Storybook

    Changelog

    Install

    $ npm install --save react-linear-layout

    Basic Usage

    Storybook Examples

    MyLinearLayoutComponent.jsx

    import React from 'react';
     
    import LinearLayout from 'react-linear-layout';
    import 'react-linear-layout/react-linear-layout.css';
     
    import './MyLinearLayoutComponent.css';
     
     
    export default function MyLinearLayoutComponent(props) {
      return (
        <LinearLayout {...props} className="layout" direction="horizontal">
          <a>Anchor 0</a>
          <a>Anchor 1</a>
          <a>Anchor 2</a>
          <LinearLayout className="sub-layout" direction="vertical">
            <a>Sub Anchor 0</a>
            <a>Sub Anchor 1</a>
            <a>Sub Anchor 2</a>
          </LinearLayout>
        </LinearLayout>
      );
    }

    MyLinearLayoutComponent.css

    .layout {
      --linear-layout-item-gap: 5px;
    }
     
    .sub-layout > * {
      --linear-layout-item-gap: 20px;
    }

    Output (Text Representation)

    The component above will lay out it's children similar to the following:
     
        |----------|----------|----------|----------------|
        | Anchor 0 | Anchor 1 | Anchor 2 ||--------------||
        |          |          |          || Sub Anchor 0 ||
        |          |          |          ||--------------||
        |          |          |          || Sub Anchor 1 ||
        |          |          |          ||--------------||
        |          |          |          || Sub Anchor 2 ||
        |          |          |          ||--------------||
        |----------|----------|----------|----------------|

    Advanced Usage: Include CSS In Import

    Everything is the same as is presented in "Basic Usage" above except the imports are slightly different:

    MyLinearLayoutComponent.jsx

    import React from 'react';
     
    // Import "with-css" and omit direct import of react-linear-layout.css file
    import LinearLayout from 'react-linear-layout/with-css';
     
    import './MyLinearLayoutComponent.css';
     
     
    export default function MyLinearLayoutComponent(props) {
      return (
        <LinearLayout {...props} className="layout" direction="horizontal">
          <a>Anchor 0</a>
          <a>Anchor 1</a>
          <a>Anchor 2</a>
          <LinearLayout className="sub-layout" direction="vertical">
            <a>Sub Anchor 0</a>
            <a>Sub Anchor 1</a>
            <a>Sub Anchor 2</a>
          </LinearLayout>
        </LinearLayout>
      );
    }

    API

    Props

    Any prop that is acceptable by a div component is acceptable by a LinearLayout component.

    • direction ?String - Default = "horizontal"

      The direction to arrange the component's children.

      Possible values:

      • "horizontal"
      • "horiz"
      • "h"
      • "vertical"
      • "vert
      • "v"
    • inline ?Boolean - Default = false

      Determines whether the layout should be treated as an inline element or a block element.

    • wrap ?Boolean - Default = false

      When true, list will be allowed to wrap instead of overflow.

    • ref ?Function

      Forwarded ref to underlying DOM element.

    CSS Custom Properties

    • --linear-layout-item-gap Same types as any "margin" CSS property

      Sets the gap (I.E. margin) between all direct children of a LinearLayout.

    Immediate Children CSS Custom Properties

    • --linear-layout-item-gap Same types as any "margin" CSS property

      Sets the gap (I.E. margin) between all direct children of a LinearLayout.

    • --linear-layout-item-size Same types as "width" or "height" CSS properties

      Sets the height (if direction = "vertical") or width (if direction = "horizontal") of all direct children of a LinearLayout.

    • --linear-layout-item-min-size Same types as "min-width" or "min-height" CSS properties

      Sets the minimum height (if direction = "vertical") or width (if direction = "horizontal") of all direct children of a LinearLayout.

    • --linear-layout-item-max-size Same types as "max-width" or "max-height" CSS properties

      Sets the maximum height (if direction = "vertical") or width (if direction = "horizontal") of all direct children of a LinearLayout.



    License

    ISC License (ISC)

    Copyright (c) 2020, Brandon D. Sara (https://bsara.dev)

    Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

    Install

    npm i react-linear-layout

    DownloadsWeekly Downloads

    20

    Version

    3.0.0

    License

    ISC

    Unpacked Size

    15.4 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar