Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add `ThemeSelector` component
Marshall Bowers100a4731e257
diff --git a/crates/storybook2/src/stories/components.rs b/crates/storybook2/src/stories/components.rsindex 97ca15c0c40..9016567de4a 100644--- a/crates/storybook2/src/stories/components.rs+++ b/crates/storybook2/src/stories/components.rs@@ -15,6 +15,7 @@ pub mod project_panel;pub mod tab;pub mod tab_bar;pub mod terminal;+pub mod theme_selector;pub mod title_bar;pub mod toast;pub mod toolbar;diff --git a/crates/storybook2/src/stories/components/theme_selector.rs b/crates/storybook2/src/stories/components/theme_selector.rsnew file mode 100644index 00000000000..b766a9afacd--- /dev/null+++ b/crates/storybook2/src/stories/components/theme_selector.rs@@ -0,0 +1,26 @@+use std::marker::PhantomData;++use ui::prelude::*;+use ui::ThemeSelector;++use crate::story::Story;++#[derive(Element)]+pub struct ThemeSelectorStory<S: 'static + Send + Sync + Clone> {+ state_type: PhantomData<S>,+}++impl<S: 'static + Send + Sync + Clone> ThemeSelectorStory<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::<_, ThemeSelector<S>>(cx))+ .child(Story::label(cx, "Default"))+ .child(ThemeSelector::new())+ }+}diff --git a/crates/storybook2/src/story_selector.rs b/crates/storybook2/src/story_selector.rsindex 9e8ae772f98..d75e14bd322 100644--- a/crates/storybook2/src/story_selector.rs+++ b/crates/storybook2/src/story_selector.rs@@ -53,6 +53,7 @@ pub enum ComponentStory {Tab,TabBar,Terminal,+ ThemeSelector,TitleBar,Toast,Toolbar,@@ -88,6 +89,7 @@ impl ComponentStory {Self::Tab => components::tab::TabStory::new().into_any(),Self::TabBar => components::tab_bar::TabBarStory::new().into_any(),Self::Terminal => components::terminal::TerminalStory::new().into_any(),+ Self::ThemeSelector => components::theme_selector::ThemeSelectorStory::new().into_any(),Self::TitleBar => components::title_bar::TitleBarStory::new().into_any(),Self::Toast => components::toast::ToastStory::new().into_any(),Self::Toolbar => components::toolbar::ToolbarStory::new().into_any(),diff --git a/crates/ui2/src/components.rs b/crates/ui2/src/components.rsindex 185e76e749d..a9557baac6e 100644--- a/crates/ui2/src/components.rs+++ b/crates/ui2/src/components.rs@@ -21,6 +21,7 @@ mod status_bar;mod tab;mod tab_bar;mod terminal;+mod theme_selector;mod title_bar;mod toast;mod toolbar;@@ -50,6 +51,7 @@ pub use status_bar::*;pub use tab::*;pub use tab_bar::*;pub use terminal::*;+pub use theme_selector::*;pub use title_bar::*;pub use toast::*;pub use toolbar::*;diff --git a/crates/ui2/src/components/theme_selector.rs b/crates/ui2/src/components/theme_selector.rsnew file mode 100644index 00000000000..d51b5c74264--- /dev/null+++ b/crates/ui2/src/components/theme_selector.rs@@ -0,0 +1,41 @@+use std::marker::PhantomData;++use crate::prelude::*;+use crate::{OrderMethod, Palette, PaletteItem};++#[derive(Element)]+pub struct ThemeSelector<S: 'static + Send + Sync + Clone> {+ state_type: PhantomData<S>,+ scroll_state: ScrollState,+}++impl<S: 'static + Send + Sync + Clone> ThemeSelector<S> {+ pub fn new() -> Self {+ Self {+ state_type: PhantomData,+ scroll_state: ScrollState::default(),+ }+ }++ fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {+ div().child(+ Palette::new(self.scroll_state.clone())+ .items(vec![+ PaletteItem::new("One Dark"),+ PaletteItem::new("Rosé Pine"),+ PaletteItem::new("Rosé Pine Moon"),+ PaletteItem::new("Sandcastle"),+ PaletteItem::new("Solarized Dark"),+ PaletteItem::new("Summercamp"),+ PaletteItem::new("Atelier Cave Light"),+ PaletteItem::new("Atelier Dune Light"),+ PaletteItem::new("Atelier Estuary Light"),+ PaletteItem::new("Atelier Forest Light"),+ PaletteItem::new("Atelier Heath Light"),+ ])+ .placeholder("Select Theme...")+ .empty_string("No matches")+ .default_order(OrderMethod::Ascending),+ )+ }+}