Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/leptos_app/components/checkbox.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use leptos::prelude::*;
use crate::leptos_app::components::FieldTooltip;

#[component]
pub fn Checkbox<T>(
#[prop(into)] id: String,
#[prop(into)] label: String,
#[prop(into)] checked: Signal<bool>,
#[prop(optional, default = true)] show_help: bool,
on_toggle: T,
) -> impl IntoView
where
Expand All @@ -19,9 +21,11 @@ where
type="checkbox"
on:input=move |_| on_toggle(!checked.get_untracked())
/>
<label for=id class="block pl-2 font-medium text-gray-900 text-sm/6">
{label}
</label>
<FieldTooltip field_id=id.clone() show_help=show_help>
<label for=id class="block pl-2 font-medium text-gray-900 text-sm/6">
{label}
</label>
</FieldTooltip>

</div>
}
Expand Down
437 changes: 437 additions & 0 deletions src/leptos_app/components/field_status.rs

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/leptos_app/components/input_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use leptos::web_sys::Event;
use leptos::{component, slot, view, IntoView};
use std::fmt::Debug;
use std::str::FromStr;
use crate::leptos_app::components::FieldTooltip;

const BASE_LABEL_CLASS: &str = "block text-sm font-medium leading-6 text-gray-900";
const BASE_INPUT_CLASS: &str = "block w-full rounded-md border-0 py-1.5 text-gray-900 ring-1 \
Expand Down Expand Up @@ -32,6 +33,7 @@ pub fn InputGroup<F, I>(
#[prop(into, optional)] error: Signal<String>,
#[prop(optional)] input_group_icon: Option<InputGroupIcon>,
#[prop(optional)] max_length: Option<usize>,
#[prop(optional, default = true)] show_help: bool,
) -> impl IntoView
where
F: Fn(I) + Clone + Send + 'static,
Expand All @@ -56,9 +58,11 @@ where

let label = label.map(|label| {
view! {
<label for=id class=label_class>
{label}
</label>
<FieldTooltip field_id=id.to_string() show_help=show_help>
<label for=id class=label_class>
{label}
</label>
</FieldTooltip>
}
});

Expand Down
2 changes: 2 additions & 0 deletions src/leptos_app/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod button;
mod checkbox;
mod controls_menu;
mod divider;
mod field_status;
mod input_group;
mod select_group;
mod slider;
Expand All @@ -11,6 +12,7 @@ pub use button::*;
pub use checkbox::*;
pub use controls_menu::*;
pub use divider::*;
pub use field_status::*;
pub use input_group::*;
pub use select_group::*;
pub use slider::*;
Expand Down
13 changes: 10 additions & 3 deletions src/leptos_app/components/select_group.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use leptos::prelude::*;
use std::fmt::Display;
use crate::leptos_app::components::FieldTooltip;

#[component]
pub fn SelectGroup<Opt, F>(
Expand All @@ -9,6 +10,7 @@ pub fn SelectGroup<Opt, F>(
#[prop(into)] selected_option: Signal<Option<Opt>>,
on_change: F,
#[prop(into, optional)] disabled: Signal<bool>,
#[prop(optional, default = true)] show_help: bool,
) -> impl IntoView
where
Opt: Display + Sync + Send + Clone + PartialEq + Eq + 'static,
Expand All @@ -25,11 +27,16 @@ where
}
};

let id_clone = id.clone();
let label_clone = label.clone();

view! {
<div class="mb-2">
<label for=id.clone() class="block font-medium text-gray-900 text-sm/6">
{label.clone()}
</label>
<FieldTooltip field_id=id_clone.clone() show_help=show_help>
<label for=id_clone.clone() class="block font-medium text-gray-900 text-sm/6">
{label_clone.clone()}
</label>
</FieldTooltip>
<div class="grid grid-cols-1 mt-2">
<select
prop:disabled=disabled
Expand Down
10 changes: 7 additions & 3 deletions src/leptos_app/components/slider.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use leptos::prelude::*;
use web_sys::Event;
use crate::leptos_app::components::FieldTooltip;

#[component]
pub fn Slider(
Expand All @@ -9,6 +10,7 @@ pub fn Slider(
#[prop(into, default = 0.0.into())] min: Signal<f64>,
#[prop(into, default = 1.0.into())] max: Signal<f64>,
#[prop(into, default = 1.0.into())] step: Signal<f64>,
#[prop(optional, default = true)] show_help: bool,
// #[prop(into, optional)] show_steps: Signal<bool>,
on_input: impl Fn(f64) + 'static + Clone,
) -> impl IntoView {
Expand Down Expand Up @@ -45,9 +47,11 @@ pub fn Slider(

view! {
<div class="mb-2">
<label for=id class="block font-medium text-gray-900 text-sm/6">
{label}
</label>
<FieldTooltip field_id=id.to_string() show_help=show_help>
<label for=id class="block font-medium text-gray-900 text-sm/6">
{label}
</label>
</FieldTooltip>
<div class="flex relative items-center rounded-md">
<input
id=id
Expand Down
13 changes: 10 additions & 3 deletions src/leptos_app/components/text_area.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use leptos::prelude::*;
use crate::leptos_app::components::FieldTooltip;

#[component]
pub fn TextArea<F>(
Expand All @@ -7,16 +8,22 @@ pub fn TextArea<F>(
#[prop(into, default = String::new())] placeholder: String,
#[prop(into)] text: Signal<String>,
#[prop(into, optional)] disabled: Signal<bool>,
#[prop(optional, default = true)] show_help: bool,
on_input: F,
) -> impl IntoView
where
F: Fn(String) + Clone + Send + 'static,
{
let id_clone = id.clone();
let label_clone = label.clone();

view! {
<div class="mb-2">
<label for=id.clone() class="block font-medium text-gray-900 text-sm/6">
{label.clone()}
</label>
<FieldTooltip field_id=id_clone.clone() show_help=show_help>
<label for=id_clone.clone() class="block font-medium text-gray-900 text-sm/6">
{label_clone.clone()}
</label>
</FieldTooltip>
<div class="mt-2">
<textarea
rows="4"
Expand Down
Loading