Skip to content

Commit 48654cc

Browse files
committed
Various Changes
- Added: RadixBadge - Added: RadixCallout - Added related DemoVViews - Removed Toast's isPresented function label
1 parent 7a11d04 commit 48654cc

File tree

7 files changed

+335
-7
lines changed

7 files changed

+335
-7
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//
2+
// BadgeDemoView.swift
3+
// RadixUI
4+
//
5+
// Created by Amir Mohammadi on 11/28/1403 AP.
6+
//
7+
8+
import SwiftUI
9+
10+
struct BadgeDemoView: View {
11+
12+
let new = "New"
13+
14+
var body: some View {
15+
VStack(spacing: 20) {
16+
HStack(spacing: 20) {
17+
Text(new)
18+
.font(.footnote)
19+
.radixBadge(variant: .outline, radius: .none, color: .grass)
20+
Text(new)
21+
.font(.footnote)
22+
.radixBadge(variant: .outline, radius: .large, color: .grass)
23+
Text(new)
24+
.font(.footnote)
25+
.radixBadge(variant: .outline, radius: .full, color: .grass)
26+
}
27+
HStack(spacing: 20) {
28+
Text(new)
29+
.font(.footnote)
30+
.radixBadge(variant: .soft, radius: .none, color: .grass)
31+
Text(new)
32+
.font(.footnote)
33+
.radixBadge(variant: .soft, radius: .large, color: .grass)
34+
Text(new)
35+
.font(.footnote)
36+
.radixBadge(variant: .soft, radius: .full, color: .grass)
37+
}
38+
HStack(spacing: 20) {
39+
Text(new)
40+
.font(.footnote)
41+
.radixBadge(variant: .solid, radius: .none, color: .grass)
42+
Text(new)
43+
.font(.footnote)
44+
.radixBadge(variant: .solid, radius: .large, color: .grass)
45+
Text(new)
46+
.font(.footnote)
47+
.radixBadge(variant: .solid, radius: .full, color: .grass)
48+
}
49+
HStack(spacing: 20) {
50+
Text(new)
51+
.font(.footnote)
52+
.radixBadge(variant: .surface, radius: .none, color: .grass)
53+
Text(new)
54+
.font(.footnote)
55+
.radixBadge(variant: .surface, radius: .large, color: .grass)
56+
Text(new)
57+
.font(.footnote)
58+
.radixBadge(variant: .surface, radius: .full, color: .grass)
59+
}
60+
}
61+
}
62+
63+
}
64+
65+
#Preview {
66+
BadgeDemoView()
67+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//
2+
// CalloutDemoView.swift
3+
// RadixUI
4+
//
5+
// Created by Amir Mohammadi on 11/28/1403 AP.
6+
//
7+
8+
import SwiftUI
9+
10+
struct CalloutDemoView: View {
11+
12+
let infoText = "You will need admin privileges to install and access this application."
13+
let alertText = "Access denied. Please contact the network administrator to view this page."
14+
15+
var body: some View {
16+
VStack(spacing: 20) {
17+
Text(infoText)
18+
.radixInfoCallout(variant: .surface, color: .grass)
19+
Text(alertText)
20+
.radixAlertCallout(variant: .surface)
21+
Text(infoText)
22+
.radixInfoCallout(variant: .soft, color: .grass)
23+
Text(alertText)
24+
.radixAlertCallout(variant: .soft)
25+
Text(infoText)
26+
.radixInfoCallout(variant: .outline, color: .grass)
27+
Text(alertText)
28+
.radixAlertCallout(variant: .outline)
29+
}
30+
}
31+
32+
}
33+
34+
#Preview {
35+
CalloutDemoView()
36+
}

