// The faces that hold several records: a section (the project page's heading,// its count and three slips) and a month (the calendar grid, a tile only).importCottonValuesimportSwiftUI/// A heading, a count and the first three slips, with the chevron that says/// the heading opens the whole list — the project overview's section.publicstructSectionFace: View {publicstaticlet shown = 3 @Environment(\.theme) privatevar themeprivatelet definition: TableDefinitionprivatelet records: [TableRecord]privatelet total: Intprivatelet onOpen: (() -> Void)?privatelet headed: Boolprivatelet onToggle: ((TableRecord) -> Void)?privatelet onSlip: ((TableRecord) -> Void)?/// - Parameter total: how many records the table holds under the current/// filter; `records` may be only the first page of them./// - Parameter headed: false under a heading somebody else drew (a/// section of the database page), so the name is said once./// - Parameter onToggle: what a tap on a slip's check does; nil draws the/// check without a press./// - Parameter onSlip: what a tap on the rest of a slip does.publicinit( definition: TableDefinition, records: [TableRecord], total: Int? = nil, headed: Bool = true, onOpen: (() -> Void)? = nil, onToggle: ((TableRecord) -> Void)? = nil, onSlip: ((TableRecord) -> Void)? = nil ) {self.definition = definitionself.records = recordsself.total = total ?? records.countself.headed = headedself.onOpen = onOpenself.onToggle = onToggleself.onSlip = onSlip }/// "3 of 12", or the count alone when every record is shown.publicstaticfunc count(shown: Int, total: Int) -> String { shown < total ? "\(shown) of \(total)" : "\(total)" }publicvar body: someView {let first = Array(records.prefix(Self.shown)) VStack(alignment: .leading, spacing: GroupFacesKnobs.faceSectionSlipGap) {if headed {Button { onOpen?() } label: {ProjectSectionHeading(title: definition.plural, count: Self.count(shown: first.count, total: total)) } .buttonStyle(.plain) .disabled(onOpen == nil) }ForEach(first) { record inlet slip = SlipFace(definition: definition, record: record, onToggle: onToggle.map { toggle in { toggle(record) } })iflet onSlip {// A tap, never a button around the slip: the check inside// it is a button of its own. slip.contentShape(Rectangle()) .onTapGesture { onSlip(record) } .accessibilityAddTraits(.isButton) } else { slip } } } }}/// The month grid with a dot under each day per record dated on it, up to/// three. A tile face: the calendar grid is not a screen in the app.publicstructMonthFace: View {privatelet definition: TableDefinitionprivatelet records: [TableRecord]privatelet now: Date @Environment(\.calendar) privatevar calendarpublicinit(definition: TableDefinition, records: [TableRecord], now: Date = Date()) {self.definition = definitionself.records = recordsself.now = now }/// Records per day key ("yyyy-MM-dd") by the table's date column.publicstaticfunc dotCounts(_ definition: TableDefinition, _ records: [TableRecord], calendar: Calendar) -> [String: Int] {var counts: [String: Int] = [:]for record in records {guardlet iso = record[definition.date].text, let key = FaceText.dayKey(iso, calendar: calendar) else { continue } counts[key, default: 0] += 1 }return counts }publicvar body: someView {let today = CalendarDates.todayKey(now: now, calendar: calendar)MonthGrid( monthKey: today, selectedKey: today, dotCounts: Self.dotCounts(definition, records, calendar: calendar), now: now, onSelectDay: { _ in } ) }}/// The sizes, counts and timings GroupFaces draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumGroupFacesKnobs {staticlet faceSectionSlipGap: CGFloat = 12}