theme_selector.rs

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