Skip to content

Commit

Permalink
[Checkbox#707] Use environment isEnabled state.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-zimmermann committed Jan 4, 2024
1 parent d558f94 commit 793c463
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final class CheckboxViewModel: ObservableObject {

var isEnabled: Bool {
didSet {
guard self.isEnabled != oldValue else { return }
self.updateOpacity()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ public struct CheckboxView: View {
)
.buttonStyle(CheckboxButtonStyle(isPressed: self.$isPressed))
.accessibilityIdentifier(CheckboxAccessibilityIdentifier.checkbox)
.isEnabledChanged { isEnabled in
self.viewModel.isEnabled = isEnabled
}
}

@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct CheckboxGroupListView: View {
@State private var intent: CheckboxIntent = .main
@State private var alignment: CheckboxAlignment = .left
@State private var layout: CheckboxSelectionState = CheckboxSelectionState.unselected
@State private var isEnabled: CheckboxSelectionState = CheckboxSelectionState.selected
@State private var isTitleHidden: CheckboxSelectionState = CheckboxSelectionState.unselected
@State private var textStyle: CheckboxTextStyle = .text
@State private var selectedIcon = CheckboxListView.Icons.checkedImage
Expand Down Expand Up @@ -78,6 +79,14 @@ struct CheckboxGroupListView: View {
selectionState: self.$layout
)

CheckboxView(
text: "Is Enabled",
checkedImage: CheckboxListView.Icons.checkedImage.image,
theme: theme,
isEnabled: true,
selectionState: self.$isEnabled
)

CheckboxView(
text: "Show Group Title",
checkedImage: CheckboxListView.Icons.checkedImage.image,
Expand Down Expand Up @@ -105,6 +114,7 @@ struct CheckboxGroupListView: View {
.onChange(of: self.groupType) { newValue in
self.items = self.setItems(groupType: newValue)
}
.disabled(self.isEnabled == .unselected)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ struct CheckboxListView: View {
alignment: self.alignment,
theme: self.theme,
intent: self.intent,
isEnabled: self.isEnabled == .selected ? true : false,
selectionState: self.isIndeterminate == .selected ? .constant(.indeterminate) : $selectionState
)
.disabled(self.isEnabled == .unselected)
}
}
)
Expand Down

0 comments on commit 793c463

Please sign in to comment.