alert: Add to support styled. (#736)
This commit is contained in:
parent
22d9394266
commit
814ea0e824
2 changed files with 79 additions and 69 deletions
58
README.md
58
README.md
|
|
@ -7,38 +7,38 @@ UI components for building fantastic desktop application by using [GPUI](https:/
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
- Accordion
|
||||||
|
- Alert
|
||||||
|
- Badge
|
||||||
|
- Breadcrumb
|
||||||
|
- Button, Link
|
||||||
|
- Checkbox, Radio, Switch
|
||||||
|
- ColorPicker
|
||||||
|
- DatePicker, DateRangePicker, Calendar
|
||||||
|
- Dock, Tiles
|
||||||
|
- Drawer
|
||||||
|
- Dropdown
|
||||||
|
- Icon
|
||||||
|
- Label
|
||||||
|
- List
|
||||||
|
- Menu
|
||||||
|
- Modal
|
||||||
|
- Notification
|
||||||
|
- Popover
|
||||||
|
- Progress & Indicator
|
||||||
|
- Resizable
|
||||||
|
- Sidebar
|
||||||
|
- Skeleton
|
||||||
|
- Slider
|
||||||
|
- Table
|
||||||
|
- Tabs
|
||||||
|
- TextInput, TextArea, OtpInput
|
||||||
|
- TextView (Markdown, Simple HTML) to native rendering, syntax highlighting.
|
||||||
- Theming
|
- Theming
|
||||||
- TitleBar
|
- TitleBar
|
||||||
- Dock, Tiles
|
|
||||||
- TextInput, TextArea, OtpInput
|
|
||||||
- Button, Link
|
|
||||||
- Label
|
|
||||||
- Icon
|
|
||||||
- Checkbox, Radio, Switch
|
|
||||||
- Dropdown
|
|
||||||
- Tabs
|
|
||||||
- Notification
|
|
||||||
- Tooltip
|
|
||||||
- Popover
|
|
||||||
- Resizable
|
|
||||||
- Progress & Indicator
|
|
||||||
- Slider
|
|
||||||
- Skeleton
|
|
||||||
- DatePicker, DateRangePicker, Calendar
|
|
||||||
- ColorPicker
|
|
||||||
- List
|
|
||||||
- Table
|
|
||||||
- Menu
|
|
||||||
- Drawer
|
|
||||||
- Modal
|
|
||||||
- WebView
|
|
||||||
- Accordion
|
|
||||||
- Sidebar
|
|
||||||
- Breadcrumb
|
|
||||||
- Badge
|
|
||||||
- TextView (Markdown, Simple HTML) to native rendering, syntax highlighting.
|
|
||||||
- Toggle, ToggleGroup
|
- Toggle, ToggleGroup
|
||||||
- Alert
|
- Tooltip
|
||||||
|
- WebView
|
||||||
|
|
||||||
## Showcase
|
## Showcase
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, px, relative, App, Hsla, IntoElement, ParentElement as _,
|
div, prelude::FluentBuilder as _, px, relative, App, Div, Hsla, IntoElement,
|
||||||
RenderOnce, SharedString, Styled, Window,
|
ParentElement as _, RenderOnce, SharedString, Styled, Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{h_flex, text::Text, ActiveTheme as _, Icon, IconName, Sizable, Size, StyledExt};
|
use crate::{h_flex, text::Text, ActiveTheme as _, Icon, IconName, Sizable, Size, StyledExt};
|
||||||
|
|
@ -37,6 +37,7 @@ impl AlertVariant {
|
||||||
/// Alert used to display a message to the user.
|
/// Alert used to display a message to the user.
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Alert {
|
pub struct Alert {
|
||||||
|
base: Div,
|
||||||
variant: AlertVariant,
|
variant: AlertVariant,
|
||||||
icon: Option<Icon>,
|
icon: Option<Icon>,
|
||||||
title: Option<SharedString>,
|
title: Option<SharedString>,
|
||||||
|
|
@ -48,6 +49,7 @@ impl Alert {
|
||||||
/// Create a new alert with the given message.
|
/// Create a new alert with the given message.
|
||||||
fn new(message: impl Into<Text>) -> Self {
|
fn new(message: impl Into<Text>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
base: div(),
|
||||||
variant: AlertVariant::default(),
|
variant: AlertVariant::default(),
|
||||||
icon: None,
|
icon: None,
|
||||||
title: None,
|
title: None,
|
||||||
|
|
@ -110,6 +112,12 @@ impl Sizable for Alert {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Styled for Alert {
|
||||||
|
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
||||||
|
self.base.style()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl RenderOnce for Alert {
|
impl RenderOnce for Alert {
|
||||||
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
let (radius, padding_x, padding_y, gap, line_height, icon_mt) = match self.size {
|
let (radius, padding_x, padding_y, gap, line_height, icon_mt) = match self.size {
|
||||||
|
|
@ -135,6 +143,7 @@ impl RenderOnce for Alert {
|
||||||
|
|
||||||
let color = self.variant.color(cx);
|
let color = self.variant.color(cx);
|
||||||
|
|
||||||
|
self.base.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
.rounded(radius)
|
.rounded(radius)
|
||||||
.border_1()
|
.border_1()
|
||||||
|
|
@ -173,6 +182,7 @@ impl RenderOnce for Alert {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.child(div().overflow_hidden().child(self.message)),
|
.child(div().overflow_hidden().child(self.message)),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue