@tonycodes-ui/mortar 0.16.2 → 0.17.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/CHANGELOG.md +2 -2
- package/catalog.json +119 -119
- package/dist/agent-data.json +1 -1
- package/docs/native.md +46 -1
- package/package.json +1 -1
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 components.
|
|
4
4
|
|
|
5
5
|
## Tokens
|
|
6
6
|
|
|
@@ -19,6 +19,51 @@ 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
|
+
|
|
22
67
|
## Brands
|
|
23
68
|
|
|
24
69
|
`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.
|