-
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
6 changed files
with
69 additions
and
1 deletion.
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
5 changes: 5 additions & 0 deletions
5
Sources/Slipstream/Documentation.docc/Views/TailwindCSS/fontSize.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,5 @@ | ||
# ```View/fontSize(_:)``` | ||
|
||
## Topics | ||
|
||
- ``FontSize`` |
33 changes: 33 additions & 0 deletions
33
Sources/Slipstream/TailwindCSS/Typography/View+fontSize.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,33 @@ | ||
/// Constants that specify the size of the text. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [`font-size`](https://tailwindcss.com/docs/font-size) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public enum FontSize: String { | ||
case extraSmall = "xs" | ||
case small = "sm" | ||
/// The default document font size. | ||
case base = "base" | ||
case large = "lg" | ||
case extraLarge = "xl" | ||
case extraExtraLarge = "2xl" | ||
case extraExtraExtraLarge = "3xl" | ||
case fourXLarge = "4xl" | ||
case fiveXLarge = "5xl" | ||
case sixXLarge = "6xl" | ||
case sevenXLarge = "7xl" | ||
case eightXLarge = "8xl" | ||
case nineXLarge = "9xl" | ||
} | ||
|
||
extension View { | ||
/// Set the font size. | ||
/// | ||
/// - Parameter fontSize: The font size to apply to the modified view. | ||
/// | ||
/// - SeeAlso: Tailwind CSS' [`font-size`](https://tailwindcss.com/docs/font-size) documentation. | ||
@available(iOS 17.0, macOS 14.0, *) | ||
public func fontSize(_ fontSize: FontSize) -> some View { | ||
return self.modifier(ClassModifier(add: "text-" + fontSize.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Testing | ||
|
||
import Slipstream | ||
|
||
struct FontSizeTests { | ||
@Test func alignments() throws { | ||
try #expect(renderHTML(Div {}.fontSize(.extraSmall)) == #"<div class="text-xs"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.small)) == #"<div class="text-sm"></div>"#) | ||
|
||
try #expect(renderHTML(Div {}.fontSize(.extraSmall)) == #"<div class="text-xs"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.small)) == #"<div class="text-sm"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.base)) == #"<div class="text-base"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.large)) == #"<div class="text-lg"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.extraLarge)) == #"<div class="text-xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.extraExtraLarge)) == #"<div class="text-2xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.extraExtraExtraLarge)) == #"<div class="text-3xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.fourXLarge)) == #"<div class="text-4xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.fiveXLarge)) == #"<div class="text-5xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.sixXLarge)) == #"<div class="text-6xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.sevenXLarge)) == #"<div class="text-7xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.eightXLarge)) == #"<div class="text-8xl"></div>"#) | ||
try #expect(renderHTML(Div {}.fontSize(.nineXLarge)) == #"<div class="text-9xl"></div>"#) | ||
} | ||
} |