@astryxdesign/native 0.7.5-canary.cd53c2d → 0.7.5-canary.d26cdf3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +16 -12
  2. package/apple/Package.swift +27 -4
  3. package/apple/README.md +203 -0
  4. package/apple/Sources/Astryx/Banner/Banner.swift +80 -0
  5. package/apple/Sources/Astryx/Base/BaseProps.swift +16 -0
  6. package/apple/Sources/Astryx/Button/Button.swift +168 -0
  7. package/apple/Sources/Astryx/Card/Card.swift +109 -0
  8. package/apple/Sources/Astryx/Exports.swift +8 -0
  9. package/apple/Sources/Astryx/Heading/Heading.swift +117 -0
  10. package/apple/Sources/Astryx/Icon/Icon.spec.md +186 -0
  11. package/apple/Sources/Astryx/Icon/Icon.swift +155 -0
  12. package/apple/Sources/Astryx/Localization/AstryxStrings.swift +22 -0
  13. package/apple/Sources/Astryx/Resources/af.lproj/Localizable.strings +4 -0
  14. package/apple/Sources/Astryx/Resources/ar.lproj/Localizable.strings +4 -0
  15. package/apple/Sources/Astryx/Resources/ca.lproj/Localizable.strings +4 -0
  16. package/apple/Sources/Astryx/Resources/cs.lproj/Localizable.strings +4 -0
  17. package/apple/Sources/Astryx/Resources/da.lproj/Localizable.strings +4 -0
  18. package/apple/Sources/Astryx/Resources/de.lproj/Localizable.strings +4 -0
  19. package/apple/Sources/Astryx/Resources/el.lproj/Localizable.strings +4 -0
  20. package/apple/Sources/Astryx/Resources/en.lproj/Localizable.strings +4 -0
  21. package/apple/Sources/Astryx/Resources/es.lproj/Localizable.strings +4 -0
  22. package/apple/Sources/Astryx/Resources/fi.lproj/Localizable.strings +4 -0
  23. package/apple/Sources/Astryx/Resources/fr.lproj/Localizable.strings +4 -0
  24. package/apple/Sources/Astryx/Resources/he.lproj/Localizable.strings +4 -0
  25. package/apple/Sources/Astryx/Resources/hu.lproj/Localizable.strings +4 -0
  26. package/apple/Sources/Astryx/Resources/it.lproj/Localizable.strings +4 -0
  27. package/apple/Sources/Astryx/Resources/ja.lproj/Localizable.strings +4 -0
  28. package/apple/Sources/Astryx/Resources/ko.lproj/Localizable.strings +4 -0
  29. package/apple/Sources/Astryx/Resources/nb.lproj/Localizable.strings +4 -0
  30. package/apple/Sources/Astryx/Resources/nl.lproj/Localizable.strings +4 -0
  31. package/apple/Sources/Astryx/Resources/pl.lproj/Localizable.strings +4 -0
  32. package/apple/Sources/Astryx/Resources/pt-BR.lproj/Localizable.strings +4 -0
  33. package/apple/Sources/Astryx/Resources/pt-PT.lproj/Localizable.strings +4 -0
  34. package/apple/Sources/Astryx/Resources/ro.lproj/Localizable.strings +4 -0
  35. package/apple/Sources/Astryx/Resources/ru.lproj/Localizable.strings +4 -0
  36. package/apple/Sources/Astryx/Resources/sr.lproj/Localizable.strings +4 -0
  37. package/apple/Sources/Astryx/Resources/sv.lproj/Localizable.strings +4 -0
  38. package/apple/Sources/Astryx/Resources/tr.lproj/Localizable.strings +4 -0
  39. package/apple/Sources/Astryx/Resources/uk.lproj/Localizable.strings +4 -0
  40. package/apple/Sources/Astryx/Resources/vi.lproj/Localizable.strings +4 -0
  41. package/apple/Sources/Astryx/Resources/zh-Hans.lproj/Localizable.strings +4 -0
  42. package/apple/Sources/Astryx/Resources/zh-Hant.lproj/Localizable.strings +4 -0
  43. package/apple/Sources/Astryx/Text/Text.swift +102 -0
  44. package/apple/Sources/Astryx/Text/TypeStyle.swift +143 -0
  45. package/apple/Sources/Astryx/TextInput/TextInput.swift +81 -0
  46. package/apple/Sources/Astryx/Theme/AstryxIcons.swift +108 -0
  47. package/apple/Sources/Astryx/Theme/Generated/ButterTheme.swift +439 -0
  48. package/apple/Sources/Astryx/Theme/Generated/ChocolateTheme.swift +439 -0
  49. package/apple/Sources/Astryx/Theme/Generated/DefaultTheme.swift +439 -0
  50. package/apple/Sources/Astryx/Theme/Generated/GothicTheme.swift +439 -0
  51. package/apple/Sources/Astryx/Theme/Generated/MatchaTheme.swift +439 -0
  52. package/apple/Sources/Astryx/Theme/Generated/NeutralTheme.swift +439 -0
  53. package/apple/Sources/Astryx/Theme/Generated/StoneTheme.swift +439 -0
  54. package/apple/Sources/Astryx/Theme/Generated/Tokens.swift +1318 -0
  55. package/apple/Sources/Astryx/Theme/Generated/Y2kTheme.swift +439 -0
  56. package/apple/Sources/Astryx/Theme/Shadow.swift +41 -0
  57. package/apple/Sources/Astryx/Theme/Theme.swift +241 -0
  58. package/apple/Sources/Astryx/Tooltip/TooltipPresenter.swift +551 -0
  59. package/apple/Sources/Astryx/Wire/AstryxNodeView.swift +75 -0
  60. package/apple/Sources/AstryxNative/Generated/AstryxNode.swift +3 -0
  61. package/apple/Sources/AstryxNative/Generated/Button.swift +14 -2
  62. package/apple/Sources/AstryxNative/Generated/Icon.swift +106 -0
  63. package/apple/Sources/AstryxNative/Generated/IconName.swift +47 -0
  64. package/apple/Sources/AstryxNative/Generated/Switch.swift +2 -26
  65. package/apple/Tests/AstryxTests/BannerTests.swift +47 -0
  66. package/apple/Tests/AstryxTests/ButtonTests.swift +72 -0
  67. package/apple/Tests/AstryxTests/CardTests.swift +159 -0
  68. package/apple/Tests/AstryxTests/EnvironmentTests.swift +87 -0
  69. package/apple/Tests/AstryxTests/HeadingTests.swift +68 -0
  70. package/apple/Tests/AstryxTests/IconTests.swift +188 -0
  71. package/apple/Tests/AstryxTests/NamesTests.swift +28 -0
  72. package/apple/Tests/AstryxTests/Pixels.swift +68 -0
  73. package/apple/Tests/AstryxTests/Resources/astryx-test-icon.png +0 -0
  74. package/apple/Tests/AstryxTests/StringsTests.swift +23 -0
  75. package/apple/Tests/AstryxTests/TextInputTests.swift +29 -0
  76. package/apple/Tests/AstryxTests/TextTests.swift +109 -0
  77. package/apple/Tests/AstryxTests/ThemeTests.swift +39 -0
  78. package/apple/Tests/AstryxTests/TooltipPresenterTests.swift +220 -0
  79. package/apple/Tests/AstryxTests/TwoThemeTests.swift +65 -0
  80. package/dist/components/Button.d.ts.map +1 -1
  81. package/dist/components/Button.js +1 -0
  82. package/dist/components/Icon.d.ts +10 -0
  83. package/dist/components/Icon.d.ts.map +1 -0
  84. package/dist/components/Icon.js +7 -0
  85. package/dist/components/Switch.d.ts.map +1 -1
  86. package/dist/components/Switch.js +13 -0
  87. package/dist/components/index.d.ts.map +1 -1
  88. package/dist/components/index.js +2 -0
  89. package/dist/contract/fromComponentDoc.d.ts +21 -2
  90. package/dist/contract/fromComponentDoc.d.ts.map +1 -1
  91. package/dist/contract/fromComponentDoc.js +31 -1
  92. package/dist/contract/generateSwift.d.ts.map +1 -1
  93. package/dist/contract/generateSwift.js +33 -0
  94. package/dist/contract/generateTypeScript.d.ts.map +1 -1
  95. package/dist/contract/generateTypeScript.js +11 -2
  96. package/dist/contract/types.d.ts +9 -0
  97. package/dist/contract/types.d.ts.map +1 -1
  98. package/dist/types/android.d.ts +18 -5
  99. package/dist/types/core.d.ts +10 -2
  100. package/dist/types/ios.d.ts +15 -5
  101. package/dist/types/macos.d.ts +15 -5
  102. package/dist/types/shared.d.ts +15 -5
  103. package/dist/types/windows.d.ts +18 -5
  104. package/package.json +6 -4
  105. package/src/components/Button.ts +1 -0
  106. package/src/components/Icon.ts +18 -0
  107. package/src/components/Switch.ts +13 -0
  108. package/src/components/index.ts +2 -0
  109. package/src/contract/contracts.test.ts +51 -0
  110. package/src/contract/fromComponentDoc.test.ts +29 -0
  111. package/src/contract/fromComponentDoc.ts +67 -3
  112. package/src/contract/generateSwift.ts +38 -0
  113. package/src/contract/generateTypeScript.ts +11 -2
  114. package/src/contract/types.ts +9 -0
  115. package/src/icons/swiftIcons.test.ts +22 -0
  116. package/src/theme/swiftIOSStrings.test.ts +49 -0
  117. package/src/theme/swiftIOSTheme.test.ts +289 -0
