OCDialog
Introduction
OCDialog
component can be used to show information/ obtain decision from users. It appears as an overlay to the content it was added to.
OCDialog
OCDialog
is developed as a view modifier and can be configured to show 3 types of dialog namely basic, bubbled, illustrative. The actions in dialog can be given using actions
view builder. OCDialog
init takes 4 parameters,
- isPresented, a binding bool to show/ hide the dialog
- type, OCDialogType, denotes which type of dialog to be shown
- configuration, OCDialogConfigurationProtocol, has all the necessary fonts, colors padding configuration
- onCloseClick: Optional completion for close icon click
- actions, a view builder that accepts the buttons to be shown for the dialog
Integration
import SwiftUI
struct ContentView: View {
// MARK: - Properties
@State private var isPresented: Bool = false
var primaryButton: OCButton {
OCButton(title: "Some title Primary",
type: .primaryDanger,
maxWidth: .infinity)
}
var secondaryButton: OCButton {
OCButton(title: "Some title Secondary", type: .secondary,
maxWidth: .infinity)
}
var textButton: OCButton {
OCButton(title: "Some title Text",
type: .textButton(hasUnderline: false))
}
var configuration = OCDialogConfiguration(title: "A longer title can extend over multiple lines ",
description: "A longer title can extend over multiple lines")
var body: some View {
Text("Show/hide dialog")
.onTapGesture {
isPresented.toggle()
}
.ocDialog(isPresented: $isPresented,
type: .bubbled(),
configuration: configuration) {
primaryButton
secondaryButton
}
}
}