1use gpui::{
2 AnyElement, App, BoxShadow, IntoElement, ParentElement, RenderOnce, Styled, Window, div, hsla,
3 point, px,
4};
5use theme::ActiveTheme;
6
7use crate::{ElevationIndex, h_flex};
8
9use super::ButtonLike;
10
11/// /// A button with two parts: a primary action on the left and a secondary action on the right.
12///
13/// The left side is a [`ButtonLike`] with the main action, while the right side can contain
14/// any element (typically a dropdown trigger or similar).
15///
16/// The two sections are visually separated by a divider, but presented as a unified control.
17#[derive(IntoElement)]
18pub struct SplitButton {
19 pub left: ButtonLike,
20 pub right: AnyElement,
21}
22
23impl RenderOnce for SplitButton {
24 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
25 h_flex()
26 .rounded_sm()
27 .border_1()
28 .border_color(cx.theme().colors().text_muted.alpha(0.12))
29 .child(div().flex_grow().child(self.left))
30 .child(
31 div()
32 .h_full()
33 .w_px()
34 .bg(cx.theme().colors().text_muted.alpha(0.16)),
35 )
36 .child(self.right)
37 .bg(ElevationIndex::Surface.on_elevation_bg(cx))
38 .shadow(smallvec::smallvec![BoxShadow {
39 color: hsla(0.0, 0.0, 0.0, 0.16),
40 offset: point(px(0.), px(1.)),
41 blur_radius: px(0.),
42 spread_radius: px(0.),
43 }])
44 }
45}