@astryxdesign/native 0.7.5-canary.f57df18 → 0.7.5-canary.f85473e

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 (39) hide show
  1. package/apple/README.md +3 -5
  2. package/apple/Sources/Astryx/Card/Card.swift +95 -19
  3. package/apple/Sources/Astryx/Theme/Generated/ButterTheme.swift +318 -308
  4. package/apple/Sources/Astryx/Theme/Generated/ChocolateTheme.swift +318 -308
  5. package/apple/Sources/Astryx/Theme/Generated/DefaultTheme.swift +318 -308
  6. package/apple/Sources/Astryx/Theme/Generated/GothicTheme.swift +318 -308
  7. package/apple/Sources/Astryx/Theme/Generated/MatchaTheme.swift +318 -308
  8. package/apple/Sources/Astryx/Theme/Generated/NeutralTheme.swift +318 -308
  9. package/apple/Sources/Astryx/Theme/Generated/StoneTheme.swift +318 -308
  10. package/apple/Sources/Astryx/Theme/Generated/Tokens.swift +57 -1
  11. package/apple/Sources/Astryx/Theme/Generated/Y2kTheme.swift +318 -308
  12. package/apple/Sources/Astryx/Theme/Shadow.swift +41 -0
  13. package/apple/Sources/Astryx/Theme/Theme.swift +0 -32
  14. package/apple/Sources/Astryx/Tooltip/TooltipPresenter.swift +551 -0
  15. package/apple/Sources/Astryx/Wire/AstryxNodeView.swift +75 -0
  16. package/apple/Sources/AstryxNative/Generated/Switch.swift +2 -26
  17. package/apple/Tests/AstryxTests/BannerTests.swift +1 -1
  18. package/apple/Tests/AstryxTests/CardTests.swift +143 -3
  19. package/apple/Tests/AstryxTests/HeadingTests.swift +1 -1
  20. package/apple/Tests/AstryxTests/TextInputTests.swift +1 -1
  21. package/apple/Tests/AstryxTests/ThemeTests.swift +2 -8
  22. package/apple/Tests/AstryxTests/TooltipPresenterTests.swift +220 -0
  23. package/apple/Tests/AstryxTests/TwoThemeTests.swift +3 -3
  24. package/dist/components/Switch.d.ts.map +1 -1
  25. package/dist/components/Switch.js +13 -0
  26. package/dist/contract/fromComponentDoc.d.ts +10 -0
  27. package/dist/contract/fromComponentDoc.d.ts.map +1 -1
  28. package/dist/contract/fromComponentDoc.js +15 -1
  29. package/dist/types/android.d.ts +4 -1
  30. package/dist/types/core.d.ts +0 -2
  31. package/dist/types/ios.d.ts +1 -1
  32. package/dist/types/macos.d.ts +1 -1
  33. package/dist/types/shared.d.ts +1 -1
  34. package/dist/types/windows.d.ts +4 -1
  35. package/package.json +3 -3
  36. package/src/components/Switch.ts +13 -0
  37. package/src/contract/contracts.test.ts +14 -0
  38. package/src/contract/fromComponentDoc.ts +35 -1
  39. package/src/theme/swiftIOSTheme.test.ts +40 -7
package/apple/README.md CHANGED
@@ -51,17 +51,15 @@ apple/
51
51
  that also imports SwiftUI, write `Astryx.Button` and `SwiftUI.Button`. A
52
52
  component's parameters use core's prop names
53
53
  and values (`variant: .primary`, `size: .lg`, `isLoading`), so code reads
54
- the same across web and native. `Text` and `Heading` take the generated
55
- `TextProps` and `HeadingProps`, as AST-093 FR5 asks; the others keep five
56
- exceptions, the interim shape FR5 exempts until they move onto the generated
54
+ the same across web and native. `Text`, `Heading`, and `Card` take the
55
+ generated `TextProps`, `HeadingProps`, and `CardProps`, as AST-093 FR5 asks;
56
+ the others keep four exceptions, the interim shape FR5 exempts until they move onto the generated
57
57
  contracts:
58
58
  - `Button` takes `action` where core has `onClick`.
59
59
  - `Button` takes `fillsWidth` where core has `width="100%"`.
60
60
  - `Button` takes `icon` as a shared icon name (`"search"`), which the
61
61
  generated `ButtonProps` does not carry yet.
62
62
  - `TextInput` takes a `Binding` where core has `value` and `onChange`.
63
- - `Card` takes `padding` as a whole spacing step, so it cannot spell
64
- core's `0.5` and `1.5` steps.
65
63
  - **`Templates/`** holds one folder per page template, named after the
66
64
  `astryx template` id. Templates are clone-only, as on the web: you copy a
67
65
  template's folder into your app and own it from then on. They are a
