1use std::marker::PhantomData;
2
3use crate::prelude::*;
4use crate::{OrderMethod, Palette, PaletteItem};
5
6#[derive(Element)]
7pub struct LanguageSelector<S: 'static + Send + Sync + Clone> {
8 id: ElementId,
9 state_type: PhantomData<S>,
10}
11
12impl<S: 'static + Send + Sync + Clone> LanguageSelector<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().id(self.id.clone()).child(
22 Palette::new("palette")
23 .items(vec![
24 PaletteItem::new("C"),
25 PaletteItem::new("C++"),
26 PaletteItem::new("CSS"),
27 PaletteItem::new("Elixir"),
28 PaletteItem::new("Elm"),
29 PaletteItem::new("ERB"),
30 PaletteItem::new("Rust (current)"),
31 PaletteItem::new("Scheme"),
32 PaletteItem::new("TOML"),
33 PaletteItem::new("TypeScript"),
34 ])
35 .placeholder("Select a language...")
36 .empty_string("No matches")
37 .default_order(OrderMethod::Ascending),
38 )
39 }
40}
41
42#[cfg(feature = "stories")]
43pub use stories::*;
44
45#[cfg(feature = "stories")]
46mod stories {
47 use crate::Story;
48
49 use super::*;
50
51 #[derive(Element)]
52 pub struct LanguageSelectorStory<S: 'static + Send + Sync + Clone> {
53 state_type: PhantomData<S>,
54 }
55
56 impl<S: 'static + Send + Sync + Clone> LanguageSelectorStory<S> {
57 pub fn new() -> Self {
58 Self {
59 state_type: PhantomData,
60 }
61 }
62
63 fn render(
64 &mut self,
65 _view: &mut S,
66 cx: &mut ViewContext<S>,
67 ) -> impl Element<ViewState = S> {
68 Story::container(cx)
69 .child(Story::title_for::<_, LanguageSelector<S>>(cx))
70 .child(Story::label(cx, "Default"))
71 .child(LanguageSelector::new("language-selector"))
72 }
73 }
74}