SPB Git

Repository Public MIT

COMPONENT_GUIDELINES.md 6.0 KB

# 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 / GlassGroup from SPGlassEffects (never call glassEffect directly, 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 a verbatim:/String variant where data is displayed). Data values (messages, rows, file names) are String.
  • GlassKit's own words (accessibility labels, default titles): GlassL10n.string(.key). To add a key, append one case at the end of GlassL10n.Key and one line at the end of both Resources/en.lproj/GlassKit.strings and Resources/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; no AnyView unless type erasure is unavoidable; no force unwrap, no try!, no fatalError, no print, no mutable singleton.
  • Put testable logic in a non-view type (struct, enum or @Observable class) next to the view. Views stay thin.
  • Swift 6 language mode with strict concurrency: UI types are @MainActor; shared mutable state lives in an actor or an @Observable @MainActor class; value types are Sendable. Async work is cancellable (Task stored 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 #available is needed for Liquid Glass.
  • Imports: SwiftUI, Foundation, the SPGlass* modules the file uses (list them explicitly: SPGlassCore, SPGlassTokens, SPGlassThemes, SPGlassEffects, and SPGlassComponents outside 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 Label with .labelStyle(.iconOnly) or GlassIconButton. 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 ViewThatFits or dynamicTypeSize to switch to a vertical layout when a row no longer fits.
  • Leading/trailing only (RTL). Numbers, dates, durations and units through FormatStyle APIs.
  • 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:

sh
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 build

All three must succeed with no warning in the files you wrote. Report honestly what was verified and what was not.

Files main
Menu

Theme