Skip to content

Commit 7040a04

Browse files
committed
Add shadows to capsule style
1 parent 6ffddd6 commit 7040a04

File tree

4 files changed

+108
-57
lines changed

4 files changed

+108
-57
lines changed

RELEASE_NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ This requires standard styles to be converted to read-only values.
1111

1212
This version also adjusts the visual appearance of some standard styles.
1313

14+
### ✨ Features
15+
16+
* `TagCapsuleStyle` now supports specifying a shadow.
17+
18+
### 💡 Behavior Changes
19+
20+
* `TagCapsule.standard` and `.standardSelected` now use material backgrounds.
21+
1422

1523

1624
## 0.2

Sources/TagKit/Views/TagCapsule.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public struct TagCapsule: View {
3333
Text(tag)
3434
.padding(style.padding)
3535
.foregroundColor(style.foregroundColor)
36-
3736
.materialCapsuleBackground(with: style.backgroundMaterial)
3837
.background(Capsule().fill(style.backgroundColor))
3938
.padding(style.borderWidth)
@@ -44,6 +43,12 @@ public struct TagCapsule: View {
4443
)
4544
)
4645
.compositingGroup()
46+
.shadow(
47+
color: style.shadow.color,
48+
radius: style.shadow.radius,
49+
x: style.shadow.offsetX,
50+
y: style.shadow.offsetY
51+
)
4752

4853
}
4954
}
@@ -76,12 +81,6 @@ private extension View {
7681
TagCapsule("standard-selected")
7782
.tagCapsuleStyle(.standardSelected)
7883
}
79-
HStack {
80-
TagCapsule("material")
81-
.tagCapsuleStyle(.standardMaterial)
82-
TagCapsule("material-selected")
83-
.tagCapsuleStyle(.standardSelectedMaterial)
84-
}
8584

8685
TagCapsule("spider-man")
8786
.tagCapsuleStyle(.init(

Sources/TagKit/Views/TagCapsuleStyle.swift

Lines changed: 87 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,34 @@
99
import 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.
1821
public 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+
71117
public 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

104149
public 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

Sources/TagKit/Views/TagEditList.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,18 @@ private extension TagEditList {
138138
ScrollView {
139139
VStack(alignment: .leading, spacing: 30) {
140140
list("Standard Style", .standard, .standardSelected)
141-
list("Standard Material Style", .standardMaterial, .standardMaterialSelected)
142141
list("Custom Style", .custom, .customSelected)
143142
}
144143
.padding()
145144

146145
}
147-
.background(
148-
LinearGradient(
149-
colors: [.red, .blue],
150-
startPoint: .top,
151-
endPoint: .bottom
152-
)
153-
)
146+
// .background(
147+
// LinearGradient(
148+
// colors: [.red, .blue],
149+
// startPoint: .top,
150+
// endPoint: .bottom
151+
// )
152+
// )
154153
.toolbar {
155154
ToolbarItem {
156155
HStack {
@@ -205,7 +204,6 @@ private extension TagEditList {
205204
}
206205

207206
return Preview()
208-
// .preferredColorScheme(.dark)
209207
}
210208

211209
private extension TagCapsuleStyle {

0 commit comments

Comments
 (0)