-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #51.
- Loading branch information
Showing
5 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...entation.docc/Views/TailwindCSS/FlexboxAndGrid/FlexboxAndGrid-JustifyContent.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Justify content | ||
|
||
Utilities for controlling how flex and grid views are positioned along a container's main axis. | ||
|
||
## Topics | ||
|
||
### Modifiers | ||
|
||
- ``View/justifyContent(_:condition:)`` | ||
|
||
### Supporting types | ||
|
||
- ``JustifyContent`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
Sources/Slipstream/TailwindCSS/FlexboxAndGrid/View+justifyContent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/// Constants that specify how flex and grid views are positioned along a container's main axis. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [`font-size`](https://tailwindcss.com/docs/font-size) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public enum JustifyContent: String { | ||
/// Packs content items in their default position as if no | ||
/// justify-content value was set. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌──────────────────────────────────────────────┐ | ||
/// │ ┌─┐ ┌─┐ ┌─┐ │ | ||
/// │ └─┘ └─┘ └─┘ │ | ||
/// └──────────────────────────────────────────────┘ | ||
/// ``` | ||
case normal | ||
|
||
/// Justifies items against the start of the container’s main axis. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌─────────────────────────────────────────────┐ | ||
/// │ ┌─┐ ┌─┐ ┌─┐ │ | ||
/// │ └─┘ └─┘ └─┘ │ | ||
/// └─────────────────────────────────────────────┘ | ||
/// ``` | ||
case start | ||
|
||
/// Justifies items against the end of the container’s main axis. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌─────────────────────────────────────────────┐ | ||
/// │ ┌─┐ ┌─┐ ┌─┐ │ | ||
/// │ └─┘ └─┘ └─┘ │ | ||
/// └─────────────────────────────────────────────┘ | ||
/// ``` | ||
case end | ||
|
||
/// Justifies items against the center of the container’s main axis. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌─────────────────────────────────────────────┐ | ||
/// │ ┌─┐ ┌─┐ ┌─┐ │ | ||
/// │ └─┘ └─┘ └─┘ │ | ||
/// └─────────────────────────────────────────────┘ | ||
/// ``` | ||
case center | ||
|
||
/// Justifies items along the container’s main axis such that there | ||
/// is an equal amount of space between each item. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌─────────────────────────────────────────────┐ | ||
/// │ ┌─┐ ┌─┐ ┌─┐ │ | ||
/// │ └─┘ └─┘ └─┘ │ | ||
/// └─────────────────────────────────────────────┘ | ||
/// ``` | ||
case between | ||
|
||
/// Justifies items along the container’s main axis such that there | ||
/// is an equal amount of space on each side of each item. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌─────────────────────────────────────────────┐ | ||
/// │ ┌─┐ ┌─┐ ┌─┐ │ | ||
/// │ └─┘ └─┘ └─┘ │ | ||
/// └─────────────────────────────────────────────┘ | ||
/// ``` | ||
case around | ||
|
||
/// Justifies items along the container’s main axis such that there | ||
/// is an equal amount of space around each item, but also | ||
/// accounting for the doubling of space you would normally see | ||
/// between each item when using ``JustifyContent/around``. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌─────────────────────────────────────────────┐ | ||
/// │ ┌─┐ ┌─┐ ┌─┐ │ | ||
/// │ └─┘ └─┘ └─┘ │ | ||
/// └─────────────────────────────────────────────┘ | ||
/// ``` | ||
case evenly | ||
|
||
/// Allows content items to fill the available space along the | ||
/// container’s main axis. | ||
/// | ||
/// When along the x-axis: | ||
/// | ||
/// ``` | ||
/// ┌───────────────────────────────────────────┐ | ||
/// │ ┌───────────┐ ┌───────────┐ ┌───────────┐ │ | ||
/// │ └───────────┘ └───────────┘ └───────────┘ │ | ||
/// └───────────────────────────────────────────┘ | ||
/// ``` | ||
case stretch | ||
} | ||
|
||
extension View { | ||
/// Controls how flex and grid views are positioned along a container's main axis. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [`justify content`](https://tailwindcss.com/docs/justify-content) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public func justifyContent(_ justifyContent: JustifyContent, condition: Condition? = nil) -> some View { | ||
return modifier(TailwindClassModifier(add: "justify-" + justifyContent.rawValue, condition: condition)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Tests/SlipstreamTests/TailwindCSS/FlexboxAndGrid/JustifyContentTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Testing | ||
import Slipstream | ||
|
||
struct JustifyContentTests { | ||
@Test func enumeration() throws { | ||
try #expect(renderHTML(Div {}.justifyContent(.normal)) == #"<div class="justify-normal"></div>"#) | ||
try #expect(renderHTML(Div {}.justifyContent(.start)) == #"<div class="justify-start"></div>"#) | ||
try #expect(renderHTML(Div {}.justifyContent(.end)) == #"<div class="justify-end"></div>"#) | ||
try #expect(renderHTML(Div {}.justifyContent(.center)) == #"<div class="justify-center"></div>"#) | ||
try #expect(renderHTML(Div {}.justifyContent(.between)) == #"<div class="justify-between"></div>"#) | ||
try #expect(renderHTML(Div {}.justifyContent(.around)) == #"<div class="justify-around"></div>"#) | ||
try #expect(renderHTML(Div {}.justifyContent(.evenly)) == #"<div class="justify-evenly"></div>"#) | ||
try #expect(renderHTML(Div {}.justifyContent(.stretch)) == #"<div class="justify-stretch"></div>"#) | ||
} | ||
} |