File tree Expand file tree Collapse file tree 2 files changed +38
-6
lines changed
Views/Controls and Indicators/Buttons Expand file tree Collapse file tree 2 files changed +38
-6
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // ButtonRole.swift
3
+ //
4
+ //
5
+ // Created by Carson Katri on 2/29/24.
6
+ //
7
+
8
+ import SwiftUI
9
+ import LiveViewNativeCore
10
+
11
+ /// The semantic role of a ``Button``.
12
+ ///
13
+ /// Possible values:
14
+ /// * `destructive`
15
+ /// * `cancel`
16
+ extension ButtonRole : AttributeDecodable {
17
+ public init ( from attribute: LiveViewNativeCore . Attribute ? ) throws {
18
+ guard let value = attribute? . value
19
+ else { throw AttributeDecodingError . missingAttribute ( Self . self) }
20
+ switch value {
21
+ case " destructive " :
22
+ self = . destructive
23
+ case " cancel " :
24
+ self = . cancel
25
+ default :
26
+ throw AttributeDecodingError . badValue ( Self . self)
27
+ }
28
+ }
29
+ }
Original file line number Diff line number Diff line change @@ -22,8 +22,8 @@ import SwiftUI
22
22
/// ```
23
23
///
24
24
/// ## Attributes
25
- /// * ``disabled ``
26
- ///
25
+ /// * ``role ``
26
+ ///
27
27
/// ## Events
28
28
/// * ``click``
29
29
@_documentation ( visibility: public)
@@ -38,19 +38,22 @@ public struct Button<R: RootRegistry>: View {
38
38
@_documentation ( visibility: public)
39
39
@Event ( " phx-click " , type: " click " ) private var click
40
40
41
- /// Boolean attribute that indicates whether the button is tappable.
41
+ /// The semantic role of the button.
42
+ ///
43
+ /// Possible values:
44
+ /// * `destructive`
45
+ /// * `cancel`
42
46
@_documentation ( visibility: public)
43
- @Attribute ( " disabled " ) private var disabled : Bool
47
+ @Attribute ( " role " ) private var role : ButtonRole ?
44
48
45
49
@_spi ( LiveForm) public init ( action: ( ( ) -> Void ) ? = nil ) {
46
50
self . action = action
47
51
}
48
52
49
53
public var body : some View {
50
- SwiftUI . Button ( action: self . handleClick) {
54
+ SwiftUI . Button ( role : role , action: self . handleClick) {
51
55
context. buildChildren ( of: element)
52
56
}
53
- . disabled ( disabled)
54
57
. preference ( key: _ProvidedBindingsKey. self, value: [ " phx-click " ] )
55
58
}
56
59
You can’t perform that action at this time.
0 commit comments