1use crate::prelude::*;
2use crate::{OrderMethod, Palette, PaletteItem};
3
4#[derive(Component)]
5pub struct LanguageSelector {
6 id: ElementId,
7}
8
9impl LanguageSelector {
10 pub fn new(id: impl Into<ElementId>) -> Self {
11 Self { id: id.into() }
12 }
13
14 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
15 div().id(self.id.clone()).child(
16 Palette::new("palette")
17 .items(vec![
18 PaletteItem::new("C"),
19 PaletteItem::new("C++"),
20 PaletteItem::new("CSS"),
21 PaletteItem::new("Elixir"),
22 PaletteItem::new("Elm"),
23 PaletteItem::new("ERB"),
24 PaletteItem::new("Rust (current)"),
25 PaletteItem::new("Scheme"),
26 PaletteItem::new("TOML"),
27 PaletteItem::new("TypeScript"),
28 ])
29 .placeholder("Select a language...")
30 .empty_string("No matches")
31 .default_order(OrderMethod::Ascending),
32 )
33 }
34}
35
36#[cfg(feature = "stories")]
37pub use stories::*;
38
39#[cfg(feature = "stories")]
40mod stories {
41 use super::*;
42 use crate::Story;
43 use gpui::{Div, Render};
44
45 pub struct LanguageSelectorStory;
46
47 impl Render for LanguageSelectorStory {
48 type Element = Div<Self>;
49
50 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
51 Story::container(cx)
52 .child(Story::title_for::<_, LanguageSelector>(cx))
53 .child(Story::label(cx, "Default"))
54 .child(LanguageSelector::new("language-selector"))
55 }
56 }
57}