// // KMLinkEmailView.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/10/18. // import Cocoa import KMComponentLibrary @objc public protocol KMLinkEmailViewDelegate: AnyObject { @objc optional func kmLinkEmailViewDidGo(_ view: KMLinkEmailView, _ emailString: String) } public class KMLinkEmailView: BaseXibView { @IBOutlet var contendBox: NSBox! @IBOutlet var inputTextarea: ComponentTextarea! @IBOutlet var goButton: ComponentButton! weak open var delegate: KMLinkEmailViewDelegate? //MARK: - func public override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } public required init?(coder decoder: NSCoder) { super.init(coder: decoder) } override init(frame frameRect: NSRect) { super.init(frame: frameRect) } public override func awakeFromNib() { super.awakeFromNib() self.setUpUI() } func setUpUI() { inputTextarea.properties = ComponentTextareaProperty(size: .m, state: .normal, isError: false, placeholderString: "support@pdfreaderpro.com", totalCount: -1, text: "", isDisabled:false) inputTextarea.delegate = self goButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .s, buttonText: KMLocalizedString("Go")) goButton.setTarget(self, action: #selector(buttonClicked(_:))) goButton.isHidden = true } @objc func buttonClicked(_ sender: NSView) { delegate?.kmLinkEmailViewDidGo?(self, inputTextarea.properties.text) } //MARK: - MouseEvent public override func mouseDown(with event: NSEvent) { super.mouseDown(with: event) self.window?.makeFirstResponder(nil) } } //MARK: - ComponentTextareaDelegate extension KMLinkEmailView: ComponentTextareaDelegate { public func componentTextareaTextDidBeginEditing(_ view: ComponentTextarea) { } public func componentTextareaTextDidChange(_ view: ComponentTextarea) { if view.properties.text.count > 0 { goButton.isHidden = false } else { goButton.isHidden = true } } public func componentTextareaTextDidEndEditing(_ view: ComponentTextarea) { } }