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