yew_bs/components/
icon_link.rs

1use yew::prelude::*;
2#[derive(Clone, Copy, PartialEq, Debug)]
3pub enum IconLinkVariant {
4    Primary,
5    Secondary,
6    Success,
7    Danger,
8    Warning,
9    Info,
10    Light,
11    Dark,
12}
13impl IconLinkVariant {
14    pub fn as_str(&self) -> &'static str {
15        match self {
16            IconLinkVariant::Primary => "icon-link-primary",
17            IconLinkVariant::Secondary => "icon-link-secondary",
18            IconLinkVariant::Success => "icon-link-success",
19            IconLinkVariant::Danger => "icon-link-danger",
20            IconLinkVariant::Warning => "icon-link-warning",
21            IconLinkVariant::Info => "icon-link-info",
22            IconLinkVariant::Light => "icon-link-light",
23            IconLinkVariant::Dark => "icon-link-dark",
24        }
25    }
26}
27/// Props for the IconLink component
28#[derive(Properties, PartialEq)]
29pub struct IconLinkProps {
30    /// The icon link variant/color
31    pub variant: IconLinkVariant,
32    /// The link href
33    #[prop_or_default]
34    pub href: Option<AttrValue>,
35    /// The link text/content
36    #[prop_or_default]
37    pub children: Children,
38    /// Additional CSS classes to apply
39    #[prop_or_default]
40    pub class: Option<AttrValue>,
41    /// Click callback
42    #[prop_or_default]
43    pub onclick: Option<Callback<MouseEvent>>,
44    /// Aria label for accessibility
45    #[prop_or_default]
46    pub aria_label: Option<AttrValue>,
47}
48/// A utility component for Bootstrap icon links
49///
50/// The IconLink component provides Bootstrap's icon link styling, which is
51#[function_component(IconLink)]
52pub fn icon_link(props: &IconLinkProps) -> Html {
53    let mut classes = Classes::new();
54    classes.push("icon-link");
55    classes.push(props.variant.as_str());
56    if let Some(custom_class) = &props.class {
57        classes.push(custom_class.to_string());
58    }
59    html! {
60        < a href = { props.href.clone() } class = { classes } onclick = { props.onclick
61        .clone() } aria - label = { props.aria_label.clone() } > { for props.children
62        .iter() } </ a >
63    }
64}