1use crate::prelude::*;
2use crate::{example_editor_actions, OrderMethod, Palette};
3
4#[derive(Component)]
5pub struct CommandPalette {
6 id: ElementId,
7}
8
9impl CommandPalette {
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(example_editor_actions())
18 .placeholder("Execute a command...")
19 .empty_string("No items found.")
20 .default_order(OrderMethod::Ascending),
21 )
22 }
23}
24
25#[cfg(feature = "stories")]
26pub use stories::*;
27
28#[cfg(feature = "stories")]
29mod stories {
30 use gpui2::{Div, Render};
31
32 use crate::Story;
33
34 use super::*;
35
36 pub struct CommandPaletteStory;
37
38 impl Render for CommandPaletteStory {
39 type Element = Div<Self>;
40
41 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
42 Story::container(cx)
43 .child(Story::title_for::<_, CommandPalette>(cx))
44 .child(Story::label(cx, "Default"))
45 .child(CommandPalette::new("command-palette"))
46 }
47 }
48}