// One search in the system, drawn ONE way.//// THE GRAMMAR (phase 20, 2026-09-14) is Home's footer's, because that is the// one the owner approved (picture 30): a 56pt paper-coloured capsule floating// over the plaster — cream, a hairline, the soft shadow — the magnifier and the// words TYPED, and a separate 56pt close circle beside it. There were two// grammars (this file's 40pt elevated capsule with "Cancel" beside it, and// Home's); `SearchField` and `SearchCloseCircle` are now the only drawing of// either, and Home's footer and every screen's pull-down pill both draw them.//// CLOSE CLEARS, THEN CLOSES. A search that ends never leaves a filter behind// silently — the list you come back to is the list you left.//// The HOST owns the query: it dims its content while the pill is open with an// empty query, and renders the filtered list at full strength once the query// bites.importSwiftUI/// The capsule: magnifier and field. Focus is the caller's, because Home's/// footer owns its field's focus from above and a screen's pill owns its own.structSearchField: View { @Binding var text: Stringlet placeholder: Stringvar isFocused: FocusState<Bool>.Binding @Environment(\.theme) privatevar themevar body: someView { HStack(spacing: 12) {Image(systemName: Glyph.symbol("search") ?? "magnifyingglass") .font(.system(size: theme.scale.sectionTitleSize, weight: .regular)) .foregroundStyle(CottonColors.inkTertiary)// The placeholder is typed in tertiary ink — the page's one// invitation, read at arm's length.TextField("", text: $text, prompt: Text(placeholder).foregroundStyle(CottonColors.inkTertiary) ) .font(CottonFonts.type(theme.scale.titleSize)) .foregroundStyle(CottonColors.ink) .textInputAutocapitalization(.never) .autocorrectionDisabled() .submitLabel(.search) .focused(isFocused) .accessibilityLabel(placeholder)// No bordered platform field inside the capsule, and no blue ring// on it (`Paper/PaperFocus.swift`). .cottonPaperField() } .padding(.horizontal, 16) .frame(height: SearchPillKnobs.chromeFooterSearchHeight) .frame(maxWidth: .infinity)// Paper-coloured, not white: the input floats over the plaster as the// quiet cream of the objects around it (paper kit §1.6). .background(Capsule().fill(SearchGrammar.fill))// The capsule's own hairline IS the focus ring: it inks while the// field has the keyboard. The walk photographed the system's blue one// over the paper instead (finding 15). .cottonInkFocusRing(isFocused.wrappedValue, in: Capsule()) .softShadow() }}/// The close beside the capsule — the capsule's own height, so the two read as/// one row. The nav circle's fill, with the shadow doing the work.structSearchCloseCircle: View {let action: () -> Void @Environment(\.theme) privatevar themevar body: someView {Button(action: action) { ZStack {Circle() .fill(NavChrome.circleFill) .overlay(Circle().strokeBorder(CottonColors.hairline, lineWidth: ComposerCardKnobs.chromeHairline)) .softShadow()Image(systemName: Glyph.symbol("x") ?? "xmark") .font(.system(size: theme.scale.sectionTitleSize, weight: .regular)) .foregroundStyle(NavChrome.glyphInk) } .frame(width: SearchPillKnobs.chromeFooterSearchHeight, height: SearchPillKnobs.chromeFooterSearchHeight) .contentShape(Circle()) } .buttonStyle(MotionButtonStyle()) .accessibilityLabel(CottonStrings.cancel) }}/// The grammar's numbers and paint, named once.enumSearchGrammar {staticlet fill: Color = PaperDye.cream.fill/// What closing does, in order: the query is cleared before the host hears.staticfunc close(clear: () -> Void, then onClose: () -> Void) { clear() onClose() }}publicstructSearchPill: View { @Binding privatevar text: Stringprivatelet placeholder: Stringprivatelet onClose: () -> Void/// The pill takes the keyboard the moment it opens, because it opens BY a/// deliberate tap on the search circle and a person who tapped it is/// already typing. A specimen that is only being LOOKED at passes `false` —/// otherwise the gallery raises a keyboard nobody asked for.privatelet takesFocus: Bool @FocusState privatevar isFocused: Boolpublicinit( text: Binding<String>, placeholder: String? = nil, takesFocus: Bool = true, onClose: @escaping () -> Void ) { _text = textself.placeholder = placeholder ?? CottonStrings.searchself.takesFocus = takesFocusself.onClose = onClose }publicvar body: someView { HStack(spacing: 10) {SearchField(text: $text, placeholder: placeholder, isFocused: $isFocused)SearchCloseCircle {// Clear, THEN close.SearchGrammar.close(clear: { text = "" }, then: onClose) } } .cottonContentMargin() .onAppear { if takesFocus { isFocused = true } } }}/// The sizes, counts and timings SearchPill draws with: Swift's own, beside/// their reader — a theme sets only its tokens (`scale.tokens`).enumSearchPillKnobs {staticlet chromeFooterSearchHeight: CGFloat = 56}/// A page head's magnifier (fan3 part 6): where a page's search face is/// `icon`, the search is this circle in the head's row, beside the stack of/// cards; a tap turns the row into the field (`SearchPill`) with the/// keyboard up, and its close gives the row back.structHeadSearchCircle: View {let action: () -> Voidvar body: someView {NavCircle(symbol: Glyph.symbol("search") ?? "magnifyingglass", label: CottonStrings.search, action: action) }}/// The board's magnifier, handed to the head it stands in; nil where the/// board offers no search in its head.privatestructHeadSearchKey: EnvironmentKey {staticlet defaultValue: (@MainActor @Sendable () -> Void)? = nil}extensionEnvironmentValues {var headSearch: (@MainActor @Sendable () -> Void)? { get { self[HeadSearchKey.self] } set { self[HeadSearchKey.self] = newValue } }}/// A page under Home's fan has its search field open: Home puts the fan and/// the record button away while it is, as it does for its own head's field.structPageSearchingKey: PreferenceKey {staticlet defaultValue = falsestaticfunc reduce(value: inoutBool, nextValue: () -> Bool) { value = value || nextValue() }}