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

Improve options parsing for all helper methods #32

Open
aviflombaum opened this issue Aug 24, 2023 · 1 comment
Open

Improve options parsing for all helper methods #32

aviflombaum opened this issue Aug 24, 2023 · 1 comment

Comments

@aviflombaum
Copy link
Owner

  def table_row(**options, &block)
    content_tag :tr,
      options.reverse_merge(
        class: tw("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", options[:class])
      ),
      & block
  end

By using reverse merge and passing in the entire options to the content tag (or to content tag to be used in partials), we can glob all things like data or aria or whatever else is passed into options correctly while still providing defaults, including merging tailwind classes with custom classes provided. As opposed to:

  def render_table(caption = nil, **options, &block)
    options[:class] = tw("w-full text-sm border-b", options[:class])
    content_tag :table, class: options[:class] do
      if caption.present?
        content_tag :caption, caption, class: "mt-4 text-sm text-muted-foreground " do
          capture(&block)
        end
      else
        capture(&block)
      end
    end
  end

Here by explicitly only handling the class of options, something like data: {controller:} would be missed.

@bibstha
Copy link
Collaborator

bibstha commented Jun 11, 2024

Shouldn't we use merge instead of the reverse_merge? The reverse_merge here introduces a but that I fixed in #67

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

No branches or pull requests

2 participants