#yew-component #component #yew #emit #events #parent #width-height

yew-component-size

A Yew component that emits events when the parent component changes width/height

1 unstable release

0.1.0 Dec 12, 2020

#1433 in WebAssembly

Download history 94/week @ 2024-04-07 203/week @ 2024-04-14 170/week @ 2024-04-21 91/week @ 2024-04-28 96/week @ 2024-05-05 41/week @ 2024-05-12 126/week @ 2024-05-19 48/week @ 2024-05-26 95/week @ 2024-06-02 184/week @ 2024-06-09 190/week @ 2024-06-16 156/week @ 2024-06-23 116/week @ 2024-06-30 102/week @ 2024-07-07 118/week @ 2024-07-14 83/week @ 2024-07-21

426 downloads per month
Used in yew-virtual-scroller

MIT/Apache

8KB
73 lines

yew-component-size

Crates.io Crates.io

A Yew component that emits events when the parent component changes width/height. Only compatible with Yew using web_sys.

Example:

let onsize = self.link.callback(|size: ComponentSize| {
    // Access to `size.width` and `size.height`
});

html! {
    // Parent that you're tracking the size of must be `position: relative`
    <div style="position: relative;">
        // ...
        <ComponentSizeObserver onsize=onsize />
    </div>
}

How it works

This uses a trick borrowed from Svelte where we use an iframe that is positioned absolutely to fill it's parent element, and then we listen to the resize event of iframe's window.

Note: This incurs a small cost and so should not be used on a large number of elements at the same time.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~12MB
~230K SLoC