Files
webawesome/docs/pages/components/resize-observer.md
Konnor Rogers 31ef2f7929 remove side-effects key, update React docs for cherry-picking (#1485)
* remove side-effects, update React docs for cherry-picking

* prettier

* add PR #

* prettier

* fix react import paths

* Update docs/pages/frameworks/react.md

Co-authored-by: Cory LaViska <cory@abeautifulsite.net>

* add colons to imports

---------

Co-authored-by: Cory LaViska <cory@abeautifulsite.net>
2023-08-07 13:20:34 -04:00

1.8 KiB

meta, layout
meta layout
title description
Resize Observer The Resize Observer component offers a thin, declarative interface to the ResizeObserver API.
component

The resize observer will report changes to the dimensions of the elements it wraps through the sl-resize event. When emitted, a collection of ResizeObserverEntry objects will be attached to event.detail that contains the target element and information about its dimensions.

<div class="resize-observer-overview">
  <sl-resize-observer>
    <div>Resize this box and watch the console 👉</div>
  </sl-resize-observer>
</div>

<script>
  const container = document.querySelector('.resize-observer-overview');
  const resizeObserver = container.querySelector('sl-resize-observer');

  resizeObserver.addEventListener('sl-resize', event => {
    console.log(event.detail);
  });
</script>

<style>
  .resize-observer-overview div {
    display: flex;
    border: solid 2px var(--sl-input-border-color);
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
  }
</style>
import SlResizeObserver from '@shoelace-style/shoelace/dist/react/sl-resize-observer';

const css = `
  .resize-observer-overview div {
    display: flex;
    border: solid 2px var(--sl-input-border-color);
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4rem 2rem;
  }
`;

const App = () => (
  <>
    <div className="resize-observer-overview">
      <SlResizeObserver onSlResize={event => console.log(event.detail)}>
        <div>Resize this box and watch the console 👉</div>
      </SlResizeObserver>
    </div>

    <style>{css}</style>
  </>
);