Sha256: 04be84225aa425afeca98f0084ed518c07f2b8132c9adb221d691544bea22410

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

module Components::TableHelper
  def render_table(caption = nil, **options, &block)
    content_tag :table, options.merge(
      class: tw("w-full text-sm border-b", 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

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

  def table_header(content = nil, **options, &block)
    content_tag :th, options.merge(
      class: tw("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0", options[:class])
    ) do
      if block
        capture(&block)
      else
        content
      end
    end
  end

  def table_body(**options, &block)
    content_tag :tbody, class: options.merge(
      class: tw("[&_tr:last-child]:border-0", options[:class])
    ), &block
  end

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

  def table_column(content = nil, **options, &block)
    content_tag :td, options.merge(
      class: tw("p-4 align-middle [&:has([role=checkbox])]:pr-0 font-medium", options[:class])
    ) do
      if block
        capture(&block)
      else
        content
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shadcn-ui-0.0.15 app/helpers/components/table_helper.rb
shadcn-ui-0.0.14 app/helpers/components/table_helper.rb