@astryxdesign/native 0.7.6-canary.2224fa8 → 0.7.6-canary.2227dcb

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.
package/apple/README.md CHANGED
@@ -29,6 +29,7 @@ apple/
29
29
  │ │ ├── Icon/ # Icon
30
30
  │ │ ├── Avatar/ # Avatar
31
31
  │ │ ├── Item/ # Item
32
+ │ │ ├── List/ # ListItem
32
33
  │ │ ├── Text/ # Text
33
34
  │ │ ├── Heading/ # Heading
34
35
  │ │ ├── Button/ # Button
@@ -29,6 +29,8 @@ public struct Item<Marker: View, StartContent: View, EndContent: View>: View {
29
29
  let startContent: StartContent
30
30
  let endContent: EndContent
31
31
  @Environment(\.astryx) private var astryx
32
+ @Environment(\.astryxItemListTreatment) private var listTreatment
33
+ @State private var wordsHeight: CGFloat = 0
32
34
 
33
35
  /// A row from its labeled props. A single trailing closure is the start
34
36
  /// content; set `onClick` by label or as a trailing `onClick:` closure.
@@ -131,29 +133,31 @@ public struct Item<Marker: View, StartContent: View, EndContent: View>: View {
131
133
  /// A link or button row's fill and its press, painted by the button style
132
134
  /// so the press sits above a selected or highlighted fill, as core's does.
133
135
  private var pressStyle: ItemPressStyle {
134
- ItemPressStyle(radius: astryx.tokens.radius.element, fill: background, pressed: astryx.tokens.color.overlayPressed)
136
+ ItemPressStyle(radius: cornerRadius, fill: background, pressed: astryx.tokens.color.overlayPressed)
135
137
  }
136
138
 
137
139
  /// The row's drawing; a tappable row is at least `minHeight` tall. A static
138
140
  /// row paints its own fill; a link or button row's style paints it.
139
141
  private func row(minHeight: CGFloat?, paintsFill: Bool) -> some View {
140
142
  HStack(alignment: rowAlignment, spacing: astryx.tokens.space.s2) {
141
- slot(marker)
142
- slot(startContent)
143
+ markerSlot
144
+ // A list's treatment is for this row only, not for rows nested in its slots.
145
+ slot(startContent.modifier(ItemSlotOutsideList()))
143
146
  // A disabled row dims its words and end content, as core does; the
144
147
  // marker and start content keep their own look (a checkbox shows its
145
148
  // own disabled state).
146
149
  words
147
150
  .frame(maxWidth: .infinity, alignment: .leading)
151
+ .modifier(ItemWordsHeight(isMeasured: measuresWords, height: $wordsHeight))
148
152
  .opacity(isDisabled ? 0.5 : 1)
149
- slot(endContent)
153
+ slot(endContent.modifier(ItemSlotOutsideList()))
150
154
  .opacity(isDisabled ? 0.5 : 1)
151
155
  }
152
156
  .padding(.horizontal, inlinePadding)
153
157
  .padding(.vertical, blockPadding)
154
158
  .frame(maxWidth: .infinity, minHeight: minHeight, alignment: .leading)
155
159
  .background(
156
- RoundedRectangle(cornerRadius: astryx.tokens.radius.element, style: .continuous)
160
+ RoundedRectangle(cornerRadius: cornerRadius, style: .continuous)
157
161
  .fill(paintsFill ? background ?? .clear : .clear)
158
162
  )
159
163
  .contentShape(Rectangle())
@@ -170,6 +174,43 @@ public struct Item<Marker: View, StartContent: View, EndContent: View>: View {
170
174
  }
171
175
  }
172
176
 
177
+ /// The marker. Inside a list it centers on the label's first line,
178
+ /// whatever the row's alignment, as core's list markers do.
179
+ @ViewBuilder private var markerSlot: some View {
180
+ if listTreatment?.markerOnFirstLine == true {
181
+ let center = firstLineBoxHeight / 2
182
+ switch resolvedAlign {
183
+ case .firstLine:
184
+ slot(marker)
185
+ case .start:
186
+ marker.alignmentGuide(.top) { d in d.height / 2 - center }
187
+ case .center:
188
+ let words = wordsHeight
189
+ marker.alignmentGuide(VerticalAlignment.center) { d in words / 2 - center + d.height / 2 }
190
+ }
191
+ } else {
192
+ slot(marker)
193
+ }
194
+ }
195
+
196
+ /// Whether the row measures its words: only a centre-aligned row in a list
197
+ /// with markers, which places its marker from the words' height.
198
+ private var measuresWords: Bool {
199
+ listTreatment?.markerOnFirstLine == true && resolvedAlign == .center
200
+ }
201
+
202
+ /// The height of the label's first line box: the theme's leading at the
203
+ /// current text size.
204
+ private var firstLineBoxHeight: CGFloat {
205
+ astryx.tokens.font.body.leading * astryx.tokens.font.body.size * astryx.textScale
206
+ }
207
+
208
+ /// The row's corner radius: the theme's element radius, or square inside a
209
+ /// list with dividers.
210
+ private var cornerRadius: CGFloat {
211
+ listTreatment?.squareCorners == true ? 0 : astryx.tokens.radius.element
212
+ }
213
+
173
214
  @ViewBuilder private var words: some View {
174
215
  let label = SwiftUI.Text(props.label)
175
216
  .font(astryx.font(size: "text-body-size", 14, weight: "text-body-weight"))
@@ -237,9 +278,15 @@ public struct Item<Marker: View, StartContent: View, EndContent: View>: View {
237
278
  }
238
279
  }
239
280
 
240
- /// Inline padding: spacing 2, or 3 when spacious.
281
+ /// Inline padding: the list's own inset when a list sets one, else core's
282
+ /// for the density.
241
283
  var inlinePadding: CGFloat {
242
- (props.density ?? .balanced) == .spacious ? astryx.tokens.space.s3 : astryx.tokens.space.s2
284
+ listTreatment?.inlineInset ?? Item.inlinePadding(density: props.density, tokens: astryx.tokens)
285
+ }
286
+
287
+ /// Core's inline padding for a density: spacing 2, or 3 when spacious.
288
+ static func inlinePadding(density: ItemDensity?, tokens: Tokens) -> CGFloat {
289
+ (density ?? .balanced) == .spacious ? tokens.space.s3 : tokens.space.s2
243
290
  }
244
291
 
245
292
  /// The space core's line height adds to the font's own line, grown with
@@ -352,3 +399,48 @@ private struct ItemAccessibility: ViewModifier {
352
399
  content.accessibilityAddTraits(Item<EmptyView, EmptyView, EmptyView>.addedTraits(isSelected: isSelected))
353
400
  }
354
401
  }
402
+
403
+ /// Measures the words' height only when the row needs it.
404
+ private struct ItemWordsHeight: ViewModifier {
405
+ let isMeasured: Bool
406
+ @Binding var height: CGFloat
407
+
408
+ func body(content: Content) -> some View {
409
+ if isMeasured {
410
+ content.onGeometryChange(for: CGFloat.self) { $0.size.height } action: { height = $0 }
411
+ } else {
412
+ content
413
+ }
414
+ }
415
+ }
416
+
417
+ /// A row's slots sit outside its list: a row nested in a slot takes neither
418
+ /// the list's treatment, its look, nor a number from it.
419
+ private struct ItemSlotOutsideList: ViewModifier {
420
+ func body(content: Content) -> some View {
421
+ content
422
+ .environment(\.astryxItemListTreatment, nil)
423
+ .environment(\.astryxListContext, nil)
424
+ .environment(\.astryxListNumbers, nil)
425
+ }
426
+ }
427
+
428
+ /// How a list draws the rows it holds: the marker on the first line, its own
429
+ /// inline inset (zero for a flush list), and square corners between dividers.
430
+ struct ItemListTreatment: Equatable {
431
+ var markerOnFirstLine: Bool
432
+ var inlineInset: CGFloat?
433
+ var squareCorners: Bool
434
+ }
435
+
436
+ private struct ItemListTreatmentKey: EnvironmentKey {
437
+ static let defaultValue: ItemListTreatment? = nil
438
+ }
439
+
440
+ extension EnvironmentValues {
441
+ /// Set by `ListItem` on the `Item` it draws; `nil` for an `Item` alone.
442
+ var astryxItemListTreatment: ItemListTreatment? {
443
+ get { self[ItemListTreatmentKey.self] }
444
+ set { self[ItemListTreatmentKey.self] = newValue }
445
+ }
446
+ }
@@ -0,0 +1,255 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import AstryxNative
4
+ import SwiftUI
5
+
6
+ /// A row of a `List` (core `ListItem`): an `Item` that takes its density,
7
+ /// marker, dividers, and edge from the list that holds it. Outside a list it
8
+ /// draws as a plain `Item`.
9
+ ///
10
+ /// ```swift
11
+ /// ListItem("Preheat the oven", description: "To 180 degrees")
12
+ /// ListItem("Wi-Fi", description: "Home") {
13
+ /// Icon(.check)
14
+ /// } onClick: { openWiFi() }
15
+ /// ```
16
+ public struct ListItem<StartContent: View, EndContent: View>: View {
17
+ /// The contract the view draws, the same for both initializers.
18
+ public let props: ListItemProps
19
+ let startContent: StartContent
20
+ let endContent: EndContent
21
+ @Environment(\.astryx) private var astryx
22
+ @Environment(\.astryxListContext) private var list
23
+ @Environment(\.astryxListNumbers) private var numbers
24
+ /// This row's identity among its list's rows, for its number.
25
+ @State private var rowID = UUID()
26
+
27
+ /// A list row from its labeled props. A single trailing closure is the start
28
+ /// content; set `onClick` by label or as a trailing `onClick:` closure.
29
+ /// - Parameters:
30
+ /// - label: The row's main words (core `label`).
31
+ /// - description: Supporting words under the label (core `description`).
32
+ /// - align: How the start and end content line up with the words; `nil` is `center` (core `align`).
33
+ /// - href: A URL the system opens when the row is tapped; the row becomes a link (core `href`).
34
+ /// - isDisabled: Dims the row; a button or link row stays reachable and does nothing (core `isDisabled`).
35
+ /// - isSelected: Draws the row as selected and reads it as selected (core `isSelected`).
36
+ /// - startContent: Content before the words, such as an `Icon` or an `Avatar` (core `startContent`).
37
+ /// - endContent: Content after the words (core `endContent`).
38
+ /// - onClick: Runs when the row is tapped; the row becomes a button when it has no `href` (core `onClick`).
39
+ public init(
40
+ _ label: String,
41
+ description: String? = nil,
42
+ align: ListItemAlign? = nil,
43
+ href: String? = nil,
44
+ isDisabled: Bool? = nil,
45
+ isSelected: Bool? = nil,
46
+ @ViewBuilder startContent: () -> StartContent = { EmptyView() },
47
+ @ViewBuilder endContent: () -> EndContent = { EmptyView() },
48
+ onClick: (() -> Void)? = nil
49
+ ) {
50
+ self.init(
51
+ ListItemProps(
52
+ label: label, description: description, onClick: onClick, href: href, align: align,
53
+ isDisabled: isDisabled, isSelected: isSelected),
54
+ startContent: startContent, endContent: endContent)
55
+ }
56
+
57
+ /// A list row from its generated contract, for generated and wire-driven callers.
58
+ public init(
59
+ _ props: ListItemProps,
60
+ @ViewBuilder startContent: () -> StartContent = { EmptyView() },
61
+ @ViewBuilder endContent: () -> EndContent = { EmptyView() }
62
+ ) {
63
+ self.props = props
64
+ self.startContent = startContent()
65
+ self.endContent = endContent()
66
+ }
67
+
68
+ public var body: some View {
69
+ Item(itemProps, startContent: { startContent }, endContent: { endContent }, marker: { marker })
70
+ .environment(\.astryxItemListTreatment, treatment)
71
+ // A row in a list announces itself so the list can number its rows in
72
+ // order, as core's CSS counter counts list items.
73
+ .preference(key: ListRowsKey.self, value: list == nil ? [] : [rowID])
74
+ }
75
+
76
+ /// The `Item` this row draws: its own props, with the list's density.
77
+ var itemProps: ItemProps {
78
+ ItemProps(
79
+ label: props.label, description: props.description,
80
+ align: props.align.flatMap { ItemAlign(rawValue: $0.rawValue) },
81
+ density: list?.density, onClick: props.onClick, href: props.href, isSelected: props.isSelected,
82
+ isDisabled: props.isDisabled, base: props.base)
83
+ }
84
+
85
+ /// How the list draws this row: the marker on the first line, no inline
86
+ /// inset in a flush list, and square corners between dividers.
87
+ var treatment: ItemListTreatment? {
88
+ guard let list else { return nil }
89
+ return ItemListTreatment(
90
+ markerOnFirstLine: list.marker != nil,
91
+ inlineInset: list.isFlush ? 0 : nil,
92
+ squareCorners: list.hasDividers)
93
+ }
94
+
95
+ /// The list's marker for this row: a dot, a ring, or its number.
96
+ @ViewBuilder var marker: some View {
97
+ switch list?.marker {
98
+ case .disc:
99
+ Circle()
100
+ .fill(astryx.tokens.color.textPrimary)
101
+ .frame(width: ListItem.markerDot, height: ListItem.markerDot)
102
+ .frame(width: ListItem.markerColumn(astryx))
103
+ .accessibilityHidden(!ListItem.markerIsRead(.disc))
104
+ case .circle:
105
+ Circle()
106
+ .strokeBorder(astryx.tokens.color.textPrimary, lineWidth: 1)
107
+ .frame(width: ListItem.markerDot, height: ListItem.markerDot)
108
+ .frame(width: ListItem.markerColumn(astryx))
109
+ .accessibilityHidden(!ListItem.markerIsRead(.circle))
110
+ case .decimal:
111
+ ListMarkerNumber(
112
+ text: ListItem.number(ordinal: numbers?.number(for: rowID) ?? 1), row: rowID, numbers: numbers,
113
+ inset: rowInset)
114
+ case nil:
115
+ EmptyView()
116
+ }
117
+ }
118
+
119
+ /// The row's inline inset, which a wide number may reach into: none in a
120
+ /// flush list, else core's padding for the list's density.
121
+ var rowInset: CGFloat {
122
+ guard let list else { return 0 }
123
+ return list.isFlush ? 0 : Item<EmptyView, EmptyView, EmptyView>.inlinePadding(density: list.density, tokens: astryx.tokens)
124
+ }
125
+
126
+ /// Whether VoiceOver reads a marker: a number is read as part of the row;
127
+ /// a dot or ring is decoration and hidden.
128
+ nonisolated static func markerIsRead(_ marker: ListContext.Marker) -> Bool { marker == .decimal }
129
+
130
+ /// The marker column: core's `space.s4`, grown with Dynamic Type as the
131
+ /// number in it grows, and the same width on every row.
132
+ static func markerColumn(_ astryx: AstryxStyle) -> CGFloat {
133
+ (astryx.tokens.space.s4 * max(astryx.textScale, 1)).rounded()
134
+ }
135
+
136
+ /// A number marker's column: the marker column, or wider when the list's
137
+ /// widest number does not fit it and the row's inline inset together, so
138
+ /// every row of the list widens alike and no number moves its own row's
139
+ /// words (core's numbered markers; `spec:AST-061` FR11).
140
+ nonisolated static func numberColumn(base: CGFloat, widest: CGFloat, inset: CGFloat) -> CGFloat {
141
+ max(base, widest - inset)
142
+ }
143
+
144
+ /// Core's marker dot: 6 points.
145
+ nonisolated static var markerDot: CGFloat { 6 }
146
+
147
+ /// A decimal marker's words: the row's number and a period, as core's
148
+ /// `counter(…) "."`.
149
+ nonisolated static func number(ordinal: Int) -> String { "\(ordinal)." }
150
+ }
151
+
152
+ /// A decimal marker: the number and its period in the body type with tabular
153
+ /// figures, ending at the column's end so every period in the list lines up,
154
+ /// as core's numbered markers do. A number wider than the column reaches into
155
+ /// the row's inline inset; past that, the list's shared column widens.
156
+ struct ListMarkerNumber: View {
157
+ let text: String
158
+ var row: UUID? = nil
159
+ var numbers: ListNumbers? = nil
160
+ var inset: CGFloat = 0
161
+ @Environment(\.astryx) private var astryx
162
+ @State private var natural: CGFloat = 0
163
+
164
+ var body: some View {
165
+ let column = ListItem<EmptyView, EmptyView>.numberColumn(
166
+ base: ListItem<EmptyView, EmptyView>.markerColumn(astryx), widest: numbers?.widest ?? natural, inset: inset)
167
+ SwiftUI.Text(text)
168
+ .font(astryx.font(size: "text-body-size", 14, weight: "text-body-weight"))
169
+ .monospacedDigit()
170
+ .foregroundStyle(astryx.tokens.color.textPrimary)
171
+ .fixedSize()
172
+ .onGeometryChange(for: CGFloat.self) { $0.size.width } action: { width in
173
+ natural = width
174
+ if let row { numbers?.report(row, width: width) }
175
+ }
176
+ .frame(width: column, alignment: .trailing)
177
+ }
178
+ }
179
+
180
+ /// The list a `ListItem` sits in, as `List` describes it to its rows.
181
+ struct ListContext: Equatable {
182
+ /// The kind of marker each row draws.
183
+ enum Marker: Equatable { case disc, circle, decimal }
184
+
185
+ var density: ItemDensity?
186
+ var hasDividers: Bool
187
+ var isFlush: Bool
188
+ var marker: Marker?
189
+ }
190
+
191
+ private struct ListContextKey: EnvironmentKey {
192
+ static let defaultValue: ListContext? = nil
193
+ }
194
+
195
+ /// The numbers a list gives its rows, by row, in the order the rows appear.
196
+ @MainActor @Observable
197
+ final class ListNumbers {
198
+ private(set) var numbers: [UUID: Int] = [:]
199
+
200
+ nonisolated init() {}
201
+
202
+ /// The widest number any row of the list draws, for the shared column.
203
+ private(set) var widest: CGFloat = 0
204
+ private var widths: [UUID: CGFloat] = [:]
205
+
206
+ /// Numbers the rows in order, the first one `start`, and forgets the widths
207
+ /// of rows that left the list.
208
+ func assign(_ rows: [UUID], start: Int) {
209
+ let numbered = Dictionary(rows.enumerated().map { ($0.element, start + $0.offset) }, uniquingKeysWith: { first, _ in first })
210
+ if numbered != numbers { numbers = numbered }
211
+ let kept = widths.filter { numbered[$0.key] != nil }
212
+ if kept.count != widths.count {
213
+ widths = kept
214
+ updateWidest()
215
+ }
216
+ }
217
+
218
+ /// Records the width a row's number draws at.
219
+ func report(_ row: UUID, width: CGFloat) {
220
+ guard widths[row] != width else { return }
221
+ widths[row] = width
222
+ updateWidest()
223
+ }
224
+
225
+ private func updateWidest() {
226
+ let next = widths.values.max() ?? 0
227
+ if next != widest { widest = next }
228
+ }
229
+
230
+ func number(for row: UUID) -> Int? { numbers[row] }
231
+ }
232
+
233
+ /// The rows of a list, in order: each `ListItem` adds its own identity.
234
+ struct ListRowsKey: PreferenceKey {
235
+ static let defaultValue: [UUID] = []
236
+ static func reduce(value: inout [UUID], nextValue: () -> [UUID]) { value.append(contentsOf: nextValue()) }
237
+ }
238
+
239
+ private struct ListNumbersKey: EnvironmentKey {
240
+ static let defaultValue: ListNumbers? = nil
241
+ }
242
+
243
+ extension EnvironmentValues {
244
+ /// The list around a row; `nil` outside a list.
245
+ var astryxListContext: ListContext? {
246
+ get { self[ListContextKey.self] }
247
+ set { self[ListContextKey.self] = newValue }
248
+ }
249
+
250
+ /// The numbers of the rows of the list around a row.
251
+ var astryxListNumbers: ListNumbers? {
252
+ get { self[ListNumbersKey.self] }
253
+ set { self[ListNumbersKey.self] = newValue }
254
+ }
255
+ }
@@ -33,6 +33,12 @@ public struct AstryxNodeView: View {
33
33
  } marker: {
34
34
  AstryxNodeList(nodes: item.props.marker ?? [], send: send)
35
35
  }
36
+ case .listItem(let row):
37
+ ListItem(row.viewProps(send: send)) {
38
+ AstryxNodeList(nodes: row.props.startContent ?? [], send: send)
39
+ } endContent: {
40
+ AstryxNodeList(nodes: row.props.endContent ?? [], send: send)
41
+ }
36
42
  default: AstryxUnsupportedNode(component: Self.componentName(node))
37
43
  }
