| 1 | mod avatar; |
| 2 | mod avatar_group; |
| 3 | |
| 4 | pub use avatar::*; |
| 5 | pub use avatar_group::*; |
| 6 | |
| 7 | use crate::{Icon, Size, StyledExt as _}; |
| 8 | use gpui::{Div, Img, IntoElement, Pixels, Styled, px, rems}; |
| 9 | |
| 10 | /// Returns the size of the avatar based on the given [`Size`]. |
| 11 | pub(super) fn avatar_size(size: Size) -> Pixels { |
| 12 | match size { |
| 13 | Size::Large => px(80.), |
| 14 | Size::Medium => px(48.), |
| 15 | Size::Small => px(24.), |
| 16 | Size::XSmall => px(16.), |
| 17 | Size::Size(size) => size, |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | /// Extension for add `avatar_size` method to `IntoElement` to apply avatar size to element. |
| 22 | pub(super) trait AvatarSized: IntoElement + Styled { |
| 23 | fn avatar_text_size(self, size: Size) -> Self { |
| 24 | match size { |
| 25 | Size::Large => self.text_3xl().font_semibold(), |
| 26 | Size::Medium => self.text_sm(), |
| 27 | Size::Small => self.text_xs(), |
| 28 | Size::XSmall => self.text_size(rems(0.65)), |
| 29 | Size::Size(size) => self.size(size * 0.5), |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | impl AvatarSized for Div {} |
| 34 | impl AvatarSized for Icon {} |
| 35 | impl AvatarSized for Img {} |