Edit Component
Adding Badges RS to your project is simple:
-
Make sure your project is set up with Yew. Follow their Getting Started Guide for setup instructions.
-
Add the Badges RS component to your dependencies by including it in your Cargo.toml file:
cargo add badges-rs --features=yew
-
Import the Badge, Anchor, and Label components into your Yew component and start using them in your app.
use badges_rs::yew::{Badge, Anchor};
use badges_rs::Color;
use yew::prelude::*;
#[function_component(MyBadge)]
pub fn my_badge() -> Html {
html! {
<Anchor>
<span aria-label="Inbox, 5 unread messages">{"📬"}</span>
<Badge color={Color::Danger} aria_label="5 unread messages">{"5"}</Badge>
</Anchor>
}
}
use badges_rs::yew::{Badge, Anchor};
use badges_rs::{Color, Placement};
use yew::prelude::*;
#[function_component(OnlineDot)]
pub fn online_dot() -> Html {
html! {
<Anchor>
<span>{"👤"}</span>
<Badge color={Color::Success} placement={Placement::BottomRight} aria_label="Online" />
</Anchor>
}
}
use badges_rs::yew::{Badge, Anchor};
use badges_rs::{Color, Variant};
use yew::prelude::*;
#[function_component(BadgeVariants)]
pub fn badge_variants() -> Html {
html! {
<>
<Anchor>
<span>{"A"}</span>
<Badge color={Color::Accent} variant={Variant::Primary}>{"5"}</Badge>
</Anchor>
<Anchor>
<span>{"B"}</span>
<Badge color={Color::Accent} variant={Variant::Secondary}>{"5"}</Badge>
</Anchor>
<Anchor>
<span>{"C"}</span>
<Badge color={Color::Accent} variant={Variant::Soft}>{"5"}</Badge>
</Anchor>
</>
}
}
use badges_rs::yew::{Badge, Anchor};
use badges_rs::{Color, Size};
use yew::prelude::*;
#[function_component(BadgeSizes)]
pub fn badge_sizes() -> Html {
html! {
<>
<Anchor>
<span>{"S"}</span>
<Badge color={Color::Danger} size={Size::Sm}>{"5"}</Badge>
</Anchor>
<Anchor>
<span>{"M"}</span>
<Badge color={Color::Danger} size={Size::Md}>{"5"}</Badge>
</Anchor>
<Anchor>
<span>{"L"}</span>
<Badge color={Color::Danger} size={Size::Lg}>{"5"}</Badge>
</Anchor>
</>
}
}
use badges_rs::yew::{Badge, Anchor};
use badges_rs::{Color, Placement};
use yew::prelude::*;
#[function_component(BadgePlacements)]
pub fn badge_placements() -> Html {
html! {
<>
<Anchor>
<span>{"TR"}</span>
<Badge color={Color::Accent} placement={Placement::TopRight} aria_label="top-right" />
</Anchor>
<Anchor>
<span>{"TL"}</span>
<Badge color={Color::Accent} placement={Placement::TopLeft} aria_label="top-left" />
</Anchor>
<Anchor>
<span>{"BR"}</span>
<Badge color={Color::Accent} placement={Placement::BottomRight} aria_label="bottom-right" />
</Anchor>
<Anchor>
<span>{"BL"}</span>
<Badge color={Color::Accent} placement={Placement::BottomLeft} aria_label="bottom-left" />
</Anchor>
</>
}
}
| Property | Type | Description | Default |
children | Children | Content inside the badge. Omit for dot mode. | "" |
color | Color | Color theme. | Color::Default |
variant | Variant | Visual style. | Variant::Primary |
size | Size | Badge size. | Size::Md |
placement | Placement | Corner placement relative to anchor. | Placement::TopRight |
class | &'static str | Extra CSS classes on root element. | "" |
style | &'static str | Extra inline CSS on root element. | "" |
id | &'static str | id attribute on root element. | "" |
aria_label | &'static str | Accessible name for screen readers. | "Badge" |
data_testid | &'static str | Testing attribute. | "" |
| Property | Type | Description | Default |
children | Children | Target element + Badge. | - |
class | &'static str | Extra CSS classes on the wrapper. | "" |
style | &'static str | Extra inline CSS on the wrapper. | "" |
id | &'static str | id attribute. | "" |
| Property | Type | Description | Default |
children | Children | Label content. | - |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
Badge must be placed inside a Anchor for correct absolute positioning.
- When
children is empty the badge renders as a dot status indicator - no text, no padding.
- Use
Color and Variant props to match your design system.
You can import Badges RS directly into your project to customize and modify it using the opensass cli:
os add badges-rs yew
Edit Component
Adding Badges RS to your project is simple:
-
Make sure your project is set up with Dioxus. Follow their Getting Started Guide for setup instructions.
-
Add the Badges RS component to your dependencies:
cargo add badges-rs --features=dio
-
Import and use the Badge, Anchor, and Label components.
use badges_rs::dioxus::{Badge, Anchor};
use badges_rs::Color;
use dioxus::prelude::*;
fn MyBadge() -> Element {
rsx! {
Anchor {
span { aria_label: "Inbox, 5 unread messages", "📬" }
Badge { color: Color::Danger, aria_label: "5 unread messages", "5" }
}
}
}
use badges_rs::dioxus::{Badge, Anchor};
use badges_rs::{Color, Placement};
use dioxus::prelude::*;
fn OnlineDot() -> Element {
rsx! {
Anchor {
span { "👤" }
Badge { color: Color::Success, placement: Placement::BottomRight, aria_label: "Online" }
}
}
}
use badges_rs::dioxus::{Badge, Anchor};
use badges_rs::{Color, Variant};
use dioxus::prelude::*;
fn BadgeVariants() -> Element {
rsx! {
Anchor { span { "A" } Badge { color: Color::Accent, variant: Variant::Primary, "5" } }
Anchor { span { "B" } Badge { color: Color::Accent, variant: Variant::Secondary, "5" } }
Anchor { span { "C" } Badge { color: Color::Accent, variant: Variant::Soft, "5" } }
}
}
use badges_rs::dioxus::{Badge, Anchor};
use badges_rs::{Color, Size};
use dioxus::prelude::*;
fn BadgeSizes() -> Element {
rsx! {
Anchor { span { "S" } Badge { color: Color::Danger, size: Size::Sm, "5" } }
Anchor { span { "M" } Badge { color: Color::Danger, size: Size::Md, "5" } }
Anchor { span { "L" } Badge { color: Color::Danger, size: Size::Lg, "5" } }
}
}
use badges_rs::dioxus::{Badge, Anchor};
use badges_rs::{Color, Placement};
use dioxus::prelude::*;
fn BadgePlacements() -> Element {
rsx! {
Anchor { span { "TR" } Badge { color: Color::Accent, placement: Placement::TopRight, aria_label: "top-right" } }
Anchor { span { "TL" } Badge { color: Color::Accent, placement: Placement::TopLeft, aria_label: "top-left" } }
Anchor { span { "BR" } Badge { color: Color::Accent, placement: Placement::BottomRight, aria_label: "bottom-right" } }
Anchor { span { "BL" } Badge { color: Color::Accent, placement: Placement::BottomLeft, aria_label: "bottom-left" } }
}
}
| Property | Type | Description | Default |
children | Option<Element> | Content inside the badge. None for dot mode. | None |
color | Color | Color theme. | Color::Default |
variant | Variant | Visual style. | Variant::Primary |
size | Size | Badge size. | Size::Md |
placement | Placement | Corner placement relative to anchor. | Placement::TopRight |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
aria_label | &'static str | Accessible name for screen readers. | "Badge" |
data_testid | &'static str | Testing attribute. | "" |
| Property | Type | Description | Default |
children | Element | Target element + Badge. | - |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
| Property | Type | Description | Default |
children | Element | Label content. | - |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
Badge must be placed inside a Anchor for correct absolute positioning.
- Pass
children: None (or omit children) to render a dot indicator.
- Use
Color and Variant props to match your design system.
You can import Badges RS directly into your project to customize and modify it using the opensass cli:
os add badges-rs dio
Edit Component
Adding Badges RS to your project is simple:
-
Make sure your project is set up with Leptos. Follow their Getting Started Guide for setup instructions.
-
Add the Badges RS component to your dependencies:
cargo add badges-rs --features=lep
-
Import and use the Badge, Anchor, and Label components.
use badges_rs::leptos::{Badge, Anchor};
use badges_rs::Color;
use leptos::prelude::*;
#[component]
pub fn MyBadge() -> impl IntoView {
view! {
<Anchor>
<span aria-label="Inbox, 5 unread messages">"📬"</span>
<Badge color=Color::Danger aria_label="5 unread messages">"5"</Badge>
</Anchor>
}
}
use badges_rs::leptos::{Badge, Anchor};
use badges_rs::{Color, Placement};
use leptos::prelude::*;
#[component]
pub fn OnlineDot() -> impl IntoView {
view! {
<Anchor>
<span>"👤"</span>
<Badge color=Color::Success placement=Placement::BottomRight aria_label="Online" />
</Anchor>
}
}
use badges_rs::leptos::{Badge, Anchor};
use badges_rs::{Color, Variant};
use leptos::prelude::*;
#[component]
pub fn BadgeVariants() -> impl IntoView {
view! {
<Anchor><span>"A"</span><Badge color=Color::Accent variant=Variant::Primary>"5"</Badge></Anchor>
<Anchor><span>"B"</span><Badge color=Color::Accent variant=Variant::Secondary>"5"</Badge></Anchor>
<Anchor><span>"C"</span><Badge color=Color::Accent variant=Variant::Soft>"5"</Badge></Anchor>
}
}
use badges_rs::leptos::{Badge, Anchor};
use badges_rs::{Color, Size};
use leptos::prelude::*;
#[component]
pub fn BadgeSizes() -> impl IntoView {
view! {
<Anchor><span>"S"</span><Badge color=Color::Danger size=Size::Sm>"5"</Badge></Anchor>
<Anchor><span>"M"</span><Badge color=Color::Danger size=Size::Md>"5"</Badge></Anchor>
<Anchor><span>"L"</span><Badge color=Color::Danger size=Size::Lg>"5"</Badge></Anchor>
}
}
use badges_rs::leptos::{Badge, Anchor};
use badges_rs::{Color, Placement};
use leptos::prelude::*;
#[component]
pub fn BadgePlacements() -> impl IntoView {
view! {
<Anchor><span>"TR"</span><Badge color=Color::Accent placement=Placement::TopRight aria_label="top-right" /></Anchor>
<Anchor><span>"TL"</span><Badge color=Color::Accent placement=Placement::TopLeft aria_label="top-left" /></Anchor>
<Anchor><span>"BR"</span><Badge color=Color::Accent placement=Placement::BottomRight aria_label="bottom-right" /></Anchor>
<Anchor><span>"BL"</span><Badge color=Color::Accent placement=Placement::BottomLeft aria_label="bottom-left" /></Anchor>
}
}
| Property | Type | Description | Default |
children | Option<ChildrenFn> | Content inside the badge. None for dot mode. | None |
color | Color | Color theme. | Color::Default |
variant | Variant | Visual style. | Variant::Primary |
size | Size | Badge size. | Size::Md |
placement | Placement | Corner placement relative to anchor. | Placement::TopRight |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
aria_label | &'static str | Accessible name for screen readers. | "Badge" |
data_testid | &'static str | Testing attribute. | "" |
| Property | Type | Description | Default |
children | Children | Target element + Badge. | - |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
| Property | Type | Description | Default |
children | Children | Label content. | - |
class | &'static str | Extra CSS classes. | "" |
style | &'static str | Extra inline CSS. | "" |
id | &'static str | id attribute. | "" |
Badge must be placed inside a Anchor for correct absolute positioning.
- Omit
children (or pass None) to render as a compact dot status indicator.
- Use
Color and Variant props to match your design system.
You can import Badges RS directly into your project to customize and modify it using the opensass cli:
os add badges-rs lep