0.13.0 • Published 1 year ago

flex-wrap-layout v0.13.0

Weekly downloads
19
License
MIT
Repository
github
Last release
1 year ago

flex-wrap-layout

npm version Node.js CI Bundle size Prettier Airbnb Code Style

Detects flex-wrap via JavaScript (unfortunately not possible in CSS).

detectWrappedElements() and useDetectWrappedElements() are JavaScript functions that detect when elements are wrapped and let you define the CSS that goes with it.

This allows for responsive UIs without hardcoded CSS (width, min-width, media queries...) using the "natural" width of elements instead.

  • With detectWrappedElements():

Minimal example with detectWrappedElements()

  • Without:

Minimal example without detectWrappedElements()

Usage

npm install flex-wrap-layout

import { useRef } from 'react';

import { useDetectWrappedElements, wrapChildrenClassName } from 'flex-wrap-layout';
import 'flex-wrap-layout/src/detectWrappedElements.scss';

const boxStyle = {
  border: '1px solid',
  height: 60,
  margin: 5,
  padding: 5
};

function MyComponent() {
  const ref = useRef(null);
  useDetectWrappedElements(ref);

  return (
    <div ref={ref} className={wrapChildrenClassName}>
      <div style={boxStyle}>Paris</div>
      <div style={{ ...boxStyle, flex: 'auto' }}>Los Angeles</div>
      <div style={boxStyle}>Phnom Penh</div>
    </div>
  );
}

Examples

Limitations

This will cause reflows (layout thrashing): https://gist.github.com/paulirish/5d52fb081b3570c81e3a

0.13.0

1 year ago

0.11.0

2 years ago

0.12.0

2 years ago

0.10.2

2 years ago

0.10.0

3 years ago

0.10.1

3 years ago

0.10.0-beta.2

3 years ago

0.10.0-beta.3

3 years ago

0.10.0-beta.1

3 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.2.1

4 years ago

0.1.2

4 years ago

0.2.0

4 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.1.0-beta.2

5 years ago

0.1.0-beta.1

5 years ago

0.0.3-beta.1

5 years ago

0.0.2

7 years ago

0.0.1

7 years ago