Skip to content

Commit

Permalink
Add ability to specify custom shadow names.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Sep 15, 2024
1 parent dabde3f commit 4ee9c6d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Sources/Slipstream/TailwindCSS/Effects/View+shadow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ extension View {
return modifier(TailwindClassModifier(add: Set(classNames), condition: condition))
}

/// Sets the shadow of the view to a specific name.
///
/// To use custom colors, add them to your tailwind.config.js `theme.extend.colors` property:
///
/// ```js
/// theme: {
/// extend: {
/// boxShadow: {
/// 'puck': '0 0 4px 0 #0003,0 2px 0 0 #0000001a'
/// },
/// }
/// }
/// ```
///
/// - SeeAlso: Tailwind CSS' [box shadow](https://tailwindcss.com/docs/box-shadow) documentation.
/// - SeeAlso: Tailwind CSS' [box shadow color](https://tailwindcss.com/docs/box-shadow-color) documentation.
@available(iOS 17.0, macOS 14.0, *)
public func shadow(_ shadow: String, condition: Condition? = nil) -> some View {
return modifier(TailwindClassModifier(add: "shadow-" + shadow, condition: condition))
}

/// Maps a shadow radius to the closest Tailwind CSS shadow class.
///
/// - Parameter radius: The radius in points to be mapped.
Expand Down
4 changes: 4 additions & 0 deletions Tests/SlipstreamTests/TailwindCSS/Effects/ShadowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ struct ShadowTests {
try #expect(renderHTML(Div {}.shadow(radius: 10)) == #"<div class="shadow-md"></div>"#)
try #expect(renderHTML(Div {}.shadow(radius: 100)) == #"<div class="shadow-2xl"></div>"#)
}

@Test func customName() throws {
try #expect(renderHTML(Div {}.shadow("puck")) == #"<div class="shadow-puck"></div>"#)
}
}

0 comments on commit 4ee9c6d

Please sign in to comment.