search_bar.rs

 1use gpui::{Action, FocusHandle, Hsla, IntoElement};
 2use ui::{IconButton, IconButtonShape};
 3use ui::{Tooltip, prelude::*};
 4
 5use crate::ToggleReplace;
 6
 7pub(super) fn render_nav_button(
 8    icon: ui::IconName,
 9    active: bool,
10    tooltip: &'static str,
11    action: &'static dyn Action,
12    focus_handle: FocusHandle,
13) -> impl IntoElement {
14    IconButton::new(
15        SharedString::from(format!("search-nav-button-{}", action.name())),
16        icon,
17    )
18    .shape(IconButtonShape::Square)
19    .on_click({
20        let focus_handle = focus_handle.clone();
21        move |_, window, cx| {
22            if !focus_handle.is_focused(&window) {
23                window.focus(&focus_handle);
24            }
25            window.dispatch_action(action.boxed_clone(), cx)
26        }
27    })
28    .tooltip(move |window, cx| Tooltip::for_action_in(tooltip, action, &focus_handle, window, cx))
29    .disabled(!active)
30}
31
32pub(crate) fn input_base_styles(border_color: Hsla, map: impl FnOnce(Div) -> Div) -> Div {
33    h_flex()
34        .min_w_32()
35        .map(map)
36        .h_8()
37        .pl_2()
38        .pr_1()
39        .py_1()
40        .border_1()
41        .border_color(border_color)
42        .rounded_lg()
43}
44
45pub(crate) fn toggle_replace_button(
46    id: &'static str,
47    focus_handle: FocusHandle,
48    replace_enabled: bool,
49    on_click: impl Fn(&gpui::ClickEvent, &mut Window, &mut App) + 'static,
50) -> IconButton {
51    IconButton::new(id, IconName::Replace)
52        .shape(IconButtonShape::Square)
53        .style(ButtonStyle::Subtle)
54        .when(replace_enabled, |button| button.style(ButtonStyle::Filled))
55        .on_click(on_click)
56        .toggle_state(replace_enabled)
57        .tooltip({
58            move |window, cx| {
59                Tooltip::for_action_in("Toggle Replace", &ToggleReplace, &focus_handle, window, cx)
60            }
61        })
62}