Repository Public MIT
1# GlassCard23| | |4|---|---|5| Identifier | `glass-card` |6| Module | `SPGlassComponents` |7| Kind | `content-component` — opaque themed surface by default; Liquid Glass only in the `.floating` style |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Containers/GlassCardExample.swift` |1011## Minimal usage1213```swift14GlassCard("Monthly rent") {15 Text("1,450 $").font(.title2)16}17```1819## Variants2021| Variant | Use |22|---|---|23| `.opaque` (default) | Dense content: text, figures, forms. Drawn with `glassOpaqueSurface`. |24| `.floating` | A card above other content (a map, a photo, a feed). Drawn with `glassSurface`; the glass is interactive only when the card has an `action`. |25| `action:` | The whole card becomes one button. |26| header / footer | Optional slots: the header uses the headline font and the header trait, the footer the caption font. |2728## Parameters2930| Parameter | Type | Default | Meaning |31|---|---|---|---|32| `titleKey` / `verbatim` | `LocalizedStringKey` / `StringProtocol` | — | Title used as the header. |33| `style` | `GlassCardStyle` | `.opaque` | Surface of the card. |34| `padding` | `GlassSpacingStep` | `.md` | Inner padding from the theme's spacing scale. |35| `action` | `(@MainActor () -> Void)?` | `nil` | Makes the card a button. |36| `content` | `@ViewBuilder` | — | Body of the card. |37| `header`, `footer` | `@ViewBuilder` | none | Optional slots. |3839### Media, header and footer4041| Parameter | Type | Default | Meaning |42|---|---|---|---|43| `media` | `() -> some View` | none | A photo, map or drawing shown edge to edge above the header and clipped to the card's rounded top. Give it a height. |4445`GlassCard(media:content:header:footer:)` and `GlassCard(media:content:)` take the media area. The footer sits under a hairline and holds secondary text or one action. The surface carries a hairline and a contact shadow; a `.floating` card uses neutral glass (never the theme's glass tint) so that its text stays legible.4647## States4849Without an action the card has no state. With an action, pressed and focused are drawn by the system button; `.disabled(_:)` applies as usual.5051## Advanced example5253```swift54GlassCard(style: .floating, action: { router.open(listing) }) {55 Text(listing.address)56 Text(listing.price, format: .currency(code: "CAD"))57} header: {58 Label("Nearby", systemImage: "mappin.and.ellipse")59} footer: {60 Text(listing.updated, format: .relative(presentation: .named))61}62.accessibilityHint("Opens the listing")63```6465## Accessibility6667- A tappable card is a single `Button`: VoiceOver reads its texts as one element with the button trait.68- A static card is a container; its header carries the header trait, so rotor navigation by headings works.69- Text uses theme fonts and wraps; the card grows with Dynamic Type.7071## Limits7273- Do not put buttons, links or fields inside a card that has an `action`; nested controls are not reachable separately.74- Do not use `.floating` for long text, and never place a floating card inside another glass surface.75- The card takes the width of its content; give it `.frame(maxWidth: .infinity, alignment: .leading)` to fill a column.76