1use gpui::{Action, FocusHandle, IntoElement};
2use ui::{IconButton, IconButtonShape};
3use ui::{Tooltip, prelude::*};
4
5pub(super) fn render_nav_button(
6 icon: ui::IconName,
7 active: bool,
8 tooltip: &'static str,
9 action: &'static dyn Action,
10 focus_handle: FocusHandle,
11) -> impl IntoElement {
12 IconButton::new(
13 SharedString::from(format!("search-nav-button-{}", action.name())),
14 icon,
15 )
16 .shape(IconButtonShape::Square)
17 .on_click({
18 let focus_handle = focus_handle.clone();
19 move |_, window, cx| {
20 if !focus_handle.is_focused(&window) {
21 window.focus(&focus_handle);
22 }
23 window.dispatch_action(action.boxed_clone(), cx)
24 }
25 })
26 .tooltip(move |window, cx| Tooltip::for_action_in(tooltip, action, &focus_handle, window, cx))
27 .disabled(!active)
28}