38
44
  }
@@ -50,6 +56,7 @@ public struct AstryxNodeView: View {
50
56
  case .hStack: "HStack"
51
57
  case .icon: "Icon"
52
58
  case .item: "Item"
59
+ case .listItem: "ListItem"
53
60
  case .progressBar: "ProgressBar"
54
61
  case .selector: "Selector"
55
62
  case .switch: "Switch"
@@ -17,6 +17,7 @@ public enum AstryxNode: Decodable, Equatable, Sendable {
17
17
  case hStack(HStackNode)
18
18
  case icon(IconNode)
19
19
  case item(ItemNode)
20
+ case listItem(ListItemNode)
20
21
  case progressBar(ProgressBarNode)
21
22
  case selector(SelectorNode)
22
23
  case `switch`(SwitchNode)
@@ -38,6 +39,7 @@ public enum AstryxNode: Decodable, Equatable, Sendable {
38
39
  case .hStack(let node): return node.key
39
40
  case .icon(let node): return node.key
40
41
  case .item(let node): return node.key
42
+ case .listItem(let node): return node.key
41
43
  case .progressBar(let node): return node.key
42
44
  case .selector(let node): return node.key
43
45
  case .`switch`(let node): return node.key
@@ -67,6 +69,7 @@ public enum AstryxNode: Decodable, Equatable, Sendable {
67
69
  case "HStack": self = .hStack(try HStackNode(from: decoder))
68
70
  case "Icon": self = .icon(try IconNode(from: decoder))
69
71
  case "Item": self = .item(try ItemNode(from: decoder))
72
+ case "ListItem": self = .listItem(try ListItemNode(from: decoder))
70
73
  case "ProgressBar": self = .progressBar(try ProgressBarNode(from: decoder))
71
74
  case "Selector": self = .selector(try SelectorNode(from: decoder))
72
75
  case "Switch": self = .`switch`(try SwitchNode(from: decoder))
@@ -0,0 +1,122 @@
1
+ // Generated by @astryxdesign/native. Do not edit.
2
+ public enum ListItemAlign: String, CaseIterable, Codable, Sendable {
3
+ case center = "center"
4
+ case start = "start"
5
+ case firstLine = "first-line"
6
+ }
7
+ #if os(iOS)
8
+ public struct ListItemProps {
9
+ /// Base props attach to this part on every platform.
10
+ public static let baseTarget: AstryxBaseTarget = .root
11
+ public var base: AstryxBaseProps
12
+ public var label: String
13
+ public var description: String?
14
+ public var onClick: (() -> Void)?
15
+ public var href: String?
16
+ public var align: ListItemAlign?
17
+ public var isDisabled: Bool?
18
+ public var isSelected: Bool?
19
+ public init(label: String, description: String? = nil, onClick: (() -> Void)? = nil, href: String? = nil, align: ListItemAlign? = nil, isDisabled: Bool? = nil, isSelected: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
20
+ self.label = label
21
+ self.description = description
22
+ self.onClick = onClick
23
+ self.href = href
24
+ self.align = align
25
+ self.isDisabled = isDisabled
26
+ self.isSelected = isSelected
27
+ self.base = base
28
+ }
29
+ }
30
+ public struct ListItemNode: Decodable, Equatable, Sendable {
31
+ public struct Props: Decodable, Equatable, Sendable {
32
+ public var label: String
33
+ public var description: String?
34
+ public var startContent: [AstryxNode]?
35
+ public var endContent: [AstryxNode]?
36
+ public var href: String?
37
+ public var align: ListItemAlign?
38
+ public var isDisabled: Bool?
39
+ public var isSelected: Bool?
40
+ }
41
+ public let key: String
42
+ public let base: AstryxBaseProps?
43
+ public let props: Props
44
+ /// The callbacks the core listens to, by prop name.
45
+ public let events: [String]?
46
+
47
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
48
+
49
+ /// The contract a ListItem view takes; its callbacks send actions to the core.
50
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ListItemProps {
51
+ let key = self.key
52
+ return ListItemProps(
53
+ label: props.label,
54
+ description: props.description,
55
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "ListItem", event: "onClick", args: [])) } : nil,
56
+ href: props.href,
57
+ align: props.align,
58
+ isDisabled: props.isDisabled,
59
+ isSelected: props.isSelected,
60
+ base: base ?? AstryxBaseProps()
61
+ )
62
+ }
63
+ }
64
+ #endif
65
+ #if os(macOS)
66
+ public struct ListItemProps {
67
+ /// Base props attach to this part on every platform.
68
+ public static let baseTarget: AstryxBaseTarget = .root
69
+ public var base: AstryxBaseProps
70
+ public var label: String
71
+ public var description: String?
72
+ public var onClick: (() -> Void)?
73
+ public var href: String?
74
+ public var align: ListItemAlign?
75
+ public var isDisabled: Bool?
76
+ public var isSelected: Bool?
77
+ public init(label: String, description: String? = nil, onClick: (() -> Void)? = nil, href: String? = nil, align: ListItemAlign? = nil, isDisabled: Bool? = nil, isSelected: Bool? = nil, base: AstryxBaseProps = AstryxBaseProps()) {
78
+ self.label = label
79
+ self.description = description
80
+ self.onClick = onClick
81
+ self.href = href
82
+ self.align = align
83
+ self.isDisabled = isDisabled
84
+ self.isSelected = isSelected
85
+ self.base = base
86
+ }
87
+ }
88
+ public struct ListItemNode: Decodable, Equatable, Sendable {
89
+ public struct Props: Decodable, Equatable, Sendable {
90
+ public var label: String
91
+ public var description: String?
92
+ public var startContent: [AstryxNode]?
93
+ public var endContent: [AstryxNode]?
94
+ public var href: String?
95
+ public var align: ListItemAlign?
96
+ public var isDisabled: Bool?
97
+ public var isSelected: Bool?
98
+ }
99
+ public let key: String
100
+ public let base: AstryxBaseProps?
101
+ public let props: Props
102
+ /// The callbacks the core listens to, by prop name.
103
+ public let events: [String]?
104
+
105
+ public func listens(_ event: String) -> Bool { events?.contains(event) ?? false }
106
+
107
+ /// The contract a ListItem view takes; its callbacks send actions to the core.
108
+ public func viewProps(send: @escaping @Sendable (AstryxAction) -> Void) -> ListItemProps {
109
+ let key = self.key
110
+ return ListItemProps(
111
+ label: props.label,
112
+ description: props.description,
113
+ onClick: listens("onClick") ? { send(AstryxAction(key: key, component: "ListItem", event: "onClick", args: [])) } : nil,
114
+ href: props.href,
115
+ align: props.align,
116
+ isDisabled: props.isDisabled,
117
+ isSelected: props.isSelected,
118
+ base: base ?? AstryxBaseProps()
119
+ )
120
+ }
121
+ }
122
+ #endif
@@ -0,0 +1,234 @@
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 ListItem spec (component:swift/ListItem): an Item that takes its
9
+ // density, marker, dividers, and edge from its list.
10
+
11
+ private let red = [255, 0, 0, 255]
12
+ @MainActor private func swatch() -> some View { Color(red: 1, green: 0, blue: 0).frame(width: 10, height: 10) }
13
+
14
+ @MainActor
15
+ private func inList<V: View>(_ view: V, _ context: ListContext) -> some View {
16
+ view.environment(\.astryxListContext, context).frame(width: 240)
17
+ }
18
+
19
+ @MainActor
20
+ @Test func listItemInitializersBuildTheSameProps() {
21
+ let labeled = ListItem("Ada", description: "Mathematician", align: .start, href: "https://example.com", isDisabled: true, isSelected: true).props
22
+ let fromProps = ListItem(ListItemProps(label: "Ada", description: "Mathematician", href: "https://example.com", align: .start, isDisabled: true, isSelected: true)).props
23
+ #expect(labeled.label == fromProps.label)
24
+ #expect(labeled.description == fromProps.description)
25
+ #expect(labeled.align == fromProps.align)
26
+ #expect(labeled.href == fromProps.href)
27
+ #expect(labeled.isDisabled == fromProps.isDisabled)
28
+ #expect(labeled.isSelected == fromProps.isSelected)
29
+ #expect(labeled.base == fromProps.base)
30
+ }
31
+
32
+ @MainActor
33
+ @Test func aListItemAloneDrawsAsAnItem() {
34
+ let row = Pixels(ListItem("Ada", description: "Mathematician").frame(width: 240))
35
+ let item = Pixels(Item("Ada", description: "Mathematician").frame(width: 240))
36
+ #expect(row.width == item.width && row.height == item.height)
37
+ }
38
+
39
+ @MainActor
40
+ @Test func aListItemTakesItsListsDensity() {
41
+ let compact = Pixels(inList(ListItem("Ada"), ListContext(density: .compact, hasDividers: false, isFlush: false)))
42
+ let spacious = Pixels(inList(ListItem("Ada"), ListContext(density: .spacious, hasDividers: false, isFlush: false)))
43
+ let tokens = Theme.default.light.space
44
+ #expect(spacious.height - compact.height == Int(2 * (tokens.s3 - tokens.s1)))
45
+ }
46
+
47
+ @MainActor
48
+ @Test func aFlushListDropsTheRowsInlineInset() {
49
+ let padded = Pixels(inList(ListItem("Ada", startContent: { swatch() }), ListContext(hasDividers: false, isFlush: false)))
50
+ let flush = Pixels(inList(ListItem("Ada", startContent: { swatch() }), ListContext(hasDividers: false, isFlush: true)))
51
+ #expect(!close(padded.at(1, padded.height / 2), red))
52
+ #expect(close(flush.at(1, flush.height / 2), red))
53
+ }
54
+
55
+ @MainActor
56
+ @Test func rowsBetweenDividersHaveSquareCorners() {
57
+ let accent = Theme.default.light.color.accentMuted
58
+ let rounded = Pixels(inList(ListItem("Ada", isSelected: true), ListContext(hasDividers: false, isFlush: false)))
59
+ let square = Pixels(inList(ListItem("Ada", isSelected: true), ListContext(hasDividers: true, isFlush: false)))
60
+ #expect(rounded.at(0, 0)[3] < 8)
61
+ #expect(close(square.at(0, 0), plate(accent), within: 6))
62
+ }
63
+
64
+ @MainActor
65
+ @Test func aDecimalListNumbersItsRows() {
66
+ #expect(ListItem<EmptyView, EmptyView>.number(ordinal: 3) == "3.")
67
+ let numbers = ListNumbers()
68
+ let first = UUID(), second = UUID()
69
+ numbers.assign([first, second], start: 3)
70
+ #expect(numbers.number(for: first) == 3 && numbers.number(for: second) == 4)
71
+ let numbered = Pixels(inList(ListItem("MMMMMM"), ListContext(hasDividers: false, isFlush: false, marker: .decimal)))
72
+ let plain = Pixels(inList(ListItem("MMMMMM"), ListContext(hasDividers: false, isFlush: false)))
73
+ // The number takes a marker column, so a run of blank columns opens
74
+ // between it and the words; without a marker the words start at once.
75
+ func longestBlankRun(_ p: Pixels) -> Int {
76
+ var longest = 0, run = 0
77
+ for x in 8..<80 {
78
+ let blank = (0..<p.height).allSatisfy { y in p.at(x, y)[3] < 64 }
79
+ run = blank ? run + 1 : 0
80
+ longest = max(longest, run)
81
+ }
82
+ return longest
83
+ }
84
+ #expect(longestBlankRun(numbered) >= 5)
85
+ #expect(longestBlankRun(plain) < 5)
86
+ }
87
+
88
+ @MainActor
89
+ @Test func aMarkerSitsOnTheLabelsFirstLineWhateverTheAlignment() {
90
+ func dotCenter(_ p: Pixels) -> Double {
91
+ let rows = (0..<p.height).filter { y in (8..<24).contains { x in p.at(x, y)[3] > 200 } }
92
+ return Double(rows.first! + rows.last!) / 2
93
+ }
94
+ func labelCenter(_ p: Pixels) -> Double {
95
+ let ink = (0..<p.height).map { y in (40..<140).contains { x in p.at(x, y)[3] > 128 } }
96
+ let top = ink.firstIndex(of: true)!
97
+ var bottom = top
98
+ while bottom + 1 < ink.count && ink[bottom + 1] { bottom += 1 }
99
+ return Double(top + bottom) / 2
100
+ }
101
+ let context = ListContext(hasDividers: false, isFlush: false, marker: .disc)
102
+ for align in [ListItemAlign.center, .start, .firstLine] {
103
+ let row = Pixels(inList(ListItem("Ada", description: "Mathematician", align: align), context))
104
+ #expect(abs(dotCenter(row) - labelCenter(row)) <= 1.5, "\(align)")
105
+ }
106
+ }
107
+
108
+ /// A translucent theme color as the renderer stores it, premultiplied.
109
+ private func plate(_ color: Color) -> [Int] {
110
+ let c = rgba(color)
111
+ return [c[0] * c[3] / 255, c[1] * c[3] / 255, c[2] * c[3] / 255, c[3]]
112
+ }
113
+
114
+ @MainActor
115
+ @Test func aWideNumberKeepsTheListsTextEdge() {
116
+ // The column is space.s4 wide while a number fits it and the row's inset,
117
+ // so labels line up; "10." reaches into a balanced row's 8-point inset.
118
+ let s4 = Int(Theme.default.light.space.s4)
119
+ #expect(Pixels(ListMarkerNumber(text: "1.", inset: 8)).width == s4)
120
+ #expect(Pixels(ListMarkerNumber(text: "10.", inset: 8)).width == s4)
121
+ }
122
+
123
+ @MainActor
124
+ @Test func numbersEndAtTheColumnsEndSoPeriodsLineUp() {
125
+ // Core's numbered markers end where the marker ends, with tabular figures,
126
+ // so "1." and "10." put their periods at the same place.
127
+ func rightmostInk(_ p: Pixels) -> Int {
128
+ (0..<p.width).last { x in (0..<p.height).contains { y in p.at(x, y)[3] > 64 } } ?? -1
129
+ }
130
+ let one = Pixels(ListMarkerNumber(text: "1.", inset: 8))
131
+ let ten = Pixels(ListMarkerNumber(text: "10.", inset: 8))
132
+ #expect(rightmostInk(one) >= 0)
133
+ #expect(abs(rightmostInk(one) - rightmostInk(ten)) <= 1)
134
+ // The number sits at the column's end, not its start.
135
+ #expect(rightmostInk(one) >= one.width - 3)
136
+ }
137
+
138
+ @Test func aNumberWiderThanTheColumnAndInsetWidensTheSharedColumn() {
139
+ typealias Row = ListItem<EmptyView, EmptyView>
140
+ #expect(Row.numberColumn(base: 16, widest: 20, inset: 8) == 16)
141
+ #expect(Row.numberColumn(base: 16, widest: 40, inset: 8) == 32)
142
+ #expect(Row.numberColumn(base: 16, widest: 30, inset: 0) == 30)
143
+ }
144
+
145
+ @MainActor
146
+ @Test func aListSharesItsWidestNumber() {
147
+ let numbers = ListNumbers()
148
+ let first = UUID(), second = UUID()
149
+ numbers.assign([first, second], start: 1)
150
+ numbers.report(first, width: 20)
151
+ numbers.report(second, width: 30)
152
+ #expect(numbers.widest == 30)
153
+ // A row that leaves the list no longer widens it.
154
+ numbers.assign([first], start: 1)
155
+ #expect(numbers.widest == 20)
156
+ }
157
+
158
+ @Test func onlyANumberMarkerIsRead() {
159
+ #expect(ListItem<EmptyView, EmptyView>.markerIsRead(.decimal))
160
+ #expect(!ListItem<EmptyView, EmptyView>.markerIsRead(.disc))
161
+ #expect(!ListItem<EmptyView, EmptyView>.markerIsRead(.circle))
162
+ }
163
+
164
+ @MainActor
165
+ @Test func aMarkerStaysOnTheFirstLineAtTheLargestTextSize() {
166
+ let context = ListContext(hasDividers: false, isFlush: false, marker: .disc)
167
+ let large = Pixels(inList(ListItem("Ada", description: "Mathematician"), context))
168
+ let largest = Pixels(inList(ListItem("Ada", description: "Mathematician"), context), typeSize: .accessibility5)
169
+ #expect(largest.height > large.height)
170
+ // The dot sits in the top part of the row, by the first line, not its middle.
171
+ // The marker column grows with text, so look across it.
172
+ let rows = (0..<largest.height).filter { y in (8..<60).contains { x in largest.at(x, y)[3] > 200 } }
173
+ #expect(!rows.isEmpty && rows.last! < largest.height / 2)
174
+ }
175
+
176
+ @MainActor
177
+ @Test func markersDrawInEachThemesPrimaryText() {
178
+ for theme in [Theme.neutral, Theme.butter] {
179
+ let drawn = Pixels(inList(ListItem("Ada"), ListContext(hasDividers: false, isFlush: false, marker: .disc)), theme: theme)
180
+ let ink = (0..<drawn.height).flatMap { y in (8..<24).map { x in drawn.at(x, y) } }.filter { $0[3] == 255 }
181
+ #expect(ink.contains { close($0, rgba(theme.light.color.textPrimary), within: 8) })
182
+ }
183
+ }
184
+
185
+ @MainActor
186
+ @Test func aRowNestedInASlotTakesNoListLook() {
187
+ // A nested row has no marker column, so its words start at its own inset.
188
+ let context = ListContext(hasDividers: false, isFlush: true, marker: .disc)
189
+ let nested = Pixels(inList(ListItem("Outer", endContent: { ListItem("MMMM").frame(width: 100) }), context))
190
+ let alone = Pixels(ListItem("MMMM").frame(width: 100))
191
+ let start = { (p: Pixels, from: Int) in (from..<p.width).first { x in (0..<p.height).contains { y in p.at(x, y)[3] > 128 } } ?? -1 }
192
+ #expect(start(nested, 140) - 140 == start(alone, 0))
193
+ }
194
+
195
+ @MainActor
196
+ @Test func aNumberFitsItsColumnAtTheLargestTextSize() {
197
+ // The column grows with the number, so a one-digit number never runs into
198
+ // its label at the largest text size.
199
+ let column = Pixels(ListMarkerNumber(text: "9."), typeSize: .accessibility5).width
200
+ let drawn = Pixels(
201
+ ZStack(alignment: .leading) {
202
+ Color.clear.frame(width: 200, height: 80)
203
+ ListMarkerNumber(text: "9.")
204
+ },
205
+ typeSize: .accessibility5)
206
+ let rightmostInk = (0..<200).last { x in (0..<drawn.height).contains { y in drawn.at(x, y)[3] > 64 } } ?? 0
207
+ #expect(column > Int(Theme.default.light.space.s4))
208
+ #expect(rightmostInk < column)
209
+ }
210
+
211
+ // AST-082 FR19: a ListItem node draws as a ListItem, with its content slots.
212
+ @MainActor
213
+ @Test func aListItemNodeDrawsItsContentSlots() {
214
+ let json = """
215
+ {"component":"ListItem","key":"r","props":{"label":"Ada Lovelace",
216
+ "startContent":[{"component":"Avatar","key":"a","props":{"name":"Ada Lovelace","size":"sm"}}]}}
217
+ """
218
+ guard let node = try? JSONDecoder().decode(AstryxNode.self, from: Data(json.utf8)) else {
219
+ Issue.record("the row did not decode")
220
+ return
221
+ }
222
+ #expect(AstryxNodeView.componentName(node) == "ListItem")
223
+ let wired = Pixels(AstryxNodeView(node) { _ in }.frame(width: 240))
224
+ let direct = Pixels(ListItem("Ada Lovelace") { Avatar("Ada Lovelace", size: .sm) }.frame(width: 240))
225
+ let bare = Pixels(ListItem("Ada Lovelace").frame(width: 240))
226
+ #expect(wired.width == direct.width && wired.height == direct.height)
227
+ // The slot draws: the leading 40 points hold the avatar, which a bare row
228
+ // leaves empty.
229
+ var leadingDiffers = false
230
+ for y in 0..<min(wired.height, bare.height) {
231
+ for x in 0..<40 where wired.at(x, y) != bare.at(x, y) { leadingDiffers = true }
232
+ }
233
+ #expect(leadingDiffers)
234
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file components/ListItem.ts
3
+ * @input None
4
+ * @output What @astryxdesign/native adds to the core ListItem contract
5
+ * @position Native additions read by fromComponentDoc together with core's
6
+ * ListItem documentation
7
+ */
8
+ import type { NativeAdditions } from '../contract/fromComponentDoc.js';
9
+ export declare const listItem: NativeAdditions;
10
+ //# sourceMappingURL=ListItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ListItem.d.ts","sourceRoot":"","sources":["../../src/components/ListItem.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAErE,eAAO,MAAM,QAAQ,EAAE,eAmBtB,CAAC"}
@@ -0,0 +1,20 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ export const listItem = {
3
+ name: 'ListItem',
4
+ doc: { file: 'List/ListItem' },
5
+ baseTarget: 'root',
6
+ slots: {
7
+ label: 'text',
8
+ description: 'text',
9
+ startContent: 'content',
10
+ endContent: 'content',
11
+ },
12
+ callbacks: ['onClick'],
13
+ sameMeaning: { onClick: 'a press, as in Compose' },
14
+ webOnly: {
15
+ target: 'HTML link target',
16
+ rel: 'HTML link relationship',
17
+ swipeActions: "a native platform's swipe actions work only inside its own scrolling list, so a row elsewhere could not honor them",
18
+ swipeBehavior: 'applies only with swipeActions',
19
+ },
20
+ };
@@ -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;AAmBrE,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAkBvD,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;AAoBrE,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAmBvD,CAAC"}
@@ -9,6 +9,7 @@ import { heading } from './Heading.js';
9
9
  import { hStack } from './HStack.js';
10
10
  import { icon } from './Icon.js';
11
11
  import { item } from './Item.js';
12
+ import { listItem } from './ListItem.js';
12
13
  import { progressBar } from './ProgressBar.js';
13
14
  import { selector } from './Selector.js';
14
15
  import { switchControl } from './Switch.js';
@@ -27,6 +28,7 @@ export const NATIVE_COMPONENTS = [
27
28
  hStack,
28
29
  icon,
29
30
  item,
31
+ listItem,
30
32
  progressBar,
31
33
  selector,
32
34
  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, 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';
2
+ import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ListItemCoreProps, 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, ListItemCoreProps, 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;
@@ -31,6 +31,9 @@ export declare function Icon(props: IconProps): unknown;
31
31
  /** Item props: core contract plus the android contract. */
32
32
  export interface ItemProps extends ItemCoreProps {}
33
33
  export declare function Item(props: ItemProps): unknown;
34
+ /** ListItem props: core contract plus the android contract. */
35
+ export interface ListItemProps extends ListItemCoreProps {}
36
+ export declare function ListItem(props: ListItemProps): unknown;
34
37
  /** ProgressBar props: core contract plus the android contract. */
35
38
  export interface ProgressBarProps extends ProgressBarCoreProps {}
36
39
  export declare function ProgressBar(props: ProgressBarProps): unknown;
@@ -133,6 +136,15 @@ export interface ItemNode {
133
136
  /** The callbacks the core listens to. */
134
137
  events?: ReadonlyArray<'onClick'>;
135
138
  }
139
+ /** ListItem as JSON from a TypeScript core. */
140
+ export interface ListItemNode {
141
+ component: 'ListItem';
142
+ key: string;
143
+ base?: AstryxSharedBaseProps;
144
+ props: {label: string; description?: string; startContent?: ReadonlyArray<AstryxNode>; endContent?: ReadonlyArray<AstryxNode>; href?: string; align?: 'center' | 'start' | 'first-line'; isDisabled?: boolean; isSelected?: boolean;};
145
+ /** The callbacks the core listens to. */
146
+ events?: ReadonlyArray<'onClick'>;
147
+ }
136
148
  /** ProgressBar as JSON from a TypeScript core. */
137
149
  export interface ProgressBarNode {
138
150
  component: 'ProgressBar';
@@ -191,12 +203,13 @@ export interface VStackNode {
191
203
  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>;};
192
204
  }
193
205
  /** Any Astryx component a TypeScript core can send. */
194
- export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
206
+ export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ListItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
195
207
  /** A callback a native view called, sent back to the core. */
196
208
  export type AstryxAction =
197
209
  | {key: string; component: 'Avatar'; event: 'onClick'; args: []}
198
210
  | {key: string; component: 'Button'; event: 'onClick'; args: []}
199
211
  | {key: string; component: 'Item'; event: 'onClick'; args: []}
212
+ | {key: string; component: 'ListItem'; event: 'onClick'; args: []}
200
213
  | {key: string; component: 'Selector'; event: 'onChange'; args: [string]}
201
214
  | {key: string; component: 'Switch'; event: 'onChange'; args: [boolean]}
202
215
  | {key: string; component: 'Thumbnail'; event: 'onRemove'; args: []}
@@ -123,6 +123,18 @@ export interface ItemCoreProps extends AstryxSharedBaseProps {
123
123
  isDisabled?: boolean;
124
124
  }
125
125
  /** Core contract. Base props attach to the root. */
126
+ export interface ListItemCoreProps extends AstryxSharedBaseProps {
127
+ label: string;
128
+ description?: string;
129
+ startContent?: ReadonlyArray<AstryxContentNode>;
130
+ endContent?: ReadonlyArray<AstryxContentNode>;
131
+ onClick?: () => void;
132
+ href?: string;
133
+ align?: 'center' | 'start' | 'first-line';
134
+ isDisabled?: boolean;
135
+ isSelected?: boolean;
136
+ }
137
+ /** Core contract. Base props attach to the root. */
126
138
  export interface ProgressBarCoreProps extends AstryxSharedBaseProps {
127
139
  label: string;
128
140
  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, 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';
2
+ import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ListItemCoreProps, 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, ListItemCoreProps, 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;
@@ -31,6 +31,9 @@ export declare function Icon(props: IconProps): unknown;
31
31
  /** Item props: core contract plus the ios contract. */
32
32
  export interface ItemProps extends ItemCoreProps {}
33
33
  export declare function Item(props: ItemProps): unknown;
34
+ /** ListItem props: core contract plus the ios contract. */
35
+ export interface ListItemProps extends ListItemCoreProps {}
36
+ export declare function ListItem(props: ListItemProps): unknown;
34
37
  /** ProgressBar props: core contract plus the ios contract. */
35
38
  export interface ProgressBarProps extends ProgressBarCoreProps {}
36
39
  export declare function ProgressBar(props: ProgressBarProps): unknown;
@@ -130,6 +133,15 @@ export interface ItemNode {
130
133
  /** The callbacks the core listens to. */
131
134
  events?: ReadonlyArray<'onClick'>;
132
135
  }
136
+ /** ListItem as JSON from a TypeScript core. */
137
+ export interface ListItemNode {
138
+ component: 'ListItem';
139
+ key: string;
140
+ base?: AstryxSharedBaseProps;
141
+ props: {label: string; description?: string; startContent?: ReadonlyArray<AstryxNode>; endContent?: ReadonlyArray<AstryxNode>; href?: string; align?: 'center' | 'start' | 'first-line'; isDisabled?: boolean; isSelected?: boolean;};
142
+ /** The callbacks the core listens to. */
143
+ events?: ReadonlyArray<'onClick'>;
144
+ }
133
145
  /** ProgressBar as JSON from a TypeScript core. */
134
146
  export interface ProgressBarNode {
135
147
  component: 'ProgressBar';
@@ -188,12 +200,13 @@ export interface VStackNode {
188
200
  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>;};
189
201
  }
190
202
  /** Any Astryx component a TypeScript core can send. */
191
- export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
203
+ export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ListItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
192
204
  /** A callback a native view called, sent back to the core. */
193
205
  export type AstryxAction =
194
206
  | {key: string; component: 'Avatar'; event: 'onClick'; args: []}
195
207
  | {key: string; component: 'Button'; event: 'onClick'; args: []}
196
208
  | {key: string; component: 'Item'; event: 'onClick'; args: []}
209
+ | {key: string; component: 'ListItem'; event: 'onClick'; args: []}
197
210
  | {key: string; component: 'Selector'; event: 'onChange'; args: [string]}
198
211
  | {key: string; component: 'Switch'; event: 'onChange'; args: [boolean]}
199
212
  | {key: string; component: 'Thumbnail'; event: 'onRemove'; args: []}
@@ -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, 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';
2
+ import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ListItemCoreProps, 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, ListItemCoreProps, ProgressBarCoreProps, SelectorOption, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
4
4
  /** Avatar props: core contract plus the macos contract. */
5
5
  export interface AvatarProps extends AvatarCoreProps {}
6
6
  export declare function Avatar(props: AvatarProps): unknown;
@@ -31,6 +31,9 @@ export declare function Icon(props: IconProps): unknown;
31
31
  /** Item props: core contract plus the macos contract. */
32
32
  export interface ItemProps extends ItemCoreProps {}
33
33
  export declare function Item(props: ItemProps): unknown;
34
+ /** ListItem props: core contract plus the macos contract. */
35
+ export interface ListItemProps extends ListItemCoreProps {}
36
+ export declare function ListItem(props: ListItemProps): unknown;
34
37
  /** ProgressBar props: core contract plus the macos contract. */
35
38
  export interface ProgressBarProps extends ProgressBarCoreProps {}
36
39
  export declare function ProgressBar(props: ProgressBarProps): unknown;
@@ -130,6 +133,15 @@ export interface ItemNode {
130
133
  /** The callbacks the core listens to. */
131
134
  events?: ReadonlyArray<'onClick'>;
132
135
  }
136
+ /** ListItem as JSON from a TypeScript core. */
137
+ export interface ListItemNode {
138
+ component: 'ListItem';
139
+ key: string;
140
+ base?: AstryxSharedBaseProps;
141
+ props: {label: string; description?: string; startContent?: ReadonlyArray<AstryxNode>; endContent?: ReadonlyArray<AstryxNode>; href?: string; align?: 'center' | 'start' | 'first-line'; isDisabled?: boolean; isSelected?: boolean;};
142
+ /** The callbacks the core listens to. */
143
+ events?: ReadonlyArray<'onClick'>;
144
+ }
133
145
  /** ProgressBar as JSON from a TypeScript core. */
134
146
  export interface ProgressBarNode {
135
147
  component: 'ProgressBar';
@@ -188,12 +200,13 @@ export interface VStackNode {
188
200
  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>;};
189
201
  }
190
202
  /** Any Astryx component a TypeScript core can send. */
191
- export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
203
+ export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ListItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
192
204
  /** A callback a native view called, sent back to the core. */
193
205
  export type AstryxAction =
194
206
  | {key: string; component: 'Avatar'; event: 'onClick'; args: []}
195
207
  | {key: string; component: 'Button'; event: 'onClick'; args: []}
196
208
  | {key: string; component: 'Item'; event: 'onClick'; args: []}
209
+ | {key: string; component: 'ListItem'; event: 'onClick'; args: []}
197
210
  | {key: string; component: 'Selector'; event: 'onChange'; args: [string]}
198
211
  | {key: string; component: 'Switch'; event: 'onChange'; args: [boolean]}
199
212
  | {key: string; component: 'Thumbnail'; event: 'onRemove'; args: []}
@@ -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, 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';
2
+ import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ListItemCoreProps, 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, ListItemCoreProps, ProgressBarCoreProps, SelectorOption, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
4
4
  /** Avatar props: core contract only. */
5
5
  export interface AvatarProps extends AvatarCoreProps {}
6
6
  export declare function Avatar(props: AvatarProps): unknown;
@@ -31,6 +31,9 @@ export declare function Icon(props: IconProps): unknown;
31
31
  /** Item props: core contract only. */
32
32
  export interface ItemProps extends ItemCoreProps {}
33
33
  export declare function Item(props: ItemProps): unknown;
34
+ /** ListItem props: core contract only. */
35
+ export interface ListItemProps extends ListItemCoreProps {}
36
+ export declare function ListItem(props: ListItemProps): unknown;
34
37
  /** ProgressBar props: core contract only. */
35
38
  export interface ProgressBarProps extends ProgressBarCoreProps {}
36
39
  export declare function ProgressBar(props: ProgressBarProps): unknown;
@@ -128,6 +131,15 @@ export interface ItemNode {
128
131
  /** The callbacks the core listens to. */
129
132
  events?: ReadonlyArray<'onClick'>;
130
133
  }
134
+ /** ListItem as JSON from a TypeScript core. */
135
+ export interface ListItemNode {
136
+ component: 'ListItem';
137
+ key: string;
138
+ base?: AstryxSharedBaseProps;
139
+ props: {label: string; description?: string; startContent?: ReadonlyArray<AstryxNode>; endContent?: ReadonlyArray<AstryxNode>; href?: string; align?: 'center' | 'start' | 'first-line'; isDisabled?: boolean; isSelected?: boolean;};
140
+ /** The callbacks the core listens to. */
141
+ events?: ReadonlyArray<'onClick'>;
142
+ }
131
143
  /** ProgressBar as JSON from a TypeScript core. */
132
144
  export interface ProgressBarNode {
133
145
  component: 'ProgressBar';
@@ -186,12 +198,13 @@ export interface VStackNode {
186
198
  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>;};
187
199
  }
188
200
  /** Any Astryx component a TypeScript core can send. */
189
- export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
201
+ export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ListItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
190
202
  /** A callback a native view called, sent back to the core. */
191
203
  export type AstryxAction =
192
204
  | {key: string; component: 'Avatar'; event: 'onClick'; args: []}
193
205
  | {key: string; component: 'Button'; event: 'onClick'; args: []}
194
206
  | {key: string; component: 'Item'; event: 'onClick'; args: []}
207
+ | {key: string; component: 'ListItem'; event: 'onClick'; args: []}
195
208
  | {key: string; component: 'Selector'; event: 'onChange'; args: [string]}
196
209
  | {key: string; component: 'Switch'; event: 'onChange'; args: [boolean]}
197
210
  | {key: string; component: 'Thumbnail'; event: 'onRemove'; args: []}
@@ -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, 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';
2
+ import type {AstryxSharedBaseProps, IconName, SelectorOption, AvatarCoreProps, AvatarStatusDotCoreProps, BadgeCoreProps, ButtonCoreProps, CardCoreProps, DividerCoreProps, HeadingCoreProps, HStackCoreProps, IconCoreProps, ItemCoreProps, ListItemCoreProps, 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, ListItemCoreProps, ProgressBarCoreProps, SelectorOption, SelectorCoreProps, SwitchCoreProps, TextCoreProps, ThumbnailCoreProps, TextInputCoreProps, VStackCoreProps} from './core.js';
4
4
  /** Avatar props: core contract plus the windows contract. */
5
5
  export interface AvatarProps extends AvatarCoreProps {}
6
6
  export declare function Avatar(props: AvatarProps): unknown;
@@ -31,6 +31,9 @@ export declare function Icon(props: IconProps): unknown;
31
31
  /** Item props: core contract plus the windows contract. */
32
32
  export interface ItemProps extends ItemCoreProps {}
33
33
  export declare function Item(props: ItemProps): unknown;
34
+ /** ListItem props: core contract plus the windows contract. */
35
+ export interface ListItemProps extends ListItemCoreProps {}
36
+ export declare function ListItem(props: ListItemProps): unknown;
34
37
  /** ProgressBar props: core contract plus the windows contract. */
35
38
  export interface ProgressBarProps extends ProgressBarCoreProps {}
36
39
  export declare function ProgressBar(props: ProgressBarProps): unknown;
@@ -131,6 +134,15 @@ export interface ItemNode {
131
134
  /** The callbacks the core listens to. */
132
135
  events?: ReadonlyArray<'onClick'>;
133
136
  }
137
+ /** ListItem as JSON from a TypeScript core. */
138
+ export interface ListItemNode {
139
+ component: 'ListItem';
140
+ key: string;
141
+ base?: AstryxSharedBaseProps;
142
+ props: {label: string; description?: string; startContent?: ReadonlyArray<AstryxNode>; endContent?: ReadonlyArray<AstryxNode>; href?: string; align?: 'center' | 'start' | 'first-line'; isDisabled?: boolean; isSelected?: boolean;};
143
+ /** The callbacks the core listens to. */
144
+ events?: ReadonlyArray<'onClick'>;
145
+ }
134
146
  /** ProgressBar as JSON from a TypeScript core. */
135
147
  export interface ProgressBarNode {
136
148
  component: 'ProgressBar';
@@ -189,12 +201,13 @@ export interface VStackNode {
189
201
  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>;};
190
202
  }
191
203
  /** Any Astryx component a TypeScript core can send. */
192
- export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
204
+ export type AstryxNode = AvatarNode | AvatarStatusDotNode | BadgeNode | ButtonNode | CardNode | DividerNode | HeadingNode | HStackNode | IconNode | ItemNode | ListItemNode | ProgressBarNode | SelectorNode | SwitchNode | TextNode | ThumbnailNode | TextInputNode | VStackNode;
193
205
  /** A callback a native view called, sent back to the core. */
194
206
  export type AstryxAction =
195
207
  | {key: string; component: 'Avatar'; event: 'onClick'; args: []}
196
208
  | {key: string; component: 'Button'; event: 'onClick'; args: []}
197
209
  | {key: string; component: 'Item'; event: 'onClick'; args: []}
210
+ | {key: string; component: 'ListItem'; event: 'onClick'; args: []}
198
211
  | {key: string; component: 'Selector'; event: 'onChange'; args: [string]}
199
212
  | {key: string; component: 'Switch'; event: 'onChange'; args: [boolean]}
200
213
  | {key: string; component: 'Thumbnail'; event: 'onRemove'; args: []}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/native",
3
- "version": "0.7.6-canary.2224fa8",
3
+ "version": "0.7.6-canary.2227dcb",
4
4
  "description": "Experimental native platforms for Astryx (iOS, Android, macOS, Windows) — published to npm only under the @canary dist-tag; never released as a stable (latest) version.",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -70,10 +70,10 @@
70
70
  }
71
71
  },
72
72
  "peerDependencies": {
73
- "@astryxdesign/core": "0.7.6-canary.2224fa8"
73
+ "@astryxdesign/core": "0.7.6-canary.2227dcb"
74
74
  },
75
75
  "devDependencies": {
76
- "@astryxdesign/core": "0.7.6-canary.2224fa8"
76
+ "@astryxdesign/core": "0.7.6-canary.2227dcb"
77
77
  },
78
78
  "scripts": {
79
79
  "build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types",
@@ -0,0 +1,32 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file components/ListItem.ts
5
+ * @input None
6
+ * @output What @astryxdesign/native adds to the core ListItem contract
7
+ * @position Native additions read by fromComponentDoc together with core's
8
+ * ListItem documentation
9
+ */
10
+
11
+ import type {NativeAdditions} from '../contract/fromComponentDoc.js';
12
+
13
+ export const listItem: NativeAdditions = {
14
+ name: 'ListItem',
15
+ doc: {file: 'List/ListItem'},
16
+ baseTarget: 'root',
17
+ slots: {
18
+ label: 'text',
19
+ description: 'text',
20
+ startContent: 'content',
21
+ endContent: 'content',
22
+ },
23
+ callbacks: ['onClick'],
24
+ sameMeaning: {onClick: 'a press, as in Compose'},
25
+ webOnly: {
26
+ target: 'HTML link target',
27
+ rel: 'HTML link relationship',
28
+ swipeActions:
29
+ "a native platform's swipe actions work only inside its own scrolling list, so a row elsewhere could not honor them",
30
+ swipeBehavior: 'applies only with swipeActions',
31
+ },
32
+ };
@@ -19,6 +19,7 @@ import {heading} from './Heading.js';
19
19
  import {hStack} from './HStack.js';
20
20
  import {icon} from './Icon.js';
21
21
  import {item} from './Item.js';
22
+ import {listItem} from './ListItem.js';
22
23
  import {progressBar} from './ProgressBar.js';
23
24
  import {selector} from './Selector.js';
24
25
  import {switchControl} from './Switch.js';
@@ -38,6 +39,7 @@ export const NATIVE_COMPONENTS: readonly NativeAdditions[] = [
38
39
  hStack,
39
40
  icon,
40
41
  item,
42
+ listItem,
41
43
  progressBar,
42
44
  selector,
43
45
  switchControl,
@@ -246,6 +246,27 @@ describe('native contracts', () => {
246
246
  );
247
247
  });
248
248
 
249
+ it('gives ListItem the row contract without density or markers, which come from its list', async () => {
250
+ const {contracts} = await buildContracts(loadCoreDoc);
251
+ const row = contracts.find(contract => contract.name === 'ListItem');
252
+ expect(row).toBeDefined();
253
+ expect(row!.core.label).toMatchObject({
254
+ type: {kind: 'string'},
255
+ optional: false,
256
+ });
257
+ expect(row!.core.startContent?.type).toEqual({kind: 'content'});
258
+ expect(Object.keys(row!.core)).not.toContain('density');
259
+ expect(row!.webOnly.map(prop => prop.name)).toEqual(
260
+ expect.arrayContaining([
261
+ 'swipeActions',
262
+ 'swipeBehavior',
263
+ 'target',
264
+ 'rel',
265
+ 'interactiveRef',
266
+ ]),
267
+ );
268
+ });
269
+
249
270
  it('reports naming and portability errors', () => {
250
271
  const bad: ComponentContract = {
251
272
  name: 'Bad',