99import SwiftUI
1010
1111/// This style can be used to style ``TagCapsule`` views. It
12- /// lets you define visual styles like colors and padding.
12+ /// lets you define visual styles, like fore- and background
13+ /// colors, background materials, border, and padding.
1314///
14- /// There is a boring ``TagCapsuleStyle/standard`` style, as
15- /// well as the even worse``TagCapsuleStyle/standardSelected``
16- /// style. There are also some material-based styles such as
17- /// ``TagCapsuleStyle/standardMaterial``.
15+ /// To style other parts of the capsule, such as the font or
16+ /// the font weight, use native SwiftUI view modifiers.
17+ ///
18+ /// The ``standard`` and ``standardSelected`` capsule styles
19+ /// use a primary foreground color, a clear background color
20+ /// and a material background.
1821public struct TagCapsuleStyle {
1922
2023 /// Create a new tag capsule style.
2124 ///
2225 /// - Parameters:
23- /// - foregroundColor: The foreground color to use, by default `.black`.
24- /// - backgroundColor: The background color to use, by default `.gray`.
25- /// - backgroundMaterial: The background material to use, by default `.blue`.
26- /// - borderColor: The border color to use, by default `.clear`.
27- /// - borderWidth: The border width to use, by default `1`.
26+ /// - foregroundColor: The foreground color, by default `.primary`.
27+ /// - backgroundColor: The background color, by default `.clear`.
28+ /// - backgroundMaterial: The background material, by default `.ultraThin`.
29+ /// - borderColor: The border color, by default `.clear`.
30+ /// - borderWidth: The border width, by default `1`.
31+ /// - shadow: The shadow style, by default ``Shadow/standard``.
2832 /// - padding: The intrinsic padding to apply, by default a small padding.
2933 public init (
30- foregroundColor: Color = . black ,
31- backgroundColor: Color = . gray ,
32- backgroundMaterial: Material ? = nil ,
34+ foregroundColor: Color = . primary ,
35+ backgroundColor: Color = . clear ,
36+ backgroundMaterial: Material ? = . ultraThin ,
3337 borderColor: Color = . clear,
3438 borderWidth: Double = 1 ,
39+ shadowStyle: Shadow = . standard,
3540 padding: EdgeInsets ? = nil
3641 ) {
3742 var defaultPadding : EdgeInsets
@@ -47,66 +52,107 @@ public struct TagCapsuleStyle {
4752 self . borderColor = borderColor
4853 self . borderWidth = borderWidth
4954 self . padding = padding ?? defaultPadding
55+ self . shadow = shadowStyle
5056 }
5157
52- /// The foreground color to use .
58+ /// The foreground color.
5359 public var foregroundColor : Color
5460
55- /// The background color to use .
61+ /// The background color.
5662 public var backgroundColor : Color
5763
58- /// The background material to use .
64+ /// The background material.
5965 public var backgroundMaterial : Material ?
6066
61- /// The border color to use .
67+ /// The border color.
6268 public var borderColor : Color
6369
64- /// The border width to use .
70+ /// The border width.
6571 public var borderWidth : Double
72+
73+ // The shadow style.
74+ public var shadow : Shadow
6675
6776 /// The padding to apply to the text.
6877 public var padding : EdgeInsets
6978}
7079
80+ public extension TagCapsuleStyle {
81+
82+ struct Shadow {
83+
84+ /// Create a new tag capsule shadow style.
85+ ///
86+ /// - Parameters:
87+ /// - color: The shadow color, by default `.clear`.
88+ /// - radius: The shadow radius, by default `0`.
89+ /// - offsetX: The x offset, by default `0`.
90+ /// - offsetY: The y offset, by default `1`.
91+ public init (
92+ color: Color = . clear,
93+ radius: Double = 0 ,
94+ offsetX: Double = 0 ,
95+ offsetY: Double = 1
96+ ) {
97+ self . color = color
98+ self . radius = radius
99+ self . offsetX = offsetX
100+ self . offsetY = offsetY
101+ }
102+
103+ /// The shadow color.
104+ public var color : Color
105+
106+ /// The shadow radius.
107+ public var radius : Double
108+
109+ /// The x offset.
110+ public var offsetX : Double
111+
112+ /// The y offset.
113+ public var offsetY : Double
114+ }
115+ }
116+
71117public extension TagCapsuleStyle {
72118
73119 /// The standard style.
74- static var standard : TagCapsuleStyle { . init( ) }
120+ static var standard : Self {
121+ . init( )
122+ }
75123
76124 /// The standard, selected style.
77- static var standardSelected : TagCapsuleStyle {
125+ static var standardSelected : Self {
78126 . init(
79- foregroundColor: . white,
80- backgroundColor: . black,
81- borderColor: . white
127+ backgroundMaterial: . regular,
128+ shadowStyle: . standardSelected
82129 )
83130 }
84-
85- /// A standard material-based style.
86- static var standardMaterial : TagCapsuleStyle {
87- . init(
88- foregroundColor: . primary,
89- backgroundColor: . clear,
90- backgroundMaterial: . ultraThin
91- )
131+ }
132+
133+ public extension TagCapsuleStyle . Shadow {
134+
135+ /// The standard style.
136+ static var standard : Self {
137+ . init( )
92138 }
93-
94- /// A standard, selected material-based style.
95- static var standardMaterialSelected : TagCapsuleStyle {
139+
140+ /// The standard, selected shadow style.
141+ static var standardSelected : Self {
96142 . init(
97- foregroundColor: . primary,
98- backgroundColor: . clear,
99- backgroundMaterial: . regular
143+ color: . primary. opacity ( 0.5 ) ,
144+ radius: 0
100145 )
101146 }
102147}
103148
104149public extension TagCapsuleStyle {
105150
106- @available ( * , deprecated, renamed: " standardMaterialSelected " )
107- static var standardSelectedMaterial : TagCapsuleStyle {
108- . standardMaterialSelected
109- }
151+ @available ( * , deprecated, renamed: " standard " )
152+ static var standardMaterial : TagCapsuleStyle { . standard }
153+
154+ @available ( * , deprecated, renamed: " standardSelected " )
155+ static var standardSelectedMaterial : TagCapsuleStyle { . standardSelected }
110156}
111157
112158
0 commit comments