1use std::marker::PhantomData;
2
3use crate::prelude::*;
4use crate::{OrderMethod, Palette, PaletteItem};
5
6#[derive(Element)]
7pub struct ThemeSelector<S: 'static + Send + Sync + Clone> {
8 state_type: PhantomData<S>,
9 scroll_state: ScrollState,
10}
11
12impl<S: 'static + Send + Sync + Clone> ThemeSelector<S> {
13 pub fn new() -> Self {
14 Self {
15 state_type: PhantomData,
16 scroll_state: ScrollState::default(),
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.scroll_state.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(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
65 Story::container(cx)
66 .child(Story::title_for::<_, ThemeSelector<S>>(cx))
67 .child(Story::label(cx, "Default"))
68 .child(ThemeSelector::new())
69 }
70 }
71}