SPB Git

Repository Public MIT

glass-button.md 2.8 KB

# GlassButton

Identifier glass-button
Module SPGlassComponents
Kind native-wrapper — the system draws the button with .buttonStyle(.glass) or .glassProminent
Platforms iOS 26, iPadOS 26, macOS 26
Example Examples/Gallery/Buttons/GlassButtonExample.swift

# Minimal usage

swift
GlassButton("Save") { save() }

# Variants

Variant Use
.regular Most actions. Untinted system glass.
.prominent The main action of a view, filled with the theme's primary colour. One per view at most.
role: .destructive Deletion and other irreversible actions. Tinted with the theme's destructive colour; the system also announces the role.

Sizes are .small, .regular and .large; they map to the system ControlSize, so the button keeps the metrics of the platform.

# Parameters

Parameter Type Default Meaning
titleKey LocalizedStringKey — Title, looked up in the host application's strings.
verbatim StringProtocol — Title that is already a string (data, user content).
systemImage String? nil SF Symbol shown before the title. Hidden while loading.
variant GlassButtonVariant .regular Visual weight.
role ButtonRole? nil System role (.destructive, .cancel).
size GlassControlSize .regular Control size.
isLoading Bool false Shows a progress indicator and ignores taps.
action @MainActor () -> Void — Called on activation.
label @ViewBuilder — Custom label, instead of a title.

# States

Idle, pressed and focused are drawn by the system. disabled is the standard .disabled(_:) modifier. loading is isLoading: the action cannot be triggered and VoiceOver reads "Loading" as the value of the button.

# Advanced example

swift
GlassButton(variant: .prominent, size: .large, isLoading: model.isUploading) {
    model.upload()
} label: {
    VStack(alignment: .leading) {
        Text("Upload")
        Text(model.fileName).font(.caption)
    }
}
.keyboardShortcut(.defaultAction)

# Accessibility

  • The title is the accessibility label; a custom label must contain text or set .accessibilityLabel.
  • Text follows Dynamic Type and wraps instead of truncating.
  • The loading state is exposed as an accessibility value, not by the spinner alone.
  • The destructive role is conveyed by the system role, not only by colour.

# Limits

  • The glass itself (blur, refraction, highlights) is drawn by the system and cannot be configured.
  • A simulated Reduce Transparency (glassSimulatedAccessibility) switches to the bordered system styles; the real setting is handled by the system inside the glass styles.
  • Several prominent buttons side by side weaken the hierarchy; prefer one.
Files main
Menu

Theme