@@ -1,33 +1,109 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
- import SwiftUI
4
-
5
- /// A card: one independent item on the theme's card ground, with a hairline
6
- /// border and the container radius.
3
+ /// A card: one independent item on the theme's card ground. It takes core's
4
+ /// Card props (`CardProps`) and stacks its content top to bottom, as children
5
+ /// flow inside core's Card.
7
6
  public struct Card<Content: View>: View {
8
- let padding: Int
7
+ public let props: CardProps
9
8
  let content: Content
10
9
  @Environment(\.astryx) private var astryx
11
10
 
12
- /// - Parameter padding: a step on the spacing ladder, as core's `padding`.
13
- public init(padding: Int = 4, @ViewBuilder content: () -> Content) {
14
- self.padding = padding
11
+ /// - Parameters:
12
+ /// - padding: core's `padding`, a step on the spacing scale; step 4 when
13
+ /// nil.
14
+ /// - variant: core's `variant`: the card ground, or `transparent` for none.
15
+ /// Only `default` draws a border.
16
+ /// - elevation: core's `elevation`, the theme's shadow at that depth.
17
+ /// - base: core's base props.
18
+ /// - content: core's `children`.
19
+ public init(
20
+ padding: CardPadding? = nil,
21
+ variant: CardVariant? = nil,
22
+ elevation: CardElevation? = nil,
23
+ base: AstryxBaseProps = AstryxBaseProps(),
24
+ @ViewBuilder content: () -> Content
25
+ ) {
26
+ self.props = CardProps(padding: padding, variant: variant, elevation: elevation, base: base)
15
27
  self.content = content()
16
28
  }
17
29
 
18
30
  public var body: some View {
19
- let shape = RoundedRectangle(
20
- cornerRadius: astryx.size("radius-container", 12),
21
- style: .continuous
22
- )
23
- // Several child views stack in one card, top to bottom with no gap of
24
- // their own, as children flow inside core's Card.
25
- VStack(alignment: .leading, spacing: 0) { content }
26
- .padding(astryx.space(padding))
31
+ let shape = RoundedRectangle(cornerRadius: astryx.tokens.radius.container, style: .continuous)
32
+ let variant = props.variant ?? .default
33
+ // The border sits inside the padding, so the content's inset is the
34
+ // padding step, as in core.
35
+ SwiftUI.VStack(alignment: .leading, spacing: 0) { content }
36
+ .padding(padding)
27
37
  .frame(maxWidth: .infinity, alignment: .leading)
28
- .background(shape.fill(astryx.color("color-background-card")))
29
- .overlay(
30
- shape.strokeBorder(astryx.color("color-border"), lineWidth: astryx.size("border-width", 1))
38
+ .background(shape.fill(Self.ground(variant, astryx.tokens.color)))
39
+ .overlay {
40
+ if variant == .default {
41
+ shape.strokeBorder(astryx.tokens.color.border, lineWidth: astryx.tokens.size.borderWidth)
42
+ }
43
+ }
44
+ .astryxShadow(
45
+ Self.shadow(props.elevation ?? .none, astryx.tokens.shadow), in: shape,
46
+ borderWidth: variant == .default ? astryx.tokens.size.borderWidth : 0
31
47
  )
48
+ .astryxBase(props.base)
49
+ }
50
+
51
+ var padding: CGFloat {
52
+ let space = astryx.tokens.space
53
+ switch props.padding ?? .v4 {
54
+ case .v0: return space.s0
55
+ case .v0_5: return space.s0_5
56
+ case .v1: return space.s1
57
+ case .v1_5: return space.s1_5
58
+ case .v2: return space.s2
59
+ case .v3: return space.s3
60
+ case .v4: return space.s4
61
+ case .v5: return space.s5
62
+ case .v6: return space.s6
63
+ case .v8: return space.s8
64
+ case .v10: return space.s10
65
+ }
66
+ }
67
+
68
+ /// The ground core's Card draws for a variant.
69
+ static func ground(_ variant: CardVariant, _ color: ColorTokens) -> Color {
70
+ switch variant {
71
+ case .default: color.backgroundCard
72
+ case .transparent: .clear
73
+ case .muted: color.backgroundMuted
74
+ case .blue: color.backgroundBlue
75
+ case .cyan: color.backgroundCyan
76
+ case .gray: color.backgroundGray
77
+ case .green: color.backgroundGreen
78
+ case .orange: color.backgroundOrange
79
+ case .pink: color.backgroundPink
80
+ case .purple: color.backgroundPurple
81
+ case .red: color.backgroundRed
82
+ case .teal: color.backgroundTeal
83
+ case .yellow: color.backgroundYellow
84
+ }
85
+ }
86
+
87
+ /// The theme's shadow at an elevation.
88
+ static func shadow(_ elevation: CardElevation, _ shadow: ShadowTokens) -> [ShadowLayer] {
89
+ switch elevation {
90
+ case .none: []
91
+ case .low: shadow.low
92
+ case .med: shadow.med
93
+ case .high: shadow.high
94
+ }
95
+ }
96
+ }
97
+
98
+ extension Card where Content == AstryxNodeList {
99
+ /// A card from core's props, with its children as the wire tree a logic
100
+ /// core sends; `send` carries the children's callbacks back to the core.
101
+ public init(
102
+ _ props: CardProps,
103
+ children: [AstryxNode],
104
+ send: @escaping @Sendable (AstryxAction) -> Void
105
+ ) {
106
+ self.props = props
107
+ self.content = AstryxNodeList(nodes: children, send: send)
32
108
  }
33
109
  }