ui2: Reorganize components (#3228)

This PR reorganizes the components in the `ui2` crate.

The distinction between "elements" and "components" is now gone, with
all of the reusable components living under `components/`.

The components that we built while prototyping but will eventually live
in other crates currently reside in the `to_extract/` module.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-11-03 22:34:11 +01:00 committed by GitHub
parent 287ea0a6e4
commit 76db100d11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 99 additions and 130 deletions

View file

@ -0,0 +1,53 @@
use crate::prelude::*;
use crate::{OrderMethod, Palette, PaletteItem};
#[derive(Component)]
pub struct RecentProjects {
id: ElementId,
}
impl RecentProjects {
pub fn new(id: impl Into<ElementId>) -> Self {
Self { id: id.into() }
}
fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
div().id(self.id.clone()).child(
Palette::new("palette")
.items(vec![
PaletteItem::new("zed").sublabel(SharedString::from("~/projects/zed")),
PaletteItem::new("saga").sublabel(SharedString::from("~/projects/saga")),
PaletteItem::new("journal").sublabel(SharedString::from("~/journal")),
PaletteItem::new("dotfiles").sublabel(SharedString::from("~/dotfiles")),
PaletteItem::new("zed.dev").sublabel(SharedString::from("~/projects/zed.dev")),
PaletteItem::new("laminar").sublabel(SharedString::from("~/projects/laminar")),
])
.placeholder("Recent Projects...")
.empty_string("No matches")
.default_order(OrderMethod::Ascending),
)
}
}
#[cfg(feature = "stories")]
pub use stories::*;
#[cfg(feature = "stories")]
mod stories {
use super::*;
use crate::Story;
use gpui2::{Div, Render};
pub struct RecentProjectsStory;
impl Render for RecentProjectsStory {
type Element = Div<Self>;
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
Story::container(cx)
.child(Story::title_for::<_, RecentProjects>(cx))
.child(Story::label(cx, "Default"))
.child(RecentProjects::new("recent-projects"))
}
}
}