@@ -19,7 +19,7 @@ macOS | iOS
1919* Support for single-select, multi-select, or no selection
2020* Option to sort by column, with indicators and concise syntax
2121* Option to specify a row background and/or overlay
22- * On macOS, option for a hovering highlight, to indicate which row the mouse is over
22+ * On macOS, option for hover events, such as to highlight row under the mouse cursor
2323* MINIMAL use of View erasure (i.e., use of ` AnyView ` ), which can impact scalability and performance\*\*
2424* No external dependencies!
2525
@@ -308,22 +308,33 @@ private func rowOverlay(fruit: Fruit) -> some View {
308308}
309309```
310310
311- ## Hover Effect
311+ ## Hover Events
312312
313- Available for macOS. It's enabled by default using the system's accent color.
314-
315- When using a row background or overlay on macOS, you might wish to disable the hover effect.
313+ For macOS only, you can capture hover events, typically to highlight the row under the mouse cursor.
316314
317315``` swift
316+ @State private var hovered: Fruit.ID? = nil
317+
318318var body: some View {
319- TablerList (.init (hoverColor : . clear ),
319+ TablerList (.init (onHover : hoverAction ),
320320 header : header,
321321 row : row,
322- rowBackground : rowBackgroundAction ,
322+ rowBackground : rowBackground ,
323323 results : fruits)
324324}
325+
326+ private func rowBackground (fruit : Fruit) -> some View {
327+ RoundedRectangle (cornerRadius : 5 )
328+ .fill (Color.accentColor .opacity (hovered == fruit.id ? 0.2 : 0.0 ))
329+ }
330+
331+ private func hoverAction (fruit : Fruit, isHovered : Bool ) {
332+ if isHovered { hovered = fruit.id } else { hovered = nil }
333+ }
325334```
326335
336+ To coordinate hover with other backgrounds, such as for selection on ** Stack** tables, see the demo apps.
337+
327338## Headless Tables
328339
329340Where you don't want a header, simply omit it from the declaration of the table:
@@ -393,7 +404,7 @@ List configuration is optional.
393404- ` canMove: CanMove<Element> ` - with a default of ` { _ in true } ` , allowing any row to move (if ` onMove ` defined)
394405- ` onMove: OnMove<Element>? ` - with a default of ` nil ` , prohibiting any move
395406- ` filter: Filter? ` - with a default of ` nil ` , indicating no filtering
396- - ` hoverColor: Color ` - per Base defaults
407+ - ` onHover: (Element, Bool) -> Void ` - defaults to ` { _,_ in } `
397408- ` tablePadding: EdgeInsets ` - per Base defaults
398409- ` sortIndicatorForward: AnyView ` - per Base defaults
399410- ` sortIndicatorReverse: AnyView ` - per Base defaults
@@ -409,7 +420,7 @@ Stack configuration is optional.
409420- ` headerSpacing: CGFloat ` - Stack-specific default, varies by platform
410421- ` rowSpacing: CGFloat ` - Stack-specific default, varies by platform
411422- ` filter: Filter? ` - with a default of ` nil ` , indicating no filtering
412- - ` hoverColor: Color ` - per Base defaults
423+ - ` onHover: (Element, Bool) -> Void ` - defaults to ` { _,_ in } `
413424- ` tablePadding: EdgeInsets ` - per Stack defaults
414425- ` sortIndicatorForward: AnyView ` - per Base defaults
415426- ` sortIndicatorReverse: AnyView ` - per Base defaults
@@ -427,7 +438,7 @@ Grid configuration is required, where you supply a `GridItem` array.
427438- ` headerSpacing: CGFloat ` - Grid-specific default, varies by platform
428439- ` rowSpacing: CGFloat ` - Grid-specific default, varies by platform
429440- ` filter: Filter? ` - with a default of ` nil ` , indicating no filtering
430- - ` hoverColor: Color ` - per Base defaults
441+ - ` onHover: (Element, Bool) -> Void ` - defaults to ` { _,_ in } `
431442- ` tablePadding: EdgeInsets ` - Grid-specific default, varies by platform
432443- ` sortIndicatorForward: AnyView ` - per Base defaults
433444- ` sortIndicatorReverse: AnyView ` - per Base defaults
0 commit comments