-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: library views and modifiers (#13)
- Loading branch information
Showing
36 changed files
with
300 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct VOErrorSheet: ViewModifier { | ||
@Environment(\.colorScheme) private var colorScheme | ||
private let isPresented: Binding<Bool> | ||
private let message: String? | ||
|
||
init(isPresented: Binding<Bool>, message: String?) { | ||
self.isPresented = isPresented | ||
self.message = message | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.sheet(isPresented: isPresented) { | ||
VStack(spacing: VOMetrics.spacing) { | ||
VOErrorMessage(message) | ||
Button { | ||
isPresented.wrappedValue = false | ||
} label: { | ||
VOButtonLabel("Dismiss") | ||
} | ||
.voSecondaryButton(colorScheme: colorScheme) | ||
} | ||
.padding() | ||
.presentationDetents([.fraction(0.25)]) | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func voErrorSheet(isPresented: Binding<Bool>, message: String?) -> some View { | ||
modifier(VOErrorSheet(isPresented: isPresented, message: message)) | ||
} | ||
} | ||
|
||
#Preview { | ||
@Previewable @State var showError = false | ||
@Previewable @State var showLongError = false | ||
|
||
VStack(spacing: VOMetrics.spacing) { | ||
Button("Show Error") { | ||
showError = true | ||
} | ||
Button("Show Long Error") { | ||
showLongError = true | ||
} | ||
} | ||
.voErrorSheet( | ||
isPresented: $showError, | ||
message: "Lorem ipsum dolor sit amet." | ||
) | ||
.voErrorSheet( | ||
isPresented: $showLongError, | ||
// swiftlint:disable:next line_length | ||
message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." | ||
) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct VOWarningSheet: ViewModifier { | ||
@Environment(\.colorScheme) private var colorScheme | ||
private let isPresented: Binding<Bool> | ||
private let message: String? | ||
|
||
init(isPresented: Binding<Bool>, message: String?) { | ||
self.isPresented = isPresented | ||
self.message = message | ||
} | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.sheet(isPresented: isPresented) { | ||
VStack(spacing: VOMetrics.spacing) { | ||
VOWarningMessage(message) | ||
Button { | ||
isPresented.wrappedValue = false | ||
} label: { | ||
VOButtonLabel("Dismiss") | ||
} | ||
.voSecondaryButton(colorScheme: colorScheme) | ||
} | ||
.padding() | ||
.presentationDetents([.fraction(0.25)]) | ||
} | ||
} | ||
} | ||
|
||
extension View { | ||
func voWarningSheet(isPresented: Binding<Bool>, message: String?) -> some View { | ||
modifier(VOWarningSheet(isPresented: isPresented, message: message)) | ||
} | ||
} | ||
|
||
#Preview { | ||
@Previewable @State var showWarning = false | ||
@Previewable @State var showLongWarning = false | ||
|
||
VStack(spacing: VOMetrics.spacing) { | ||
Button("Show Warning") { | ||
showWarning = true | ||
} | ||
Button("Show Long Warning") { | ||
showLongWarning = true | ||
} | ||
} | ||
.voWarningSheet( | ||
isPresented: $showWarning, | ||
message: "Lorem ipsum dolor sit amet." | ||
) | ||
.voWarningSheet( | ||
isPresented: $showLongWarning, | ||
// swiftlint:disable:next line_length | ||
message: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct VOErrorMessage: View { | ||
let message: String? | ||
|
||
init() { | ||
message = nil | ||
} | ||
|
||
init(_ message: String?) { | ||
self.message = message | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: VOMetrics.spacingXs) { | ||
VOErrorIcon() | ||
if let message { | ||
Text(message) | ||
.foregroundStyle(.secondary) | ||
.lineLimit(1) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
VStack(spacing: VOMetrics.spacing2Xl) { | ||
VOErrorMessage("Lorem ipsum dolor sit amet.") | ||
// swiftlint:disable:next line_length | ||
VOErrorMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") | ||
} | ||
.padding() | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct VOWarningIcon: View { | ||
var body: some View { | ||
Image(systemName: "exclamationmark.triangle") | ||
.font(.title) | ||
.foregroundStyle(Color.yellow400) | ||
} | ||
} | ||
|
||
#Preview { | ||
VOWarningIcon() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2024 Anass Bouassaba. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file LICENSE in the root of this repository. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the GNU Affero General Public License v3.0 only, included in the file | ||
// AGPL-3.0-only in the root of this repository. | ||
|
||
import SwiftUI | ||
|
||
struct VOWarningMessage: View { | ||
let message: String? | ||
|
||
init() { | ||
message = nil | ||
} | ||
|
||
init(_ message: String?) { | ||
self.message = message | ||
} | ||
|
||
var body: some View { | ||
VStack(spacing: VOMetrics.spacingXs) { | ||
VOWarningIcon() | ||
if let message { | ||
Text(message) | ||
.foregroundStyle(.secondary) | ||
.lineLimit(1) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
VStack(spacing: VOMetrics.spacing2Xl) { | ||
VOWarningMessage("Lorem ipsum dolor sit amet.") | ||
// swiftlint:disable:next line_length | ||
VOWarningMessage("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") | ||
} | ||
.padding() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.