Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

flex-wrap-layout

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flex-wrap-layout

Experiments with flexbox layout

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-30%
Maintainers
1
Weekly downloads
 
Created
Source

flex-wrap-layout

npm version Build status

Experimentations with flexbox and flex-wrap: wrap to get rid of the classic and limited 12 columns grid (e.g. things like .col-md-6 { width: 50% }).

Web technologies (HTML, CSS, JavaScript) are now used for creating complex GUIs (web apps vs web sites). Desktop tools and libraries like Qt have elegantly solved the problem for decades.

Usage

npm install flex-wrap-layout

Import layout.scss or flex-wrap-layout.scss:

$layout-item-margin-y: $form-group-margin-bottom;
$layout-item-margin-x: $form-group-margin-bottom;
@import '~flex-wrap-layout/src/layout';

If you need to detect CSS flex wrap:

import { detectRowWrap } from 'flex-wrap-layout';

Examples

detectRowWrap() example

https://codepen.io/tkrotoff/pen/pWzKqZ

HTML form example

Basic demo

<form vspace>
  <div layout="row" hspace vspace>
    <div layout="column" vspace grow>
      <div layout="row">
        <label for="firstname" offset-with-content>First Name</label>
        <input id="firstname" grow>
      </div>

      <div layout="row">
        <label for="lastname" offset-with-content>Last Name</label>
        <input id="lastname" grow>
      </div>
    </div>

    <div layout="column" vspace grow>
      <div layout="row">
        <label for="arrival" offset-with-content>Arrival</label>
        <input type="date" id="arrival" grow>
      </div>

      <div layout="row">
        <label for="departure" offset-with-content>Departure</label>
        <input type="date" id="departure" grow>
      </div>
    </div>
  </div>

  <div layout="row">
    <div grow></div>
    <div layout="row" hspace vspace>
      <button>Save</button>
      <button>Cancel</button>
    </div>
    <div grow></div>
  </div>
</form>

API

layout="row"

Lines up child elements horizontally (QHBoxLayout equivalent).

<1> <2> <3>

layout="column"

Lines up child elements vertically (QVBoxLayout equivalent).

<1>
<2>
<3>

grow

Grows the element if extra space is available, the element won't shrink below its natural width (QSizePolicy equivalent).

  • Without grow:
| <1> <2> <3>         |
  • Element 1 with grow attribute:
| <    1    > <2> <3> |

Element 1 fills the extra space if any

  • Elements 2 and 3 with grow attribute:
| <1> <  2  > <  3  > |

Elements 2 and 3 share the extra space if any

vspace

Vertical space (margin-bottom) between child elements (QLayout::spacing equivalent).

<1>  instead of  <1>
                 <2>
<2>              <3>

<3>

hspace

Horizontal space (margin-right) between child elements (QLayout::spacing equivalent).

<1> <2> <3> instead of <1><2><3>

Spacer (<div grow></div>)

Stretchable blank space (QSpacerItem equivalent).

| <1> <2>   <->   <3> |
| <1> <-> <2> <-> <3> |

Limitations

I would like to right-align the labels of a form:

| <    label> <input> |  instead of  | <label    > <input> |
| <    label> <input> |              | <label    > <input> |

Unfortunately it is not possible to detect when an element is wrapped in CSS:

| <    label> |  instead of  | <label    > |
| <input>     |              | <input>     |
| <    label> |              | <label    > |
| <input>     |              | <input>     |

This would also solve other problems (all of them?).

To work around this, detectRowWrap() is a JavaScript function that detects when an element is wrapped and lets you define the CSS that goes with it.

Build and run

yarn build:examples:watch
open build/examples/demo.html

Keywords

FAQs

Package last updated on 31 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc