@astryxdesign/native 0.7.6-canary.f73623d → 0.7.6-canary.f78b205

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 (32) hide show
  1. package/apple/Package.swift +0 -2
  2. package/apple/README.md +18 -3
  3. package/apple/Sources/Astryx/Avatar/Avatar.swift +2 -9
  4. package/apple/Sources/Astryx/Base/SafeDestination.swift +48 -0
  5. package/apple/Sources/Astryx/Button/Button.swift +3 -21
  6. package/apple/Sources/Astryx/Item/Item.swift +354 -0
  7. package/apple/Sources/Astryx/Wire/AstryxNodeView.swift +9 -0
  8. package/apple/Sources/AstryxNative/Generated/AstryxNode.swift +3 -0
  9. package/apple/Sources/AstryxNative/Generated/Item.swift +173 -0
  10. package/apple/Tests/AstryxTests/ItemTests.swift +295 -0
  11. package/dist/components/Item.d.ts +10 -0
  12. package/dist/components/Item.d.ts.map +1 -0
  13. package/dist/components/Item.js +22 -0
  14. package/dist/components/index.d.ts.map +1 -1
  15. package/dist/components/index.js +2 -0
  16. package/dist/types/android.d.ts +16 -3
  17. package/dist/types/core.d.ts +18 -0
  18. package/dist/types/ios.d.ts +16 -3
  19. package/dist/types/macos.d.ts +16 -3
  20. package/dist/types/shared.d.ts +16 -3
  21. package/dist/types/windows.d.ts +16 -3
  22. package/package.json +3 -3
  23. package/src/components/Item.ts +34 -0
  24. package/src/components/index.ts +2 -0
  25. package/src/contract/contracts.test.ts +39 -0
  26. package/src/theme/swiftIOSTheme.test.ts +372 -38
  27. package/apple/Sources/Astryx/Avatar/Avatar.spec.md +0 -219
  28. package/apple/Sources/Astryx/Avatar/AvatarStatusDot.spec.md +0 -162
  29. package/apple/Sources/Astryx/Button/Button.spec.md +0 -174
  30. package/apple/Sources/Astryx/Icon/Icon.spec.md +0 -189
  31. package/apple/Sources/Astryx/TextInput/TextInput.spec.md +0 -179
  32. package/apple/Sources/Astryx/Thumbnail/Thumbnail.spec.md +0 -191
