2.0.6 • Published 2 years ago

@paprika/resize-detector v2.0.6

Weekly downloads
56
License
MIT
Repository
github
Last release
2 years ago

@paprika/resize-detector

Description

A wrapper that provides debounced updates of its dimensions.

Installation

yarn add @paprika/resize-detector

or with npm:

npm install @paprika/resize-detector

Props

ResizeDetector

PropTyperequireddefaultDescription
breakpointLargenumberfalse768The width at which the size will change from the default (medium) to large. 0 or null value will disable.
breakpointSmallnumberfalse360The width at which the size will change from small to the default (medium). 0 or null value will disable.
childrenReactReactNode,unknownfalse-Content to be wrapped which will be provided with live dimensions and (tshirt) size values.
debounceDelaynumberfalse30The ms delay before firing resize events / making live updates.
isFullWidthbooleanfalsetrueIf the container will match its parent's width like a block level element (width: 100%).
isFullHeightbooleanfalsefalseIf the container will match its parent's height (height: 100%).
onBreaksignaturefalse() => nullCallback that fires when the size change crosses a breakpoint threshold (returns new T-Shirt size value).
onResizesignaturefalse() => nullCallback that fires when the size changes (returns new width + height values).

Usage

<ResizeDetector> is a provider component that implements a simple DOM wrapper element and provides callbacks for resize events and custom hooks with dimension values for a consuming application or child component.

Two callback props are provided (onResize + onBreak), as well a custom hook(useResizeDetector) that a child component can use.

It provides the up-to-date width and height of its root DOM element as well as a simple tshirt size value (small | medium | large) that is determined by two breakpoints, which can be customized or disabled.

Custom Hooks Example

import ResizeDetector, { useResizeDetector } from "@paprika/resize-detector";

function ResizeConsumer() {
  const { width, height } = useResizeDetector();
  return (
    <div>
      {width} x {height}
    </div>
  );
}

function ResizeApp() {
  return (
    <ResizeDetector>
      <ResizeConsumer />
    </ResizeDetector>;
  );
}

Render Prop Example

import ResizeDetector, { useResizeDetector, ResizeDetectorContextValue } from "@paprika/resize-detector";

function ResizeApp() {
  return (
    <ResizeDetector>
      {({ width, height }: ResizeDetectorContextValue) => <div>{width} x {height}</div>}
    </ResizeDetector>;
  );
}

Callback Example

function ResizeApp() {
  const handleBreak = (size) => {
    doSomethingWithSize(size);
  }

  return (
    <ResizeDetector onBreak={handleBreak}>
      <ResizeConsumer />
    </ResizeDetector>;
  );
}

Links

2.0.6-next.0

2 years ago

2.0.6

2 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.5-next.0

3 years ago

2.0.4-next.0

3 years ago

2.0.3

3 years ago

2.0.3-next.0

3 years ago

2.0.2

3 years ago

2.0.2-next.0

3 years ago

2.0.1

3 years ago

2.0.1-next.0

3 years ago

2.0.0-next.4

4 years ago

2.0.0-next.2

4 years ago

2.0.0-next.3

4 years ago

1.0.9-next.0

4 years ago

1.0.9-next.1

4 years ago

2.0.0

4 years ago

1.0.8

4 years ago

1.0.8-next.0

4 years ago

1.0.7

4 years ago

1.0.7-next.0

4 years ago

1.0.6

4 years ago

1.0.6-alpha.2

4 years ago

1.0.6-alpha.1

4 years ago

1.0.6-alpha.0

4 years ago

1.0.5

4 years ago

1.0.5-alpha.0

4 years ago

1.0.4

4 years ago

1.0.4-alpha.0

4 years ago

1.0.3

4 years ago

1.0.3-alpha.0

4 years ago

1.0.2

5 years ago

1.0.2-alpha.0

5 years ago

1.0.1

5 years ago

1.0.1-alpha.0

5 years ago

1.0.0

5 years ago

0.1.4

5 years ago

0.1.4-alpha.1

5 years ago

0.1.4-alpha.0

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago