76 lines
3.5 KiB
Swift
76 lines
3.5 KiB
Swift
import HelderCore
|
|
import SwiftUI
|
|
|
|
/// One table on the canvas at 100%: a 33pt header, then a 22pt row per column. The line geometry depends on these sizes.
|
|
struct SchemaTableCard: View {
|
|
let table: SchemaTable
|
|
let highlight: SchemaHighlight
|
|
let isSelected: Bool
|
|
let onHoverColumn: (_ id: String, _ inside: Bool) -> Void
|
|
|
|
var body: some View {
|
|
let isFocus = highlight.focus == table.name
|
|
let lit = isFocus || isSelected
|
|
VStack(spacing: 0) {
|
|
HStack(spacing: 8) {
|
|
Text(table.name)
|
|
.typeRole(Typography.schemaCardName)
|
|
.foregroundStyle(lit ? Palette.text1 : Palette.text2)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
Text(table.rowsLabel).typeRole(Typography.meta).foregroundStyle(Palette.text4).lineLimit(1).fixedSize()
|
|
}
|
|
.padding(.horizontal, 10)
|
|
.frame(height: SchemaMetrics.headerHeight - Metrics.hairline)
|
|
.background(lit ? Palette.amberTint : Palette.panel)
|
|
Hairline()
|
|
ForEach(Array(table.columns.enumerated()), id: \.offset) { _, column in
|
|
row(column)
|
|
}
|
|
}
|
|
.padding(Metrics.hairline)
|
|
.frame(width: SchemaMetrics.cardWidth, height: table.cardHeight, alignment: .top)
|
|
.background(Palette.panel, in: RoundedRectangle(cornerRadius: Metrics.radiusMedium))
|
|
.clipShape(RoundedRectangle(cornerRadius: Metrics.radiusMedium))
|
|
.overlay(RoundedRectangle(cornerRadius: Metrics.radiusMedium).strokeBorder(border(isFocus: isFocus), lineWidth: Metrics.hairline))
|
|
.opacity(highlight.opacity(of: table.name))
|
|
.animation(Metrics.colorTransition, value: highlight)
|
|
.animation(Metrics.colorTransition, value: isSelected)
|
|
}
|
|
|
|
private func row(_ column: SchemaColumn) -> some View {
|
|
let lit = highlight.isHighlighted(table: table.name, column: column.name)
|
|
let isKey = column.isPrimary || column.isForeign
|
|
return HStack(spacing: 6) {
|
|
Text(column.keyLabel)
|
|
.typeRole(Typography.schemaKey)
|
|
.foregroundStyle(lit ? Palette.amber : column.isPrimary ? Palette.amberSoft : Palette.textMuted)
|
|
.frame(width: 20, alignment: .leading)
|
|
Text(column.name)
|
|
.typeRole(Typography.path)
|
|
.foregroundStyle(lit ? Palette.text1 : isKey ? Palette.text2 : Palette.text3)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
Text(column.displayType).typeRole(Typography.meta).foregroundStyle(Palette.text4).lineLimit(1).fixedSize()
|
|
}
|
|
.padding(.horizontal, 10)
|
|
.frame(height: SchemaMetrics.rowHeight)
|
|
.background(lit ? Palette.amberTint : .clear)
|
|
.onHover { inside in
|
|
guard column.isForeign else { return }
|
|
onHoverColumn(SchemaColumnRef(table: table.name, column: column.name).id, inside)
|
|
}
|
|
}
|
|
|
|
/// Focus amber, a selection under another hover amber-deep, related text-4, a search match amber-soft.
|
|
private func border(isFocus: Bool) -> Color {
|
|
if isFocus { return Palette.amber }
|
|
if isSelected { return Palette.amberDeep }
|
|
if highlight.relatedTables.contains(table.name) { return Palette.text4 }
|
|
if highlight.searchMatches.contains(table.name) { return Palette.amberSoft }
|
|
return Palette.raised
|
|
}
|
|
}
|