1use std::marker::PhantomData;
2
3use crate::prelude::*;
4use crate::{OrderMethod, Palette, PaletteItem};
5
6#[derive(Element)]
7pub struct RecentProjects<S: 'static + Send + Sync + Clone> {
8 id: ElementId,
9 state_type: PhantomData<S>,
10}
11
12impl<S: 'static + Send + Sync + Clone> RecentProjects<S> {
13 pub fn new(id: impl Into<ElementId>) -> Self {
14 Self {
15 id: id.into(),
16 state_type: PhantomData,
17 }
18 }
19
20 fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
21 div().id(self.id.clone()).child(
22 Palette::new("palette")
23 .items(vec![
24 PaletteItem::new("zed").sublabel(SharedString::from("~/projects/zed")),
25 PaletteItem::new("saga").sublabel(SharedString::from("~/projects/saga")),
26 PaletteItem::new("journal").sublabel(SharedString::from("~/journal")),
27 PaletteItem::new("dotfiles").sublabel(SharedString::from("~/dotfiles")),
28 PaletteItem::new("zed.dev").sublabel(SharedString::from("~/projects/zed.dev")),
29 PaletteItem::new("laminar").sublabel(SharedString::from("~/projects/laminar")),
30 ])
31 .placeholder("Recent Projects...")
32 .empty_string("No matches")
33 .default_order(OrderMethod::Ascending),
34 )
35 }
36}
37
38#[cfg(feature = "stories")]
39pub use stories::*;
40
41#[cfg(feature = "stories")]
42mod stories {
43 use crate::Story;
44
45 use super::*;
46
47 #[derive(Element)]
48 pub struct RecentProjectsStory<S: 'static + Send + Sync + Clone> {
49 state_type: PhantomData<S>,
50 }
51
52 impl<S: 'static + Send + Sync + Clone> RecentProjectsStory<S> {
53 pub fn new() -> Self {
54 Self {
55 state_type: PhantomData,
56 }
57 }
58
59 fn render(
60 &mut self,
61 _view: &mut S,
62 cx: &mut ViewContext<S>,
63 ) -> impl Element<ViewState = S> {
64 Story::container(cx)
65 .child(Story::title_for::<_, RecentProjects<S>>(cx))
66 .child(Story::label(cx, "Default"))
67 .child(RecentProjects::new("recent-projects"))
68 }
69 }
70}