Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ a component already exists before building your own.
| `FilterBar` | Bottom "Filtered by" bar with a round filter button; a toast can take the caption's place | [Navigation & containers](docs/navigation-and-containers.md) |
| `MenuViewModifier` | Card chrome — rounded background + shadow | [Navigation & containers](docs/navigation-and-containers.md) |
| `Toast` | Blurred toast — warning/info/error/success/copied/loading/noInternet; optional VoiceOver label | [Feedback](docs/feedback.md) |
| `ModalDialog` | Dialog card — warning icon, heading, paragraphs, one or two stacked buttons (one destructive) | [Feedback](docs/feedback.md) |
| `LoadingIllustration` / `LoadingSpinner` | iOS-style activity spinner | [Feedback](docs/feedback.md) |
| `SuccessIllustration` / `ErrorIllustration` | 90×90 status badges | [Feedback](docs/feedback.md) |
| `XmarkIcon` | Code-drawn close (✕) icon | [Feedback](docs/feedback.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Copyright © 2026 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#if canImport(UIKit)
import DashUIKit
import SwiftUI
import XCTest

@MainActor
final class ModalDialogSnapshotTests: XCTestCase {

/// One full-width button under a paragraph.
func testOneButton() throws {
let view = ModalDialog(
icon: .warning, heading: "Success",
paragraphs: ["Disconnected. This wallet could not tell yet which app holds some keys on your identity (1). Open Connections again later to see them."],
primaryAction: .init(title: "OK") {})
try assertComponentSnapshots(of: view, named: "one-button")
}

/// The secondary action above a destructive primary one.
func testTwoButtons() throws {
let view = ModalDialog(
icon: .warning, heading: "Keys left on your identity",
paragraphs: ["Disconnected. Keys this wallet did not record giving are still on your identity (2): keys of this app from another device or from before a restore, or DashPay profile keys no connection holds. Turn them off too?"],
primaryAction: .init(title: "Turn them off", role: .destructive) {},
secondaryAction: .init(title: "Leave them") {})
try assertComponentSnapshots(of: view, named: "two-buttons")
}

/// Several paragraphs, a blank line between them; and a heading with no
/// icon and no paragraph.
func testParagraphsAndBare() throws {
let view = VStack(spacing: 16) {
ModalDialog(
icon: .warning, heading: "Success",
paragraphs: [
"Disconnected. This wallet could not tell yet which app holds some keys on your identity (1). Open Connections again later to see them.",
"Some keys on your identity (1) may belong to another app of the same developer, so this wallet left them on. Each one shows on its own row in Connections; disconnect it there if you no longer need it.",
"Disconnected. Some keys of this app are still on your identity (1). Disconnect it again to turn them off.",
],
primaryAction: .init(title: "OK") {})
ModalDialog(heading: "Disconnected", paragraphs: [], primaryAction: .init(title: "OK") {})
}
try assertComponentSnapshots(of: view, named: "paragraphs-bare")
}

/// Text taller than the height the host gives scrolls inside the card,
/// and the button stays visible under it.
func testLongTextScrollsAboveTheButtons() throws {
let paragraph = "Some keys on your identity (1) may belong to another app of the same developer, so this wallet left them on. Each one shows on its own row in Connections; disconnect it there if you no longer need it."
let view = ModalDialog(
icon: .warning, heading: "Success",
paragraphs: Array(repeating: paragraph, count: 5),
primaryAction: .init(title: "OK") {})
.frame(height: 500)
try assertComponentSnapshots(of: view, named: "scrolls")
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
195 changes: 195 additions & 0 deletions Sources/DashUIKit/Components/ModalDialog.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
//
// Copyright © 2026 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftUI

/// A dialog card: an optional icon, a heading, any number of paragraphs and
/// one or two actions stacked full width. The host presents it (over a dim,
/// centred); the card only lays itself out. Text longer than the screen
/// scrolls inside the card, and the buttons stay visible.
public struct ModalDialog: View {
Comment thread
romchornyi marked this conversation as resolved.
Resolved

public enum Icon: Sendable {
/// The yellow warning tile.
case warning
}

/// One button of the dialog.
public struct Action {
public enum Role: Sendable {
case regular
/// Ends something the user cannot simply get back: drawn in red.
case destructive
}

public let title: String
public let role: Role
public let handler: () -> Void

public init(title: String, role: Role = .regular, handler: @escaping () -> Void) {
self.title = title
self.role = role
self.handler = handler
}
}

/// A button as drawn, top to bottom.
struct DrawnButton {
let title: String
let style: DashButtonStyle
let handler: () -> Void
}

public let icon: Icon?
public let heading: String
public let paragraphs: [String]
public let primaryAction: Action
public let secondaryAction: Action?

public init(
icon: Icon? = nil,
heading: String,
paragraphs: [String],
primaryAction: Action,
secondaryAction: Action? = nil
) {
self.icon = icon
self.heading = heading
self.paragraphs = paragraphs
self.primaryAction = primaryAction
self.secondaryAction = secondaryAction
}

/// The secondary action above the primary one; a destructive one is red,
/// whichever button it is.
var buttons: [DrawnButton] {
[secondaryAction, primaryAction].compactMap { action in
action.map { action in
DrawnButton(
title: action.title,
style: action.role == .destructive ? .tintedRed : .tintedGray,
handler: action.handler)
}
}
}

/// The paragraphs as one text, a blank line between them; nil without any.
var bodyText: String? {
paragraphs.isEmpty ? nil : paragraphs.joined(separator: "\n\n")
}

public var body: some View {
VStack(spacing: 30) {
ViewThatFits(in: .vertical) {
Comment thread
romchornyi marked this conversation as resolved.
Resolved
topContent
ScrollView {
topContent
}
.scrollBounceBehavior(.basedOnSize)
}
VStack(spacing: 20) {
ForEach(Array(buttons.enumerated()), id: \.offset) { _, button in
DashButton(text: button.title, fillsWidth: true, size: .medium, style: button.style, action: button.handler)
}
}
}
.padding(.top, 30)
.padding([.horizontal, .bottom], 20)
.frame(maxWidth: 330)
.background(Color.dash.secondaryBackground)
.clipShape(RoundedRectangle(cornerRadius: 34, style: .continuous))
// VoiceOver stays in the card while it is open, whatever the host
// presents it in.
.accessibilityAddTraits(.isModal)
}

private var topContent: some View {
VStack(alignment: .leading, spacing: 20) {
if let icon {
iconImage(icon)
.accessibilityHidden(true)
}
VStack(alignment: .leading, spacing: 2) {
Text(heading)
.dashFont(.headline)
.accessibilityAddTraits(.isHeader)
if let bodyText {
Text(bodyText)
.dashFont(.subhead)
}
}
.foregroundStyle(Color.dash.primaryText)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
}
.padding(.horizontal, 10)
}

private func iconImage(_ icon: Icon) -> some View {
switch icon {
case .warning:
DashIcon.Illustrations.dialogueWarning.image
.resizable()
.frame(width: 46, height: 46)
}
}
}

#if DEBUG

private let questionText = "Disconnected. Keys this wallet did not record giving are still on your identity (2): keys of this app from another device or from before a restore, or DashPay profile keys no connection holds. Turn them off too?"
private let notCheckedText = "Disconnected. This wallet could not tell yet which app holds some keys on your identity (1). Open Connections again later to see them."
private let notAttributableText = "Some keys on your identity (1) may belong to another app of the same developer, so this wallet left them on. Each one shows on its own row in Connections; disconnect it there if you no longer need it."
private let leftText = "Disconnected. Some keys of this app are still on your identity (1). Disconnect it again to turn them off."

private func dimmed(_ dialog: ModalDialog) -> some View {
ZStack {
Color.dash.backgroundOverlay.ignoresSafeArea()
dialog.padding(.horizontal, 20)
}
}

#Preview("One button") {
dimmed(ModalDialog(icon: .warning, heading: "Success", paragraphs: [notCheckedText], primaryAction: .init(title: "OK") {}))
}

#Preview("Two buttons") {
dimmed(ModalDialog(
icon: .warning, heading: "Keys left on your identity", paragraphs: [questionText],
primaryAction: .init(title: "Turn them off", role: .destructive) {},
secondaryAction: .init(title: "Leave them") {}))
}

#Preview("Long text") {
dimmed(ModalDialog(
icon: .warning, heading: "Success",
paragraphs: [notCheckedText, notAttributableText, leftText, questionText, notAttributableText],
primaryAction: .init(title: "OK") {}))
}

