use yew::prelude::*;
use super::style_cache::StyleCache;
#[derive(Properties, PartialEq)]
pub struct StyleProviderProps {
pub root: web_sys::HtmlElement,
#[prop_or(true)]
pub is_shadow: bool,
pub children: Children,
}
pub struct StyleProvider {
cache: StyleCache,
}
impl Component for StyleProvider {
type Message = ();
type Properties = StyleProviderProps;
fn create(ctx: &Context<Self>) -> Self {
let cache = StyleCache::new(ctx.props().is_shadow, &ctx.props().root);
Self { cache }
}
fn view(&self, ctx: &Context<Self>) -> Html {
html! {
<ContextProvider<StyleCache> context={self.cache.clone()}>
{ for ctx.props().children.iter() }
</ContextProvider<StyleCache>>
}
}
}