From 40c2869d473b8a3fee390e652dd805412ac914c9 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Sat, 14 Sep 2024 22:59:21 -0700 Subject: [PATCH] Add gridCellRows modifier. (#197) Part of https://github.com/jverkoey/slipstream/issues/51. --- .../SlipstreamForTailwindCSSDevelopers.md | 2 +- .../FlexboxAndGrid-GridRowStartEnd.md | 14 ++++++++++ .../FlexboxAndGrid/View+gridCellRows.swift | 27 +++++++++++++++++++ .../FlexboxAndGrid/GridCellRowsTests.swift | 14 ++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 Sources/Slipstream/Documentation.docc/TailwindCSS/FlexboxAndGrid/FlexboxAndGrid-GridRowStartEnd.md create mode 100644 Sources/Slipstream/TailwindCSS/FlexboxAndGrid/View+gridCellRows.swift create mode 100644 Tests/SlipstreamTests/TailwindCSS/FlexboxAndGrid/GridCellRowsTests.swift diff --git a/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForTailwindCSSDevelopers.md b/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForTailwindCSSDevelopers.md index d086eac..fca6554 100644 --- a/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForTailwindCSSDevelopers.md +++ b/Sources/Slipstream/Documentation.docc/Guides/SlipstreamForTailwindCSSDevelopers.md @@ -46,7 +46,7 @@ Tailwind utility | Slipstream modifier [Grid Template Columns](https://tailwindcss.com/docs/grid-template-columns) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51) [Grid Column Start / End](https://tailwindcss.com/docs/grid-column) | ``View/gridCellColumns(_:condition:)``, ``View/gridCellColumns(_:condition:)-2tedw`` [Grid Template Rows](https://tailwindcss.com/docs/grid-template-rows) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51) -[Grid Row Start / End](https://tailwindcss.com/docs/grid-row) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51) +[Grid Row Start / End](https://tailwindcss.com/docs/grid-row) | ``View/gridCellRows(_:condition:)``, ``View/gridCellRows(_:condition:)-75orh`` [Grid Auto Flow](https://tailwindcss.com/docs/grid-auto-flow) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51) [Grid Auto Columns](https://tailwindcss.com/docs/grid-auto-columns) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51) [Grid Auto Rows](https://tailwindcss.com/docs/grid-auto-rows) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51) diff --git a/Sources/Slipstream/Documentation.docc/TailwindCSS/FlexboxAndGrid/FlexboxAndGrid-GridRowStartEnd.md b/Sources/Slipstream/Documentation.docc/TailwindCSS/FlexboxAndGrid/FlexboxAndGrid-GridRowStartEnd.md new file mode 100644 index 0000000..a70e3ac --- /dev/null +++ b/Sources/Slipstream/Documentation.docc/TailwindCSS/FlexboxAndGrid/FlexboxAndGrid-GridRowStartEnd.md @@ -0,0 +1,14 @@ +# Grid column start / end + +Utilities for controlling how views are sized and placed across grid columns. + +## Topics + +### Modifiers + +- ``View/gridCellRows(_:condition:)`` +- ``View/gridCellRows(_:condition:)-75orh`` + +### Supporting types + +- ``GridSpan`` diff --git a/Sources/Slipstream/TailwindCSS/FlexboxAndGrid/View+gridCellRows.swift b/Sources/Slipstream/TailwindCSS/FlexboxAndGrid/View+gridCellRows.swift new file mode 100644 index 0000000..e622a33 --- /dev/null +++ b/Sources/Slipstream/TailwindCSS/FlexboxAndGrid/View+gridCellRows.swift @@ -0,0 +1,27 @@ +extension View { + /// Tells a view that acts as a cell in a grid to span the specified number of rows. + /// + /// - SeeAlso: Tailwind CSS' [grid-row](https://tailwindcss.com/docs/grid-row) documentation. + @available(iOS 17.0, macOS 14.0, *) + public func gridCellRows(_ count: Int, condition: Condition? = nil) -> some View { + return modifier( + TailwindClassModifier( + add: "row-span-\(count)", + condition: condition + ) + ) + } + + /// Tells a view that acts as a cell in a grid to span the specified number of rows. + /// + /// - SeeAlso: Tailwind CSS' [grid-row](https://tailwindcss.com/docs/grid-row) documentation. + @available(iOS 17.0, macOS 14.0, *) + public func gridCellRows(_ span: GridSpan, condition: Condition? = nil) -> some View { + return modifier( + TailwindClassModifier( + add: "row-span-" + span.rawValue, + condition: condition + ) + ) + } +} diff --git a/Tests/SlipstreamTests/TailwindCSS/FlexboxAndGrid/GridCellRowsTests.swift b/Tests/SlipstreamTests/TailwindCSS/FlexboxAndGrid/GridCellRowsTests.swift new file mode 100644 index 0000000..8117c22 --- /dev/null +++ b/Tests/SlipstreamTests/TailwindCSS/FlexboxAndGrid/GridCellRowsTests.swift @@ -0,0 +1,14 @@ +import Testing +import Slipstream + +struct GridCellRowsTests { + @Test func rows() throws { + try #expect(renderHTML(Div {}.gridCellRows(1)) == #"
"#) + try #expect(renderHTML(Div {}.gridCellRows(2)) == #"
"#) + try #expect(renderHTML(Div {}.gridCellRows(3)) == #"
"#) + try #expect(renderHTML(Div {}.gridCellRows(4)) == #"
"#) + try #expect(renderHTML(Div {}.gridCellRows(5)) == #"
"#) + try #expect(renderHTML(Div {}.gridCellRows(6)) == #"
"#) + try #expect(renderHTML(Div {}.gridCellRows(.full)) == #"
"#) + } +}