import SwiftUI import SFSafeSymbols struct InsertableLabels: View, InsertableCommandView { static let title = "Labels" static let sheetTitle = "Insert labels" static let icon: SFSymbol = .squaresBelowRectangle final class Model: InsertableCommandModel { @Published var labels: [ContentLabel] = [] var isReady: Bool { !labels.isEmpty } init() { } var command: String? { guard !labels.isEmpty else { return nil } var result = "```labels" for label in labels { result += "\n\(label.icon.rawValue): \(label.value)" } result += "\n```" return result } } @Environment(\.colorScheme) private var colorScheme @ObservedObject private var model: Model init(model: Model) { self.model = model } var body: some View { VStack(spacing: 2) { ForEach(model.labels, id: \.icon) { label in HStack { Button(action: { remove(label) }) { Image(systemSymbol: .minusCircleFill) .foregroundStyle(.red) } .buttonStyle(.plain) LabelEditingView(label: label) } .padding(.vertical, 2) .padding(.horizontal, 8) .background(colorScheme == .light ? Color.white : Color.black) .cornerRadius(8) } Button("Add", action: addLabel) .padding(.vertical, 2) } } private func addLabel() { model.labels.append(.init(icon: .clockFill, value: "Value")) } private func remove(_ label: ContentLabel) { guard let index = model.labels.firstIndex(of: label) else { return } model.labels.remove(at: index) } }