An open source design system that's fully customizable and agent ready
TypeScript
spec(native): Astryx looks as SwiftUI styles, with views built on them (#8091)
Cindy Zhang20bde8411028
diff --git a/packages/native/specs/swift/library/README.md b/packages/native/specs/swift/library/README.mdindex 0029311d8c..9c52111153 100644--- a/packages/native/specs/swift/library/README.md+++ b/packages/native/specs/swift/library/README.md@@ -15,5 +15,6 @@ wins.| `augmentable-variants.md` | How a theme's own variants reach Swift as open types || `component-api.md` | How a SwiftUI view is named and takes its generated contract || `slots.md` | How each slot kind (text, icon, content) appears in SwiftUI |+| `styles.md` | How Astryx's look ships as SwiftUI styles || `theme-environment.md` | How the theme rides on SwiftUI's environment in both directions || `theme-generator.md` | How any Astryx theme becomes a Swift `Theme` |diff --git a/packages/native/specs/swift/library/styles.md b/packages/native/specs/swift/library/styles.mdnew file mode 100644index 0000000000..2f17838dd6--- /dev/null+++ b/packages/native/specs/swift/library/styles.md@@ -0,0 +1,89 @@+# SwiftUI styles (Swift)++- Status: draft+- Relation: extends `packages/native/specs/swift/library/component-api.md`,+ reads the theme as `packages/native/specs/swift/library/theme-environment.md`+ says, and applies AST-093 FR2 (native-first: a component sits on the platform's+ own control). It decides how Astryx's look reaches SwiftUI's own controls.++## Summary++An app that already uses SwiftUI's buttons, toggles, and progress views can+adopt Astryx's look one control at a time, with+`.buttonStyle(.astryx(variant: .primary))`, instead of replacing whole+screens. The person using the app keeps the system controls' accessibility and+behavior, now in the brand. Astryx's own views are built on the same styles,+so a theme change reaches both.++## Requirements++- **Y1 — Astryx looks as SwiftUI styles.** For each component whose core+ contract matches a SwiftUI control whose style protocol accepts a custom+ conformance, Astryx ships a conformance to that control's style protocol, with only the component's core visual props as parameters. A protocol that+ styles one component reaches it as `.astryx` (`ButtonStyle`, `LabelStyle`,+ `MenuStyle`, `GroupBoxStyle`, `LabeledContentStyle`, `ControlGroupStyle`);+ one that styles several reaches each as `.astryx<Component>` (`.astryxSwitch`,+ `.astryxCheckbox`, `.astryxProgressBar`, `.astryxSpinner`). Each style reads the theme from the+ environment. The component's view is the SwiftUI control with that style,+ plus the contract's behavior props. Astryx declares no style protocol of its+ own.+- **Y2 — Styles are look-only.** A style's parameters are the component's core+ visual props (such as `variant`, `size`, and `elevation`), with the generated+ types and defaults. Behavior props (such as `isLoading`, `disabledMessage`,+ `tooltip`, and `href`) are never style parameters; they stay on the view.+- **Y3 — The styles.**++ | SwiftUI style | Member | Astryx look |+ | --------------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |+ | `ButtonStyle` | `.astryx(variant:size:elevation:)` | Button, IconButton; also SwiftUI's own `Link`, `NavigationLink`, and `ShareLink`, which SwiftUI styles with `ButtonStyle` |+ | `ToggleStyle` | `.astryxSwitch`; `.astryxCheckbox` on macOS | Switch; CheckboxInput |+ | `ProgressViewStyle` | `.astryxProgressBar`; `.astryxSpinner` | ProgressBar (determinate or not); Spinner |+ | `LabelStyle` | `.astryx` | the icon-and-label layout of Button and Badge |+ | `MenuStyle` | `.astryx` | DropdownMenu trigger (menu contents stay system) |+ | `GroupBoxStyle` | `.astryx` | Card |+ | `LabeledContentStyle` | `.astryx` | Field: a label beside or above its control |+ | `ControlGroupStyle` | `.astryx` | ButtonGroup |++ `PickerStyle` and `TextFieldStyle` accept no custom conformance, so Selector and TextInput use the system styles and take the theme's+ tint and text colors from the theme environment. A component added later+ joins this table when its core contract matches a SwiftUI control whose+ style protocol accepts a custom conformance.++- **Y4 — Style types keep the prefix.** A style's type is+ `Astryx<Control>Style` (`AstryxButtonStyle`), because the unprefixed name is+ SwiftUI's own protocol; callers reach it through its Y3 static member and do not write+ the type.+- **Y5 — Accessibility comes from the system control.** A style draws only;+ the control keeps its name, traits, actions, and focus. `ToggleStyle` is the+ exception: a custom toggle style draws the control and flips its on state+ itself, so the Astryx toggle styles also keep the toggle trait and its+ on/off value for VoiceOver and act on a tap or the default action. A stock control+ styled with `.astryx` gets the look and not the view's behavior contract+ (for example, loading announced once).++## Acceptance checks++| Requirement | Check |+| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| Y1 | A compile test applies every Y3 style to its SwiftUI control through its Y3 member; a source check finds no public protocol declared by Astryx whose name ends in `Style`. |+| Y1 | A capture test draws `SwiftUI.Button("x") {}.buttonStyle(.astryx(variant: .primary))` and `Button("x", variant: .primary) {}` identically in two themes, light and dark. `SwiftUI.Link`, `NavigationLink`, and `ShareLink` with `.buttonStyle(.astryx(variant: .primary))` draw the same look. |+| Y2 | A source check finds no style parameter that is not a core visual prop of its component. |+| Y3 | Each component in the Y3 table has its style; Selector and TextInput inside a theme draw the theme's tint. |+| Y5 | Accessibility assertions for a styled stock control equal those for the same unstyled stock control. A `Toggle` with `.astryxSwitch` reads as a toggle with its value and flips on a tap and on VoiceOver's default action. |++## Current state++- On `main`, the Swift package `packages/native/apple` holds generated props,+ the wire, and the logic host. There are no SwiftUI views or styles.++## Open questions++None.++## References++- `ButtonStyle`: https://developer.apple.com/documentation/swiftui/buttonstyle+- `ToggleStyle`: https://developer.apple.com/documentation/swiftui/togglestyle+- `ProgressViewStyle`: https://developer.apple.com/documentation/swiftui/progressviewstyle+- `LabelStyle`: https://developer.apple.com/documentation/swiftui/labelstyle+- `MenuStyle`: https://developer.apple.com/documentation/swiftui/menustylediff --git a/packages/native/specs/swift/library/theme-environment.md b/packages/native/specs/swift/library/theme-environment.mdindex e1e2a7bcbe..fa6dc548dd 100644--- a/packages/native/specs/swift/library/theme-environment.md+++ b/packages/native/specs/swift/library/theme-environment.md@@ -42,8 +42,8 @@ Astryx adds no second settings system for an app to keep in step.So stock SwiftUI controls (`Toggle`, `Picker`, `ProgressView`, `Menu`,`List`, `Slider`, `Link`) draw with the brand's accent and text colors.Whether the theme also sets the default font is OQ1. Theme values with no SwiftUI environment equivalent are read only- by Astryx components: corner radius, spacing, element heights, borders, and- backgrounds. Control size has no clean mapping: Astryx sizes are a per-+ by Astryx components and Astryx's SwiftUI styles: corner radius, spacing,+ element heights, borders, and backgrounds. Control size has no clean mapping: Astryx sizes are a per-component prop, so the theme sets no `controlSize`.- **E3 — The mode always follows SwiftUI.** A token value is chosen from the