// The small record primitive: the chip. // // THE COLOUR RULE: colour NEVER names a kind. A chip is typed on the straw // pill every kind shares. // // ON PAPER (phase 20, 2026-09-14) it speaks one of the kit's voices: a chip is // typed. // // Five more lived here — the date line, the kind badge, the pending badge and // the todo check until 2026-09-15, the mark line until the gallery went. Each // was left with no caller but its own gallery specimen and went with it; what // survived them is drawn elsewhere — the hand tick is `Paper/Marks.swift`'s // `HandTick`, and the box around it the todo card's own `TodoCheckSquare`. import SwiftUI // ── The chip ────────────────────────────────────────────────────────────── /// The paper pill a badge and a chip are typed on — ONE dye for every kind, /// because colour never names a kind. enum RecordPill { static let dye: PaperDye = .straw } /// TWO STATES, ONE OBJECT. With no action it is bare TEXT — no ground, no /// padding, no chip form; a data chip is a fact, not a control that does /// nothing. With one it is a pill. /// /// A chip is TEXT: no colour dot, no hue coding. Callers pass the bare name and /// the sigil separately — a double `##` is a caller's bug, not a chip's. public struct Chip: View { @Environment(\.theme) private var theme public enum Prefix: String, Sendable { case project = "#", person = "@" } private let label: String private let prefix: Prefix? private let isSelected: Bool private let isDisabled: Bool private let accessibilityText: String? private let action: (() -> Void)? public init( label: String, prefix: Prefix? = nil, selected: Bool = false, disabled: Bool = false, accessibilityLabel: String? = nil, action: (() -> Void)? = nil ) { self.label = label self.prefix = prefix self.isSelected = selected self.isDisabled = disabled self.accessibilityText = accessibilityLabel self.action = action } private var shown: String { "\(prefix?.rawValue ?? "")\(label)" } public var body: some View { if let action { Button { // Guarded in the HANDLER as well as by `disabled`: the phone // learned that a disabled pressable can still fire under some // gesture responders, and the guard costs nothing. guard !isDisabled else { return } action() } label: { Text(shown) .font(CottonFonts.type(13)) .foregroundStyle(isSelected ? RecordPill.dye.fill : theme.print(.ink)) .padding(.horizontal, 10) .padding(.vertical, 4) .background( // Selected is the ink disc's own grammar: ink under // paper-coloured type. Capsule().fill(isSelected ? theme.print(.ink) : RecordPill.dye.fill) ) .opacity(isDisabled ? DisabledOpacity.control : 1) } .buttonStyle(MotionButtonStyle()) .disabled(isDisabled) .accessibilityLabel(accessibilityText ?? label) .accessibilityAddTraits(isSelected ? .isSelected : []) } else { Text(shown).paperBody(13, ink: .pencil) } } }