SPB Git

Repository Public MIT

COMPONENT_GUIDELINES.md 6.0 KB 61 lines markdown

1# Component guidelines23Rules 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.45## Deliverables per component67| Deliverable | Path | Notes |8|---|---|---|9| 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. |10| 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. |11| Tests | `Tests/<Module>Tests/<Name>Tests.swift` | Swift Testing. Test the logic: state machines, validation, formatting, bounds, sorting, queues. |12| Documentation | `docs/components/<id>.md` | Same sections as `glass-button.md`: table, Minimal usage, Variants, Parameters, States, Advanced example, Accessibility, Limits. |1314The 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.1516## Kinds1718- `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`.19- `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.20- `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.2122Glass belongs to controls and navigation layers, not to content. Never one glass surface per list cell. Never glass inside glass.2324## API2526- Controlled state through `Binding`; actions through closures typed `@MainActor () -> Void` (or with parameters). No business logic, no networking, no persistence inside a component.27- Titles supplied by the host: `LocalizedStringKey` (plus a `verbatim:`/`String` variant where data is displayed). Data values (messages, rows, file names) are `String`.28- 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.29- 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).30- Generic content via `@ViewBuilder`; no `AnyView` unless type erasure is unavoidable; no force unwrap, no `try!`, no `fatalError`, no `print`, no mutable singleton.31- Put testable logic in a non-view type (struct, enum or `@Observable` class) next to the view. Views stay thin.32- 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:)`).33- 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.34- 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.3536## Accessibility and layout3738- Every interactive element has a label; symbol-only controls use `Label` with `.labelStyle(.iconOnly)` or `GlassIconButton`. Decorative images are `.accessibilityHidden(true)`.39- State is exposed with `accessibilityValue`, traits (`.isSelected`, `.isHeader`, `.updatesFrequently`) and adjustable actions where a value changes; status is never colour alone (icon + text).40- Hit targets: `.glassMinimumHitTarget()` on custom tappable elements.41- 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.42- Leading/trailing only (RTL). Numbers, dates, durations and units through `FormatStyle` APIs.43- 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.44- Long text, empty data, Unicode (emoji, combining marks, RTL scripts) and narrow widths must not break the layout.4546## Privacy and safety4748No 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.4950## Verification before reporting5152Build and test with your own scratch directory so that parallel work does not collide:5354```sh55swift build --scratch-path .build-<name> 2>&1 | grep -E "error|warning:" 56swift test  --scratch-path .build-<name> --filter <Module>Tests57xcodebuild -scheme SPGlassExamples -destination 'generic/platform=iOS Simulator' -derivedDataPath .build-<name>/xcode build58```5960All three must succeed with no warning in the files you wrote. Report honestly what was verified and what was not.61
Files main
Menu

Theme