leptos-use/src/math/use_floor.rs

34 lines
723 B
Rust
Raw Normal View History

2023-06-03 05:25:45 +01:00
use leptos::*;
use num::Float;
/// Reactive `floor()`.
///
/// ## Demo
///
/// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/use_floor)
///
2023-06-03 14:58:30 +01:00
/// ## Usage
2023-06-03 05:25:45 +01:00
///
/// ```
/// # use leptos::*;
/// # use leptos_use::math::use_floor;
/// #
/// # #[component]
/// # fn Demo(cx: Scope) -> impl IntoView {
/// let (value, set_value) = create_signal(cx, 45.95);
/// let result: Signal<f64> = use_floor(cx, value); // 45
2023-06-03 14:58:30 +01:00
/// #
/// # assert_eq!(result.get(), 45.0);
2023-06-03 05:25:45 +01:00
/// # view! { cx, }
/// # }
/// ```
2023-06-03 14:58:30 +01:00
#[doc(cfg(feature = "math"))]
2023-06-03 05:25:45 +01:00
pub fn use_floor<S, N>(cx: Scope, x: S) -> Signal<N>
where
S: Into<MaybeSignal<N>>,
N: Float,
{
let x = x.into();
Signal::derive(cx, move || x.get().floor())
}