66 lines
1.4 KiB
Rust
66 lines
1.4 KiB
Rust
|
use crate::image::Image;
|
||
|
use std::rc::Rc;
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub struct Icon {
|
||
|
pub(crate) href: String,
|
||
|
pub(crate) small: bool,
|
||
|
pub(crate) dark: bool,
|
||
|
image: Option<Rc<dyn Image>>,
|
||
|
}
|
||
|
|
||
|
impl Icon {
|
||
|
pub fn new(href: String) -> Self {
|
||
|
Icon {
|
||
|
href,
|
||
|
small: false,
|
||
|
dark: false,
|
||
|
image: None,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn image(mut self, image: impl Image + 'static) -> Self {
|
||
|
self.image = Some(Rc::new(image));
|
||
|
self
|
||
|
}
|
||
|
|
||
|
pub fn dark(mut self, dark: bool) -> Self {
|
||
|
self.dark = dark;
|
||
|
self
|
||
|
}
|
||
|
|
||
|
pub fn small(mut self, small: bool) -> Self {
|
||
|
self.small = small;
|
||
|
self
|
||
|
}
|
||
|
|
||
|
pub(crate) fn image_opt(&self) -> Option<&dyn Image> {
|
||
|
self.image.as_deref()
|
||
|
}
|
||
|
|
||
|
pub(crate) fn class_string(&self) -> String {
|
||
|
let mut classes = vec!["toolkit-icon--link".to_owned()];
|
||
|
|
||
|
if self.small {
|
||
|
classes.push("toolkit-icon--link__small".to_owned());
|
||
|
}
|
||
|
|
||
|
if self.dark {
|
||
|
classes.push("toolkit-dark".to_owned());
|
||
|
}
|
||
|
|
||
|
classes.join(" ")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl std::fmt::Debug for Icon {
|
||
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||
|
f.debug_struct("Icon")
|
||
|
.field("href", &self.href)
|
||
|
.field("small", &self.dark)
|
||
|
.field("dark", &self.dark)
|
||
|
.field("image", &"Rc<dyn Image>")
|
||
|
.finish()
|
||
|
}
|
||
|
}
|