Cotton code
61 lines · 2.6 KB · SwiftRaw
// Search is a bar, not a button (owner's ruling, 6 Oct 2026): on Home and on// every list a slip of paper at the column's full width sits directly under// the title — a small magnifier at its left, the typewriter placeholder in// pencil ("Search Mukya", "Search todos"). It is the first thing in the// scrolling content: it scrolls away with the page and is there again at the// top, never stuck. Tapping it opens the search that exists today. A record// page has none: search is one Back away.//// It is a slip like the slips under it — the same paper, edge and pencil —// so it brings no new colour, face or shape onto the page.import SwiftUIpublic struct SearchSlip: View {    @Environment(\.theme) private var theme    private let placeholder: String    private let identifier: String    private let action: () -> Void    public init(placeholder: String, identifier: String, action: @escaping () -> Void) {        self.placeholder = placeholder        self.identifier = identifier        self.action = action    }    public var body: some View {        Button(action: action) {            Paper(dye: .cream, edge: .cut, seed: identifier, tilt: false, inset: 0) {                HStack(spacing: SearchSlipKnobs.paperSearchSlipGlyphGap) {                    Image(systemName: "magnifyingglass")                        .font(theme.type.interface(SearchSlipKnobs.paperSearchSlipGlyphSize, weight: .regular))                        .foregroundStyle(theme.print(.pencil))                        .accessibilityHidden(true)                    Text(placeholder)                        .paperBody(theme.scale.bodySize + 1, ink: .pencil)                        .lineLimit(1)                        .truncationMode(.tail)                    Spacer(minLength: 0)                }                .padding(.horizontal, SearchSlipKnobs.paperSearchSlipHorizontalInset)                .frame(maxWidth: .infinity, minHeight: SearchSlipKnobs.paperSearchSlipHeight, alignment: .leading)            }            // The whole slip takes the tap (S1).            .contentShape(Rectangle())        }        .buttonStyle(MotionButtonStyle())        .accessibilityLabel(placeholder)        .accessibilityAddTraits(.isSearchField)        .accessibilityIdentifier(identifier)    }}/// The sizes, counts and timings SearchSlip draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enum SearchSlipKnobs {    static let paperSearchSlipGlyphGap: CGFloat = 8    static let paperSearchSlipGlyphSize: CGFloat = 13    static let paperSearchSlipHeight: CGFloat = 40    static let paperSearchSlipHorizontalInset: CGFloat = 12}