Sources/RadixUI/DemoViews/ToastDemoView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ToastDemoView: View {
5252
)
5353
}
5454
.radixInfoToast(
55-
isPresented: $presentInfoToast,
55+
$presentInfoToast,
5656
variant: .surface,
5757
position: .bottom,
5858
color: .grass,
@@ -66,7 +66,7 @@ struct ToastDemoView: View {
6666
)
6767
}
6868
.radixActionToast(
69-
isPresented: $presentActionToast,
69+
$presentActionToast,
7070
variant: .soft,
7171
position: .top,
7272
color: .grass,

Sources/RadixUI/Helpers/Enums.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ public enum RadixElementShapeRadius {
1818
case none, large, full
1919
}
2020

21+
// MARK: - Enums used in RadixBadge
22+
public enum RadixBadgeVariant {
23+
case outline, soft, solid, surface
24+
}
25+
26+
// MARK: - Enums used in RadixCollout
27+
public enum RadixCalloutRole {
28+
case alert, info
29+
}
30+
31+
public enum RadixCalloutVariant {
32+
case outline, soft, surface
33+
}
34+
2135
// MARK: - Enums used in ButtonStyle
2236
public enum RadixButtonLayout {
2337
case icon, title, leading, trailing

Sources/RadixUI/Helpers/Extensions/View+Extenstions.swift

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010
extension View {
1111

1212
/// Make any presented modals dismissable
13-
func radixSwipeToDismiss(
13+
public func radixSwipeToDismiss(
1414
_ isPresented: Binding<Bool>,
1515
direction: DismissSwipeDirection
1616
) -> some View {
@@ -23,9 +23,9 @@ extension View {
2323
)
2424
}
2525

26-
/// Shows a Toast on any View of your choice with a Dismiss Button Action, use it on highest container in your view hierarchy
26+
/// Shows a Toast on any View of your choice with a Dismiss Button Action, use it on highest container in your view hierarchy, duration == 0 will disable auto dismiss
2727
public func radixInfoToast<ToastLabel: View>(
28-
isPresented: Binding<Bool>,
28+
_ isPresented: Binding<Bool>,
2929
variant: RadixToastVariant,
3030
position: RadixToastPosition,
3131
color: RadixAutoColor?,
@@ -45,9 +45,9 @@ extension View {
4545
)
4646
}
4747

48-
/// Shows a Toast on any View of your choice with a Custom Button Action, use it on highest container in your view hierarchy
48+
/// Shows a Toast on any View of your choice with a Custom Button Action, use it on highest container in your view hierarchy, duration == 0 will disable auto dismiss
4949
public func radixActionToast<ButtonLabel: View, ToastLabel: View>(
50-
isPresented: Binding<Bool>,
50+
_ isPresented: Binding<Bool>,
5151
variant: RadixToastVariant,
5252
position: RadixToastPosition,
5353
color: RadixAutoColor?,
@@ -72,3 +72,50 @@ extension View {
7272
}
7373

7474
}
75+
76+
extension View where Self == Text {
77+
78+
///
79+
public func radixBadge(
80+
variant: RadixBadgeVariant,
81+
radius: RadixElementShapeRadius,
82+
color: RadixAutoColor
83+
) -> some View {
84+
self
85+
.modifier(
86+
RadixBadge(
87+
variant: variant,
88+
radius: radius,
89+
color: color
90+
)
91+
)
92+
}
93+
94+
/// Modifies a Text View to become an Info Callout with Customizable Color
95+
public func radixInfoCallout(
96+
variant: RadixCalloutVariant,
97+
color: RadixAutoColor
98+
) -> some View {
99+
self
100+
.modifier(
101+
RadixCallout(
102+
variant: variant,
103+
role: .info,
104+
color: color
105+
)
106+
)
107+
}
108+
109+
/// Modifies a Text View to become an Alert Callout with Red Color
110+
public func radixAlertCallout(variant: RadixCalloutVariant) -> some View {
111+
self
112+
.modifier(
113+
RadixCallout(
114+
variant: variant,
115+
role: .alert,
116+
color: .red
117+
)
118+
)
119+
}
120+
121+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
//
2+
// RadixBadge.swift
3+
// RadixUI
4+
//
5+
// Created by Amir Mohammadi on 11/28/1403 AP.
6+
//
7+
8+
import SwiftUI
9+
10+
public struct RadixBadge: ViewModifier {
11+
12+
@Environment(\.colorScheme) private var colorScheme
13+
14+
private var variant: RadixBadgeVariant
15+
private var radius: RadixElementShapeRadius
16+
private var color: RadixAutoColor
17+
18+
init(
19+
variant: RadixBadgeVariant,
20+
radius: RadixElementShapeRadius,
21+
color: RadixAutoColor
22+
) {
23+
self.variant = variant
24+
self.radius = radius
25+
self.color = color
26+
}
27+
28+
private var badgeColor: [Color] {
29+
switch variant {
30+
// 1st Entry is Fill and 2nd is Stroke Colors
31+
case .outline: [ .clear, color.solid1 ]
32+
case .soft: [ color.component2, .clear ]
33+
case .solid: [ color.border3, .clear ]
34+
case .surface: [ color.background2, color.solid1 ]
35+
}
36+
}
37+
38+
private var fgColor: Color {
39+
guard color != .blackA else { return .whiteA11 }
40+
guard color != .whiteA else { return .blackA11 }
41+
guard variant != .solid else {
42+
return colorScheme == .light ? color.background2 : color.text2
43+
}
44+
return color.text1
45+
}
46+
47+
public func body(content: Content) -> some View {
48+
content
49+
.padding(.horizontal, 10)
50+
.padding(.vertical, 5)
51+
.background(shape)
52+
.foregroundStyle(fgColor)
53+
}
54+
55+
@ViewBuilder
56+
private var shape: some View {
57+
switch radius {
58+
case .none:
59+
Rectangle()
60+
.radixShapeFillApplier(
61+
color: badgeColor.first!,
62+
width: nil, height: nil
63+
)
64+
.overlay {
65+
Rectangle()
66+
.radixShapeBorderApplier(
67+
color: badgeColor.last!,
68+
width: nil, height: nil
69+
)
70+
}
71+
case .large:
72+
RoundedRectangle(cornerRadius: 8)
73+
.radixShapeFillApplier(
74+
color: badgeColor.first!,
75+
width: nil, height: nil
76+
)
77+
.overlay {
78+
RoundedRectangle(cornerRadius: 8)
79+
.radixShapeBorderApplier(
80+
color: badgeColor.last!,
81+
width: nil, height: nil
82+
)
83+
}
84+
case .full:
85+
Capsule()
86+
.radixShapeFillApplier(
87+
color: badgeColor.first!,
88+
width: nil, height: nil
89+
)
90+
.overlay {
91+
Capsule()
92+
.radixShapeBorderApplier(
93+
color: badgeColor.last!,
94+
width: nil, height: nil
95+
)
96+
}
97+
}
98+
}
99+
100+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// RadixCallout.swift
3+
// RadixUI
4+
//
5+
// Created by Amir Mohammadi on 11/28/1403 AP.
6+
//
7+
8+
import SwiftUI
9+
10+
public struct RadixCallout: ViewModifier {
11+
12+
private var variant: RadixCalloutVariant
13+
private var role: RadixCalloutRole
14+
private var color: RadixAutoColor
15+
16+
init(
17+
variant: RadixCalloutVariant,
18+
role: RadixCalloutRole,
19+
color: RadixAutoColor
20+
) {
21+
self.variant = variant
22+
self.role = role
23+
self.color = color
24+
}
25+
26+
private var calloutColor: [Color] {
27+
switch variant {
28+
// 1st Entry is Fill and 2nd is Stroke Colors
29+
case .outline: [ .clear, color.solid1 ]
30+
case .soft: [ color.component2, .clear ]
31+
case .surface: [ color.background2, color.solid1 ]
32+
}
33+
}
34+
35+
public func body(content: Content) -> some View {
36+
HStack(spacing: 12) {
37+
Image(role == .info ? "info-circled" : "exclamation-triangle", bundle: .module)
38+
.resizable()
39+
.aspectRatio(contentMode: .fit)
40+
.frame(width: 20, height: 20)
41+
content
42+
Spacer()
43+
}
44+
.padding(.leading, 20)
45+
.padding(.vertical)
46+
.frame(width: 380)
47+
.background(
48+
RoundedRectangle(cornerRadius: 8)
49+
.radixShapeFillApplier(
50+
color: calloutColor.first!,
51+
width: nil, height: nil
52+
)
53+
.overlay {
54+
RoundedRectangle(cornerRadius: 8)
55+
.radixShapeBorderApplier(
56+
color: calloutColor.last!,
57+
width: nil, height: nil
58+
)
59+
}
60+
)
61+
.foregroundStyle(color.solid2)
62+
}
63+
64+
}

0 commit comments

Comments
 (0)