Skip to content

Commit

Permalink
Add gridCellColumns modifier. (#196)
Browse files Browse the repository at this point in the history
Part of #51.
  • Loading branch information
jverkoey authored Sep 15, 2024
1 parent 4497642 commit 0452b87
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Tailwind utility | Slipstream modifier
[Flex Shrink](https://tailwindcss.com/docs/flex-shrink) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[Order](https://tailwindcss.com/docs/order) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
[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) | [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 Auto Flow](https://tailwindcss.com/docs/grid-auto-flow) | [Not implemented yet](https://github.com/jverkoey/slipstream/issues/51)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Grid column start / end

Utilities for controlling how views are sized and placed across grid columns.

## Topics

### Modifiers

- ``View/gridCellColumns(_:condition:)``
- ``View/gridCellColumns(_:condition:)-2tedw``

### Supporting types

- ``GridSpan``
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extension View {
/// Tells a view that acts as a cell in a grid to span the specified number of columns.
///
/// - SeeAlso: Tailwind CSS' [grid-column](https://tailwindcss.com/docs/grid-column) documentation.
@available(iOS 17.0, macOS 14.0, *)
public func gridCellColumns(_ count: Int, condition: Condition? = nil) -> some View {
return modifier(
TailwindClassModifier(
add: "col-span-\(count)",
condition: condition
)
)
}

/// Tells a view that acts as a cell in a grid to span the specified number of columns.
///
/// - SeeAlso: Tailwind CSS' [grid-column](https://tailwindcss.com/docs/grid-column) documentation.
@available(iOS 17.0, macOS 14.0, *)
public func gridCellColumns(_ span: GridSpan, condition: Condition? = nil) -> some View {
return modifier(
TailwindClassModifier(
add: "col-span-" + span.rawValue,
condition: condition
)
)
}
}
5 changes: 5 additions & 0 deletions Sources/Slipstream/TailwindCSS/GridSpan.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// A generic representation of a span in a grid.
@available(iOS 17.0, macOS 14.0, *)
public enum GridSpan: String {
case full
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Testing
import Slipstream

struct GridCellColumnsTests {
@Test func columns() throws {
try #expect(renderHTML(Div {}.gridCellColumns(1)) == #"<div class="col-span-1"></div>"#)
try #expect(renderHTML(Div {}.gridCellColumns(2)) == #"<div class="col-span-2"></div>"#)
try #expect(renderHTML(Div {}.gridCellColumns(3)) == #"<div class="col-span-3"></div>"#)
try #expect(renderHTML(Div {}.gridCellColumns(4)) == #"<div class="col-span-4"></div>"#)
try #expect(renderHTML(Div {}.gridCellColumns(5)) == #"<div class="col-span-5"></div>"#)
try #expect(renderHTML(Div {}.gridCellColumns(6)) == #"<div class="col-span-6"></div>"#)
try #expect(renderHTML(Div {}.gridCellColumns(.full)) == #"<div class="col-span-full"></div>"#)
}
}

0 comments on commit 0452b87

Please sign in to comment.