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

templ version #1

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

templ version #1

wants to merge 2 commits into from

Conversation

matthewmueller
Copy link
Owner

@matthewmueller matthewmueller commented Sep 4, 2024

a-h/templ#740

Input:

package view

templ Story(story *hackernews.Story) {
  <div class="story">
    <div>
      <a>
        { story.Title }
      </a>
      if story.URL  != "" {
        <a class="url" href={ templ.URL(story.URL) }>({ formatURL(story.URL) })</a>
      }
    </div>
    <div class="meta">
      { strconv.Itoa(story.Points) } points by { story.Author } • { " " }
      @Time(story.CreatedAt)
    </div>
    <style scoped>{`
      .story {
        background: red;
      }
      .url {
        text-transform: none;
      }
      .meta {
        padding: 10px;
      }
    `}</style>
  </div>
}

Output:

import Style from "styled-jsx";

package view

templ Story(story *hackernews.Story) {
  <div class="jsx-4GjC3K story">
    <div class="jsx-4GjC3K">
      <a class="jsx-4GjC3K">
        { story.Title }
      </a>
      if story.URL  != "" {
        <a class="jsx-4GjC3K url" href={ templ.URL(story.URL) }>({ formatURL(story.URL) })</a>
      }
    </div>
    <div class="jsx-4GjC3K meta">
      { strconv.Itoa(story.Points) } points by { story.Author } • { " " }
      @Time(story.CreatedAt)
    </div>
    <Style scoped id="jsx-4GjC3K">{`.story.jsx-4GjC3K { background: red }
.url.jsx-4GjC3K { text-transform: none }
.meta.jsx-4GjC3K { padding: 10px }`}</Style>
  </div>
}

Issues (so far):

  • Scoped CSS is not removed
  • import Style from "styled-jsx"; is invalid
  • No way in styledjsx yet to yank out the CSS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant