Component guidelines
Rules every catalogue component follows. The five buttons (Sources/SPGlassComponents/Buttons/) are the reference implementation; read GlassButton.swift, GlassSplitButton.swift, their example, test and documentation page before writing a component.
Deliverables per component
| Deliverable | Path | Notes |
|---|---|---|
| Implementation | Sources/<Module>/<Category>/<Name>.swift (+ <Name>+<Part>.swift if it grows past ~250 lines) |
Public API with a doc comment on every public symbol; the type comment contains a short usage snippet. |
| Example | Examples/Gallery/<Category>/<Name>Example.swift |
public struct <Name>Example: GlassExample, componentID = catalogue id, fictitious data only, ends with a #Preview. Shows the main variants and states. |
| Tests | Tests/<Module>Tests/<Name>Tests.swift |
Swift Testing. Test the logic: state machines, validation, formatting, bounds, sorting, queues. |
| Documentation | docs/components/<id>.md |
Same sections as glass-button.md: table, Minimal usage, Variants, Parameters, States, Advanced example, Accessibility, Limits. |
The catalogue entry already exists in Sources/SPGlassCore/GlassComponentCatalog.swift. If what you built is of another kind than the entry says, fix the entry and say so in your report.
Kinds
native-wrapper: configures a system control or presentation. Never draw a glass surface over or under it, never restyle its shape. Theme influence is limited to.tint.custom-glass: a control or navigation-layer surface drawn with.glassSurface(_:in:)/GlassSurface/GlassGroupfromSPGlassEffects(never callglassEffectdirectly, so the Reduce Transparency fallback is always present). Interactive glass (.interactive) only on surfaces that are themselves tappable.content-component: content on an opaque surface (.glassOpaqueSurface(in:)or no surface at all). Glass only for a small floating control on top, if any.
Glass belongs to controls and navigation layers, not to content. Never one glass surface per list cell. Never glass inside glass.
API
- Controlled state through
Binding; actions through closures typed@MainActor () -> Void(or with parameters). No business logic, no networking, no persistence inside a component. - Titles supplied by the host:
LocalizedStringKey(plus averbatim:/Stringvariant where data is displayed). Data values (messages, rows, file names) areString. - GlassKit's own words (accessibility labels, default titles):
GlassL10n.string(.key). To add a key, append one case at the end ofGlassL10n.Keyand one line at the end of bothResources/en.lproj/GlassKit.stringsandResources/fr.lproj/GlassKit.strings, with real French. Tests check that both files match the enum. - Read the theme with
@GlassThemed private var theme(theme.color(.textPrimary),theme.font(.headline),theme.spacing.md,theme.radii.medium,theme.shape(\.large),theme.metrics,theme.animation(.standard, reduceMotion:)) and accessibility with@GlassAccessibility private var accessibility(reduceMotion,reduceTransparency, which include the Studio's simulation). - Generic content via
@ViewBuilder; noAnyViewunless type erasure is unavoidable; no force unwrap, notry!, nofatalError, noprint, no mutable singleton. - Put testable logic in a non-view type (struct, enum or
@Observableclass) next to the view. Views stay thin. - Swift 6 language mode with strict concurrency: UI types are
@MainActor; shared mutable state lives in anactoror an@Observable @MainActorclass; value types areSendable. Async work is cancellable (Taskstored and cancelled,.task(id:)). - Platform differences with
#if os(macOS)/#if os(iOS); give each platform a fitting form rather than forcing the iPhone layout everywhere. Deployment target is iOS 26 / macOS 26, so no#availableis needed for Liquid Glass. - Imports:
SwiftUI,Foundation, theSPGlass*modules the file uses (list them explicitly:SPGlassCore,SPGlassTokens,SPGlassThemes,SPGlassEffects, andSPGlassComponentsoutside that module), and the Apple frameworks the component needs. No third-party package.
Accessibility and layout
- Every interactive element has a label; symbol-only controls use
Labelwith.labelStyle(.iconOnly)orGlassIconButton. Decorative images are.accessibilityHidden(true). - State is exposed with
accessibilityValue, traits (.isSelected,.isHeader,.updatesFrequently) and adjustable actions where a value changes; status is never colour alone (icon + text). - Hit targets:
.glassMinimumHitTarget()on custom tappable elements. - Text uses theme fonts (Dynamic Type) and wraps; no fixed font size for text, no fixed height that would clip at accessibility sizes. Use
ViewThatFitsordynamicTypeSizeto switch to a vertical layout when a row no longer fits. - Leading/trailing only (RTL). Numbers, dates, durations and units through
FormatStyleAPIs. - Animations come from
theme.animation(_:reduceMotion:); with Reduce Motion no travel, scale or repeat — a fade or nothing. No animation delays a response to input and nothing animates forever while idle. - Long text, empty data, Unicode (emoji, combining marks, RTL scripts) and narrow widths must not break the layout.
Privacy and safety
No network call, no tracking, no logging of user content, no persistence of entered secrets or codes. Components that need a system permission (location, microphone) never request it: they display a state injected by the host.
Verification before reporting
Build and test with your own scratch directory so that parallel work does not collide:
swift build --scratch-path .build-<name> 2>&1 | grep -E "error|warning:"
swift test --scratch-path .build-<name> --filter <Module>Tests
xcodebuild -scheme SPGlassExamples -destination 'generic/platform=iOS Simulator' -derivedDataPath .build-<name>/xcode buildAll three must succeed with no warning in the files you wrote. Report honestly what was verified and what was not.