1use std::rc::Rc;
2
3use gpui::{div, ClickEvent, Element, IntoElement, ParentElement, WindowContext};
4
5use crate::{Color, Icon, IconButton, IconSize, Toggle};
6
7pub fn disclosure_control(
8 toggle: Toggle,
9 on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
10) -> impl Element {
11 match (toggle.is_toggleable(), toggle.is_toggled()) {
12 (false, _) => div(),
13 (_, true) => div().child(
14 IconButton::new("toggle", Icon::ChevronDown)
15 .color(Color::Muted)
16 .size(IconSize::Small)
17 .when_some(on_toggle, move |el, on_toggle| {
18 el.on_click(move |e, cx| on_toggle(e, cx))
19 }),
20 ),
21 (_, false) => div().child(
22 IconButton::new("toggle", Icon::ChevronRight)
23 .color(Color::Muted)
24 .size(IconSize::Small)
25 .when_some(on_toggle, move |el, on_toggle| {
26 el.on_click(move |e, cx| on_toggle(e, cx))
27 }),
28 ),
29 }
30}