@@ -0,0 +1,8 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ // `import Astryx` is the only import an app file needs: it brings SwiftUI and
4
+ // the generated contracts with it. In a file that imports only Astryx, a name
5
+ // Astryx shares with SwiftUI (`Button`, `Text`) means Astryx's view, and
6
+ // `SwiftUI.Button` names the system one (Swift component API spec, A1, A1a).
7
+ @_exported import AstryxNative
8
+ @_exported import SwiftUI
@@ -0,0 +1,117 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ // Adapted from github.com/ejc3/astryx-swift (MIT).
3
+
4
+ /// A heading at levels 1 through 6, painted with the theme's heading tokens
5
+ /// and exposed to VoiceOver as a heading. It takes core's Heading props
6
+ /// (`HeadingProps`).
7
+ public struct Heading: View {
8
+ public let props: HeadingProps
9
+ @Environment(\.astryx) private var astryx
10
+ @Environment(\.multilineTextAlignment) private var inheritedAlignment
11
+
12
+ public init(_ props: HeadingProps) {
13
+ self.props = props
14
+ }
15
+
16
+ /// - Parameters:
17
+ /// - children: the words, core's `children`.
18
+ /// - level: core's `level`: the heading's place in the outline, which
19
+ /// also sets its look unless `type` is given.
20
+ /// - type: core's `type`, a display style that replaces the level's look.
21
+ /// - weight: core's `weight`, replacing the look's weight.
22
+ /// - accessibilityLevel: core's `accessibilityLevel`, the level VoiceOver
23
+ /// reads when it differs from `level`.
24
+ /// - color: core's `color`; primary when nil.
25
+ /// - maxLines: core's `maxLines`; text past it is truncated. Unset, a
26
+ /// surrounding `.lineLimit` still applies.
27
+ /// - justify: core's `justify`, the alignment of wrapped lines.
28
+ /// - hasStrikethrough: core's `hasStrikethrough`.
29
+ /// - base: core's base props.
30
+ public init(
31
+ _ children: String,
32
+ level: HeadingLevel,
33
+ type: HeadingType? = nil,
34
+ weight: HeadingWeight? = nil,
35
+ accessibilityLevel: HeadingAccessibilityLevel? = nil,
36
+ color: HeadingColor? = nil,
37
+ maxLines: Double? = nil,
38
+ justify: HeadingJustify? = nil,
39
+ hasStrikethrough: Bool? = nil,
40
+ base: AstryxBaseProps = AstryxBaseProps()
41
+ ) {
42
+ self.init(
43
+ HeadingProps(
44
+ level: level,
45
+ type: type,
46
+ weight: weight,
47
+ children: children,
48
+ accessibilityLevel: accessibilityLevel,
49
+ color: color,
50
+ maxLines: maxLines,
51
+ justify: justify,
52
+ hasStrikethrough: hasStrikethrough,
53
+ base: base
54
+ )
55
+ )
56
+ }
57
+
58
+ public var body: some View {
59
+ styled(SwiftUI.Text(props.children))
60
+ .astryxMaxLines(props.maxLines)
61
+ .multilineTextAlignment(props.justify?.alignment ?? inheritedAlignment)
62
+ .astryxJustified(props.justify?.frameAlignment)
63
+ .accessibilityAddTraits(Self.accessibilityTraits)
64
+ .accessibilityHeading(headingLevel)
65
+ .astryxBase(props.base)
66
+ }
67
+
68
+ func styled(_ text: SwiftUI.Text) -> SwiftUI.Text {
69
+ var style = typeStyle
70
+ if let weight = props.weight {
71
+ style.weight = astryx.tokens.font.weight.value(named: weight.rawValue)
72
+ }
73
+ var text = text.font(astryx.font(style))
74
+ if let color = astryx.tokens.color.text(named: (props.color ?? .primary).rawValue) {
75
+ text = text.foregroundStyle(color)
76
+ }
77
+ if props.hasStrikethrough == true { text = text.strikethrough() }
78
+ return text
79
+ }
80
+
81
+ /// The level's heading style, or the display style `type` names, in the
82
+ /// theme's heading family.
83
+ var typeStyle: TypeStyle {
84
+ let font = astryx.tokens.font
85
+ let style: TypeStyleTokens =
86
+ switch props.type {
87
+ case .display1: font.display1
88
+ case .display2: font.display2
89
+ case .display3: font.display3
90
+ case nil:
91
+ switch props.level {
92
+ case .v1: font.heading1
93
+ case .v2: font.heading2
94
+ case .v3: font.heading3
95
+ case .v4: font.heading4
96
+ case .v5: font.heading5
97
+ case .v6: font.heading6
98
+ }
99
+ }
100
+ return TypeStyle(style, families: font.family.heading)
101
+ }
102
+
103
+ /// The traits assistive technology gets: a header.
104
+ static var accessibilityTraits: AccessibilityTraits { .isHeader }
105
+
106
+ /// The level VoiceOver reads: `accessibilityLevel` when given, else `level`.
107
+ var headingLevel: AccessibilityHeadingLevel {
108
+ switch props.accessibilityLevel?.rawValue ?? props.level.rawValue {
109
+ case 1: .h1
110
+ case 2: .h2
111
+ case 3: .h3
112
+ case 4: .h4
113
+ case 5: .h5
114
+ default: .h6
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,186 @@
1
+ ---
2
+ schema_version: 5
3
+ template_version: 8
4
+ kind: component
5
+ id: component:swift/Icon
6
+ platform_of: component:Icon
7
+ authority: draft
8
+ archive_reason: null
9
+ superseded_by: null
10
+ approved_by: null
11
+ approved_at: null
12
+ owners: [cixzhang]
13
+ review_triggers: [public-api, behavior, theming, accessibility]
14
+ verified_by:
15
+ [
16
+ packages/native/apple/Tests/AstryxTests/IconTests.swift,
17
+ packages/native/src/contract/contracts.test.ts,
18
+ ]
19
+ modules: []
20
+ families: []
21
+ design_specs: []
22
+ architecture:
23
+ [
24
+ architecture:component-size-cascade,
25
+ architecture:icon-resolution-and-component-slots,
26
+ ]
27
+ contributing: []
28
+ system_specs: [spec:AST-082, spec:AST-093]
29
+ ---
30
+
31
+ # Icon (Swift) component contract
32
+
33
+ ## Contract at a glance
34
+
35
+ | Area | Contract |
36
+ | ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
37
+ | Public contract | `Icon(_ icon: IconName, color: IconColor? = nil, size: IconSize? = nil, label: String? = nil)` and `Icon(_ props: IconProps)`, a SwiftUI `View` in module `Astryx`. `IconName` is a string-backed name with every built-in name as a static member (`.search`, `.close`). |
38
+ | Behavior | Draws the image the theme or the platform maps the name to (an SF Symbol, or an asset the app ships), in a square box at core's icon size grown with Dynamic Type, in core's icon color token or the surrounding foreground. A name nothing maps, or an asset the app does not ship, draws nothing. |
39
+ | End-user impact | A person sees the platform's own symbol for each shared icon, or the app's own artwork where its theme maps one, sized and colored as on the web, and VoiceOver reads only icons that carry a label. |
40
+ | Builder impact | An app passes a shared name (`.search`) or a name it maps in its theme (`"acme:rocket"`). An SVG component, which the web also accepts, has no Swift form. |
41
+ | Compatibility/readiness | Additive: a new view and a new generated `IconName` type. Draft; built and tested on macOS and the iOS Simulator; device captures are attached to the change. |
42
+ | Review checks | Reject a substitute symbol for an unknown name, an image or attributed-text form of the icon slot, a visual parameter beyond the contract, an unlabeled icon that VoiceOver reads, or an owner's size winning over an explicit `size`. |
43
+ | Governing rules | `spec:AST-082` FR4, FR7, FR17; `spec:AST-093` FR1–FR5; the Swift component API, styles, slots, theme environment, and accessibility records under `packages/native/specs/swift/library/`. |
44
+
45
+ This table is a review projection; the body below is authoritative.
46
+
47
+ ## Intent
48
+
49
+ Icon on Apple platforms draws Astryx's shared icon names as SF Symbols, or as
50
+ images the app ships where its theme maps them, so an
51
+ icon beside system controls looks like the platform's own while its size, color,
52
+ and accessibility follow the core `Icon` contract.
53
+
54
+ ## Compatibility and migration
55
+
56
+ - Released default preserved: `not yet released`
57
+ - Compatibility class: additive
58
+ - Controlled/uncontrolled behavior: not applicable
59
+ - Migration decision: none
60
+
61
+ Consumer migration instructions belong in consumer docs and release notes.
62
+
63
+ ## Ownership boundary
64
+
65
+ **Owns**
66
+
67
+ - Resolving a shared icon name to an image: the theme's mapping (an SF Symbol
68
+ or an app asset), else the platform's default SF Symbol.
69
+ - Drawing the image in a square box at core's icon size, grown with Dynamic
70
+ Type, in core's icon color token. An asset takes the color token when its
71
+ asset catalog renders it as a template image, and keeps its own colors when
72
+ it renders as an original image.
73
+ - The icon's VoiceOver exposure.
74
+
75
+ **Does not own / non-goals**
76
+
77
+ - The meaning of `icon`, `color`, `size`, and `label` and the built-in names —
78
+ owned by `component:Icon` and `spec:AST-082` FR17.
79
+ - Which size an owner gives the icons in its icon slot — owned by each owning
80
+ component and `architecture:component-size-cascade`.
81
+ - The default SF Symbol for each name — owned by `@astryxdesign/native`'s icon
82
+ defaults, which a test keeps equal to the Swift map.
83
+
84
+ ## Public concepts
85
+
86
+ | Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |
87
+ | ------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------- | -------------------------- | ---------------------- | ------------ | ----------------------------------------------------------------------- |
88
+ | icon name | the built-in names; a `<library>:<name>` the theme maps | `IconName`, a string on the wire, with each built-in as a static member | always | required | `component:Icon` | experimental | an unmapped name stops a development build and draws nothing in release |
89
+ | symbol source | theme mapping; platform default | `Theme(icons:)` replaces a built-in or registers a library name with an SF Symbol or an app asset | always | platform default | `component:swift/Icon` | experimental | a theme entry wins over the default |
90
+ | size | `xsm`, `sm`, `md`, `lg`; unset | 12, 16, 20, 24 points at the default text size | always | owner's icon size, else md | `component:Icon` | experimental | unset takes the owner's size, then `md` |
91
+ | color | `primary`, `secondary`, `tertiary`, `disabled`, `accent`, `success`, `error`, `warning`, `inherit`; unset | core's icon color tokens; `inherit` keeps the surrounding foreground | always | `inherit` | `component:Icon` | experimental | unset is `inherit` |
92
+
93
+ ## Behavioral and layout contract
94
+
95
+ | ID | Candidate invariant | Basis | Draft review state |
96
+ | --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ------------------ |
97
+ | FR1 | The view MUST draw the image the theme's `icons` maps the name to, an SF Symbol or an asset the app ships, else the platform default for a built-in name. A name neither maps, or an asset the app does not ship, MUST stop a development build with a message naming it and draw nothing in a release build, never a substitute. | `spec:AST-082` FR17; Swift slots S2 | verify |
98
+ | FR2 | The symbol MUST fit a square box whose side is core's size in points (12, 16, 20, 24 for `xsm`, `sm`, `md`, `lg`), multiplied by the Dynamic Type scale the theme environment reads. | core `Icon` sizes; `spec:AST-093` FR3; theme environment E1 | verify |
99
+ | FR3 | The view MUST use its own `size`, else the size its owning component gives icons in its documented icon slot, else `md`. | `architecture:component-size-cascade`; Swift slots S4 | verify |
100
+ | FR4 | The view MUST draw in core's token for its `color` — primary and secondary icon tokens, the secondary icon token for `tertiary`, the disabled icon token, and the accent, success, error, and warning colors — and, for `inherit` or no color, MUST keep the surrounding foreground style. | core `Icon` color map; `spec:AST-093` FR4 | verify |
101
+ | FR5 | Both initializers MUST build the same `IconProps`; the labeled initializer takes the contract's props with the generated types and defaults, and base props (`id`, `isHidden`) come through `IconProps`. With `isHidden` the view draws nothing; `id` becomes the accessibility identifier. | Swift component API A2, A3, A7; `spec:AST-082` FR7 | verify |
102
+
103
+ ### Allowed variation
104
+
105
+ - **AV1 — Glyph shape.** The glyph is the platform's SF Symbol, not the web's
106
+ SVG; a theme may map any name to another SF Symbol or to an image the app
107
+ ships (`spec:AST-082` FR17).
108
+
109
+ ### Representative states
110
+
111
+ | State | Required invariant | Allowed variation |
112
+ | --------------------------- | --------------------------------------------- | ---------------------------- |
113
+ | every size | box side 12, 16, 20, 24 points at Large text | glyph proportions per symbol |
114
+ | every color, light and dark | the color's token in the current mode | none |
115
+ | inside an owner's icon slot | the owner's size unless the icon sets its own | none |
116
+ | largest text size | the box grows with Dynamic Type | none |
117
+ | labeled and unlabeled | VoiceOver reads only the labeled icon | none |
118
+
119
+ ### Transformation and precedence order
120
+
121
+ - **ORD1 — Image.** Theme mapping (SF Symbol or app asset) → platform default
122
+ SF Symbol → nothing.
123
+ - **ORD2 — Size.** Explicit `size` → owner's icon size → `md`, then × Dynamic
124
+ Type scale.
125
+
126
+ ### Performance and resources
127
+
128
+ - **PR1 — No image data of its own.** The view draws a system symbol by name,
129
+ or an asset from the app's main bundle by name; it holds no image data and
130
+ loads nothing from the network.
131
+
132
+ ## Accessibility contract
133
+
134
+ - **AR1 — Decorative unless labeled.** With no `label`, or an empty one, the
135
+ view is hidden from VoiceOver. With a label, it is one image element named by
136
+ the label, keeping SwiftUI's image trait and adding none (`spec:AST-082` FR17;
137
+ Swift accessibility X1, X4).
138
+ - **AR2 — Rendered tree not measured.** Tests assert what the view sets; the
139
+ rendered accessibility tree is not measured until an app-hosted target exists.
140
+
141
+ ## Design relationships
142
+
143
+ | Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
144
+ | ---------------- | -------------------------------------------------------------- | -------------------------- | -------------- | ------------------ |
145
+ | Glyph | SF Symbols (Apple Human Interface Guidelines), or an app asset | prescribed by the platform | supporting | FR1, FR2 |
146
+
147
+ The component implements design requirements without copying their rationale.
148
+
149
+ Platform control: SwiftUI `Image(systemName:)`, or `Image(_:bundle:)` for an
150
+ app asset. It is the platform's own icon view and satisfies the contract, so no custom drawing is needed (`spec:AST-093`
151
+ FR2). Guideline pages: SF Symbols and Accessibility in the Apple Human
152
+ Interface Guidelines.
153
+
154
+ Theme values read: `color.iconPrimary`, `color.iconSecondary`,
155
+ `color.iconDisabled`, `color.accent`, `color.success`, `color.error`,
156
+ `color.warning`, the theme's `icons` map, and the Dynamic Type scale.
157
+
158
+ ## Family and system relationships
159
+
160
+ - `component:Icon` owns the props, the built-in names, the size scale, and the
161
+ color map; this record states only how Swift draws them.
162
+ - `architecture:component-size-cascade` owns when an owner's icon size applies;
163
+ owners set it through an internal environment value this view reads.
164
+
165
+ ## Verification map
166
+
167
+ | Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
168
+ | -------- | ------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | -------------------------- |
169
+ | FR1 | `IconTests.swift` symbol and asset tests (a test bundle stands in for the app's); `contracts.test.ts` IconName test | every built-in; theme replacement; library name; a shipped asset; a missing asset drawing nothing and reported (the release-build path) | a missing default, a symbol absent on the platform, a missing asset that draws or goes unreported, or a substitute fails | `audit:swift/Icon/symbols` |
170
+ | FR2, FR3 | `IconTests.swift` size and Dynamic Type renders | each size; owner size; explicit size; AX5 | a wrong side or an owner size beating an explicit size fails | `audit:swift/Icon/size` |
171
+ | FR4 | `IconTests.swift` color map and two-theme render | every color; neutral and butter | a wrong token or a color of the view's own fails | `audit:swift/Icon/color` |
172
+ | FR5 | `IconTests.swift` initializer and hidden tests | both initializers; `isHidden` | differing props or a drawn hidden icon fails | `audit:swift/Icon/api` |
173
+ | AR1 | `IconTests.swift` accessibility assertions | labeled, unlabeled, empty label | an unlabeled icon with a label, or a labeled one without, fails | `audit:swift/Icon/a11y` |
174
+
175
+ ## Decision log
176
+
177
+ No component-local decision is recorded.
178
+
179
+ ## Open questions
180
+
181
+ None.
182
+
183
+ ## Content boundary
184
+
185
+ This file does not duplicate consumer prop tables/examples, current audit
186
+ results, implementation steps, or family/system rules. It links to their owners.
@@ -0,0 +1,155 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import AstryxNative
4
+ import SwiftUI
5
+
6
+ /// One symbol for a shared icon name, at core's icon size and color, hidden
7
+ /// from VoiceOver unless it carries a label (core `Icon`).
8
+ ///
9
+ /// ```swift
10
+ /// Icon(.search)
11
+ /// Icon(.success, color: .success, label: "Completed")
12
+ /// ```
13
+ public struct Icon: View {
14
+ /// The contract the view draws, the same for both initializers.
15
+ public let props: IconProps
16
+ @Environment(\.astryx) private var astryx
17
+ @Environment(\.astryxIconDefaultSize) private var contextualSize
18
+
19
+ /// An icon from its labeled props.
20
+ /// - Parameters:
21
+ /// - icon: The shared icon name to draw (core `icon`).
22
+ /// - color: The icon color token; `nil` keeps the surrounding foreground (core `color`).
23
+ /// - size: The icon size; `nil` takes the owning component's icon size, else `md` (core `size`).
24
+ /// - label: The accessible name of a meaningful icon; `nil` or empty keeps it decorative (core `label`).
25
+ public init(_ icon: IconName, color: IconColor? = nil, size: IconSize? = nil, label: String? = nil) {
26
+ self.init(IconProps(icon: icon, color: color, size: size, label: label))
27
+ }
28
+
29
+ /// An icon from its generated contract, for generated and wire-driven callers.
30
+ public init(_ props: IconProps) {
31
+ self.props = props
32
+ }
33
+
34
+ public var body: some View {
35
+ if props.base.isHidden != true {
36
+ if let source = Icon.symbol(for: props.icon, themeIcons: astryx.icons) {
37
+ let side = Icon.points(for: resolvedSize) * astryx.textScale
38
+ // An asset the app does not ship draws nothing (IconImage.image).
39
+ source.image?
40
+ .resizable()
41
+ .scaledToFit()
42
+ .frame(width: side, height: side)
43
+ .modifier(IconTint(color: tint))
44
+ .modifier(IconAccessibility(label: accessibilityLabel))
45
+ .modifier(IconIdentifier(id: props.base.id))
46
+ } else {
47
+ // AST-082 FR17: a name nothing maps draws nothing, never a substitute.
48
+ let _ = assertionFailure("Astryx has no icon named \"\(props.icon.rawValue)\"")
49
+ }
50
+ }
51
+ }
52
+
53
+ /// The size the icon draws at: its own, else its owner's icon size, else `md`.
54
+ var resolvedSize: IconSize {
55
+ props.size ?? contextualSize ?? .md
56
+ }
57
+
58
+ /// The theme color the icon draws in, or `nil` to keep the surrounding
59
+ /// foreground (`inherit`).
60
+ var tint: Color? {
61
+ Icon.color(for: props.color ?? .inherit, in: astryx.tokens)
62
+ }
63
+
64
+ /// The name VoiceOver reads, or `nil` when the icon is decorative.
65
+ var accessibilityLabel: String? {
66
+ guard let label = props.label, !label.isEmpty else { return nil }
67
+ return label
68
+ }
69
+
70
+ /// Core's fixed icon scale in points at the default text size: 12, 16, 20,
71
+ /// and 24, as core's 0.75, 1, 1.25, and 1.5 rem.
72
+ nonisolated static func points(for size: IconSize) -> CGFloat {
73
+ switch size {
74
+ case .xsm: 12
75
+ case .sm: 16
76
+ case .md: 20
77
+ case .lg: 24
78
+ }
79
+ }
80
+
81
+ /// The theme token each color draws with, as core maps them; `inherit` has none.
82
+ nonisolated static func color(for color: IconColor, in tokens: Tokens) -> Color? {
83
+ switch color {
84
+ case .primary: tokens.color.iconPrimary
85
+ case .secondary, .tertiary: tokens.color.iconSecondary
86
+ case .disabled: tokens.color.iconDisabled
87
+ case .accent: tokens.color.accent
88
+ case .success: tokens.color.success
89
+ case .error: tokens.color.error
90
+ case .warning: tokens.color.warning
91
+ case .inherit: nil
92
+ }
93
+ }
94
+
95
+ /// The SF Symbol a name draws: the theme's mapping (which also registers a
96
+ /// `<library>:<name>` name), else the platform default; `nil` for a name
97
+ /// neither maps.
98
+ nonisolated static func symbol(for name: IconName, themeIcons: [String: IconImage]) -> IconImage? {
99
+ themeIcons[name.rawValue] ?? astryxDefaultIcons[name.rawValue].map(IconImage.systemName)
100
+ }
101
+ }
102
+
103
+ /// A labeled icon reads as an image with its label; an unlabeled one is
104
+ /// hidden from VoiceOver (AST-082 FR17).
105
+ private struct IconAccessibility: ViewModifier {
106
+ let label: String?
107
+
108
+ func body(content: Content) -> some View {
109
+ if let label {
110
+ content.accessibilityLabel(label)
111
+ } else {
112
+ content.accessibilityHidden(true)
113
+ }
114
+ }
115
+ }
116
+
117
+ /// A theme color, or no style of its own so the surrounding foreground
118
+ /// reaches the symbol (`inherit`).
119
+ private struct IconTint: ViewModifier {
120
+ let color: Color?
121
+
122
+ func body(content: Content) -> some View {
123
+ if let color {
124
+ content.foregroundStyle(color)
125
+ } else {
126
+ content
127
+ }
128
+ }
129
+ }
130
+
131
+ /// The base `id` becomes the accessibility identifier (AST-082 FR7).
132
+ private struct IconIdentifier: ViewModifier {
133
+ let id: String?
134
+
135
+ func body(content: Content) -> some View {
136
+ if let id {
137
+ content.accessibilityIdentifier(id)
138
+ } else {
139
+ content
140
+ }
141
+ }
142
+ }
143
+
144
+ private struct AstryxIconDefaultSizeKey: EnvironmentKey {
145
+ static let defaultValue: IconSize? = nil
146
+ }
147
+
148
+ extension EnvironmentValues {
149
+ /// The icon size a component gives the icons in its documented icon slot;
150
+ /// an `Icon` with no size of its own draws at it (core's contextual size).
151
+ var astryxIconDefaultSize: IconSize? {
152
+ get { self[AstryxIconDefaultSizeKey.self] }
153
+ set { self[AstryxIconDefaultSizeKey.self] = newValue }
154
+ }
155
+ }
@@ -0,0 +1,22 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import Foundation
4
+
5
+ /// Core's catalog messages, read from `Resources/<locale>.lproj`, which
6
+ /// `generate:swift-ios` writes from core's locale catalogs.
7
+ enum AstryxStrings {
8
+ /// What a loading button says to assistive technology.
9
+ static var buttonLoading: String { localized("@astryx.button.loading", "Loading") }
10
+
11
+ static func localized(_ key: String, _ english: String) -> String {
12
+ resourceBundle.localizedString(forKey: key, value: english, table: nil)
13
+ }
14
+
15
+ static var resourceBundle: Bundle {
16
+ #if SWIFT_PACKAGE
17
+ Bundle.module
18
+ #else
19
+ Bundle.main
20
+ #endif
21
+ }
22
+ }
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Laai tans";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "جارٍ التحميل";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "S’està carregant";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Načítání";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Indlæser";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Wird geladen";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Φόρτωση";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Loading";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Cargando";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Ladataan";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Chargement";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "טוען";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Betöltés";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Caricamento";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "読み込み中";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "로드 중";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Laster";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Laden";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Ładowanie";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Carregando";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "A carregar";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Se încarcă";
@@ -0,0 +1,4 @@
1
+ /* Generated by @astryxdesign/native from core's locale catalogs. Do not edit. */
2
+
3
+ /* Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense ("work in progress"), not a noun. Kept separate from `typeahead.loading` — translations may diverge. */
4
+ "@astryx.button.loading" = "Загрузка";