Checkbox
A control that allows the user to toggle between checked and not checked.
use leptos::prelude::*; use singlestage::checkbox::*; #[component] pub fn CheckboxExample() -> impl IntoView { view! { <Checkbox>"Accept terms and conditions"</Checkbox> } }
By clicking this checkbox, you agree to the terms and conditions.
use leptos::prelude::*; use singlestage::{Label, checkbox::*}; #[component] pub fn SubtextExample() -> impl IntoView { view! { <div class="flex items-start gap-3"> <Checkbox id="checkbox-with-text" /> <div class="grid gap-2"> <Label label_for="checkbox-with-text">"Accept terms and conditions"</Label> <p class="text-(--muted-foreground) text-sm"> "By clicking this checkbox, you agree to the terms and conditions." </p> </div> </div> } }
use leptos::prelude::*; use singlestage::{Label, checkbox::*}; #[component] pub fn FormExample() -> impl IntoView { view! { <form class="form flex flex-row items-start gap-3 rounded-md border p-4 shadow-xs"> <Checkbox id="checkbox-form-1" /> <div class="flex flex-col gap-1"> <Label label_for="checkbox-form-1" class="leading-snug"> "Use different settings for my mobile devices" </Label> <p class="text-(--muted-foreground) text-sm leading-snug"> "You can manage your mobile notifications in the mobile settings page." </p> </div> </form> } }
Checkbox Group
use leptos::prelude::*; use singlestage::{Button, checkbox::*}; #[component] pub fn GroupExample() -> impl IntoView { let value = RwSignal::new(vec![ "recents".to_string(), "home".to_string(), "applications".to_string(), ]); view! { <form class="form flex flex-col gap-4"> <p>"Value: "{move || format!("{:#?}", value.get())}</p> <CheckboxGroup value> <legend> "Sidebar" <p class="text-(--muted-foreground) text-sm"> "Select the items you want to display in the sidebar." </p> </legend> <Checkbox value="recents">"Recents"</Checkbox> <Checkbox value="home">"Home"</Checkbox> <Checkbox value="applications">"Applications"</Checkbox> <Checkbox value="desktop">"Desktop"</Checkbox> <Checkbox value="download">"Download"</Checkbox> <Checkbox value="documents">"Documents"</Checkbox> </CheckboxGroup> <Button class="w-fit">"Submit"</Button> </form> } }
Anatomy
Import all parts and piece them together.
use leptos::prelude::*; #[component] pub fn CheckboxAnatomy() -> impl IntoView { view! { <CheckboxGroup> <Checkbox /> </CheckboxGroup> } }
API Reference
Checkbox
A control that allows the user to toggle between checked and not checked.
Name | Type | Default | Description |
---|---|---|---|
checked | Reactive<bool> | false | A reactive signal coupled to the checkbox's checked value. |
CheckboxGroup
Contains all the parts of a checkbox group.
Name | Type | Default | Description |
---|---|---|---|
invalid | Reactive<bool> | false | A reactive signal that toggles whether all the children Checkboxes appear invalid or not. |
value | Reactive<Vec<String>> | [] | A dynamic list of all the values of checked children Checkboxes. |