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 crate::Story;
31
32 use super::*;
33
34 #[derive(Component)]
35 pub struct CommandPaletteStory;
36
37 impl CommandPaletteStory {
38 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
39 Story::container(cx)
40 .child(Story::title_for::<_, CommandPalette>(cx))
41 .child(Story::label(cx, "Default"))
42 .child(CommandPalette::new("command-palette"))
43 }
44 }
45}