Buttons

Close Button

A button for dismissing dialogs, modals and inline content.

Rust
1use herogpui::components::close_button::CloseButton;

Usage

Rust
1use herogpui::prelude::CloseButton;
2
3CloseButton::new("close-button")

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

CloseButton

Close Button is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Close Button uses.

Styling

Close Button styling
StyleDescription
flex + size(px(24.)) + p(px(4.)) + items_center + justify_centerBase 24px square and alignment; GPUI has no isolation, selection, highlight or transform-origin controls.
cursor_pointer()Enabled close buttons use the interactive pointer cursor.
small_radius(cx)Twelve-pixel root corner radius.
colors.default.color + colors.mutedDefault surface and foreground semantic tokens.
hover(colors.default.hover())Hover surface uses the default-hover role token.
active centered root-bounds shrinkThe root bounds shrink to 93% about the center without moving neighboring layout; fixed child content remains unscaled.
svg().size(px(16.)) / icon(element)The built-in glyph is 16px; selector-specific margins and pointer behavior are unavailable for arbitrary replacement children.
immediate hover/active/ring stylesChanges hover, press and focus styling on a frame without these interpolation timelines.
ring_if_focused(offset = true)Shared focus-visible ring and offset treatment.
disabled_opacity + listener/callback/tab-stop gatesMatches opacity and interaction semantics through explicit gates rather than hit testing.

API reference

Builders

Close Button builders
BuilderTypeDefaultDescription
content(render)AnyElement | Fn(values: CloseButtonRenderProps) -> AnyElement<CloseIcon />Replaces the default glyph with an element or an interactive-state render function.
on_press(callback)Fn() -> ()Handler called when the enabled button is pressed.
is_disabled(bool)boolfalseWhether the close button is disabled.

Parts

Close Button parts
PartDescription
CloseButtonFocusable root button and owner of disabled, hover, press and focus state.
CloseButtonBuilt-in close glyph; icon(element) or content(render) replaces it in the port.

States

Close Button states
BuilderStateDescription
hover(colors.default.hover()) + InteractiveState::is_hoveredHoveredEnabled buttons use the default-hover background and report hover to render content.
active centered root-bounds shrink + InteractiveState::is_pressedPressedPressed state reaches custom content; the root bounds shrink to a centered 93%, but fixed child content does not scale with the CSS transform.
tab_stop_handle + ring_if_focusedFocus visibleKeyboard focus draws the shared status-focused ring.
is_disabled + disabled_opacity + interaction gatesDisabledDisabled buttons are dimmed, removed from the tab order and expose no hover, press or activation.