Class: ShadcnPhlexcomponents::SheetContent

Inherits:
Base
  • Object
show all
Defined in:
lib/shadcn_phlexcomponents/components/sheet.rb

Constant Summary

Constants inherited from Base

Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER

Instance Method Summary collapse

Methods inherited from Base

#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child

Constructor Details

#initialize(side: :right, aria_id: nil, **attributes) ⇒ SheetContent

Returns a new instance of SheetContent.



130
131
132
133
134
# File 'lib/shadcn_phlexcomponents/components/sheet.rb', line 130

def initialize(side: :right, aria_id: nil, **attributes)
  @class_variants = { side: side }
  @aria_id = aria_id
  super(**attributes)
end

Instance Method Details

#default_attributesObject



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/shadcn_phlexcomponents/components/sheet.rb', line 154

def default_attributes
  {
    id: "#{@aria_id}-content",
    tabindex: -1,
    role: "dialog",
    aria: {
      describedby: "#{@aria_id}-description",
      labelledby: "#{@aria_id}-title",
    },
    data: {
      state: "closed",
      dialog_target: "content",
    },
  }
end

#view_templateObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/shadcn_phlexcomponents/components/sheet.rb', line 136

def view_template(&)
  div(style: { display: "none" }, **@attributes) do
    yield

    button(
      class: <<~HEREDOC,
        ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs
        opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden
        disabled:pointer-events-none
      HEREDOC
      data: { action: "click->dialog#close" },
    ) do
      icon("x", class: "size-4")
      span(class: "sr-only") { "close" }
    end
  end
end