SPB Git

Repository Public MIT

glass-badge.md 3.6 KB 79 lines markdown

1# GlassBadge23| | |4|---|---|5| Identifier | `glass-badge` |6| Module | `SPGlassComponents` |7| Kind | `content-component` — solid fill, no glass |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Feedback/GlassBadgeExample.swift` |1011## Minimal usage1213```swift14GlassBadge(count: unreadCount)15```1617## Variants1819| Variant | Appearance |20|---|---|21| `GlassBadge(count:cap:showsZero:tone:)` | Number in a capsule; above `cap` it reads "99+"; hidden at zero unless `showsZero`. |22| `GlassBadge("New", tone:)` | Short value in a capsule. |23| `GlassBadge(status: "Online", tone:)` | Symbol in the tone's colour followed by the status name. |2425Tones: `.neutral`, `.accent`, `.success`, `.warning`, `.critical`. Each status tone has a symbol of a different shape (`circle`, `info.circle`, `checkmark.circle`, `exclamationmark.triangle`, `xmark.octagon`).2627## Parameters2829| Parameter | Type | Default | Meaning |30|---|---|---|---|31| `count` | `Int` | — | Number of items; negative values count as zero. |32| `cap` | `Int` | `99` | Largest number shown; a cap below 1 counts as 1. |33| `showsZero` | `Bool` | `false` | Shows "0" instead of hiding the badge. |34| `value` | `String` | — | Short text; an empty string hides the badge. |35| `status` | `String` | — | Status name, already localised by the host. |36| `showsLabel` | `Bool` | `true` | `false` shows the status symbol alone. |37| `tone` | `GlassBadgeTone` | `.critical` for counts, `.neutral` for values | Meaning and colour. |3839`GlassBadgeFormatter.countText(_:cap:showsZero:locale:)` and `countAccessibilityLabel(_:cap:)` are pure and public.4041### Style and placement4243| Parameter | Type | Default | Meaning |44|---|---|---|---|45| `style` | `GlassBadgeStyle` | `.solid` (`nil` for a status badge) | `.solid`: filled with the tone's colour. `.soft`: a light tint with dark text, for labels repeated down a list or a table. `.outline`: a hairline on a clear background. A status badge with a style is enclosed in a pill. |4647`view.glassBadge(count:cap:showsZero:tone:)` places a count badge on the top trailing corner of a view, typically an icon. `GlassIconTile(systemImage:tone:size:)` is the tinted rounded tile used next to a row, a banner or a timeline event; it is decorative and hidden from assistive technologies.4849## States5051Hidden (count of zero, empty value) or visible. No interaction.5253## Advanced example5455```swift56HStack {57    Label("Inbox", systemImage: "tray")58    Spacer()59    GlassBadge(count: model.unread, cap: 999)60        .accessibilityLabel("\(model.unread) unread messages")61}6263GlassBadge(status: server.isHealthy ? "Operational" : "Outage", tone: server.isHealthy ? .success : .critical)64```6566## Accessibility6768- A count is read as "7 items", or "More than 99" above the cap; replace it with `.accessibilityLabel` when the unit matters ("7 unread messages").69- A status badge is read by its label; the symbol is hidden from VoiceOver. With `showsLabel: false` the label remains the accessibility label and the symbol shape still identifies the tone.70- Text on a coloured fill uses `theme.onColor`, the more legible of white and near-black for that fill. Digits follow the locale.71- The caption font follows Dynamic Type.7273## Limits7475- Never rely on the tone's colour for meaning: give a status badge a label, and a value badge a self-explanatory text.76- With the System theme (roles left to the system) a toned capsule uses a tinted surface with the primary text colour instead of a solid fill, because the contrast of white text on a system colour cannot be measured.77- A badge is not a button. Do not use it for long text: it does not wrap.78- For tab bars and list rows prefer the system `.badge(_:)` modifier.79
Files main
Menu

Theme