// The box's "+" (architect 6 Oct 07:25Z): ONE act everywhere — attach a photo, // photos or a file to whatever the box sends from here. On the database page // onto the thought; on a list onto the thought said there; on a record's page // onto that record, through the thought said on it, which its page shows. // The menu is this one row, the same words on every box, just above it. // Scan a page may follow. import CottonKit import SwiftUI enum BoxAttach { /// What the "+" says aloud. static var label: String { ShellLines.line("input", "attach.label") } /// The menu, in the ruling's order. static var choices: [AttachmentChoice] { (Camera.isAvailable ? [.camera] : []) + [.library, .file] } static func label(_ choice: AttachmentChoice) -> String { switch choice { case .camera: return ShellLines.line("input", "attach.camera") case .library: return ShellLines.line("input", "attach.library") case .file: return ShellLines.line("input", "attach.file") } } /// The source state a menu choice opens. static func open(_ choice: AttachmentChoice) -> AttachmentSourceState { var sources = AttachmentSourceState() switch choice { case .library: sources.library = true case .camera: sources.camera = Camera.isAvailable case .file: sources.files = true } return sources } } /// The "+"'s menu, in the page's own hand, just above the box it adds to. struct BoxAttachMenu: View { let onChoose: (AttachmentChoice) -> Void var body: some View { HStack(spacing: 18) { ForEach(BoxAttach.choices) { choice in PaperTypedButton(BoxAttach.label(choice), size: 14) { onChoose(choice) } .fixedSize() .accessibilityIdentifier("cap-add-\(choice.rawValue)") } } .frame(maxWidth: .infinity, alignment: .leading) .padding(.horizontal, 6) .accessibilityElement(children: .contain) .accessibilityLabel(BoxAttach.label) } }