123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //
- // ComponentAlertProperty.swift
- // KMComponentLibrary
- //
- // Created by Niehaoyu on 2024/9/12.
- //
- import Foundation
- import AppKit
- public class ComponentAlertProperty: NSObject {
-
- public var messageType: ComponentMessageType = .info
- public var title: String? //传nil时表示不显示Title
- public var subTitle: String? //副文本信息
- public var iconImage: NSImage?
- public var detailButtonString: String? //传nil时表示不显示
- public var cancelButtonString: String? //传nil时表示不显示
-
- public var propertyInfo = AlertPropertyInfo()
-
- public init(messageType: ComponentMessageType = .info,
- title: String? = nil,
- subTitle: String? = nil,
- iconImage: NSImage?
- detailButtonString: String? = nil,
- cancelButtonString: String? = nil) {
-
- self.messageType = messageType
- self.title = title
- self.subTitle = subTitle
- self.iconImage = iconImage
- self.detailButtonString = detailButtonString
- self.cancelButtonString = cancelButtonString
-
- }
-
- }
- public class AlertPropertyInfo: ComponentPropertyInfo {
-
- var lineBorderColor: NSColor?
-
- var subTextFont: NSFont = NSFont.labelFont(ofSize: 14)
-
- //MARK: - Function
- override init() {
- super.init()
-
- }
-
- }
- //MARK: - ComponentLibrary
- extension ComponentLibrary {
-
- func configAlertComponent(properties: ComponentAlertProperty) -> Void {
-
- var colorKey = "colorAlert/bg-info"
- var lineBorderColorKey = "colorPrimary/border1"
- if properties.messageType == .success {
- colorKey = "colorAlert/bg-success"
- lineBorderColorKey = "colorSuccess/border1"
- } else if properties.messageType == .warning {
- colorKey = "colorAlert/bg-warning"
- lineBorderColorKey = "colorWarning/border1"
- } else if properties.messageType == .error {
- colorKey = "colorAlert/bg-error"
- lineBorderColorKey = "colorError/border1"
- }
-
- if let value = ComponentLibrary.shared.getComponentValueFromKey(colorKey) {
- let currentValue = value as! [String : Any]
- properties.propertyInfo.color_nor = ComponentLibrary.shared.getColor(rgbaDict: currentValue)
- } else {
- properties.propertyInfo.color_nor = NSColor.clear
- }
-
- properties.propertyInfo.borderWidth = 0
- properties.propertyInfo.cornerRadius = 0
-
- if let value = ComponentLibrary.shared.getComponentValueFromKey(lineBorderColorKey) {
- let currentValue = value as! [String : Any]
- properties.propertyInfo.lineBorderColor = ComponentLibrary.shared.getColor(rgbaDict: currentValue)
- } else {
- properties.propertyInfo.lineBorderColor = NSColor.clear
- }
-
- //Text
- if let value = ComponentLibrary.shared.getComponentValueFromKey("colorText/1") {
- let currentValue = value as! [String : Any]
- properties.propertyInfo.textColor = ComponentLibrary.shared.getColor(rgbaDict: currentValue)
- } else {
- properties.propertyInfo.textColor = NSColor.clear
- }
-
- if let value = ComponentLibrary.shared.getComponentValueFromKey("mac/body-m-medium") {
- let currentValue = value as! [String : Any]
-
- if let fontSize = currentValue["fontSize"] as? Float,
- let fontFamily = currentValue["fontFamily"] as? String,
- let fontWeight = currentValue["fontWeight"] as? String {
-
- let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [NSFontDescriptor.AttributeName.family: fontFamily, NSFontDescriptor.AttributeName.face: fontWeight])
- if let newFont = NSFont(descriptor: attributeFontDescriptor, size: CGFloat(fontSize)) {
- properties.propertyInfo.textFont = newFont
- }
- }
- }
-
- if let value = ComponentLibrary.shared.getComponentValueFromKey("mac/body-s-regular") {
- let currentValue = value as! [String : Any]
-
- if let fontSize = currentValue["fontSize"] as? Float,
- let fontFamily = currentValue["fontFamily"] as? String,
- let fontWeight = currentValue["fontWeight"] as? String {
-
- let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [NSFontDescriptor.AttributeName.family: fontFamily, NSFontDescriptor.AttributeName.face: fontWeight])
- if let newFont = NSFont(descriptor: attributeFontDescriptor, size: CGFloat(fontSize)) {
- properties.propertyInfo.subTextFont = newFont
- }
- }
- }
-
- }
-
-
-
- }
|