MCPcopy Create free account
hub / github.com/Effect-TS/effect / EffectUIButtonView

Class EffectUIButtonView

packages/ui/native/apple/EffectUIButton.swift:7–57  ·  view source on GitHub ↗

An `NSButton` with an SF Symbol, a label, or both. Its bezel is Liquid Glass on macOS 26, which `tintColor` tints, and none when `bezel` is `"plain"`.

Source from the content-addressed store, hash-verified

5/// Glass on macOS 26, which `tintColor` tints, and none when `bezel` is
6/// `"plain"`.
7final class EffectUIButtonView: NSButton, EffectUIHostedView {
8 private let context: EffectUIContext
9 private var props: [String: Any] = [:]
10
11 init(_ context: EffectUIContext) {
12 self.context = context
13 super.init(frame: .zero)
14 setButtonType(.momentaryPushIn)
15 title = ""
16 target = self
17 action = #selector(activated)
18 }
19
20 @available(*, unavailable)
21 required init?(coder: NSCoder) {
22 nil
23 }
24
25 func update(_ changed: [String: Any]) {
26 props.merge(changed) { $1 }
27 let label = props["label"] as? String
28 let description = props["accessibilityLabel"] as? String
29 let tint = props["tintColor"] as? NSColor
30 let plain = props["bezel"] as? String == "plain"
31 image = (props["symbol"] as? String).flatMap {
32 NSImage(systemSymbolName: $0, accessibilityDescription: description)
33 }
34 title = label ?? ""
35 imagePosition = label == nil ? .imageOnly : image == nil ? .noImage : .imageLeading
36 controlSize = kitControlSize(props["size"])
37 isBordered = !plain
38 contentTintColor = plain ? tint ?? .secondaryLabelColor : nil
39 bezelColor = plain ? nil : tint
40 if !plain {
41 bezelStyle = label == nil ? .circular : .push
42 #if compiler(>=6.2)
43 if #available(macOS 26.0, *) {
44 bezelStyle = .glass
45 borderShape = label == nil ? .circle : .capsule
46 }
47 #endif
48 }
49 setAccessibilityLabel(description)
50 toolTip = label == nil ? description : nil
51 isEnabled = !kitBool(props["disabled"])
52 }
53
54 @objc private func activated() {
55 context.emit("activate")
56 }
57}
58#else
59import UIKit
60

Callers 1

registerViewsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected