Skip to content

Commit 87adc79

Browse files
committed
Document default styling preservation in defaultCellConfiguration
1 parent b805cb0 commit 87adc79

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

SwiftDataTables/SwiftDataTables.docc/DefaultCellConfiguration.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,38 @@ This is ideal when you need to:
1212
- Customise alternating row colours
1313
- Style cells based on their position or content
1414

15+
## How It Works
16+
17+
Your callback only overrides what you explicitly set. Everything else keeps its default styling:
18+
19+
| Property | Default | Preserved Unless You Change It |
20+
|----------|---------|-------------------------------|
21+
| `cell.dataLabel.font` | System font, 17pt ||
22+
| `cell.dataLabel.textColor` | `.label` ||
23+
| `cell.dataLabel.textAlignment` | `.left` ||
24+
| `cell.dataLabel.numberOfLines` | `1` (or `0` if wrapping enabled) ||
25+
| `cell.contentView.backgroundColor` | From colour arrays ||
26+
27+
This means you can change just one property without affecting others:
28+
29+
```swift
30+
config.defaultCellConfiguration = { cell, _, _, _ in
31+
// Only change the font - text colour, alignment, background all keep defaults
32+
cell.dataLabel.font = .monospacedSystemFont(ofSize: 13, weight: .regular)
33+
}
34+
```
35+
36+
Or conditionally style specific cells while others remain untouched:
37+
38+
```swift
39+
config.defaultCellConfiguration = { cell, value, _, _ in
40+
// Only "Error" cells get red text - all other cells keep default styling
41+
if value.stringRepresentation == "Error" {
42+
cell.dataLabel.textColor = .systemRed
43+
}
44+
}
45+
```
46+
1547
## Basic Usage
1648

1749
```swift
@@ -147,8 +179,9 @@ The ``DataTableConfiguration/highlightedAlternatingRowColors`` and ``DataTableCo
147179

148180
1. **Colour arrays are applied first** as the baseline background
149181
2. **Your callback runs after**, allowing you to override or extend the styling
182+
3. **Properties you don't touch keep their values** - the callback is additive, not destructive
150183

151-
This means you can use colour arrays for row backgrounds while using the callback for fonts, text colours, and conditional styling:
184+
This means you can use colour arrays for row backgrounds while using the callback for fonts, text colours, and conditional styling—without losing any defaults:
152185

153186
```swift
154187
var config = DataTableConfiguration()

0 commit comments

Comments
 (0)