#Preview("No icon, no paragraphs") {
dimmed(ModalDialog(heading: "Disconnected", paragraphs: [], primaryAction: .init(title: "OK") {}))
}

#Preview("Dark") {
dimmed(ModalDialog(
icon: .warning, heading: "Keys left on your identity", paragraphs: [questionText, notAttributableText],
primaryAction: .init(title: "Turn them off", role: .destructive) {},
secondaryAction: .init(title: "Leave them") {}))
.preferredColorScheme(.dark)
}

#endif
1 change: 1 addition & 0 deletions Sources/DashUIKit/Foundation/Icon_DashUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public enum DashIcon {
public enum Illustrations: String, CaseIterable, DashIconAsset {
case crowdnodeWarning = "crowdnode.warning"
case dashDex = "illustration-dash-dex"
case dialogueWarning = "dialogue-warning"
}

// MARK: - Features
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"images" : [
{
"filename" : "dialogue-warning.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true,
"template-rendering-intent" : "original"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions Tests/DashUIKitTests/ModalDialogTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// Copyright © 2026 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import XCTest
@testable import DashUIKit

@MainActor
final class ModalDialogTests: XCTestCase {

/// The secondary action sits above the primary one, as in the design, and
/// each button runs its own action.
func testTheSecondaryButtonComesFirstAndEachRunsItsOwnAction() {
var ran: [String] = []
let dialog = ModalDialog(
heading: "Keys left on your identity",
paragraphs: ["One.", "Two."],
primaryAction: .init(title: "Turn them off", role: .destructive) { ran.append("primary") },
secondaryAction: .init(title: "Leave them") { ran.append("secondary") })

XCTAssertEqual(dialog.buttons.map(\.title), ["Leave them", "Turn them off"])
XCTAssertEqual(dialog.buttons.map(\.style), [.tintedGray, .tintedRed])
dialog.buttons.forEach { $0.handler() }
XCTAssertEqual(ran, ["secondary", "primary"])
}

func testOneButtonIsThePrimaryAction() {
var ran = false
let dialog = ModalDialog(heading: "Success", paragraphs: [], primaryAction: .init(title: "OK") { ran = true })

XCTAssertEqual(dialog.buttons.map(\.title), ["OK"])
XCTAssertEqual(dialog.buttons.map(\.style), [.tintedGray])
dialog.buttons[0].handler()
XCTAssertTrue(ran)
}

/// A destructive secondary action is red as well: the colour follows the
/// role, whichever button it is.
func testADestructiveSecondaryActionIsRedToo() {
let dialog = ModalDialog(
heading: "Remove", paragraphs: [],
primaryAction: .init(title: "Cancel") {},
secondaryAction: .init(title: "Remove", role: .destructive) {})

XCTAssertEqual(dialog.buttons.map(\.style), [.tintedRed, .tintedGray])
}

/// The paragraphs are drawn as one text, in the order given, a blank line
/// between them.
func testParagraphsAreDrawnInOrderWithABlankLineBetween() {
let dialog = ModalDialog(heading: "Success", paragraphs: ["First.", "Second.", "Third."], primaryAction: .init(title: "OK") {})

XCTAssertEqual(dialog.bodyText, "First.\n\nSecond.\n\nThird.")
}

func testNoParagraphsDrawNoText() {
let dialog = ModalDialog(heading: "Success", paragraphs: [], primaryAction: .init(title: "OK") {})

XCTAssertNil(dialog.bodyText)
}
}
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ and callbacks; they render and report intent. They require `import DashUIKit` an
- **[Navigation & containers](navigation-and-containers.md)** — `NavigationBar`,
`NavigationBarElement`, `NavigationBarCircleButton`, `NavigationBarCircleMenu`,
`NavigationBarCircleIcon`, `TopIntroView`, `BottomSheet`, `FilterBar`, `MenuViewModifier`.
- **[Feedback](feedback.md)** — `Toast`, `SystemMessageView`,
- **[Feedback](feedback.md)** — `Toast`, `SystemMessageView`, `ModalDialog`,
`LoadingIllustration` / `LoadingSpinner`, `SuccessIllustration`, `ErrorIllustration`,
`XmarkIcon`, `CheckmarkIcon`, `ChevronIcon`, `InfoRoundIcon`.
- **[Utilities](utilities.md)** — geometry reader (`readingFrame`),
Expand All @@ -36,6 +36,7 @@ and callbacks; they render and report intent. They require `import DashUIKit` an
| Symbol | Page |
|---|---|
| `AddressFieldView` | [Buttons & inputs](buttons-and-inputs.md#addressfieldview) |
| `ModalDialog` | [Feedback](feedback.md#modaldialog) |
| `SheetFeature` | [Navigation & containers](navigation-and-containers.md#sheetfeature) |
| `BottomSheet` | [Navigation & containers](navigation-and-containers.md#bottomsheet) |
| `Bundle.dashUIKit` | [Foundation](foundation.md#bundle) |
Expand Down
Loading
Loading