1use crate::prelude::*;
2use crate::{example_editor_actions, OrderMethod, Palette};
3
4#[derive(RenderOnce)]
5pub struct CommandPalette {
6 id: ElementId,
7}
8
9impl<V: 'static> Component<V> for CommandPalette {
10 type Rendered = Stateful<V, Div<V>>;
11
12 fn render(self, view: &mut V, cx: &mut ViewContext<V>) -> Self::Rendered {
13 div().id(self.id.clone()).child(
14 Palette::new("palette")
15 .items(example_editor_actions())
16 .placeholder("Execute a command...")
17 .empty_string("No items found.")
18 .default_order(OrderMethod::Ascending),
19 )
20 }
21}
22
23impl CommandPalette {
24 pub fn new(id: impl Into<ElementId>) -> Self {
25 Self { id: id.into() }
26 }
27}
28
29use gpui::{Div, RenderOnce, Stateful};
30#[cfg(feature = "stories")]
31pub use stories::*;
32
33#[cfg(feature = "stories")]
34mod stories {
35 use gpui::{Div, Render};
36
37 use crate::Story;
38
39 use super::*;
40
41 pub struct CommandPaletteStory;
42
43 impl Render<Self> for CommandPaletteStory {
44 type Element = Div<Self>;
45
46 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
47 Story::container(cx)
48 .child(Story::title_for::<_, CommandPalette>(cx))
49 .child(Story::label(cx, "Default"))
50 .child(CommandPalette::new("command-palette"))
51 }
52 }
53}