chore: improve markdown component

This commit is contained in:
2026-11-11 08:58:17 +07:00
parent a952e6cb30
commit 6d6861a766
5 changed files with 387 additions and 288 deletions
+16
View File
@@ -1,5 +1,7 @@
//! The checkbox: a controlled on/off value with an optional label.
use std::rc::Rc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
App, ElementId, InteractiveElement as _, IntoElement, ParentElement as _, RenderOnce, Role,
@@ -23,6 +25,7 @@ pub struct Checkbox {
checked: bool,
size: Size,
disabled: bool,
debug_selector: Option<Rc<dyn Fn() -> String>>,
a11y_label: Option<SharedString>,
on_change: Option<ChangeHandler>,
}
@@ -39,6 +42,7 @@ impl Checkbox {
checked: false,
size: Size::default(),
disabled: false,
debug_selector: None,
a11y_label: None,
on_change: None,
}
@@ -65,6 +69,15 @@ impl Checkbox {
self
}
/// Sets the debug-bounds selector, for headless tests.
pub fn debug_selector<F>(mut self, selector: F) -> Self
where
F: Fn() -> String + 'static,
{
self.debug_selector = Some(Rc::new(selector));
self
}
/// Overrides the accessibility label, which defaults to the visible label.
pub fn accessibility_label<L>(mut self, label: L) -> Self
where
@@ -104,6 +117,9 @@ impl RenderOnce for Checkbox {
.id(self.id)
.gap_1p5()
.text_size(metrics.text_size)
.when_some(self.debug_selector, |checkbox, selector| {
checkbox.debug_selector(move || selector())
})
.role(Role::CheckBox)
.when_some(a11y_label, |checkbox, label| checkbox.aria_label(label))
.aria_toggled(Toggled::from(self.checked))