#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Size {
Xs,
Sm,
#[default]
Md,
Lg,
Xl,
Xxl,
Custom(&'static str),
}
impl Size {
pub fn to_style(self) -> &'static str {
match self {
Self::Xs => "width: 24px; height: 24px;",
Self::Sm => "width: 32px; height: 32px;",
Self::Md => "width: 40px; height: 40px;",
Self::Lg => "width: 48px; height: 48px;",
Self::Xl => "width: 64px; height: 64px;",
Self::Xxl => "width: 80px; height: 80px;",
Self::Custom(s) => s,
}
}
pub fn to_font_style(self) -> &'static str {
match self {
Self::Xs => "font-size: 10px;",
Self::Sm => "font-size: 12px;",
Self::Md => "font-size: 14px;",
Self::Lg => "font-size: 16px;",
Self::Xl => "font-size: 20px;",
Self::Xxl => "font-size: 24px;",
Self::Custom(_) => "font-size: 14px;",
}
}
pub fn to_px(self) -> u32 {
match self {
Self::Xs => 24,
Self::Sm => 32,
Self::Md => 40,
Self::Lg => 48,
Self::Xl => 64,
Self::Xxl => 80,
Self::Custom(_) => 40,
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Color {
#[default]
Default,
Accent,
Success,
Warning,
Danger,
Custom(&'static str),
}
impl Color {
pub fn to_style(self) -> &'static str {
match self {
Self::Default => "background-color: #4b5563; color: #ffffff;",
Self::Accent => "background-color: #7c3aed; color: #ffffff;",
Self::Success => "background-color: #16a34a; color: #ffffff;",
Self::Warning => "background-color: #d97706; color: #ffffff;",
Self::Danger => "background-color: #dc2626; color: #ffffff;",
Self::Custom(s) => s,
}
}
pub fn to_soft_style(self) -> &'static str {
match self {
Self::Default => "background-color: #374151; color: #d1d5db;",
Self::Accent => "background-color: #ede9fe; color: #7c3aed;",
Self::Success => "background-color: #dcfce7; color: #16a34a;",
Self::Warning => "background-color: #fef3c7; color: #d97706;",
Self::Danger => "background-color: #fee2e2; color: #dc2626;",
Self::Custom(s) => s,
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Variant {
#[default]
Default,
Soft,
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum Overlap {
#[default]
Clip,
Ring,
}
impl Overlap {
pub fn to_class(self) -> &'static str {
match self {
Self::Clip => "avatar-group--clip",
Self::Ring => "avatar-group--ring",
}
}
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub enum ImageLoadingStatus {
#[default]
Idle,
Loading,
Loaded,
Error,
}
impl ImageLoadingStatus {
pub fn is_loaded(self) -> bool {
self == Self::Loaded
}
pub fn should_show_fallback(self) -> bool {
!self.is_loaded()
}
}
pub fn base_container_style() -> &'static str {
"display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; overflow: hidden; vertical-align: middle; user-select: none; flex-shrink: 0; position: relative;"
}
pub fn base_image_style() -> &'static str {
"width: 100%; height: 100%; object-fit: cover; border-radius: inherit;"
}
pub fn base_fallback_style() -> &'static str {
"display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-weight: 600; line-height: 1; border-radius: inherit; letter-spacing: 0.025em;"
}
pub fn base_group_style() -> &'static str {
"display: inline-flex; align-items: center; flex-direction: row; flex-shrink: 0;"
}
pub fn base_group_grid_style() -> &'static str {
"display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px;"
}
pub fn child_overlap_style(overlap: Overlap, _size: Size) -> &'static str {
match overlap {
Overlap::Clip => "margin-inline-start: -0.5rem; filter: drop-shadow(-2px 0 0 transparent);",
Overlap::Ring => "margin-inline-start: -0.5rem; box-shadow: 0 0 0 2px #1a1a1a;",
}
}