
This PR reworks the theme definition in the `theme2` crate to be based off of the new theme work that @iamnbutler has been working on. We're still developing the new theme system, but it is complete enough that we can now load the default theme and use it to theme the storybook (albeit with some further refining of the color palette required). --------- Co-authored-by: Nate Butler <iamnbutler@gmail.com> Co-authored-by: Marshall Bowers <marshall@zed.dev>
81 lines
2.4 KiB
Rust
81 lines
2.4 KiB
Rust
use gpui2::AnyElement;
|
|
use smallvec::SmallVec;
|
|
|
|
use crate::{h_stack, prelude::*, v_stack, Button, Icon, IconButton, Label};
|
|
|
|
#[derive(Component)]
|
|
pub struct Modal<V: 'static> {
|
|
id: ElementId,
|
|
title: Option<SharedString>,
|
|
primary_action: Option<Button<V>>,
|
|
secondary_action: Option<Button<V>>,
|
|
children: SmallVec<[AnyElement<V>; 2]>,
|
|
}
|
|
|
|
impl<V: 'static> Modal<V> {
|
|
pub fn new(id: impl Into<ElementId>) -> Self {
|
|
Self {
|
|
id: id.into(),
|
|
title: None,
|
|
primary_action: None,
|
|
secondary_action: None,
|
|
children: SmallVec::new(),
|
|
}
|
|
}
|
|
|
|
pub fn title(mut self, title: impl Into<SharedString>) -> Self {
|
|
self.title = Some(title.into());
|
|
self
|
|
}
|
|
|
|
pub fn primary_action(mut self, action: Button<V>) -> Self {
|
|
self.primary_action = Some(action);
|
|
self
|
|
}
|
|
|
|
pub fn secondary_action(mut self, action: Button<V>) -> Self {
|
|
self.secondary_action = Some(action);
|
|
self
|
|
}
|
|
|
|
fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
|
|
v_stack()
|
|
.id(self.id.clone())
|
|
.w_96()
|
|
// .rounded_xl()
|
|
.bg(cx.theme().colors().background)
|
|
.border()
|
|
.border_color(cx.theme().colors().border)
|
|
.shadow_2xl()
|
|
.child(
|
|
h_stack()
|
|
.justify_between()
|
|
.p_1()
|
|
.border_b()
|
|
.border_color(cx.theme().colors().border)
|
|
.child(div().children(self.title.clone().map(|t| Label::new(t))))
|
|
.child(IconButton::new("close", Icon::Close)),
|
|
)
|
|
.child(v_stack().p_1().children(self.children))
|
|
.when(
|
|
self.primary_action.is_some() || self.secondary_action.is_some(),
|
|
|this| {
|
|
this.child(
|
|
h_stack()
|
|
.border_t()
|
|
.border_color(cx.theme().colors().border)
|
|
.p_1()
|
|
.justify_end()
|
|
.children(self.secondary_action)
|
|
.children(self.primary_action),
|
|
)
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
impl<V: 'static> ParentElement<V> for Modal<V> {
|
|
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement<V>; 2]> {
|
|
&mut self.children
|
|
}
|
|
}
|