Add ThemeSelector
component
This commit is contained in:
parent
000ae27aff
commit
100a4731e2
5 changed files with 72 additions and 0 deletions
|
@ -15,6 +15,7 @@ pub mod project_panel;
|
||||||
pub mod tab;
|
pub mod tab;
|
||||||
pub mod tab_bar;
|
pub mod tab_bar;
|
||||||
pub mod terminal;
|
pub mod terminal;
|
||||||
|
pub mod theme_selector;
|
||||||
pub mod title_bar;
|
pub mod title_bar;
|
||||||
pub mod toast;
|
pub mod toast;
|
||||||
pub mod toolbar;
|
pub mod toolbar;
|
||||||
|
|
26
crates/storybook2/src/stories/components/theme_selector.rs
Normal file
26
crates/storybook2/src/stories/components/theme_selector.rs
Normal file
|
@ -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())
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,6 +53,7 @@ pub enum ComponentStory {
|
||||||
Tab,
|
Tab,
|
||||||
TabBar,
|
TabBar,
|
||||||
Terminal,
|
Terminal,
|
||||||
|
ThemeSelector,
|
||||||
TitleBar,
|
TitleBar,
|
||||||
Toast,
|
Toast,
|
||||||
Toolbar,
|
Toolbar,
|
||||||
|
@ -88,6 +89,7 @@ impl ComponentStory {
|
||||||
Self::Tab => components::tab::TabStory::new().into_any(),
|
Self::Tab => components::tab::TabStory::new().into_any(),
|
||||||
Self::TabBar => components::tab_bar::TabBarStory::new().into_any(),
|
Self::TabBar => components::tab_bar::TabBarStory::new().into_any(),
|
||||||
Self::Terminal => components::terminal::TerminalStory::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::TitleBar => components::title_bar::TitleBarStory::new().into_any(),
|
||||||
Self::Toast => components::toast::ToastStory::new().into_any(),
|
Self::Toast => components::toast::ToastStory::new().into_any(),
|
||||||
Self::Toolbar => components::toolbar::ToolbarStory::new().into_any(),
|
Self::Toolbar => components::toolbar::ToolbarStory::new().into_any(),
|
||||||
|
|
|
@ -21,6 +21,7 @@ mod status_bar;
|
||||||
mod tab;
|
mod tab;
|
||||||
mod tab_bar;
|
mod tab_bar;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
mod theme_selector;
|
||||||
mod title_bar;
|
mod title_bar;
|
||||||
mod toast;
|
mod toast;
|
||||||
mod toolbar;
|
mod toolbar;
|
||||||
|
@ -50,6 +51,7 @@ pub use status_bar::*;
|
||||||
pub use tab::*;
|
pub use tab::*;
|
||||||
pub use tab_bar::*;
|
pub use tab_bar::*;
|
||||||
pub use terminal::*;
|
pub use terminal::*;
|
||||||
|
pub use theme_selector::*;
|
||||||
pub use title_bar::*;
|
pub use title_bar::*;
|
||||||
pub use toast::*;
|
pub use toast::*;
|
||||||
pub use toolbar::*;
|
pub use toolbar::*;
|
||||||
|
|
41
crates/ui2/src/components/theme_selector.rs
Normal file
41
crates/ui2/src/components/theme_selector.rs
Normal file
|
@ -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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue