theme_selector.rs

 1use crate::prelude::*;
 2use crate::{OrderMethod, Palette, PaletteItem};
 3
 4#[derive(RenderOnce)]
 5pub struct ThemeSelector {
 6    id: ElementId,
 7}
 8
 9impl<V: 'static> Component<V> for ThemeSelector {
10    type Rendered = Div<V>;
11
12    fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
13        let cx: &mut ViewContext<V> = cx;
14        div().child(
15            Palette::new(self.id.clone())
16                .items(vec![
17                    PaletteItem::new("One Dark"),
18                    PaletteItem::new("Rosé Pine"),
19                    PaletteItem::new("Rosé Pine Moon"),
20                    PaletteItem::new("Sandcastle"),
21                    PaletteItem::new("Solarized Dark"),
22                    PaletteItem::new("Summercamp"),
23                    PaletteItem::new("Atelier Cave Light"),
24                    PaletteItem::new("Atelier Dune Light"),
25                    PaletteItem::new("Atelier Estuary Light"),
26                    PaletteItem::new("Atelier Forest Light"),
27                    PaletteItem::new("Atelier Heath Light"),
28                ])
29                .placeholder("Select Theme...")
30                .empty_string("No matches")
31                .default_order(OrderMethod::Ascending),
32        )
33    }
34}
35
36impl ThemeSelector {
37    pub fn new(id: impl Into<ElementId>) -> Self {
38        Self { id: id.into() }
39    }
40}
41
42use gpui::{Div, RenderOnce};
43#[cfg(feature = "stories")]
44pub use stories::*;
45
46#[cfg(feature = "stories")]
47mod stories {
48    use gpui::{Div, Render};
49
50    use crate::Story;
51
52    use super::*;
53
54    pub struct ThemeSelectorStory;
55
56    impl Render<Self> for ThemeSelectorStory {
57        type Element = Div<Self>;
58
59        fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
60            Story::container(cx)
61                .child(Story::title_for::<_, ThemeSelector>(cx))
62                .child(Story::label(cx, "Default"))
63                .child(ThemeSelector::new("theme-selector"))
64        }
65    }
66}