use crate::core::ElementMaybeSignal; use crate::{use_mutation_observer_with_options, watch, watch_with_options, WatchOptions}; use default_struct_builder::DefaultBuilder; use leptos::*; use std::marker::PhantomData; use std::time::Duration; use wasm_bindgen::{JsCast, JsValue}; /// Manipulate CSS variables. /// /// ## Demo /// /// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/use_css_var) /// /// ## Usage /// /// ``` /// # use leptos::*; /// # use leptos_use::use_css_var; /// # /// # #[component] /// # fn Demo(cx: Scope) -> impl IntoView { /// let (color, set_color) = use_css_var(cx, "--color"); /// /// set_color.set("red".to_string()); /// # /// # view! { cx, } /// # } /// ``` /// /// The variable name itself can be a `Signal`. /// /// ``` /// # use leptos::*; /// # use leptos_use::use_css_var; /// # /// # #[component] /// # fn Demo(cx: Scope) -> impl IntoView { /// let (key, set_key) = create_signal(cx, "--color".to_string()); /// let (color, set_color) = use_css_var(cx, key); /// # /// # view! { cx, } /// # } /// ``` /// /// You can specify the element that the variable is applied to as well as an initial value in case /// the variable is not set yet. The option to listen for changes to the variable is also available. /// /// ``` /// # use leptos::*; /// # use leptos_use::{use_css_var_with_options, UseCssVarOptions}; /// # /// # #[component] /// # fn Demo(cx: Scope) -> impl IntoView { /// let el = create_node_ref(cx); /// /// let (color, set_color) = use_css_var_with_options( /// cx, /// "--color", /// UseCssVarOptions::default() /// .target(el) /// .initial_value("#eee") /// .observe(true), /// ); /// /// view! { cx, ///
(
cx: Scope,
prop: P,
options: UseCssVarOptions