Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the full suite of Tailwind CSS modifiers #51

Open
jverkoey opened this issue Aug 3, 2024 · 4 comments
Open

Implement the full suite of Tailwind CSS modifiers #51

jverkoey opened this issue Aug 3, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@jverkoey
Copy link
Collaborator

jverkoey commented Aug 3, 2024

Layout

Flexbox & Grid

Spacing

Sizing

Typography

Backgrounds

Borders

Effects

Filters

Tables

Transitions & Animation

Transforms

Interactivity

SVG

@jverkoey jverkoey added enhancement New feature or request good first issue Good for newcomers labels Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
@Avinashshiyani
Copy link

Can you specify More ? @jverkoey

@jverkoey
Copy link
Collaborator Author

jverkoey commented Aug 3, 2024

I'll be adding an example PR for some of these modifiers shortly :)

jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
@jverkoey
Copy link
Collaborator Author

jverkoey commented Aug 3, 2024

@Avinashshiyani #55 is a PR that adds support for Tailwind CSS' text-align classes.

The basic workflow behind adding support for each of the classes in this list is:

  1. Open the Tailwind CSS documentation page. In this case, text-align. Notice the grouping of this class under "Typography".
  2. Look at the different classes and match them to a SwiftUI equivalent. In this case, TextAlignment
  3. Add a new .swift file in Sources/Slipstream/TailwindCSS within the right sub-directory. For text-align, we want to put it in the Typography folder.
  4. Define a View modifier function. Most modifiers will look something like this:
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))
  }
}
  1. Define any enum types needed for the modifier. It's typically best to make the enum conform to the String type so that you can easily convert it to its string representation. In the text-align case, we created a TextAlignment enum like so:
/// 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
}
  1. Add an example of this modifier to Tests/SlipstreamTests/Sites/CatalogSiteTests.swift, which is meant to have an exhaustive catalog of all of Slipstream's views + modifiers.
  2. Add a unit test to Tests/SlipstreamTests. The text-align tests looked like this:
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>"#)
  }
}

jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
@jverkoey
Copy link
Collaborator Author

jverkoey commented Aug 3, 2024

@Avinashshiyani #60 might be an easier issue to take on because it requires fewer moving parts.

@jverkoey jverkoey removed the good first issue Good for newcomers label Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 3, 2024
jverkoey added a commit that referenced this issue Aug 10, 2024
jverkoey added a commit that referenced this issue Aug 10, 2024
jverkoey added a commit that referenced this issue Aug 10, 2024
jverkoey added a commit that referenced this issue Aug 10, 2024
jverkoey added a commit that referenced this issue Aug 10, 2024
jverkoey added a commit that referenced this issue Aug 10, 2024
jverkoey added a commit that referenced this issue Aug 10, 2024
@jverkoey jverkoey added this to the Full Tailwind CSS coverage milestone Aug 13, 2024
jverkoey added a commit that referenced this issue Sep 14, 2024
jverkoey added a commit that referenced this issue Sep 14, 2024
jverkoey added a commit that referenced this issue Sep 14, 2024
jverkoey added a commit that referenced this issue Sep 14, 2024
jverkoey added a commit that referenced this issue Sep 14, 2024
jverkoey added a commit that referenced this issue Sep 14, 2024
jverkoey added a commit that referenced this issue Sep 15, 2024
jverkoey added a commit that referenced this issue Sep 15, 2024
jverkoey added a commit that referenced this issue Sep 15, 2024
jverkoey added a commit that referenced this issue Sep 15, 2024
jverkoey added a commit that referenced this issue Sep 15, 2024
jverkoey added a commit that referenced this issue Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants