use std::marker::PhantomData; use crate::prelude::*; use crate::{example_editor_actions, OrderMethod, Palette}; #[derive(Element)] pub struct CommandPalette { id: ElementId, state_type: PhantomData, } impl CommandPalette { pub fn new(id: impl Into) -> Self { Self { id: id.into(), state_type: PhantomData, } } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { div().id(self.id.clone()).child( Palette::new("palette") .items(example_editor_actions()) .placeholder("Execute a command...") .empty_string("No items found.") .default_order(OrderMethod::Ascending), ) } } #[cfg(feature = "stories")] pub use stories::*; #[cfg(feature = "stories")] mod stories { use crate::Story; use super::*; #[derive(Element)] pub struct CommandPaletteStory { state_type: PhantomData, } impl CommandPaletteStory { pub fn new() -> Self { Self { state_type: PhantomData, } } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl IntoAnyElement { Story::container(cx) .child(Story::title_for::<_, CommandPalette>(cx)) .child(Story::label(cx, "Default")) .child(CommandPalette::new("command-palette")) } } }