We all love using CSS Flex and Grids. However, in certain cases, a change in Dom container dimension may require its content to be redrawn. To address such uses cases, Resize Observer Specification was published. Resize Observer is now widely supported in modern browsers.
However, In the age of RxJs Observables, I find the API for Resize Observer a bit cumbersome to use. So I thought, it would be nice to build an RxJs wrapper around this API.
- Returns an Observable that emits on every container dimension change
- You can set the watch direction to be
Horizontal
,Vertical
orBoth
. - Set an initial debounceTime to control the emit frequency
- React on first load using
emitOnStart
- Harness the power of RxJs Operators to do wonders!
Checkout github packages for instructions.
- Create an
.npmrc
file in your repo - Add @twig-it:registry=https://npm.pkg.github.com
- Create a PAT that has read access to Github Packages. Let's call this token
GPRead
- Set this token in npm for your CI runs. Example below:
- name: Npm Install run: npm config set '//npm.pkg.github.com/:_authToken' "${GPRREAD}" && npm ci env: GPRREAD: ${{ secrets.GPREAD }}
An Example usage where from-resize
will be useful.
- An SVG/Canvas chart inside an HTML container
- After initial render, the dimension of this HTML container changes without a window resize event.
- This requires us to redraw the chart. To do this, we need to watch the container for dimension changes and then redraw.
Checkout Demo page!
Checkout Api docs!
Thanks goes to these wonderful people (emoji key):
Anand Tiwary 🤔 💻 🔧 |
This project follows the all-contributors specification. Contributions of any kind welcome!