From 40395ffd1688b3d3e686ecc859b18cceacc721b9 Mon Sep 17 00:00:00 2001 From: Alexander Romanov Date: Tue, 25 Jul 2023 22:40:39 +0300 Subject: [PATCH] Added KeyboardToolbar --- .../KeyboardToolbar/KeyboardToolbar.swift | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Sources/OversizeUI/Controls/KeyboardToolbar/KeyboardToolbar.swift diff --git a/Sources/OversizeUI/Controls/KeyboardToolbar/KeyboardToolbar.swift b/Sources/OversizeUI/Controls/KeyboardToolbar/KeyboardToolbar.swift new file mode 100644 index 0000000..b66ddfc --- /dev/null +++ b/Sources/OversizeUI/Controls/KeyboardToolbar/KeyboardToolbar.swift @@ -0,0 +1,50 @@ +// +// Copyright © 2021 Alexander Romanov +// KeyboardToolbar.swift, created on 25.07.2023 +// + +import SwiftUI + +public struct KeyboardToolbar: View where A: View { + private let actions: Group? + private let doneAction: (() -> Void)? + + public init( + @ViewBuilder actions: @escaping () -> A, + doneAction: (() -> Void)? = nil + ) { + self.actions = Group { actions() } + self.doneAction = doneAction + } + + public var body: some View { + HStack(spacing: .xSmall) { + if actions != nil { + HStack(spacing: .xxxSmall) { + actions + .buttonStyle(.quaternary) + .controlBorderShape(.capsule) + .controlSize(.mini) + } + } + + Spacer() + + if doneAction != nil { + Button { + doneAction?() + } label: { + Text("Done") + } + .buttonStyle(.quaternary) + .controlBorderShape(.capsule) + .accent() + .controlSize(.mini) + } + } + .padding(.horizontal, .small) + .padding(.vertical, .xxSmall) + .background(Color.surfacePrimary) + .shadowElevaton(.z1) + } +}