-
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
51 additions
and
3 deletions.
There are no files selected for viewing
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
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
27 changes: 27 additions & 0 deletions
27
Sources/Slipstream/TailwindCSS/Typography/View+textAlignment.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,27 @@ | ||
/// Constants that specify the visual alignment of the text. | ||
public enum TextAlignment: String { | ||
/// Aligns text to the left edge of the text container in | ||
/// left-to-right (LTR) languages, and to the right edge | ||
/// in right-to-left (RTL) languages.. | ||
case leading = "start" | ||
|
||
/// Aligns text to the center of the text container. | ||
case center | ||
|
||
/// Aligns text to the right edge of the text container in | ||
/// left-to-right (LTR) languages, and to the left edge | ||
/// in right-to-left (RTL) languages.. | ||
case trailing = "end" | ||
|
||
/// Text will fill the container, adding spacing between words as needed. | ||
case justify | ||
} | ||
|
||
extension View { | ||
/// Control the alignment of text. | ||
/// | ||
/// - Parameter alignment: Text alignment to be applied to text within the modified view. | ||
public func textAlignment(_ alignment: TextAlignment) -> some View { | ||
return self.modifier(ClassModifier(add: "text-" + alignment.rawValue)) | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
Tests/SlipstreamTests/Views/TailwindCSS/TextAlignmentTests.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,12 @@ | ||
import Testing | ||
|
||
import Slipstream | ||
|
||
struct TextAlignmentTests { | ||
@Test func alignments() throws { | ||
try #expect(renderHTML(Div {}.textAlignment(.leading)) == #"<div class="text-start"></div>"#) | ||
try #expect(renderHTML(Div {}.textAlignment(.center)) == #"<div class="text-center"></div>"#) | ||
try #expect(renderHTML(Div {}.textAlignment(.trailing)) == #"<div class="text-end"></div>"#) | ||
try #expect(renderHTML(Div {}.textAlignment(.justify)) == #"<div class="text-justify"></div>"#) | ||
} | ||
} |