Skip to content

Commit

Permalink
Add support for shadow modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
literalpie committed Jan 17, 2021
1 parent e893e7a commit ccad5fb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sources/TokamakCore/Modifiers/Shadow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public struct _ShadowLayout: ViewModifier {
public var color: Color
public var radius: CGFloat
public var x: CGFloat
public var y: CGFloat

public func body(content: Content) -> some View {
content
}
}

public extension View {
func shadow(
color: Color = Color(.sRGBLinear, white: 0, opacity: 0.33),
radius: CGFloat,
x: CGFloat = 0,
y: CGFloat = 0
) -> some View {
modifier(_ShadowLayout(color: color, radius: radius, x: x, y: y))
}
}
8 changes: 8 additions & 0 deletions Sources/TokamakDemo/ShadowDemo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import TokamakShim

struct ShadowDemo: View {
var body: some View {
Color.red.frame(width: 60, height: 60, alignment: .center)
.shadow(color: .black, radius: 5, x: 10, y: 10)
}
}
3 changes: 3 additions & 0 deletions Sources/TokamakDemo/TokamakDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ struct TokamakDemoView: View {
}.padding(20))
NavItem("GeometryReader", destination: GeometryReaderDemo())
}
Section(header: Text("Modifiers")) {
NavItem("Shadow", destination: ShadowDemo())
}
Section(header: Text("Selectors")) {
NavItem("Picker", destination: PickerDemo())
NavItem("Slider", destination: SliderDemo())
Expand Down
8 changes: 8 additions & 0 deletions Sources/TokamakStaticHTML/Modifiers/LayoutModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@ extension _PaddingLayout: DOMViewModifier {
.joined(separator: " ")]
}
}

extension _ShadowLayout: DOMViewModifier {
public var attributes: [HTMLAttribute: String] {
["style": "box-shadow: \(x)px \(y)px \(radius)px 0px \(color.cssValue(.defaultEnvironment));"]
}

public var isOrderDependent: Bool { true }
}

0 comments on commit ccad5fb

Please sign in to comment.