@tonycodes-ui/mortar 0.16.2 → 0.18.0

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/docs/native.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Native apps
2
2
 
3
- Mortar is coming to iPhone, iPad and Android as a SwiftUI package and a Jetpack Compose library, tracked in [#95](https://github.com/tonycodes/mortar/issues/95). This page covers what exists so far: the design tokens both libraries are built on.
3
+ Mortar is coming to iPhone, iPad and Android as a SwiftUI package and a Jetpack Compose library, tracked in [#95](https://github.com/tonycodes/mortar/issues/95). This page covers what exists so far: the design tokens both libraries are built on, and the first SwiftUI and Jetpack Compose components.
4
4
 
5
5
  ## Tokens
6
6
 
@@ -19,6 +19,86 @@ Each file holds:
19
19
 
20
20
  `touchTarget` is Mortar's 44. Material asks for 48dp on Android, so the Compose components will use the larger of the two.
21
21
 
22
+ ## SwiftUI
23
+
24
+ Add the package in Xcode (File > Add Package Dependencies…) or in `Package.swift`, from this repository's URL and a release tag:
25
+
26
+ ```swift
27
+ .package(url: "https://github.com/tonycodes/mortar", from: "0.17.0")
28
+ ```
29
+
30
+ It needs iOS 17, iPadOS 17 or macOS 14. Theme the app once near its root, then use the components:
31
+
32
+ ```swift
33
+ import Mortar
34
+
35
+ @main
36
+ struct HiveApp: App {
37
+ var body: some Scene {
38
+ WindowGroup {
39
+ ContentView().mortarTheme(.neutral)
40
+ }
41
+ }
42
+ }
43
+
44
+ MortarButton("Save", variant: .primary) { save() }
45
+ Button("Cancel", action: cancel).buttonStyle(.mortar(.ghost))
46
+ ```
47
+
48
+ A brand is a `MortarTheme`: its light and dark `MortarPalette`s, font family names (registered by the app) and density. Every component reads the palette that matches the colour scheme, and scales its text with Dynamic Type.
49
+
50
+ | Component | Web equivalent | Notes |
51
+ | ---------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52
+ | `MortarButton`, `.buttonStyle(.mortar(_:size:isLoading:))` | Button | `primary`, `secondary`, `ghost`, `danger`, `accent`; `sm`, `md`, `lg`; loading; SF Symbol, icon-only with the title as its accessible name. Medium is at least 44pt tall. |
53
+ | `MortarBadge` | Badge | Tones `neutral`, `info`, `success`, `warning`, `danger`. |
54
+ | `MortarCard` | Card | Title, description, header actions, footer, `compact` or `none` padding, `muted` tone. |
55
+ | `MortarTextField` | Input | Label, prompt, hint, error, required marker, secure entry. VoiceOver reads the label as its name, then "required", the error and the hint. |
56
+ | `MortarSwitch`, `.toggleStyle(.mortar)` | Switch | The whole row toggles; VoiceOver sees a standard switch. |
57
+ | `MortarAvatar` | Avatar | Image URL with initials while loading or on failure, five sizes, circle or square, online or offline status, decorative. |
58
+ | `MortarNotice` | Notice | Tone, message, actions, dismiss button, VoiceOver announcement. |
59
+ | `MortarEmptyState` | EmptyState | SF Symbol, description, action, dashed, centred or leading. |
60
+
61
+ ### Snapshot tests
62
+
63
+ `native/apple/Tests/MortarTests` renders each component on an iPhone simulator in light, dark and a large accessibility text size, and a branded screen on iPad, with [swift-snapshot-testing](https://github.com/pointfreeco/swift-snapshot-testing). The **Mortar for SwiftUI** workflow runs them on macOS on every change to `Package.swift` or `native/apple`, and builds the package for Mac.
64
+
65
+ Rendering differs between iOS versions, so the reference images are recorded on CI's simulator, not on a developer's Mac. To add or update one, delete the old image (or add the test), push, and download the `mortar-swift-snapshots-<sha>` artifact from the failed run: it holds the newly recorded images and any failed comparisons. Review them, commit them under `__Snapshots__`, and push again.
66
+
67
+ ## Jetpack Compose
68
+
69
+ The library is in `native/android` (module `mortar`, package `codes.tony.mortar`) for Android 7.0 (API 24) and later. Until its Maven repository is chosen ([#95](https://github.com/tonycodes/mortar/issues/95)), build it into your local Maven repository with Gradle 8.11 and JDK 17:
70
+
71
+ ```sh
72
+ gradle -p native/android :mortar:publishToMavenLocal -Pversion=0.0.0-local
73
+ ```
74
+
75
+ ```kotlin
76
+ implementation("codes.tony:mortar:0.0.0-local")
77
+ ```
78
+
79
+ Theme the app once near its root, then use the components:
80
+
81
+ ```kotlin
82
+ setContent {
83
+ MortarTheme(brand = MortarBrand.Neutral) {
84
+ MortarButton("Save", onClick = ::save, variant = MortarButtonVariant.Primary)
85
+ }
86
+ }
87
+ ```
88
+
89
+ A brand is a `MortarBrand`: its light and dark `MortarPalette`s, `FontFamily`s and density. `MortarTheme` follows the system's dark theme unless you pass `darkTheme`; components read `Mortar.palette` and `Mortar.brand`. Text sizes are in sp, so they follow the font scale.
90
+
91
+ The components and their parameters match the SwiftUI table above, with Compose names: `MortarButton`, `MortarBadge`, `MortarCard`, `MortarTextField`, `MortarSwitch`, `MortarAvatar`, `MortarNotice` and `MortarEmptyState`. Differences:
92
+
93
+ - Medium controls and touch targets are 48dp, Material's minimum, instead of 44.
94
+ - `MortarAvatar` takes a `Painter`: load the picture with your image library (Coil, Glide) and pass null while it loads or when it fails, to show the initials.
95
+ - Icons are `ImageVector`s, such as `Icons.Filled.Share`.
96
+ - `MortarNotice(announce = true)` is a live region: polite, or assertive for `Danger`.
97
+
98
+ ### Snapshot tests
99
+
100
+ `native/android/mortar/src/test` holds unit tests and [Paparazzi](https://github.com/cashapp/paparazzi) snapshots of each component on a Pixel 5 in light, dark and twice the font size, and a branded screen on a Pixel C tablet. Paparazzi renders on the JVM, without an emulator, so the references in `src/test/snapshots` match on any machine. The **Mortar for Compose** workflow runs `gradle :mortar:verifyPaparazziDebug` on every change to `native/android`. When it fails, it records what the code renders now and uploads the images as `mortar-compose-snapshots-<sha>` to review and commit. Locally, `gradle -p native/android :mortar:recordPaparazziDebug` does the same.
101
+
22
102
  ## Brands
23
103
 
24
104
  `nativeTheme(brand)` in `src/native-theme.ts` resolves a `BrandDefinition` to literal light and dark palettes the way `tokens.css` resolves it: omitted values keep the defaults or derive from primary, and `color-mix(in oklab, …)` tints are computed in JS. Brand colours must be literal and opaque (hex, `white`, `black`, `rgb()`, `hsl()`, `oklab()` or `oklch()`). Accents use the flat `accent`, not the gradient. Fonts become family names plus a generic family; the app bundles the fonts itself.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonycodes-ui/mortar",
3
- "version": "0.16.2",
3
+ "version": "0.18.0",
4
4
  "description": "Mortar: a shared design foundation, application and marketing UI for React and Tailwind.",
5
5
  "type": "module",
6
6
  "files": [