Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(native): Swift Text and Heading take core's props (#8303)

Cindy Zhangf41fc050ad2f
diff --git a/packages/native/apple/README.md b/packages/native/apple/README.md
index 9395b3e669..c59be309a6 100644
--- a/packages/native/apple/README.md
+++ b/packages/native/apple/README.md
@@ -51,14 +51,15 @@ apple/
that also imports SwiftUI, write `Astryx.Button` and `SwiftUI.Button`. A
component's parameters use core's prop names
and values (`variant: .primary`, `size: .lg`, `isLoading`), so code reads
- the same across web and native, with six exceptions, the interim shape
- AST-093 FR5 exempts until the components move onto the generated contracts:
+ the same across web and native. `Text` and `Heading` take the generated
+ `TextProps` and `HeadingProps`, as AST-093 FR5 asks; the others keep five
+ exceptions, the interim shape FR5 exempts until they move onto the generated
+ contracts:
- `Button` takes `action` where core has `onClick`.
- `Button` takes `fillsWidth` where core has `width="100%"`.
- `Button` takes `icon` as a shared icon name (`"search"`), which the
generated `ButtonProps` does not carry yet.
- `TextInput` takes a `Binding` where core has `value` and `onChange`.
- - `Heading`'s `level` is optional where core requires it.
- `Card` takes `padding` as a whole spacing step, so it cannot spell
core's `0.5` and `1.5` steps.
- **`Templates/`** holds one folder per page template, named after the
diff --git a/packages/native/apple/Sources/Astryx/Base/BaseProps.swift b/packages/native/apple/Sources/Astryx/Base/BaseProps.swift
new file mode 100644
index 0000000000..7718913f74
--- /dev/null
+++ b/packages/native/apple/Sources/Astryx/Base/BaseProps.swift
@@ -0,0 +1,16 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+extension View {
+ /// Core's base props on a view: `id` names it for UI tests, and `isHidden`
+ /// removes it from layout and from assistive technology, as core's `hidden`
+ /// attribute does.
+ @ViewBuilder func astryxBase(_ base: AstryxBaseProps) -> some View {
+ if base.isHidden == true {
+ EmptyView()
+ } else if let id = base.id {
+ accessibilityIdentifier(id)
+ } else {
+ self
+ }
+ }
+}
diff --git a/packages/native/apple/Sources/Astryx/Heading/Heading.swift b/packages/native/apple/Sources/Astryx/Heading/Heading.swift
index ac2a708410..59f2e0624c 100644
--- a/packages/native/apple/Sources/Astryx/Heading/Heading.swift
+++ b/packages/native/apple/Sources/Astryx/Heading/Heading.swift
@@ -1,40 +1,111 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
// Adapted from github.com/ejc3/astryx-swift (MIT).
-import SwiftUI
-
/// A heading at levels 1 through 6, painted with the theme's heading tokens
-/// and exposed to VoiceOver as a heading.
+/// and exposed to VoiceOver as a heading. It takes core's Heading props
+/// (`HeadingProps`).
public struct Heading: View {
- let content: String
- let level: Int
+ public let props: HeadingProps
@Environment(\.astryx) private var astryx
+ @Environment(\.multilineTextAlignment) private var inheritedAlignment
- public init(_ content: String, level: Int = 2) {
- self.content = content
- self.level = min(max(level, 1), 6)
+ public init(_ props: HeadingProps) {
+ self.props = props
}
- public var body: some View {
- SwiftUI.Text(content)
- .font(
- astryx.font(
- size: "text-heading-\(level)-size",
- 20,
- weight: "text-heading-\(level)-weight",
- family: "font-family-heading"
- )
+ /// - Parameters:
+ /// - children: the words, core's `children`.
+ /// - level: core's `level`: the heading's place in the outline, which
+ /// also sets its look unless `type` is given.
+ /// - type: core's `type`, a display style that replaces the level's look.
+ /// - weight: core's `weight`, replacing the look's weight.
+ /// - accessibilityLevel: core's `accessibilityLevel`, the level VoiceOver
+ /// reads when it differs from `level`.
+ /// - color: core's `color`; primary when nil.
+ /// - maxLines: core's `maxLines`; text past it is truncated. Unset, a
+ /// surrounding `.lineLimit` still applies.
+ /// - justify: core's `justify`, the alignment of wrapped lines.
+ /// - hasStrikethrough: core's `hasStrikethrough`.
+ /// - base: core's base props.
+ public init(
+ _ children: String,
+ level: HeadingLevel,
+ type: HeadingType? = nil,
+ weight: HeadingWeight? = nil,
+ accessibilityLevel: HeadingAccessibilityLevel? = nil,
+ color: HeadingColor? = nil,
+ maxLines: Double? = nil,
+ justify: HeadingJustify? = nil,
+ hasStrikethrough: Bool? = nil,
+ base: AstryxBaseProps = AstryxBaseProps()
+ ) {
+ self.init(
+ HeadingProps(
+ level: level,
+ type: type,
+ weight: weight,
+ children: children,
+ accessibilityLevel: accessibilityLevel,
+ color: color,
+ maxLines: maxLines,
+ justify: justify,
+ hasStrikethrough: hasStrikethrough,
+ base: base
)
- .foregroundStyle(astryx.color("color-text-primary"))
+ )
+ }
+
+ public var body: some View {
+ styled(SwiftUI.Text(props.children))
+ .astryxMaxLines(props.maxLines)
+ .multilineTextAlignment(props.justify?.alignment ?? inheritedAlignment)
+ .astryxJustified(props.justify?.frameAlignment)
.accessibilityAddTraits(Self.accessibilityTraits)
.accessibilityHeading(headingLevel)
+ .astryxBase(props.base)
+ }
+
+ func styled(_ text: SwiftUI.Text) -> SwiftUI.Text {
+ var style = typeStyle
+ if let weight = props.weight {
+ style.weight = astryx.tokens.font.weight(named: weight.rawValue)
+ }
+ var text = text.font(astryx.font(style))
+ if let color = astryx.tokens.color.text(named: (props.color ?? .primary).rawValue) {
+ text = text.foregroundStyle(color)
+ }
+ if props.hasStrikethrough == true { text = text.strikethrough() }
+ return text
+ }
+
+ /// The level's heading style, or the display style `type` names, in the
+ /// theme's heading family.
+ var typeStyle: TypeStyle {
+ let font = astryx.tokens.font
+ let (size, weight): (CGFloat, CGFloat) =
+ switch props.type {
+ case .display1: (font.display1Size, font.display1Weight)
+ case .display2: (font.display2Size, font.display2Weight)
+ case .display3: (font.display3Size, font.display3Weight)
+ case nil:
+ switch props.level {
+ case .v1: (font.heading1Size, font.heading1Weight)
+ case .v2: (font.heading2Size, font.heading2Weight)
+ case .v3: (font.heading3Size, font.heading3Weight)
+ case .v4: (font.heading4Size, font.heading4Weight)
+ case .v5: (font.heading5Size, font.heading5Weight)
+ case .v6: (font.heading6Size, font.heading6Weight)
+ }
+ }
+ return TypeStyle(size: size, weight: weight, families: font.familyHeading)
}
/// The traits assistive technology gets: a header.
static var accessibilityTraits: AccessibilityTraits { .isHeader }
+ /// The level VoiceOver reads: `accessibilityLevel` when given, else `level`.
var headingLevel: AccessibilityHeadingLevel {
- switch level {
+ switch props.accessibilityLevel?.rawValue ?? props.level.rawValue {
case 1: .h1
case 2: .h2
case 3: .h3
diff --git a/packages/native/apple/Sources/Astryx/Text/Text.swift b/packages/native/apple/Sources/Astryx/Text/Text.swift
index c4c85bc3a9..52852d3d8b 100644
--- a/packages/native/apple/Sources/Astryx/Text/Text.swift
+++ b/packages/native/apple/Sources/Astryx/Text/Text.swift
@@ -1,83 +1,102 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
// Adapted from github.com/ejc3/astryx-swift (MIT).
-import SwiftUI
-
-/// Core's `Text` semantic types this package draws so far.
-public enum AstryxTextType: String, CaseIterable, Sendable {
- case body
- case large
- case label
- case supporting
-
- var token: String { "text-\(rawValue)" }
-
- /// The color core's Text uses when none is given: secondary for supporting
- /// text, primary otherwise.
- var defaultColor: AstryxTextColor { self == .supporting ? .secondary : .primary }
-}
-
-/// Core's `Text` colors this package draws so far.
-public enum AstryxTextColor: String, CaseIterable, Sendable {
- case primary
- case secondary
- case disabled
- case accent
-
- var token: String { "color-text-\(rawValue)" }
-}
-
-/// Core's `Text` weights.
-public enum AstryxTextWeight: String, CaseIterable, Sendable {
- case normal
- case medium
- case semibold
- case bold
-
- var token: String { "font-weight-\(rawValue)" }
-}
-
-/// Core's `Text` sizes this package draws so far, used to override the size
-/// a semantic type sets. Core spells the extra-small size `xsm`; its token is
-/// `font-size-xs`.
-public enum AstryxTextSize: String, CaseIterable, Sendable {
- case xsm
- case sm
- case base
- case lg
- case xl
-
- var token: String { self == .xsm ? "font-size-xs" : "font-size-\(rawValue)" }
-}
-
-/// A run of text in a semantic type, painted with the theme's type tokens.
+/// A run of text in one of core's type styles, painted with the theme's type
+/// tokens. It takes core's Text props (`TextProps`).
public struct Text: View {
- let content: String
- let type: AstryxTextType
- let color: AstryxTextColor?
- let size: AstryxTextSize?
- let weight: AstryxTextWeight?
+ public let props: TextProps
@Environment(\.astryx) private var astryx
+ @Environment(\.multilineTextAlignment) private var inheritedAlignment
+
+ public init(_ props: TextProps) {
+ self.props = props
+ }
+ /// - Parameters:
+ /// - children: the words, core's `children`.
+ /// - type: core's `type`; `body` when nil. `inherit` keeps the
+ /// surrounding font and color, unless `size` is also set (below).
+ /// - size: core's `size`, replacing the type's size. With `inherit`,
+ /// SwiftUI cannot change only the size of an inherited font, so the text
+ /// draws in the theme's body family at normal weight (or at `weight`,
+ /// when set) at that size: a documented Swift gap from core, where an
+ /// inherited family and weight keep their face.
+ /// - color: core's `color`; secondary for `supporting`, primary otherwise.
+ /// - weight: core's `weight`, replacing the type's weight.
+ /// - maxLines: core's `maxLines`; text past it is truncated. Unset, a
+ /// surrounding `.lineLimit` still applies.
+ /// - justify: core's `justify`, the alignment of wrapped lines.
+ /// - hasStrikethrough: core's `hasStrikethrough`.
+ /// - hasTabularNumbers: core's `hasTabularNumbers`; digits take equal
+ /// widths.
+ /// - base: core's base props.
public init(
- _ content: String,
- type: AstryxTextType = .body,
- color: AstryxTextColor? = nil,
- size: AstryxTextSize? = nil,
- weight: AstryxTextWeight? = nil
+ _ children: String,
+ type: TextType? = nil,
+ size: TextSize? = nil,
+ color: TextColor? = nil,
+ weight: TextWeight? = nil,
+ maxLines: Double? = nil,
+ justify: TextJustify? = nil,
+ hasStrikethrough: Bool? = nil,
+ hasTabularNumbers: Bool? = nil,
+ base: AstryxBaseProps = AstryxBaseProps()
) {
- self.content = content
- self.type = type
- self.color = color
- self.size = size
- self.weight = weight
+ self.init(
+ TextProps(
+ type: type,
+ children: children,
+ size: size,
+ color: color,
+ weight: weight,
+ maxLines: maxLines,
+ justify: justify,
+ hasStrikethrough: hasStrikethrough,
+ hasTabularNumbers: hasTabularNumbers,
+ base: base
+ )
+ )
}
public var body: some View {
- let sizeToken = size?.token ?? "\(type.token)-size"
- let weightToken = weight?.token ?? "\(type.token)-weight"
- SwiftUI.Text(content)
- .font(astryx.font(size: sizeToken, 14, weight: weightToken))
- .foregroundStyle(astryx.color((color ?? type.defaultColor).token))
+ styled(SwiftUI.Text(props.children))
+ .astryxMaxLines(props.maxLines)
+ .multilineTextAlignment(props.justify?.alignment ?? inheritedAlignment)
+ .astryxBase(props.base)
+ }
+
+ func styled(_ text: SwiftUI.Text) -> SwiftUI.Text {
+ var text = text
+ let font = astryx.tokens.font
+ let type = props.type ?? .body
+ if let style = font.style(type) {
+ var style = style
+ if let size = props.size { style.size = font.size(size) }
+ if let weight = props.weight { style.weight = font.weight(named: weight.rawValue) }
+ text = text.font(astryx.font(style))
+ } else if let size = props.size {
+ // `inherit` with a size: SwiftUI cannot change only the size of an
+ // inherited font, so it draws the body family at normal weight (or the
+ // given weight) at that size, a documented gap.
+ let weight = font.weight(named: props.weight?.rawValue ?? "normal")
+ text = text.font(astryx.font(TypeStyle(size: font.size(size), weight: weight, families: font.familyBody)))
+ } else if let weight = props.weight {
+ text = text.fontWeight(astryx.fontWeight(font.weight(named: weight.rawValue)))
+ }
+ if let color = astryx.tokens.color.text(named: (props.color ?? Self.defaultColor(type)).rawValue) {
+ text = text.foregroundStyle(color)
+ }
+ if props.hasStrikethrough == true { text = text.strikethrough() }
+ if props.hasTabularNumbers == true { text = text.monospacedDigit() }
+ return text
+ }
+
+ /// The color core's Text uses when none is given.
+ static func defaultColor(_ type: TextType) -> TextColor {
+ switch type {
+ case .supporting: .secondary
+ case .inherit: .inherit
+ default: .primary
+ }
}
}
diff --git a/packages/native/apple/Sources/Astryx/Text/TypeStyle.swift b/packages/native/apple/Sources/Astryx/Text/TypeStyle.swift
new file mode 100644
index 0000000000..d8f8594d2e
--- /dev/null
+++ b/packages/native/apple/Sources/Astryx/Text/TypeStyle.swift
@@ -0,0 +1,132 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/// One of core's type styles, read from the theme's typed tokens: a size and
+/// weight in core's units, and the family stack to draw it in.
+struct TypeStyle: Equatable {
+ var size: CGFloat
+ var weight: CGFloat
+ var families: [String]
+}
+
+extension FontTokens {
+ /// The style core's Text draws for a type, or nil for `inherit`. Display
+ /// types draw in the heading family, as core's type scale sets them.
+ func style(_ type: TextType) -> TypeStyle? {
+ switch type {
+ case .body: TypeStyle(size: bodySize, weight: bodyWeight, families: familyBody)
+ case .large: TypeStyle(size: largeSize, weight: largeWeight, families: familyBody)
+ case .label: TypeStyle(size: labelSize, weight: labelWeight, families: familyBody)
+ case .supporting: TypeStyle(size: supportingSize, weight: supportingWeight, families: familyBody)
+ case .code: TypeStyle(size: codeSize, weight: codeWeight, families: familyCode)
+ case .display1: TypeStyle(size: display1Size, weight: display1Weight, families: familyHeading)
+ case .display2: TypeStyle(size: display2Size, weight: display2Weight, families: familyHeading)
+ case .display3: TypeStyle(size: display3Size, weight: display3Weight, families: familyHeading)
+ case .inherit: nil
+ }
+ }
+
+ /// The font size core's Text draws for an explicit `size`. Core spells the
+ /// extra-small size `xsm`; its token is `font-size-xs`.
+ func size(_ size: TextSize) -> CGFloat {
+ switch size {
+ case .v4xs: size4xs
+ case .v3xs: size3xs
+ case .v2xs: size2xs
+ case .xsm: sizeXs
+ case .sm: sizeSm
+ case .base: sizeBase
+ case .lg: sizeLg
+ case .xl: sizeXl
+ case .v2xl: size2xl
+ case .v3xl: size3xl
+ case .v4xl: size4xl
+ }
+ }
+
+ /// The numeric weight behind one of core's weight names.
+ func weight(named name: String) -> CGFloat {
+ switch name {
+ case "medium": weightMedium
+ case "semibold": weightSemibold
+ case "bold": weightBold
+ default: weightNormal
+ }
+ }
+}
+
+extension ColorTokens {
+ /// The text color behind one of core's Text and Heading color names, or nil
+ /// for `inherit`. Core draws `placeholder` in the secondary text color.
+ func text(named name: String) -> Color? {
+ switch name {
+ case "secondary", "placeholder": textSecondary
+ case "disabled": textDisabled
+ case "accent": textAccent
+ case "inherit": nil
+ default: textPrimary
+ }
+ }
+}
+
+extension AstryxStyle {
+ /// A type style at the person's text size, in the first family the device
+ /// has, stepped heavier under Bold Text for a custom face.
+ func font(_ style: TypeStyle) -> Font {
+ astryxFont(
+ families: style.families,
+ size: style.size * textScale,
+ weight: fontWeight(style.weight),
+ isBoldText: isBoldText
+ )
+ }
+}
+
+extension TextJustify {
+ var alignment: TextAlignment {
+ switch self {
+ case .start: .leading
+ case .center: .center
+ case .end: .trailing
+ }
+ }
+}
+
+extension HeadingJustify {
+ var alignment: TextAlignment {
+ switch self {
+ case .start: .leading
+ case .center: .center
+ case .end: .trailing
+ }
+ }
+
+ /// Where a heading's line sits in its container: core's heading is a block,
+ /// so `justify` aligns even a single line across the full width.
+ var frameAlignment: Alignment {
+ switch self {
+ case .start: .leading
+ case .center: .center
+ case .end: .trailing
+ }
+ }
+}
+
+extension View {
+ /// Core's `maxLines` as a line limit, only when set: with it unset, a
+ /// caller's own `.lineLimit` around the view still applies.
+ @ViewBuilder func astryxMaxLines(_ maxLines: Double?) -> some View {
+ if let limit = astryxLineLimit(maxLines) { lineLimit(limit) } else { self }
+ }
+
+ /// Spans the offered width and places the content at `alignment`, when set.
+ @ViewBuilder func astryxJustified(_ alignment: Alignment?) -> some View {
+ if let alignment { frame(maxWidth: .infinity, alignment: alignment) } else { self }
+ }
+}
+
+/// Core's `maxLines`: a positive count clamps the text; zero, none, or a count
+/// too large to reach (including infinity) does not.
+func astryxLineLimit(_ maxLines: Double?) -> Int? {
+ guard let maxLines, maxLines >= 1, maxLines < Double(Int32.max) else { return nil }
+ return Int(maxLines)
+}
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/ButterTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/ButterTheme.swift
index ac8b2a5177..2919a0d8d9 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/ButterTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/ButterTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.283,
+ display1Size: 53,
+ display1Weight: 400,
+ display2Leading: 1.2093,
+ display2Size: 43,
+ display2Weight: 400,
+ display3Leading: 1.2941,
+ display3Size: 34,
+ display3Weight: 400,
familyBody: ["Outfit", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Outfit", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.283,
+ display1Size: 53,
+ display1Weight: 400,
+ display2Leading: 1.2093,
+ display2Size: 43,
+ display2Weight: 400,
+ display3Leading: 1.2941,
+ display3Size: 34,
+ display3Weight: 400,
familyBody: ["Outfit", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Outfit", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/ChocolateTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/ChocolateTheme.swift
index 69e95e4080..207f91fc50 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/ChocolateTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/ChocolateTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.2381,
+ display1Size: 42,
+ display1Weight: 400,
+ display2Leading: 1.2571,
+ display2Size: 35,
+ display2Weight: 400,
+ display3Leading: 1.3793,
+ display3Size: 29,
+ display3Weight: 400,
familyBody: ["Albert Sans", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Fraunces", "Georgia", "Times New Roman", "Times", "serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.2381,
+ display1Size: 42,
+ display1Weight: 400,
+ display2Leading: 1.2571,
+ display2Size: 35,
+ display2Weight: 400,
+ display3Leading: 1.3793,
+ display3Size: 29,
+ display3Weight: 400,
familyBody: ["Albert Sans", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Fraunces", "Georgia", "Times New Roman", "Times", "serif"],
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/DefaultTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/DefaultTheme.swift
index 58539b7591..1565979e47 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/DefaultTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/DefaultTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.2381,
+ display1Size: 42,
+ display1Weight: 400,
+ display2Leading: 1.2571,
+ display2Size: 35,
+ display2Weight: 400,
+ display3Leading: 1.2414,
+ display3Size: 29,
+ display3Weight: 400,
familyBody: ["-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.2381,
+ display1Size: 42,
+ display1Weight: 400,
+ display2Leading: 1.2571,
+ display2Size: 35,
+ display2Weight: 400,
+ display3Leading: 1.2414,
+ display3Size: 29,
+ display3Weight: 400,
familyBody: ["-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/GothicTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/GothicTheme.swift
index d0b2a1e985..6f21268110 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/GothicTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/GothicTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.5,
bodySize: 16,
bodyWeight: 400,
+ codeLeading: 1.5,
+ codeSize: 16,
+ codeWeight: 400,
+ display1Leading: 1.2459,
+ display1Size: 61,
+ display1Weight: 400,
+ display2Leading: 1.2245,
+ display2Size: 49,
+ display2Weight: 400,
+ display3Leading: 1.2308,
+ display3Size: 39,
+ display3Weight: 400,
familyBody: ["Fustat", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Fustat", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.5,
bodySize: 16,
bodyWeight: 400,
+ codeLeading: 1.5,
+ codeSize: 16,
+ codeWeight: 400,
+ display1Leading: 1.2459,
+ display1Size: 61,
+ display1Weight: 400,
+ display2Leading: 1.2245,
+ display2Size: 49,
+ display2Weight: 400,
+ display3Leading: 1.2308,
+ display3Size: 39,
+ display3Weight: 400,
familyBody: ["Fustat", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Fustat", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/MatchaTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/MatchaTheme.swift
index 9257b09ccb..46768aad37 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/MatchaTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/MatchaTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.5,
bodySize: 16,
bodyWeight: 400,
+ codeLeading: 1.5,
+ codeSize: 16,
+ codeWeight: 400,
+ display1Leading: 1.2459,
+ display1Size: 61,
+ display1Weight: 400,
+ display2Leading: 1.2245,
+ display2Size: 49,
+ display2Weight: 400,
+ display3Leading: 1.2308,
+ display3Size: 39,
+ display3Weight: 400,
familyBody: ["DM Sans", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Playwrite US Trad", "Georgia", "Times New Roman", "Times", "serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.5,
bodySize: 16,
bodyWeight: 400,
+ codeLeading: 1.5,
+ codeSize: 16,
+ codeWeight: 400,
+ display1Leading: 1.2459,
+ display1Size: 61,
+ display1Weight: 400,
+ display2Leading: 1.2245,
+ display2Size: 49,
+ display2Weight: 400,
+ display3Leading: 1.2308,
+ display3Size: 39,
+ display3Weight: 400,
familyBody: ["DM Sans", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Playwrite US Trad", "Georgia", "Times New Roman", "Times", "serif"],
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/NeutralTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/NeutralTheme.swift
index d142046e9c..1ca995c0bf 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/NeutralTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/NeutralTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.2381,
+ display1Size: 42,
+ display1Weight: 400,
+ display2Leading: 1.2571,
+ display2Size: 35,
+ display2Weight: 400,
+ display3Leading: 1.3793,
+ display3Size: 29,
+ display3Weight: 400,
familyBody: ["Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["ui-monospace", "SF Mono", "Monaco", "Consolas", "Liberation Mono", "Courier New", "monospace"],
familyHeading: ["Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.2381,
+ display1Size: 42,
+ display1Weight: 400,
+ display2Leading: 1.2571,
+ display2Size: 35,
+ display2Weight: 400,
+ display3Leading: 1.3793,
+ display3Size: 29,
+ display3Weight: 400,
familyBody: ["Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["ui-monospace", "SF Mono", "Monaco", "Consolas", "Liberation Mono", "Courier New", "monospace"],
familyHeading: ["Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/StoneTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/StoneTheme.swift
index aa1cdf2e76..e326779fa6 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/StoneTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/StoneTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.283,
+ display1Size: 53,
+ display1Weight: 400,
+ display2Leading: 1.2093,
+ display2Size: 43,
+ display2Weight: 400,
+ display3Leading: 1.2941,
+ display3Size: 34,
+ display3Weight: 400,
familyBody: ["Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Montserrat", "Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.4286,
bodySize: 14,
bodyWeight: 400,
+ codeLeading: 1.4286,
+ codeSize: 14,
+ codeWeight: 400,
+ display1Leading: 1.283,
+ display1Size: 53,
+ display1Weight: 400,
+ display2Leading: 1.2093,
+ display2Size: 43,
+ display2Weight: 400,
+ display3Leading: 1.2941,
+ display3Size: 34,
+ display3Weight: 400,
familyBody: ["Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Montserrat", "Figtree", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/Tokens.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/Tokens.swift
index 2ef0c7ebb0..52c829091c 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/Tokens.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/Tokens.swift
@@ -999,6 +999,30 @@ public struct FontTokens: Equatable, Sendable {
public var bodySize: CGFloat
/// `--text-body-weight`
public var bodyWeight: CGFloat
+ /// `--text-code-leading`
+ public var codeLeading: CGFloat
+ /// `--text-code-size`
+ public var codeSize: CGFloat
+ /// `--text-code-weight`
+ public var codeWeight: CGFloat
+ /// `--text-display-1-leading`
+ public var display1Leading: CGFloat
+ /// `--text-display-1-size`
+ public var display1Size: CGFloat
+ /// `--text-display-1-weight`
+ public var display1Weight: CGFloat
+ /// `--text-display-2-leading`
+ public var display2Leading: CGFloat
+ /// `--text-display-2-size`
+ public var display2Size: CGFloat
+ /// `--text-display-2-weight`
+ public var display2Weight: CGFloat
+ /// `--text-display-3-leading`
+ public var display3Leading: CGFloat
+ /// `--text-display-3-size`
+ public var display3Size: CGFloat
+ /// `--text-display-3-weight`
+ public var display3Weight: CGFloat
/// `--font-family-body`
public var familyBody: [String]
/// `--font-family-code`
@@ -1096,6 +1120,18 @@ public struct FontTokens: Equatable, Sendable {
bodyLeading: CGFloat,
bodySize: CGFloat,
bodyWeight: CGFloat,
+ codeLeading: CGFloat,
+ codeSize: CGFloat,
+ codeWeight: CGFloat,
+ display1Leading: CGFloat,
+ display1Size: CGFloat,
+ display1Weight: CGFloat,
+ display2Leading: CGFloat,
+ display2Size: CGFloat,
+ display2Weight: CGFloat,
+ display3Leading: CGFloat,
+ display3Size: CGFloat,
+ display3Weight: CGFloat,
familyBody: [String],
familyCode: [String],
familyHeading: [String],
@@ -1146,6 +1182,18 @@ public struct FontTokens: Equatable, Sendable {
self.bodyLeading = bodyLeading
self.bodySize = bodySize
self.bodyWeight = bodyWeight
+ self.codeLeading = codeLeading
+ self.codeSize = codeSize
+ self.codeWeight = codeWeight
+ self.display1Leading = display1Leading
+ self.display1Size = display1Size
+ self.display1Weight = display1Weight
+ self.display2Leading = display2Leading
+ self.display2Size = display2Size
+ self.display2Weight = display2Weight
+ self.display3Leading = display3Leading
+ self.display3Size = display3Size
+ self.display3Weight = display3Weight
self.familyBody = familyBody
self.familyCode = familyCode
self.familyHeading = familyHeading
@@ -1201,6 +1249,18 @@ public struct FontTokens: Equatable, Sendable {
case "text-body-leading": bodyLeading
case "text-body-size": bodySize
case "text-body-weight": bodyWeight
+ case "text-code-leading": codeLeading
+ case "text-code-size": codeSize
+ case "text-code-weight": codeWeight
+ case "text-display-1-leading": display1Leading
+ case "text-display-1-size": display1Size
+ case "text-display-1-weight": display1Weight
+ case "text-display-2-leading": display2Leading
+ case "text-display-2-size": display2Size
+ case "text-display-2-weight": display2Weight
+ case "text-display-3-leading": display3Leading
+ case "text-display-3-size": display3Size
+ case "text-display-3-weight": display3Weight
case "text-heading-1-leading": heading1Leading
case "text-heading-1-size": heading1Size
case "text-heading-1-weight": heading1Weight
diff --git a/packages/native/apple/Sources/Astryx/Theme/Generated/Y2kTheme.swift b/packages/native/apple/Sources/Astryx/Theme/Generated/Y2kTheme.swift
index 29fb1d8c48..3d8167f2b9 100644
--- a/packages/native/apple/Sources/Astryx/Theme/Generated/Y2kTheme.swift
+++ b/packages/native/apple/Sources/Astryx/Theme/Generated/Y2kTheme.swift
@@ -200,6 +200,18 @@ extension Theme {
bodyLeading: 1.5,
bodySize: 16,
bodyWeight: 400,
+ codeLeading: 1.5,
+ codeSize: 16,
+ codeWeight: 400,
+ display1Leading: 1.2459,
+ display1Size: 61,
+ display1Weight: 400,
+ display2Leading: 1.2245,
+ display2Size: 49,
+ display2Weight: 400,
+ display3Leading: 1.2308,
+ display3Size: 39,
+ display3Weight: 400,
familyBody: ["Poppins", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Poppins", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
@@ -441,6 +453,18 @@ extension Theme {
bodyLeading: 1.5,
bodySize: 16,
bodyWeight: 400,
+ codeLeading: 1.5,
+ codeSize: 16,
+ codeWeight: 400,
+ display1Leading: 1.2459,
+ display1Size: 61,
+ display1Weight: 400,
+ display2Leading: 1.2245,
+ display2Size: 49,
+ display2Weight: 400,
+ display3Leading: 1.2308,
+ display3Size: 39,
+ display3Weight: 400,
familyBody: ["Poppins", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
familyCode: ["JetBrains Mono", "SF Mono", "Monaco", "Consolas", "monospace"],
familyHeading: ["Poppins", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica", "Arial", "sans-serif"],
diff --git a/packages/native/apple/Templates/Login/LoginTemplate.swift b/packages/native/apple/Templates/Login/LoginTemplate.swift
index 4bd25fc882..c352f5f2d5 100644
--- a/packages/native/apple/Templates/Login/LoginTemplate.swift
+++ b/packages/native/apple/Templates/Login/LoginTemplate.swift
@@ -71,8 +71,8 @@ struct LoginTemplateContent: View {
Card(padding: 8) {
VStack(alignment: .leading, spacing: astryx.space(4)) {
VStack(spacing: astryx.space(1)) {
- Heading("Sign in", level: 2)
- Text("Enter your credentials to continue", color: .secondary, size: .sm)
+ Heading("Sign in", level: .v2)
+ Text("Enter your credentials to continue", size: .sm, color: .secondary)
}
.frame(maxWidth: .infinity)
diff --git a/packages/native/apple/Tests/AstryxTests/HeadingTests.swift b/packages/native/apple/Tests/AstryxTests/HeadingTests.swift
index f5a2a8f1c5..7d3f599f99 100644
--- a/packages/native/apple/Tests/AstryxTests/HeadingTests.swift
+++ b/packages/native/apple/Tests/AstryxTests/HeadingTests.swift
@@ -5,31 +5,47 @@ import Testing
@testable import Astryx
@MainActor
-@Test func headingLevelsAreClampedAndExposedToVoiceOver() {
- #expect(Astryx.Heading("Title", level: 0).level == 1)
- #expect(Astryx.Heading("Title", level: 9).level == 6)
- #expect(Astryx.Heading("Title", level: 1).headingLevel == .h1)
- #expect(Astryx.Heading("Title", level: 3).headingLevel == .h3)
- #expect(Astryx.Heading("Title", level: 6).headingLevel == .h6)
+@Test func headingLevelsAreExposedToVoiceOver() {
+ #expect(Astryx.Heading("Title", level: .v1).headingLevel == .h1)
+ #expect(Astryx.Heading("Title", level: .v3).headingLevel == .h3)
+ #expect(Astryx.Heading("Title", level: .v6).headingLevel == .h6)
+ #expect(Astryx.Heading("Sidebar", level: .v2, accessibilityLevel: .v3).headingLevel == .h3)
+}
+
+@MainActor
+@Test func headingInitializersBuildTheSameProps() {
+ let labeled = Astryx.Heading("Revenue", level: .v2, type: .display2, color: .secondary)
+ let fromProps = Astryx.Heading(HeadingProps(level: .v2, type: .display2, children: "Revenue", color: .secondary))
+ #expect(labeled.props.level == fromProps.props.level)
+ #expect(labeled.props.type == fromProps.props.type)
+ #expect(labeled.props.children == fromProps.props.children)
+ #expect(labeled.props.color == fromProps.props.color)
}
@MainActor
@Test func headingsShrinkByLevel() {
- let h1 = Pixels(Astryx.Heading("Settings", level: 1).fixedSize())
- let h4 = Pixels(Astryx.Heading("Settings", level: 4).fixedSize())
+ let h1 = Pixels(Astryx.Heading("Settings", level: .v1).fixedSize())
+ let h4 = Pixels(Astryx.Heading("Settings", level: .v4).fixedSize())
#expect(h1.width > h4.width)
}
+@MainActor
+@Test func aDisplayTypeReplacesTheLevelsLook() {
+ let h2 = Pixels(Astryx.Heading("Settings", level: .v2).fixedSize())
+ let display = Pixels(Astryx.Heading("Settings", level: .v2, type: .display1).fixedSize())
+ #expect(display.width > h2.width)
+}
+
@MainActor
@Test func headingsGrowAtTheLargestTextSizeAndFollowASecondTheme() {
- let large = Pixels(Astryx.Heading("Settings").fixedSize())
- let largest = Pixels(Astryx.Heading("Settings").fixedSize(), typeSize: .accessibility5)
+ let large = Pixels(Astryx.Heading("Settings", level: .v2).fixedSize())
+ let largest = Pixels(Astryx.Heading("Settings", level: .v2).fixedSize(), typeSize: .accessibility5)
#expect(largest.width > large.width * 2)
var theme = Theme.default
theme.light.font.heading2Size = 48
theme.light.color.textPrimary = Color(astryxRGBA: 0xFF0000FF)
- let themed = Pixels(Astryx.Heading("Settings").fixedSize(), theme: theme)
+ let themed = Pixels(Astryx.Heading("Settings", level: .v2).fixedSize(), theme: theme)
#expect(themed.width > large.width)
#expect(themed.contains { $0[0] > 200 && $0[1] < 60 && $0[2] < 60 && $0[3] > 200 })
}
@@ -38,3 +54,15 @@ import Testing
@Test func aHeadingIsAHeader() {
#expect(Astryx.Heading.accessibilityTraits.contains(.isHeader))
}
+
+@MainActor
+@Test func justifyAlignsAOneLineHeadingAcrossItsContainer() {
+ // A fixed frame centers whatever it holds, so start and end are measured
+ // against each other, both justified.
+ let start = Pixels(Astryx.Heading("Hi", level: .v4, justify: .start).frame(width: 300))
+ let end = Pixels(Astryx.Heading("Hi", level: .v4, justify: .end).frame(width: 300))
+ let firstInk = { (p: Pixels) in (0..<p.width).first { x in (0..<p.height).contains { y in p.at(x, y)[3] > 0 } } ?? 0 }
+ #expect(firstInk(start) < end.width / 4)
+ #expect(firstInk(end) > end.width * 3 / 4)
+ #expect(HeadingJustify.end.frameAlignment == .trailing)
+}
diff --git a/packages/native/apple/Tests/AstryxTests/TextTests.swift b/packages/native/apple/Tests/AstryxTests/TextTests.swift
index 6a4219c020..76bc5dd6bf 100644
--- a/packages/native/apple/Tests/AstryxTests/TextTests.swift
+++ b/packages/native/apple/Tests/AstryxTests/TextTests.swift
@@ -4,17 +4,64 @@ import SwiftUI
import Testing
@testable import Astryx
+// Swift component API spec, A2 and A3: Text takes core's Text props, and both
+// initializers build it from the same TextProps.
+
+@MainActor
+@Test func textInitializersBuildTheSameProps() {
+ let labeled = Astryx.Text("Total", type: .large, size: .xl, color: .accent, maxLines: 2, hasTabularNumbers: true)
+ let fromProps = Astryx.Text(
+ TextProps(type: .large, children: "Total", size: .xl, color: .accent, maxLines: 2, hasTabularNumbers: true))
+ #expect(labeled.props.children == fromProps.props.children)
+ #expect(labeled.props.type == fromProps.props.type)
+ #expect(labeled.props.size == fromProps.props.size)
+ #expect(labeled.props.color == fromProps.props.color)
+ #expect(labeled.props.maxLines == fromProps.props.maxLines)
+ #expect(labeled.props.hasTabularNumbers == fromProps.props.hasTabularNumbers)
+}
+
+@MainActor
@Test func textColorDefaultsByTypeAsCoreDoes() {
- #expect(AstryxTextType.supporting.defaultColor == .secondary)
- for type in [AstryxTextType.body, .large, .label] {
- #expect(type.defaultColor == .primary)
+ #expect(Astryx.Text.defaultColor(.supporting) == .secondary)
+ #expect(Astryx.Text.defaultColor(.inherit) == .inherit)
+ for type in [TextType.body, .large, .label, .code, .display1] {
+ #expect(Astryx.Text.defaultColor(type) == .primary)
}
+ let color = Theme.default.light.color
+ #expect(color.text(named: "placeholder") == color.textSecondary)
+ #expect(color.text(named: "accent") == color.textAccent)
+ #expect(color.text(named: "inherit") == nil)
+}
+
+@MainActor
+@Test func everyTypeReadsItsOwnTokens() {
+ let font = Theme.default.light.font
+ #expect(font.style(.body) == TypeStyle(size: font.bodySize, weight: font.bodyWeight, families: font.familyBody))
+ #expect(font.style(.code)?.families == font.familyCode)
+ #expect(font.style(.code)?.size == font.codeSize)
+ #expect(font.style(.display1)?.size == font.display1Size)
+ #expect(font.style(.display2)?.families == font.familyHeading)
+ #expect(font.style(.display3)?.weight == font.display3Weight)
+ #expect(font.style(.inherit) == nil)
}
+@MainActor
@Test func extraSmallIsSpelledAsCoreSpellsIt() {
- #expect(AstryxTextSize(rawValue: "xsm") == .xsm)
- #expect(AstryxTextSize.xsm.token == "font-size-xs")
- #expect(AstryxTextSize.sm.token == "font-size-sm")
+ let font = Theme.default.light.font
+ #expect(TextSize(rawValue: "xsm") == .xsm)
+ #expect(font.size(.xsm) == font.sizeXs)
+ #expect(font.size(.v4xl) == font.size4xl)
+}
+
+@MainActor
+@Test func maxLinesClampsOnlyAPositiveCount() {
+ #expect(astryxLineLimit(nil) == nil)
+ #expect(astryxLineLimit(0) == nil)
+ #expect(astryxLineLimit(2) == 2)
+ #expect(astryxLineLimit(2.7) == 2)
+ #expect(astryxLineLimit(.infinity) == nil)
+ #expect(astryxLineLimit(1e30) == nil)
+ #expect(astryxLineLimit(.nan) == nil)
}
@MainActor
@@ -23,3 +70,40 @@ import Testing
let largest = Pixels(Astryx.Text("Hello").fixedSize(), typeSize: .accessibility5)
#expect(largest.width > large.width * 2)
}
+
+@MainActor
+@Test func displayTextIsLargerThanBodyText() {
+ let body = Pixels(Astryx.Text("Revenue").fixedSize())
+ let display = Pixels(Astryx.Text("Revenue", type: .display1).fixedSize())
+ #expect(display.width > body.width * 2)
+}
+
+@MainActor
+@Test func maxLinesStopsTheTextGrowing() {
+ let words = String(repeating: "word ", count: 40)
+ let open = Pixels(Astryx.Text(words).frame(width: 120).fixedSize(horizontal: false, vertical: true))
+ let clamped = Pixels(Astryx.Text(words, maxLines: 1).frame(width: 120).fixedSize(horizontal: false, vertical: true))
+ #expect(clamped.height * 3 < open.height)
+}
+
+@MainActor
+@Test func aHiddenTextTakesNoSpace() {
+ let alone = Pixels(SwiftUI.HStack(spacing: 0) { Rectangle().frame(width: 20, height: 20) }.fixedSize())
+ let withHidden = Pixels(
+ SwiftUI.HStack(spacing: 0) {
+ Rectangle().frame(width: 20, height: 20)
+ Astryx.Text("Gone", base: AstryxBaseProps(isHidden: true))
+ }.fixedSize())
+ #expect(withHidden.width == alone.width)
+}
+
+@MainActor
+@Test func withoutMaxLinesACallersLineLimitStillApplies() {
+ let words = String(repeating: "word ", count: 40)
+ let open = Pixels(Astryx.Text(words).frame(width: 120).fixedSize(horizontal: false, vertical: true))
+ let callerLimited = Pixels(Astryx.Text(words).lineLimit(1).frame(width: 120).fixedSize(horizontal: false, vertical: true))
+ #expect(callerLimited.height * 3 < open.height)
+ let heading = Pixels(Astryx.Heading(words, level: .v4).lineLimit(1).frame(width: 120).fixedSize(horizontal: false, vertical: true))
+ let openHeading = Pixels(Astryx.Heading(words, level: .v4).frame(width: 120).fixedSize(horizontal: false, vertical: true))
+ #expect(heading.height * 3 < openHeading.height)
+}
diff --git a/packages/native/scripts/swift-ios-theme.mjs b/packages/native/scripts/swift-ios-theme.mjs
index f3ba686a91..9ba82631bc 100644
--- a/packages/native/scripts/swift-ios-theme.mjs
+++ b/packages/native/scripts/swift-ios-theme.mjs
@@ -39,7 +39,7 @@ const REGENERATE = 'pnpm -F @astryxdesign/native generate:swift-ios';
// G5: the token groups Swift keeps. Everything else (shadows, motion, layout
// breakpoints) stays out until a component needs it.
const KEEP =
- /^--(color-|spacing-|radius-|size-element-|border-width$|font-size-|font-weight-|font-family-|text-(heading-\d|body|large|label|supporting)-)/;
+ /^--(color-|spacing-|radius-|size-element-|border-width$|font-size-|font-weight-|font-family-|text-(heading-\d|display-\d|body|large|label|supporting|code)-)/;
const REM = 16;
// Words Swift reserves as identifiers. A member or theme name that equals one
diff --git a/packages/native/specs/swift/library/theme-generator.md b/packages/native/specs/swift/library/theme-generator.md
index 2451a7303d..82dcc8ab3f 100644
--- a/packages/native/specs/swift/library/theme-generator.md
+++ b/packages/native/specs/swift/library/theme-generator.md
@@ -63,7 +63,8 @@ re-implements theme logic.
core's resolved token names: `color-*`, `spacing-*`, `radius-*`,
`size-element-*`, `border-width`, `font-size-*`, `font-weight-*`,
`font-family-*`, and `text-<style>-*` for `heading-1` to `heading-6`,
- `body`, `large`, `label`, and `supporting`. Core fills every shared token a
+ `display-1` to `display-3`, `body`, `large`, `label`, `supporting`, and
+ `code`, the type styles core's Text and Heading draw. Core fills every shared token a
theme leaves out, so every theme has the same shared members. Adding a group
changes this spec, the generator, and the Swift reader in one pull request,
together with the first component that reads it.