Add xsmall controls for close affordances

- Add the xsmall size class and Sizable::xsmall().
- Use xsmall close buttons in tabs, dialogs, and alerts.
- Assert xsmall and medium button heights.
This commit is contained in:
2026-11-16 19:05:44 +07:00
parent 03648469ec
commit be457c1bba
7 changed files with 71 additions and 11 deletions
+1 -1
View File
@@ -183,7 +183,7 @@ impl RenderOnce for Alert {
Button::new((self.id.clone(), "alert-close"))
.icon(IconRole::Close)
.variant(ButtonVariant::Ghost)
.small()
.xsmall()
.accessibility_label("Dismiss")
.on_click(move |_, _window, cx| on_dismiss(cx))
});
+8
View File
@@ -24,6 +24,14 @@ pub trait Sizable: Sized {
/// Applies the size to the component's fields.
fn apply_size(&mut self, size: Size);
/// Sets `Size::XSmall`.
fn xsmall(self) -> Self
where
Self: Sized,
{
self.with_size(Size::XSmall)
}
/// Sets `Size::Small`.
fn small(self) -> Self
where
+1 -1
View File
@@ -245,7 +245,7 @@ impl RenderOnce for Dialog {
Button::new("dialog-close")
.icon(IconRole::Close)
.variant(ButtonVariant::Ghost)
.small()
.xsmall()
.debug_selector(|| "dialog-close".to_string())
.accessibility_label("Close")
.on_click({
+24 -8
View File
@@ -5,28 +5,44 @@ use gpui::{
VisualTestContext, Window, div, px, size,
};
use gpui_native_core::button::Button;
use gpui_native_core::common::Sizable as _;
use gpui_native_theme::Theme;
struct Harness;
impl Render for Harness {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div().size_full().child(
Button::new("height-probe")
.label("Probe")
.debug_selector(|| "height-probe".to_string()),
)
div()
.size_full()
.flex()
.flex_col()
.gap_2()
.child(
Button::new("height-probe")
.label("Probe")
.debug_selector(|| "height-probe".to_string()),
)
.child(
Button::new("xsmall-height-probe")
.label("Probe")
.xsmall()
.debug_selector(|| "xsmall-height-probe".to_string()),
)
}
}
#[gpui::test]
fn medium_button_renders_at_the_token_height(cx: &mut TestAppContext) {
fn buttons_render_at_their_token_heights(cx: &mut TestAppContext) {
cx.update(Theme::init);
let window = cx.open_window(size(px(400.), px(400.)), |_, _| Harness);
let mut cx = VisualTestContext::from_window(window.into(), cx);
cx.run_until_parked();
let bounds = cx.debug_bounds("height-probe").expect("button laid out");
let medium = cx.debug_bounds("height-probe").expect("button laid out");
let xsmall = cx
.debug_bounds("xsmall-height-probe")
.expect("xsmall button laid out");
assert_eq!(bounds.size.height, px(32.0));
assert_eq!(medium.size.height, px(32.0));
assert_eq!(xsmall.size.height, px(24.0));
}