|
@@ -7,13 +7,382 @@
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
+@objc enum TokenButtonType : Int {
|
|
|
+ case Cta = 0 //强调按钮
|
|
|
+ case Brand //品牌按钮
|
|
|
+ case Sec //二级按钮
|
|
|
+ case Sec_Icon
|
|
|
+ case Link //链接按钮
|
|
|
+ case Text //文字按钮
|
|
|
+ case Ghost //幽灵按钮
|
|
|
+ case Icon_Fill //icon按钮
|
|
|
+ case Upgrade //升级按钮
|
|
|
+}
|
|
|
+
|
|
|
+@objc enum TokenButtonSize : Int {
|
|
|
+ case l = 0
|
|
|
+ case m
|
|
|
+ case s
|
|
|
+}
|
|
|
+
|
|
|
@objc extension NSViewController {
|
|
|
|
|
|
// MARK: - Button
|
|
|
|
|
|
- func button(bg: String = "", text: String = "", height: NSLayoutConstraint = NSLayoutConstraint(), state: KMDesignTokenState = .Norm) -> Void {
|
|
|
+ func button(type: TokenButtonType, size: TokenButtonSize, height: NSLayoutConstraint = NSLayoutConstraint()) -> Void {
|
|
|
if self is KMDesignButton {
|
|
|
- KMDesignToken.shared.buttonDesignToken(bgToken: bg, textToken: text, heightConstraint: height, control: self as! KMDesignButton, state: state)
|
|
|
+ var bg = ""
|
|
|
+ var text = ""
|
|
|
+ var state: KMDesignTokenState = .Norm
|
|
|
+ let states = [KMDesignTokenState.Norm, KMDesignTokenState.Hov, KMDesignTokenState.Act, KMDesignTokenState.Disabled]
|
|
|
+ for s in states {
|
|
|
+ state = s
|
|
|
+ if (type == .Cta) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.cta.l.bg.norm"
|
|
|
+ text = "btn.cta.l.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.cta.l.bg.hov"
|
|
|
+ text = "btn.cta.l.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.cta.l.bg.act"
|
|
|
+ text = "btn.cta.l.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.cta.l.bg.dis"
|
|
|
+ text = "btn.cta.l.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.cta.m.bg.norm"
|
|
|
+ text = "btn.cta.m.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.cta.m.bg.hov"
|
|
|
+ text = "btn.cta.m.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.cta.m.bg.act"
|
|
|
+ text = "btn.cta.m.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.cta.m.bg.dis"
|
|
|
+ text = "btn.cta.m.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .s) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.cta.s.bg.norm"
|
|
|
+ text = "btn.cta.s.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.cta.s.bg.hov"
|
|
|
+ text = "btn.cta.s.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.cta.s.bg.act"
|
|
|
+ text = "btn.cta.s.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.cta.s.bg.dis"
|
|
|
+ text = "btn.cta.s.mac-text.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if (type == .Brand) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.brand.l.bg.norm"
|
|
|
+ text = "btn.brand.l.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.brand.l.bg.hov"
|
|
|
+ text = "btn.brand.l.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.brand.l.bg.act"
|
|
|
+ text = "btn.brand.l.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.brand.l.bg.dis"
|
|
|
+ text = "btn.brand.l.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.brand.m.bg.norm"
|
|
|
+ text = "btn.brand.m.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.brand.m.bg.hov"
|
|
|
+ text = "btn.brand.m.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.brand.m.bg.act"
|
|
|
+ text = "btn.brand.m.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.brand.m.bg.dis"
|
|
|
+ text = "btn.brand.m.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .s) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.brand.s.bg.norm"
|
|
|
+ text = "btn.brand.s.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.brand.s.bg.hov"
|
|
|
+ text = "btn.brand.s.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.brand.s.bg.act"
|
|
|
+ text = "btn.brand.s.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.brand.s.bg.dis"
|
|
|
+ text = "btn.brand.s.mac-text.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == .Sec) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.sec.l.bg.norm"
|
|
|
+ text = "btn.sec.l.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.sec.l.bg.hov"
|
|
|
+ text = "btn.sec.l.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.sec.l.bg.act"
|
|
|
+ text = "btn.sec.l.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.sec.l.bg.dis"
|
|
|
+ text = "btn.sec.l.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.sec.m.bg.norm"
|
|
|
+ text = "btn.sec.m.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.sec.m.bg.hov"
|
|
|
+ text = "btn.sec.m.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.sec.m.bg.act"
|
|
|
+ text = "btn.sec.m.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.sec.m.bg.dis"
|
|
|
+ text = "btn.sec.m.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .s) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.sec.s.bg.norm"
|
|
|
+ text = "btn.sec.s.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.sec.s.bg.hov"
|
|
|
+ text = "btn.sec.s.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.sec.s.bg.act"
|
|
|
+ text = "btn.sec.s.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.sec.s.bg.dis"
|
|
|
+ text = "btn.sec.s.mac-text.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == .Sec_Icon) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.sec-icon.l.bg.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.sec-icon.l.bg.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.sec-icon.l.bg.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.sec-icon.l.bg.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.sec-icon.m.bg.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.sec-icon.m.bg.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.sec-icon.m.bg.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.sec-icon.m.bg.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == .Link) {
|
|
|
+ if (size == .l) {
|
|
|
+ bg = "btn.link.l.bg"
|
|
|
+ if (s == .Norm) {
|
|
|
+ text = "btn.link.l.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ text = "btn.link.l.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ text = "btn.link.l.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ text = "btn.link.l.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ bg = "btn.link.m.bg"
|
|
|
+ if (s == .Norm) {
|
|
|
+ text = "btn.link.m.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ text = "btn.link.m.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ text = "btn.link.m.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ text = "btn.link.m.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .s) {
|
|
|
+ bg = "btn.link.s.bg"
|
|
|
+ if (s == .Norm) {
|
|
|
+ text = "btn.link.s.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ text = "btn.link.s.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ text = "btn.link.s.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ text = "btn.link.s.mac-text.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == .Text) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.text.l.bg.norm"
|
|
|
+ text = "btn.text.l.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.text.l.bg.hov"
|
|
|
+ text = "btn.text.l.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.text.l.bg.act"
|
|
|
+ text = "btn.text.l.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.text.l.bg.dis"
|
|
|
+ text = "btn.text.l.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.text.m.bg.norm"
|
|
|
+ text = "btn.text.m.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.text.m.bg.hov"
|
|
|
+ text = "btn.text.m.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.text.m.bg.act"
|
|
|
+ text = "btn.text.m.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.text.m.bg.dis"
|
|
|
+ text = "btn.text.m.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .s) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.text.s.bg.norm"
|
|
|
+ text = "btn.text.s.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.text.s.bg.hov"
|
|
|
+ text = "btn.text.s.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.text.s.bg.act"
|
|
|
+ text = "btn.text.s.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.text.s.bg.dis"
|
|
|
+ text = "btn.text.s.mac-text.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == .Ghost) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.ghost.l.bg.norm"
|
|
|
+ text = "btn.ghost.l.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.ghost.l.bg.hov"
|
|
|
+ text = "btn.ghost.l.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.ghost.l.bg.act"
|
|
|
+ text = "btn.ghost.l.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.ghost.l.bg.dis"
|
|
|
+ text = "btn.ghost.l.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.ghost.m.bg.norm"
|
|
|
+ text = "btn.ghost.m.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.ghost.m.bg.hov"
|
|
|
+ text = "btn.ghost.m.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.ghost.m.bg.act"
|
|
|
+ text = "btn.ghost.m.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.ghost.m.bg.dis"
|
|
|
+ text = "btn.ghost.m.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .s) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.ghost.s.bg.norm"
|
|
|
+ text = "btn.ghost.s.mac-text.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.ghost.s.bg.hov"
|
|
|
+ text = "btn.ghost.s.mac-text.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.ghost.s.bg.act"
|
|
|
+ text = "btn.ghost.s.mac-text.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.ghost.s.bg.dis"
|
|
|
+ text = "btn.ghost.s.mac-text.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == .Icon_Fill) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.icon-fill.l.bg.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.icon-fill.l.bg.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.icon-fill.l.bg.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.icon-fill.l.bg.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.icon-fill.m.bg.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.icon-fill.m.bg.hov"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.icon-fill.m.bg.act"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.icon-fill.m.bg.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (type == .Upgrade) {
|
|
|
+ if (size == .l) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.upgrade.l.bg.norm"
|
|
|
+ text = "btn.upgrade.l.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.upgrade.l.bg.hov"
|
|
|
+ text = "btn.upgrade.l.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.upgrade.l.bg.act"
|
|
|
+ text = "btn.upgrade.l.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.upgrade.l.bg.dis"
|
|
|
+ text = "btn.upgrade.l.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .m) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.upgrade.m.bg.norm"
|
|
|
+ text = "btn.upgrade.m.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.upgrade.m.bg.hov"
|
|
|
+ text = "btn.upgrade.m.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.upgrade.m.bg.act"
|
|
|
+ text = "btn.upgrade.m.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.upgrade.m.bg.dis"
|
|
|
+ text = "btn.upgrade.m.mac-text.dis"
|
|
|
+ }
|
|
|
+ } else if (size == .s) {
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "btn.upgrade.s.bg.norm"
|
|
|
+ text = "btn.upgrade.s.mac-text.def"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "btn.upgrade.s.bg.hov"
|
|
|
+ text = "btn.upgrade.s.mac-text.def"
|
|
|
+ } else if (s == .Act) {
|
|
|
+ bg = "btn.upgrade.s.bg.act"
|
|
|
+ text = "btn.upgrade.s.mac-text.def"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "btn.upgrade.s.bg.dis"
|
|
|
+ text = "btn.upgrade.s.mac-text.dis"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ KMDesignToken.shared.buttonDesignToken(bgToken: bg, textToken: text, heightConstraint: height, control: self as! KMDesignButton, state: state)
|
|
|
+ }
|
|
|
} else {
|
|
|
print("传入视图类型错误,组件库处理失败,本接口应传入 KMDesignButton 对象")
|
|
|
}
|
|
@@ -56,6 +425,29 @@ import Foundation
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // MARK: - Pagination
|
|
|
+
|
|
|
+ func pagination() -> Void {
|
|
|
+ if self is KMDesignButton {
|
|
|
+ var bg = ""
|
|
|
+ var state: KMDesignTokenState = .Norm
|
|
|
+ let states = [KMDesignTokenState.Norm, KMDesignTokenState.Hov, KMDesignTokenState.Disabled]
|
|
|
+ for s in states {
|
|
|
+ state = s
|
|
|
+ if (s == .Norm) {
|
|
|
+ bg = "pagination.selector.bg.norm"
|
|
|
+ } else if (s == .Hov) {
|
|
|
+ bg = "pagination.selector.bg.hov"
|
|
|
+ } else if (s == .Disabled) {
|
|
|
+ bg = "pagination.selector.bg.dis"
|
|
|
+ }
|
|
|
+ KMDesignToken.shared.buttonDesignToken(bgToken: bg, textToken: "", heightConstraint: NSLayoutConstraint(), control: self as! KMDesignButton, state: state)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ print("传入视图类型错误,组件库处理失败,本接口应传入 KMDesignButton 对象")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: - Select
|
|
|
|
|
|
func select(bg: String = "", text: String = "", textbg: String = "", height: NSLayoutConstraint = NSLayoutConstraint(), state: KMDesignTokenState = .Norm) -> Void {
|