1use crate::theme::theme;
2use gpui2::elements::svg;
3use gpui2::style::{StyleHelpers, Styleable};
4use gpui2::{elements::div, IntoElement};
5use gpui2::{Element, ParentElement, ViewContext};
6
7#[derive(Element)]
8pub(crate) struct IconButton {
9 path: &'static str,
10 variant: ButtonVariant,
11}
12
13#[derive(PartialEq)]
14pub enum ButtonVariant {
15 Ghost,
16 Filled,
17}
18
19pub fn icon_button<V: 'static>(path: &'static str, variant: ButtonVariant) -> impl Element<V> {
20 IconButton { path, variant }
21}
22
23impl IconButton {
24 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
25 let theme = theme(cx);
26
27 let mut div = div();
28 if self.variant == ButtonVariant::Filled {
29 div = div.fill(theme.highest.on.default.background);
30 }
31
32 div.w_7()
33 .h_6()
34 .flex()
35 .items_center()
36 .justify_center()
37 .rounded_md()
38 .hover()
39 .fill(theme.highest.base.hovered.background)
40 .active()
41 .fill(theme.highest.base.pressed.background)
42 .child(
43 svg()
44 .path(self.path)
45 .w_4()
46 .h_4()
47 .fill(theme.highest.variant.default.foreground),
48 )
49 }
50}