Add ContextMenu component

This commit is contained in:
Marshall Bowers 2023-10-09 11:25:33 -04:00
parent f7721d0523
commit 333e3e4f01
5 changed files with 102 additions and 0 deletions

View file

@ -4,6 +4,7 @@ pub mod buffer;
pub mod chat_panel;
pub mod collab_panel;
pub mod command_palette;
pub mod context_menu;
pub mod facepile;
pub mod keybinding;
pub mod palette;

View file

@ -0,0 +1,30 @@
use std::marker::PhantomData;
use ui::prelude::*;
use ui::{ContextMenu, ContextMenuItem, Label};
use crate::story::Story;
#[derive(Element)]
pub struct ContextMenuStory<S: 'static + Send + Sync + Clone> {
state_type: PhantomData<S>,
}
impl<S: 'static + Send + Sync + Clone> ContextMenuStory<S> {
pub fn new() -> Self {
Self {
state_type: PhantomData,
}
}
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
Story::container(cx)
.child(Story::title_for::<_, ContextMenu<S>>(cx))
.child(Story::label(cx, "Default"))
.child(ContextMenu::new([
ContextMenuItem::header("Section header"),
ContextMenuItem::Separator,
ContextMenuItem::entry(Label::new("Some entry")),
]))
}
}

View file

@ -42,6 +42,7 @@ pub enum ComponentStory {
ChatPanel,
CollabPanel,
CommandPalette,
ContextMenu,
Facepile,
Keybinding,
Palette,
@ -71,6 +72,7 @@ impl ComponentStory {
Self::CommandPalette => {
components::command_palette::CommandPaletteStory::new().into_any()
}
Self::ContextMenu => components::context_menu::ContextMenuStory::new().into_any(),
Self::Facepile => components::facepile::FacepileStory::new().into_any(),
Self::Keybinding => components::keybinding::KeybindingStory::new().into_any(),
Self::Palette => components::palette::PaletteStory::new().into_any(),