facepile.rs

 1use gpui2::elements::div;
 2use gpui2::style::StyleHelpers;
 3use gpui2::{Element, IntoElement, ParentElement, ViewContext};
 4use ui::prelude::*;
 5use ui::{avatar, facepile, theme};
 6
 7use crate::story::Story;
 8
 9#[derive(Element, Default)]
10pub struct FacepileStory {}
11
12impl FacepileStory {
13    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
14        let theme = theme(cx);
15
16        let avatars = vec![
17            avatar("https://avatars.githubusercontent.com/u/1714999?v=4"),
18            avatar("https://avatars.githubusercontent.com/u/482957?v=4"),
19            avatar("https://avatars.githubusercontent.com/u/1789?v=4"),
20        ];
21
22        Story::container()
23            .child(Story::title_for::<_, ui::Facepile>())
24            .child(Story::label("Default"))
25            .child(
26                div()
27                    .flex()
28                    .gap_3()
29                    .child(facepile(avatars.clone().into_iter().take(1)))
30                    .child(facepile(avatars.clone().into_iter().take(2)))
31                    .child(facepile(avatars.clone().into_iter().take(3))),
32            )
33            .child(Story::label("Rounded rectangle avatars"))
34            .child({
35                let shape = Shape::RoundedRectangle;
36
37                let avatars = avatars
38                    .clone()
39                    .into_iter()
40                    .map(|avatar| avatar.shape(Shape::RoundedRectangle));
41
42                div()
43                    .flex()
44                    .gap_3()
45                    .child(facepile(avatars.clone().take(1)))
46                    .child(facepile(avatars.clone().take(2)))
47                    .child(facepile(avatars.clone().take(3)))
48            })
49    }
50}