Skip to content

Commit 6fdf296

Browse files
committed
Create POSShadowStyle with view modifier and preview.
1 parent a24425f commit 6fdf296

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import Foundation
2+
import SwiftUI
3+
4+
/// Defines shadow styles used across POS UI components.
5+
/// Design ref: 1qcjzXitBHU7xPnpCOWnNM-fi-22_7198
6+
enum POSShadowStyle {
7+
case medium
8+
case large
9+
}
10+
11+
/// A ViewModifier that applies predefined shadow styles
12+
struct POSShadowStyleModifier: ViewModifier {
13+
let style: POSShadowStyle
14+
15+
func body(content: Content) -> some View {
16+
switch style {
17+
case .medium:
18+
content
19+
.shadow(color: Color.posShadow.opacity(0.02), radius: 16, x: 0, y: 16)
20+
.shadow(color: Color.posShadow.opacity(0.03), radius: 8, x: 0, y: 4)
21+
.shadow(color: Color.posShadow.opacity(0.04), radius: 5, x: 0, y: 4)
22+
.shadow(color: Color.posShadow.opacity(0.05), radius: 3, x: 0, y: 2)
23+
case .large:
24+
content
25+
.shadow(color: Color.posShadow.opacity(0.02), radius: 43, x: 0, y: 50)
26+
.shadow(color: Color.posShadow.opacity(0.04), radius: 36, x: 0, y: 30)
27+
.shadow(color: Color.posShadow.opacity(0.07), radius: 27, x: 0, y: 15)
28+
.shadow(color: Color.posShadow.opacity(0.08), radius: 15, x: 0, y: 5)
29+
}
30+
}
31+
}
32+
33+
extension View {
34+
/// Applies a shadow style to the view.
35+
/// - Parameter style: The shadow style to apply.
36+
func posShadow(_ style: POSShadowStyle) -> some View {
37+
modifier(POSShadowStyleModifier(style: style))
38+
}
39+
}
40+
41+
#Preview {
42+
VStack(spacing: 40) {
43+
Text("Medium Shadow")
44+
.padding()
45+
.frame(width: 200, height: 100)
46+
.foregroundStyle(Color.posOnSecondaryContainer)
47+
.background(Color.posOutlineVariant)
48+
.posShadow(.medium)
49+
50+
Text("Large Shadow")
51+
.padding()
52+
.frame(width: 200, height: 100)
53+
.foregroundStyle(Color.posOnSecondaryContainer)
54+
.background(Color.posOutlineVariant)
55+
.posShadow(.large)
56+
}
57+
.padding(100)
58+
}

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
0204F0CA29C047A400CFC78F /* SelfSizingHostingController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0204F0C929C047A400CFC78F /* SelfSizingHostingController.swift */; };
8282
0205021E27C8B6C600FB1C6B /* InboxEligibilityUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0205021D27C8B6C600FB1C6B /* InboxEligibilityUseCase.swift */; };
8383
02055B142D5DAB6400E51059 /* POSCornerRadiusStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02055B132D5DAB6400E51059 /* POSCornerRadiusStyle.swift */; };
84+
020564982D5DC96600E51059 /* POSShadowStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020564972D5DC96600E51059 /* POSShadowStyle.swift */; };
8485
0206483A23FA4160008441BB /* OrdersRootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0206483923FA4160008441BB /* OrdersRootViewController.swift */; };
8586
0206E296299CD2C900C061C1 /* WooAnalyticsEvent+DomainSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0206E295299CD2C900C061C1 /* WooAnalyticsEvent+DomainSettings.swift */; };
8687
020732042988AB7B000A53C2 /* DomainContactInfoForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 020732032988AB7B000A53C2 /* DomainContactInfoForm.swift */; };
@@ -3285,6 +3286,7 @@
32853286
0204F0C929C047A400CFC78F /* SelfSizingHostingController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfSizingHostingController.swift; sourceTree = "<group>"; };
32863287
0205021D27C8B6C600FB1C6B /* InboxEligibilityUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InboxEligibilityUseCase.swift; sourceTree = "<group>"; };
32873288
02055B132D5DAB6400E51059 /* POSCornerRadiusStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSCornerRadiusStyle.swift; sourceTree = "<group>"; };
3289+
020564972D5DC96600E51059 /* POSShadowStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSShadowStyle.swift; sourceTree = "<group>"; };
32883290
0206483923FA4160008441BB /* OrdersRootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrdersRootViewController.swift; sourceTree = "<group>"; };
32893291
0206E295299CD2C900C061C1 /* WooAnalyticsEvent+DomainSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WooAnalyticsEvent+DomainSettings.swift"; sourceTree = "<group>"; };
32903292
020732032988AB7B000A53C2 /* DomainContactInfoForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainContactInfoForm.swift; sourceTree = "<group>"; };
@@ -7159,6 +7161,7 @@
71597161
01FB19572C6E901800A44FF0 /* DynamicHStack.swift */,
71607162
68625DE52D4134D50042B231 /* DynamicVStack.swift */,
71617163
02055B132D5DAB6400E51059 /* POSCornerRadiusStyle.swift */,
7164+
020564972D5DC96600E51059 /* POSShadowStyle.swift */,
71627165
);
71637166
path = Utils;
71647167
sourceTree = "<group>";
@@ -16994,6 +16997,7 @@
1699416997
26C98F9829C1247000F96503 /* WPComSitePlan+FreeTrial.swift in Sources */,
1699516998
3120491726DD807900A4EC4F /* LabelAndButtonTableViewCell.swift in Sources */,
1699616999
024DF31423742B7A006658FE /* AztecUnderlineFormatBarCommand.swift in Sources */,
17000+
020564982D5DC96600E51059 /* POSShadowStyle.swift in Sources */,
1699717001
CE32B10D20BEDE1C006FBCF4 /* TwoColumnSectionHeaderView.swift in Sources */,
1699817002
AE7C957D27C3F187007E8E12 /* FeeOrDiscountLineDetailsViewModel.swift in Sources */,
1699917003
4520A15C2721B2A9001FA573 /* FilterOrderListViewModel.swift in Sources */,

0 commit comments

Comments
 (0)