@@ -0,0 +1,173 @@
1
+ // Generated by @astryxdesign/native. Do not edit.
2
+ public enum ItemAlign: String, CaseIterable, Codable, Sendable {
3
+ case center = "center"
4
+ case start = "start"
5
+ case firstLine = "first-line"
6
+ }
7
+ public enum ItemDensity: String, CaseIterable, Codable, Sendable {
8
+ case compact = "compact"
9
+ case balanced = "balanced"
10
+ case spacious = "spacious"
11
+ }
12
+ public enum ItemLayout: String, CaseIterable, Codable, Sendable {
13
+ case stacked = "stacked"
14
+ case inline = "inline"
15
+ }
16
+ #if os(iOS)
17
+ public struct ItemProps {
18
+ /// Base props attach to this part on every platform.
19
+ public static let baseTarget: AstryxBaseTarget = .root
20
+ public var base: AstryxBaseProps
21
+ public var label: String
22
+ public var description: String?
23
+ public var align: ItemAlign?
24
+ public var density: ItemDensity?
25
+ public var labelLines: Double?
26
+ public var descriptionLines: Double?
27
+ public var layout: ItemLayout?
28
+ public var onClick: (() -> Void)?
29
+ public var href: String?
30
+ public var isHighlighted: Bool?
31
+ public var isSelected: Bool?
32
+ public var isDisabled: Bool?
33
+ public init(label: String, description: String? = nil, align: ItemAlign? = nil, density: ItemDensity? = nil, labelLines: Double? = nil, descriptionLines: Double? = nil, layout: ItemLayout? = nil, onClick: (() -> Void)? = nil, href: String? = nil, isHighlighted: Bool? = nil, isSelected: Bool? = nil, isDisabled: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
34
+ self.label = label
35
+ self.description = description
36
+ self.align = align
37
+ self.density = density
38
+ self.labelLines = labelLines
39
+ self.descriptionLines = descriptionLines
40
+ self.layout = layout
41
+ self.onClick = onClick
42
+ self.href = href
43
+ self.isHighlighted = isHighlighted
44
+ self.isSelected = isSelected
45
+ self.isDisabled = isDisabled
46
+ self.base = base
47
+ }
48
+ }
49
+ public struct ItemNode: Decodable, Equatable, Sendable {
50
+ public struct Props: Decodable, Equatable, Sendable {
51
+ public var label: String
52
+ public var marker: [AstryxNode]?
53
+ public var startContent: [AstryxNode]?
54
+ public var description: String?
55
+ public var endContent: [AstryxNode]?
56
+ public var align: ItemAlign?
57
+ public var density: ItemDensity?
58
+ public var labelLines: Double?
59
+ public var descriptionLines: Double?
60
+ public var layout: ItemLayout?
61
+ public var href: String?
62
+ public var isHighlighted: Bool?
63
+ public var isSelected: Bool?
64
+ public var isDisabled: Bool?
65
+ }
66
+ public let key: String
67
+ public let base: AstryxBaseProps?
68
+ public let props: Props
69
+ /// The callbacks the core listens to, by prop name.
70
+ public let events: [String]?
71
+
72
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
73
+
74
+ /// The contract a Item view takes; its callbacks send actions to the core.
75
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ItemProps {
76
+ let key = self.key
77
+ return ItemProps(
78
+ label: props.label,
79
+ description: props.description,
80
+ align: props.align,
81
+ density: props.density,
82
+ labelLines: props.labelLines,
83
+ descriptionLines: props.descriptionLines,
84
+ layout: props.layout,
85
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "Item", event: "onClick", args: [])) } : nil,
86
+ href: props.href,
87
+ isHighlighted: props.isHighlighted,
88
+ isSelected: props.isSelected,
89
+ isDisabled: props.isDisabled,
90
+ base: base ?? AstryxBaseProps()
91
+ )
92
+ }
93
+ }
94
+ #endif
95
+ #if os(macOS)
96
+ public struct ItemProps {
97
+ /// Base props attach to this part on every platform.
98
+ public static let baseTarget: AstryxBaseTarget = .root
99
+ public var base: AstryxBaseProps
100
+ public var label: String
101
+ public var description: String?
102
+ public var align: ItemAlign?
103
+ public var density: ItemDensity?
104
+ public var labelLines: Double?
105
+ public var descriptionLines: Double?
106
+ public var layout: ItemLayout?
107
+ public var onClick: (() -> Void)?
108
+ public var href: String?
109
+ public var isHighlighted: Bool?
110
+ public var isSelected: Bool?
111
+ public var isDisabled: Bool?
112
+ public init(label: String, description: String? = nil, align: ItemAlign? = nil, density: ItemDensity? = nil, labelLines: Double? = nil, descriptionLines: Double? = nil, layout: ItemLayout? = nil, onClick: (() -> Void)? = nil, href: String? = nil, isHighlighted: Bool? = nil, isSelected: Bool? = nil, isDisabled: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
113
+ self.label = label
114
+ self.description = description
115
+ self.align = align
116
+ self.density = density
117
+ self.labelLines = labelLines
118
+ self.descriptionLines = descriptionLines
119
+ self.layout = layout
120
+ self.onClick = onClick
121
+ self.href = href
122
+ self.isHighlighted = isHighlighted
123
+ self.isSelected = isSelected
124
+ self.isDisabled = isDisabled
125
+ self.base = base
126
+ }
127
+ }
128
+ public struct ItemNode: Decodable, Equatable, Sendable {
129
+ public struct Props: Decodable, Equatable, Sendable {
130
+ public var label: String
131
+ public var marker: [AstryxNode]?
132
+ public var startContent: [AstryxNode]?
133
+ public var description: String?
134
+ public var endContent: [AstryxNode]?
135
+ public var align: ItemAlign?
136
+ public var density: ItemDensity?
137
+ public var labelLines: Double?
138
+ public var descriptionLines: Double?
139
+ public var layout: ItemLayout?
140
+ public var href: String?
141
+ public var isHighlighted: Bool?
142
+ public var isSelected: Bool?
143
+ public var isDisabled: Bool?
144
+ }
145
+ public let key: String
146
+ public let base: AstryxBaseProps?
147
+ public let props: Props
148
+ /// The callbacks the core listens to, by prop name.
149
+ public let events: [String]?
150
+
151
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
152
+
153
+ /// The contract a Item view takes; its callbacks send actions to the core.
154
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ItemProps {
155
+ let key = self.key
156
+ return ItemProps(
157
+ label: props.label,
158
+ description: props.description,
159
+ align: props.align,
160
+ density: props.density,
161
+ labelLines: props.labelLines,
162
+ descriptionLines: props.descriptionLines,
163
+ layout: props.layout,
164
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "Item", event: "onClick", args: [])) } : nil,
165
+ href: props.href,
166
+ isHighlighted: props.isHighlighted,
167
+ isSelected: props.isSelected,
168
+ isDisabled: props.isDisabled,
169
+ base: base ?? AstryxBaseProps()
170
+ )
171
+ }
172
+ }
173
+ #endif
@@ -0,0 +1,295 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import AstryxNative
4
+ import SwiftUI
5
+ import Testing
6
+ @testable import Astryx
7
+
8
+ // Swift Item spec (component:swift/Item): core's row, its slots in reading
9
+ // order, density, alignment, and states, drawn the same static, as a button,
10
+ // or as a link.
11
+
12
+ @MainActor
13
+ @Test func trailingClosuresFillTheSlotsTheyName() {
14
+ let start = Item("Ada") { Color.red }
15
+ let both = Item("Ada") { Color.red } endContent: { Color.blue }
16
+ let end = Item("Ada", endContent: { Color.blue })
17
+ let pressable = Item("Settings", onClick: {})
18
+ let trailingPress = Item("Archive") { Color.red } onClick: {}
19
+ #expect(type(of: start) == Item<EmptyView, Color, EmptyView>.self)
20
+ #expect(type(of: both) == Item<EmptyView, Color, Color>.self)
21
+ #expect(type(of: end) == Item<EmptyView, EmptyView, Color>.self)
22
+ #expect(type(of: pressable) == Item<EmptyView, EmptyView, EmptyView>.self)
23
+ #expect(pressable.props.onClick != nil)
24
+ #expect(type(of: trailingPress) == Item<EmptyView, Color, EmptyView>.self)
25
+ #expect(trailingPress.props.onClick != nil)
26
+ }
27
+
28
+ @MainActor
29
+ @Test func itemInitializersBuildTheSameProps() {
30
+ let labeled = Item(
31
+ "Ada", description: "Mathematician", align: .firstLine, density: .spacious, labelLines: 2,
32
+ descriptionLines: 3, layout: .inline, href: "https://example.com", isHighlighted: true, isSelected: true,
33
+ isDisabled: true
34
+ ).props
35
+ let fromProps = Item(
36
+ ItemProps(
37
+ label: "Ada", description: "Mathematician", align: .firstLine, density: .spacious, labelLines: 2,
38
+ descriptionLines: 3, layout: .inline, href: "https://example.com", isHighlighted: true, isSelected: true,
39
+ isDisabled: true)
40
+ ).props
41
+ #expect(labeled.label == fromProps.label)
42
+ #expect(labeled.description == fromProps.description)
43
+ #expect(labeled.align == fromProps.align)
44
+ #expect(labeled.density == fromProps.density)
45
+ #expect(labeled.labelLines == fromProps.labelLines)
46
+ #expect(labeled.descriptionLines == fromProps.descriptionLines)
47
+ #expect(labeled.layout == fromProps.layout)
48
+ #expect(labeled.href == fromProps.href)
49
+ #expect(labeled.isHighlighted == fromProps.isHighlighted)
50
+ #expect(labeled.isSelected == fromProps.isSelected)
51
+ #expect(labeled.isDisabled == fromProps.isDisabled)
52
+ #expect(labeled.base == fromProps.base)
53
+ }
54
+
55
+ @MainActor
56
+ @Test func densityAddsCoresBlockPadding() {
57
+ let tokens = Theme.default.light.space
58
+ let compact = Pixels(Item("Ada", density: .compact).frame(width: 240))
59
+ let balanced = Pixels(Item("Ada").frame(width: 240))
60
+ let spacious = Pixels(Item("Ada", density: .spacious).frame(width: 240))
61
+ #expect(balanced.height - compact.height == Int(2 * (tokens.s2 - tokens.s1)))
62
+ #expect(spacious.height - balanced.height == Int(2 * (tokens.s3 - tokens.s2)))
63
+ }
64
+
65
+ @MainActor
66
+ @Test func aTappableRowIsAtLeast44PointsTallAndAStaticOneKeepsCoresHeight() {
67
+ let still = Pixels(Item("Ada", density: .compact).frame(width: 240))
68
+ let button = Pixels(Item("Ada", density: .compact, onClick: {}).frame(width: 240))
69
+ let link = Pixels(Item("Ada", density: .compact, href: "https://example.com").frame(width: 240))
70
+ #expect(still.height < 44)
71
+ #expect(button.height == 44)
72
+ #expect(link.height == 44)
73
+ }
74
+
75
+ @MainActor
76
+ @Test func selectedWinsOverHighlightedAndBothUseTheTheme() {
77
+ let accentMuted = rgba(Theme.default.light.color.accentMuted)
78
+ let overlay = rgba(Theme.default.light.color.overlayHover)
79
+ let selected = Pixels(Item("Ada", isHighlighted: true, isSelected: true).frame(width: 240).background(Color.white))
80
+ let highlighted = Pixels(Item("Ada", isHighlighted: true).frame(width: 240).background(Color.white))
81
+ let plain = Pixels(Item("Ada").frame(width: 240).background(Color.white))
82
+ let x = 230, y = 10
83
+ #expect(close(selected.at(x, y), onWhite(accentMuted), within: 3))
84
+ #expect(close(highlighted.at(x, y), onWhite(overlay), within: 3))
85
+ #expect(close(plain.at(x, y), [255, 255, 255, 255], within: 1))
86
+ }
87
+
88
+ @MainActor
89
+ @Test func anItemRendersFromTwoThemesWithNoColorOfItsOwn() {
90
+ let view = Item("Ada", isSelected: true).frame(width: 240).background(Color.white)
91
+ let neutral = Pixels(view, theme: .neutral).at(230, 10)
92
+ let butter = Pixels(view, theme: .butter).at(230, 10)
93
+ #expect(close(neutral, onWhite(rgba(Theme.neutral.light.color.accentMuted)), within: 3))
94
+ #expect(close(butter, onWhite(rgba(Theme.butter.light.color.accentMuted)), within: 3))
95
+ }
96
+
97
+ @MainActor
98
+ @Test func aDisabledRowDimsItsWordsAndEndContentNotItsStartContent() {
99
+ let red = [255, 0, 0, 255]
100
+ let swatch = { Color(red: 1, green: 0, blue: 0).frame(width: 12, height: 12) }
101
+ let start = Pixels(Item("Ada", isDisabled: true, startContent: swatch).frame(width: 240))
102
+ let end = Pixels(Item("Ada", isDisabled: true, endContent: swatch).frame(width: 240))
103
+ let enabledEnd = Pixels(Item("Ada", endContent: swatch).frame(width: 240))
104
+ #expect(start.contains { close($0, red) })
105
+ #expect(!end.contains { close($0, red) })
106
+ #expect(enabledEnd.contains { close($0, red) })
107
+ }
108
+
109
+ @MainActor
110
+ @Test func alignPlacesTheSlotsOnTheWords() {
111
+ let tokens = Theme.default.light
112
+ let marker = { Color(red: 1, green: 0, blue: 0).frame(width: 8, height: 8) }
113
+ let start = Pixels(Item("Ada", description: "Mathematician", align: .start, startContent: marker).frame(width: 240))
114
+ let centered = Pixels(Item("Ada", description: "Mathematician", startContent: marker).frame(width: 240))
115
+ let red = [255, 0, 0, 255]
116
+ let x = Int(tokens.space.s2) + 4
117
+ // `start`: the slot's top is on the row's top padding.
118
+ #expect(close(start.at(x, Int(tokens.space.s2) + 1), red))
119
+ #expect(!close(start.at(x, start.height / 2 + 6), red))
120
+ // `center`: the slot sits in the middle of the row.
121
+ #expect(close(centered.at(x, centered.height / 2), red))
122
+ }
123
+
124
+ @MainActor
125
+ @Test func aLineTakesTheThemesLeading() {
126
+ let tokens = Theme.default.light
127
+ let row = Pixels(Item("Ada", density: .compact).frame(width: 240))
128
+ #expect(abs(row.height - Int((2 * tokens.space.s1 + tokens.font.body.leading * tokens.font.body.size).rounded())) <= 1)
129
+ }
130
+
131
+ @MainActor
132
+ @Test func firstLineCentersATallSlotOnTheLabelsFirstLine() {
133
+ let red = [255, 0, 0, 255]
134
+ let tall = { Color(red: 1, green: 0, blue: 0).frame(width: 10, height: 40) }
135
+ func slotCenter(_ p: Pixels) -> Double {
136
+ let rows = (0..<p.height).filter { y in close(p.at(14, y), red) }
137
+ return Double(rows.first! + rows.last!) / 2
138
+ }
139
+ /// The middle of the label's ink: the first run of drawn rows in the words.
140
+ func labelCenter(_ p: Pixels) -> Double {
141
+ let ink = (0..<p.height).map { y in (30..<120).contains { x in p.at(x, y)[3] > 128 } }
142
+ let top = ink.firstIndex(of: true)!
143
+ var bottom = top
144
+ while bottom + 1 < ink.count && ink[bottom + 1] { bottom += 1 }
145
+ return Double(top + bottom) / 2
146
+ }
147
+ let first = Pixels(Item("Ada", description: "Mathematician", align: .firstLine, startContent: tall).frame(width: 240))
148
+ let center = Pixels(Item("Ada", description: "Mathematician", startContent: tall).frame(width: 240))
149
+ #expect(abs(slotCenter(first) - labelCenter(first)) <= 1.5)
150
+ // `center` puts the same slot on the middle of the words instead.
151
+ #expect(abs(slotCenter(center) - labelCenter(center)) > 4)
152
+ }
153
+
154
+ @MainActor
155
+ @Test func rowsReadTheirTapAndState() {
156
+ #expect(Item("Ada").tap == .none)
157
+ #expect(Item("Ada", onClick: {}).tap == .button)
158
+ #expect(Item("Ada", href: "https://example.com", onClick: {}).tap == .link)
159
+ #expect(Item<EmptyView, EmptyView, EmptyView>.addedTraits(isSelected: true) == .isSelected)
160
+ #expect(Item<EmptyView, EmptyView, EmptyView>.addedTraits(isSelected: false) == [])
161
+ }
162
+
163
+ @MainActor
164
+ @Test func rowsGrowWithTheLargestTextSize() {
165
+ let large = Pixels(Item("Ada", description: "Mathematician").frame(width: 320))
166
+ let largest = Pixels(Item("Ada", description: "Mathematician").frame(width: 320), typeSize: .accessibility5)
167
+ #expect(largest.height > large.height * 2)
168
+ let tappable = Pixels(Item("Ada", onClick: {}).frame(width: 320), typeSize: .accessibility5)
169
+ #expect(tappable.height > 44)
170
+ }
171
+
172
+ @MainActor
173
+ @Test func aWebPathIsAnItemHrefTheAppCannotOpen() {
174
+ #expect(Item<EmptyView, EmptyView, EmptyView>.isUnusableHref("/calendar"))
175
+ #expect(!Item<EmptyView, EmptyView, EmptyView>.isUnusableHref("https://example.com/calendar"))
176
+ #expect(!Item<EmptyView, EmptyView, EmptyView>.isUnusableHref(nil))
177
+ // The check reads the href as the link does: a padded absolute URL opens
178
+ // as a link and is not flagged.
179
+ #expect(!Item<EmptyView, EmptyView, EmptyView>.isUnusableHref(" https://example.com "))
180
+ #expect(Item("Ada", href: " https://example.com ").linkURL == URL(string: "https://example.com"))
181
+ }
182
+
183
+ @MainActor
184
+ @Test func anInlineLabelWithoutADescriptionStillTruncates() {
185
+ let words = "A label long enough to need more than the row's width at one line"
186
+ let stacked = Pixels(Item(words).frame(width: 160))
187
+ let inline = Pixels(Item(words, layout: .inline).frame(width: 160))
188
+ #expect(inline.width == 160)
189
+ #expect(inline.height == stacked.height)
190
+ // The end content stays inside the row instead of being pushed past it.
191
+ let withEnd = Pixels(Item(words, layout: .inline, endContent: { Color(red: 1, green: 0, blue: 0).frame(width: 10, height: 10) }).frame(width: 160))
192
+ #expect(withEnd.contains { close($0, [255, 0, 0, 255]) })
193
+ }
194
+
195
+ @MainActor
196
+ @Test func aPressShowsAboveASelectedFill() {
197
+ let tokens = Theme.neutral.light.color
198
+ let rest = Pixels(ItemPressBackground(radius: 0, fill: tokens.accentMuted, pressed: tokens.overlayPressed, isPressed: false).frame(width: 8, height: 8))
199
+ let pressed = Pixels(ItemPressBackground(radius: 0, fill: tokens.accentMuted, pressed: tokens.overlayPressed, isPressed: true).frame(width: 8, height: 8))
200
+ #expect(!close(rest.at(4, 4), pressed.at(4, 4), within: 3))
201
+ }
202
+
203
+ @Test func lineCountsComeFromTheContract() {
204
+ // Unset is one line; otherwise core's shared count: zero, a fraction, or a
205
+ // count too large to reach shows every line, as core's unclamped row does.
206
+ #expect(Item<EmptyView, EmptyView, EmptyView>.lines(nil) == 1)
207
+ #expect(Item<EmptyView, EmptyView, EmptyView>.lines(0) == nil)
208
+ #expect(Item<EmptyView, EmptyView, EmptyView>.lines(3) == 3)
209
+ #expect(Item<EmptyView, EmptyView, EmptyView>.lines(.infinity) == nil)
210
+ #expect(Item<EmptyView, EmptyView, EmptyView>.lines(1e300) == nil)
211
+ }
212
+
213
+ @MainActor
214
+ @Test func aLongLabelTruncatesToItsLines() {
215
+ let words = "A label long enough to wrap onto more than one line in a narrow row"
216
+ let one = Pixels(Item(words).frame(width: 160))
217
+ let three = Pixels(Item(words, labelLines: 3).frame(width: 160))
218
+ #expect(three.height > one.height)
219
+ }
220
+
221
+ @MainActor
222
+ @Test func hrefMakesALinkAndStatesReadFromTheContract() {
223
+ #expect(Item("Ada", href: "https://example.com/ada").linkURL == URL(string: "https://example.com/ada"))
224
+ #expect(Item("Ada", href: "").linkURL == nil)
225
+ #expect(Item("Ada", href: "not a url").linkURL == nil)
226
+ #expect(Item("Ada", href: "/calendar").linkURL == nil)
227
+ // A script URL or an HTML document in a data URL stays inert, as core's
228
+ // navigation destinations refuse them; the row is static or a button.
229
+ for refused in ["javascript:alert(1)", " JavaScript: alert(1)", "vbscript:msgbox", "data:text/html,<p>", "data: text/html,<p>"] {
230
+ #expect(Item("Ada", href: refused).linkURL == nil, "\(refused)")
231
+ #expect(Item("Ada", href: refused).tap == .none, "\(refused)")
232
+ }
233
+ #expect(Item("Ada", href: "javascript:alert(1)", onClick: {}).tap == .button)
234
+ #expect(Item("Ada", isSelected: true).isSelected)
235
+ #expect(!Item("Ada").isSelected)
236
+ #expect(Item("Ada", isDisabled: true).isDisabled)
237
+ }
238
+
239
+ @MainActor
240
+ @Test func aHiddenItemDrawsNothing() {
241
+ let hidden = Pixels(
242
+ HStack(spacing: 0) {
243
+ Color.clear.frame(width: 1, height: 1)
244
+ Item(ItemProps(label: "Ada", base: AstryxBaseProps(isHidden: true)))
245
+ }.fixedSize()
246
+ )
247
+ #expect(hidden.width == 1)
248
+ }
249
+
250
+ /// A theme color drawn over white.
251
+ private func onWhite(_ c: [Int]) -> [Int] {
252
+ (0..<3).map { (c[$0] * c[3] + 255 * (255 - c[3])) / 255 } + [255]
253
+ }
254
+
255
+ // AST-082 FR19: an Item node from a logic core draws as Item.
256
+ @MainActor
257
+ @Test func anItemNodeDrawsAsAnItem() {
258
+ let json = #"{"component":"Item","key":"i","props":{"label":"Ada Lovelace"}}"#
259
+ guard let node = try? JSONDecoder().decode(AstryxNode.self, from: Data(json.utf8)) else {
260
+ Issue.record("the item did not decode")
261
+ return
262
+ }
263
+ #expect(AstryxNodeView.componentName(node) == "Item")
264
+ let wired = Pixels(AstryxNodeView(node) { _ in }.frame(width: 200))
265
+ let direct = Pixels(Item("Ada Lovelace").frame(width: 200))
266
+ #expect(wired.height == direct.height)
267
+ }
268
+
269
+ // AST-082 FR19: an Item node's content slots draw their nodes, as a direct
270
+ // Item draws its slots.
271
+ @MainActor
272
+ @Test func anItemNodeDrawsItsContentSlots() {
273
+ let json = """
274
+ {"component":"Item","key":"i","props":{"label":"Ada Lovelace",
275
+ "startContent":[{"component":"Avatar","key":"a","props":{"name":"Ada Lovelace","size":"sm"}}],
276
+ "endContent":[{"component":"Text","key":"t","props":{"children":"Admin"}}]}}
277
+ """
278
+ guard let node = try? JSONDecoder().decode(AstryxNode.self, from: Data(json.utf8)) else {
279
+ Issue.record("the item did not decode")
280
+ return
281
+ }
282
+ let wired = Pixels(AstryxNodeView(node) { _ in }.frame(width: 240))
283
+ let direct = Pixels(
284
+ Item("Ada Lovelace") { Avatar("Ada Lovelace", size: .sm) } endContent: { Astryx.Text("Admin") }.frame(width: 240))
285
+ let bare = Pixels(Item("Ada Lovelace").frame(width: 240))
286
+ #expect(wired.width == direct.width && wired.height == direct.height)
287
+ // The slots draw: the wired row is not the bare row. The leading 40
288
+ // points hold the avatar, which a bare row leaves empty.
289
+ var leadingDiffers = false
290
+ for y in 0..<min(wired.height, bare.height) {
291
+ for x in 0..<40 where wired.at(x, y) != bare.at(x, y) { leadingDiffers = true }
292
+ }
293
+ #expect(leadingDiffers)
294
+ }
295
+
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file components/Item.ts
3
+ * @input None
4
+ * @output What @astryxdesign/native adds to the core Item contract
5
+ * @position Native additions read by fromComponentDoc together with core's
6
+ * Item documentation
7
+ */
8
+ import type { NativeAdditions } from '../contract/fromComponentDoc.js';
9
+ export declare const item: NativeAdditions;
10
+ //# sourceMappingURL=Item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../src/components/Item.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAErE,eAAO,MAAM,IAAI,EAAE,eAqBlB,CAAC"}
@@ -0,0 +1,22 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ export const item = {
3
+ name: 'Item',
4
+ doc: { file: 'Item/Item', component: 'Item' },
5
+ baseTarget: 'root',
6
+ slots: {
7
+ label: 'text',
8
+ description: 'text',
9
+ marker: 'content',
10
+ startContent: 'content',
11
+ endContent: 'content',
12
+ },
13
+ callbacks: ['onClick'],
14
+ sameMeaning: { onClick: 'a press, as in Compose' },
15
+ webOnly: {
16
+ target: 'HTML link target',
17
+ rel: 'HTML link relationship',
18
+ 'data-testid': 'web test selector; native platforms use the base id',
19
+ swipeActions: "a native platform's swipe actions work only inside its own scrolling list, so a row elsewhere could not honor them",
20
+ swipeBehavior: 'applies only with swipeActions',
21
+ },
22
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAkBrE,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAiBvD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAmBrE,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAkBvD,CAAC"}
@@ -8,6 +8,7 @@ import { divider } from './Divider.js';
8
8
  import { heading } from './Heading.js';
9
9
  import { hStack } from './HStack.js';
10
10
  import { icon } from './Icon.js';
11
+ import { item } from './Item.js';
11
12
  import { progressBar } from './ProgressBar.js';
12
13
  import { selector } from './Selector.js';
13
14
  import { switchControl } from './Switch.js';
@@ -25,6 +26,7 @@ export const NATIVE_COMPONENTS = [
25
26
  heading,
26
27
  hStack,
27
28
  icon,
29
+ item,
28
30
  progressBar,
29
31
  selector,
30
32
  switchControl,
@@ -1,6 +1,6 @@
1
1
  // Generated by @astryxdesign/native. Do not edit.
2
- import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ProgressBarCoreProps, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
3
- export type {AstryxSharedBaseProps, AstryxContentNode, IconName, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ProgressBarCoreProps, SelectorOption, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
2
+ import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ProgressBarCoreProps, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
3
+ export type {AstryxSharedBaseProps, AstryxContentNode, IconName, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ProgressBarCoreProps, SelectorOption, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
4
4
  /** Avatar props: core contract plus the android contract. */
5
5
  export interface AvatarProps extends AvatarCoreProps {}
6
6
  export declare function Avatar(props: AvatarProps): unknown;
@@ -28,6 +28,9 @@ export declare function HStack(props: HStackProps): unknown;
28
28
  /** Icon props: core contract plus the android contract. */
29
29
  export interface IconProps extends IconCoreProps {}
30
30
  export declare function Icon(props: IconProps): unknown;
31
+ /** Item props: core contract plus the android contract. */
32
+ export interface ItemProps extends ItemCoreProps {}
33
+ export declare function Item(props: ItemProps): unknown;
31
34
  /** ProgressBar props: core contract plus the android contract. */
32
35
  export interface ProgressBarProps extends ProgressBarCoreProps {}
33
36
  export declare function ProgressBar(props: ProgressBarProps): unknown;
@@ -121,6 +124,15 @@ export interface IconNode {
121
124
  base?: AstryxSharedBaseProps;
122
125
  props: {icon: IconName; color?: 'primary' | 'secondary' | 'tertiary' | 'disabled' | 'accent' | 'info' | 'success' | 'error' | 'warning' | 'inherit'; size?: 'xsm' | 'sm' | 'md' | 'lg'; label?: string;};
123
126
  }
127
+ /** Item as JSON from a TypeScript core. */
128
+ export interface ItemNode {
129
+ component: 'Item';
130
+ key: string;
131
+ base?: AstryxSharedBaseProps;
132
+ props: {label: string; marker?: ReadonlyArray<AstryxNode>; startContent?: ReadonlyArray<AstryxNode>; description?: string; endContent?: ReadonlyArray<AstryxNode>; align?: 'center' | 'start' | 'first-line'; density?: 'compact' | 'balanced' | 'spacious'; labelLines?: number; descriptionLines?: number; layout?: 'stacked' | 'inline'; href?: string; isHighlighted?: boolean; isSelected?: boolean; isDisabled?: boolean;};
133
+ /** The callbacks the core listens to. */
134
+ events?: ReadonlyArray<'onClick'>;
135
+ }
124
136
  /** ProgressBar as JSON from a TypeScript core. */
125
137
  export interface ProgressBarNode {
126
138
  component: 'ProgressBar';
@@ -179,11 +191,12 @@ export interface VStackNode {
179
191
  props: {gap?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; padding?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingInline?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingInlineStart?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingInlineEnd?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingBlock?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingBlockStart?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingBlockEnd?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; isScrollable?: boolean; hAlign?: 'start' | 'center' | 'end' | 'stretch'; vAlign?: 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'; justify?: 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'; align?: 'start' | 'center' | 'end' | 'stretch'; wrap?: 'nowrap' | 'wrap' | 'wrap-reverse'; children?: ReadonlyArray<AstryxNode>;};
180
192
  }
181
193
  /** Any Astryx component a TypeScript core can send. */
182
- export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
194
+ export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
183
195
  /** A callback a native view called, sent back to the core. */
184
196
  export type AstryxAction =
185
197
  | {key: string; component: 'Avatar'; event: 'onClick'; args: []}
186
198
  | {key: string; component: 'Button'; event: 'onClick'; args: []}
199
+ | {key: string; component: 'Item'; event: 'onClick'; args: []}
187
200
  | {key: string; component: 'Selector'; event: 'onChange'; args: [string]}
188
201
  | {key: string; component: 'Switch'; event: 'onChange'; args: [boolean]}
189
202
  | {key: string; component: 'Thumbnail'; event: 'onRemove'; args: []}
@@ -105,6 +105,24 @@ export interface IconCoreProps extends AstryxSharedBaseProps {
105
105
  label?: string;
106
106
  }
107
107
  /** Core contract. Base props attach to the root. */
108
+ export interface ItemCoreProps extends AstryxSharedBaseProps {
109
+ label: string;
110
+ marker?: ReadonlyArray<AstryxContentNode>;
111
+ startContent?: ReadonlyArray<AstryxContentNode>;
112
+ description?: string;
113
+ endContent?: ReadonlyArray<AstryxContentNode>;
114
+ align?: 'center' | 'start' | 'first-line';
115
+ density?: 'compact' | 'balanced' | 'spacious';
116
+ labelLines?: number;
117
+ descriptionLines?: number;
118
+ layout?: 'stacked' | 'inline';
119
+ onClick?: () => void;
120
+ href?: string;
121
+ isHighlighted?: boolean;
122
+ isSelected?: boolean;
123
+ isDisabled?: boolean;
124
+ }
125
+ /** Core contract. Base props attach to the root. */
108
126
  export interface ProgressBarCoreProps extends AstryxSharedBaseProps {
109
127
  label: string;
110
128
  value?: number;
@@ -1,6 +1,6 @@
1
1
  // Generated by @astryxdesign/native. Do not edit.
2
- import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ProgressBarCoreProps, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
3
- export type {AstryxSharedBaseProps, AstryxContentNode, IconName, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ProgressBarCoreProps, SelectorOption, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
2
+ import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ProgressBarCoreProps, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
3
+ export type {AstryxSharedBaseProps, AstryxContentNode, IconName, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ProgressBarCoreProps, SelectorOption, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
4
4
  /** Avatar props: core contract plus the ios contract. */
5
5
  export interface AvatarProps extends AvatarCoreProps {}
6
6
  export declare function Avatar(props: AvatarProps): unknown;
@@ -28,6 +28,9 @@ export declare function HStack(props: HStackProps): unknown;
28
28
  /** Icon props: core contract plus the ios contract. */
29
29
  export interface IconProps extends IconCoreProps {}
30
30
  export declare function Icon(props: IconProps): unknown;
31
+ /** Item props: core contract plus the ios contract. */
32
+ export interface ItemProps extends ItemCoreProps {}
33
+ export declare function Item(props: ItemProps): unknown;
31
34
  /** ProgressBar props: core contract plus the ios contract. */
32
35
  export interface ProgressBarProps extends ProgressBarCoreProps {}
33
36
  export declare function ProgressBar(props: ProgressBarProps): unknown;
@@ -118,6 +121,15 @@ export interface IconNode {
118
121
  base?: AstryxSharedBaseProps;
119
122
  props: {icon: IconName; color?: 'primary' | 'secondary' | 'tertiary' | 'disabled' | 'accent' | 'info' | 'success' | 'error' | 'warning' | 'inherit'; size?: 'xsm' | 'sm' | 'md' | 'lg'; label?: string;};
120
123
  }
124
+ /** Item as JSON from a TypeScript core. */
125
+ export interface ItemNode {
126
+ component: 'Item';
127
+ key: string;
128
+ base?: AstryxSharedBaseProps;
129
+ props: {label: string; marker?: ReadonlyArray<AstryxNode>; startContent?: ReadonlyArray<AstryxNode>; description?: string; endContent?: ReadonlyArray<AstryxNode>; align?: 'center' | 'start' | 'first-line'; density?: 'compact' | 'balanced' | 'spacious'; labelLines?: number; descriptionLines?: number; layout?: 'stacked' | 'inline'; href?: string; isHighlighted?: boolean; isSelected?: boolean; isDisabled?: boolean;};
130
+ /** The callbacks the core listens to. */
131
+ events?: ReadonlyArray<'onClick'>;
132
+ }
121
133
  /** ProgressBar as JSON from a TypeScript core. */
122
134
  export interface ProgressBarNode {
123
135
  component: 'ProgressBar';
@@ -176,11 +188,12 @@ export interface VStackNode {
176
188
  props: {gap?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; padding?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingInline?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingInlineStart?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingInlineEnd?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingBlock?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingBlockStart?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; paddingBlockEnd?: 0 | 0.5 | 1 | 1.5 | 2 | 3 | 4 | 5 | 6 | 8 | 10; isScrollable?: boolean; hAlign?: 'start' | 'center' | 'end' | 'stretch'; vAlign?: 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'; justify?: 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'; align?: 'start' | 'center' | 'end' | 'stretch'; wrap?: 'nowrap' | 'wrap' | 'wrap-reverse'; children?: ReadonlyArray<AstryxNode>;};
177
189
  }
178
190
  /** Any Astryx component a TypeScript core can send. */
179
- export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
191
+ export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
180
192
  /** A callback a native view called, sent back to the core. */
181
193
  export type AstryxAction =
182
194
  | {key: string; component: 'Avatar'; event: 'onClick'; args: []}
183
195
  | {key: string; component: 'Button'; event: 'onClick'; args: []}
196
+ | {key: string; component: 'Item'; event: 'onClick'; args: []}
184
197
  | {key: string; component: 'Selector'; event: 'onChange'; args: [string]}
185
198
  | {key: string; component: 'Switch'; event: 'onChange'; args: [boolean]}
186
199
  | {key: string; component: 'Thumbnail'; event: 'onRemove'; args: []}