mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 04:09:12 +00:00
1.8 KiB
1.8 KiB
meta, layout
| meta | layout | ||||
|---|---|---|---|---|---|
|
component |
The resize observer will report changes to the dimensions of the elements it wraps through the wa-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">
<wa-resize-observer>
<div>Resize this box and watch the console 👉</div>
</wa-resize-observer>
</div>
<script>
const container = document.querySelector('.resize-observer-overview');
const resizeObserver = container.querySelector('wa-resize-observer');
resizeObserver.addEventListener('wa-resize', event => {
console.log(event.detail);
});
</script>
<style>
.resize-observer-overview div {
display: flex;
border: solid 2px var(--wa-color-surface-outline);
align-items: center;
justify-content: center;
text-align: center;
padding: 4rem 2rem;
}
</style>
import WaResizeObserver from '@shoelace-style/shoelace/dist/react/resize-observer';
const css = `
.resize-observer-overview div {
display: flex;
border: solid 2px var(--wa-color-surface-outline);
align-items: center;
justify-content: center;
text-align: center;
padding: 4rem 2rem;
}
`;
const App = () => (
<>
<div className="resize-observer-overview">
<WaResizeObserver onWaResize={event => console.log(event.detail)}>
<div>Resize this box and watch the console 👉</div>
</WaResizeObserver>
</div>
<style>{css}</style>
</>
);