<img width="1342" alt="SCR-20250327-jfzq" src="https://github.com/user-attachments/assets/7c44458a-9467-4095-9cd6-1dcb35cc351b" /> <img width="1342" alt="SCR-20250327-jgak" src="https://github.com/user-attachments/assets/07d33d60-f581-46d4-9a54-174e56ab82ca" />
115 lines
3.6 KiB
Rust
115 lines
3.6 KiB
Rust
use gpui::*;
|
|
use gpui_component::{
|
|
alert::Alert,
|
|
button::{Button, ButtonGroup},
|
|
v_flex, IconName, Selectable as _, Sizable as _, Size,
|
|
};
|
|
use story::Assets;
|
|
|
|
pub struct Example {
|
|
size: Size,
|
|
}
|
|
|
|
impl Example {
|
|
pub fn new(_: &mut Window, _: &mut Context<Self>) -> Self {
|
|
Self {
|
|
size: Size::default(),
|
|
}
|
|
}
|
|
|
|
fn view(window: &mut Window, cx: &mut App) -> Entity<Self> {
|
|
cx.new(|cx| Self::new(window, cx))
|
|
}
|
|
|
|
fn set_size(&mut self, size: Size, _: &mut Window, cx: &mut Context<Self>) {
|
|
self.size = size;
|
|
cx.notify();
|
|
}
|
|
}
|
|
|
|
impl Render for Example {
|
|
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
|
v_flex()
|
|
.m_4()
|
|
.gap_4()
|
|
.child(
|
|
ButtonGroup::new("toggle-size")
|
|
.outline()
|
|
.compact()
|
|
.child(
|
|
Button::new("xsmall")
|
|
.label("XSmall")
|
|
.selected(self.size == Size::XSmall),
|
|
)
|
|
.child(
|
|
Button::new("small")
|
|
.label("Small")
|
|
.selected(self.size == Size::Small),
|
|
)
|
|
.child(
|
|
Button::new("medium")
|
|
.label("Medium")
|
|
.selected(self.size == Size::Medium),
|
|
)
|
|
.child(
|
|
Button::new("large")
|
|
.label("Large")
|
|
.selected(self.size == Size::Large),
|
|
)
|
|
.on_click(cx.listener(|this, selecteds: &Vec<usize>, window, cx| {
|
|
let size = match selecteds[0] {
|
|
0 => Size::XSmall,
|
|
1 => Size::Small,
|
|
2 => Size::Medium,
|
|
3 => Size::Large,
|
|
_ => unreachable!(),
|
|
};
|
|
this.set_size(size, window, cx);
|
|
})),
|
|
)
|
|
.child(
|
|
Alert::info("This is an info alert.")
|
|
.with_size(self.size)
|
|
.title("Info message"),
|
|
)
|
|
.child(
|
|
Alert::success(
|
|
"You have successfully submitted your form.\n\
|
|
Thank you for your submission!",
|
|
)
|
|
.with_size(self.size)
|
|
.title("Submit Successful"),
|
|
)
|
|
.child(
|
|
Alert::warning(
|
|
"This is a warning alert with icon and title.\n\
|
|
This is second line of text to test is the line-height is correct.",
|
|
)
|
|
.with_size(self.size),
|
|
)
|
|
.child(
|
|
Alert::error(
|
|
"There was an error submitting your form.\n\
|
|
Please try again later, if you still have issues, please contact support.",
|
|
)
|
|
.with_size(self.size)
|
|
.title("Error!"),
|
|
)
|
|
.child(
|
|
Alert::info("Custom icon with info alert.")
|
|
.with_size(self.size)
|
|
.icon(IconName::Bell),
|
|
)
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let app = Application::new().with_assets(Assets);
|
|
|
|
app.run(move |cx| {
|
|
story::init(cx);
|
|
cx.activate(true);
|
|
|
|
story::create_new_window("Alert Example", Example::view, cx);
|
|
});
|
|
}
|