Class: Shadcn::Dialog::Content::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Dialog::Content::Component
- Defined in:
- app/components/shadcn/dialog/content/component.rb
Overview
DialogContent — renders its own overlay, as the TSX does, and the dismiss button in the corner unless asked not to.
Constant Summary collapse
- CLOSE_CLASSES =
"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background " \ "transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring " \ "focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none " \ "data-[state=open]:bg-accent data-[state=open]:text-muted-foreground " \ "[&_svg]:pointer-events-none [&_svg]:shrink-0 " \ "[&_svg:not([class*='size-'])]:size-4"
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#show_close_button ⇒ Object
readonly
Returns the value of attribute show_close_button.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
-
#call ⇒ Object
shadcn wraps the overlay and the content in a DialogPortal.
- #element_attributes(**defaults) ⇒ Object
-
#initialize(show_close_button: true, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(show_close_button: true, **attributes) ⇒ Component
Returns a new instance of Component.
34 35 36 37 |
# File 'app/components/shadcn/dialog/content/component.rb', line 34 def initialize(show_close_button: true, **attributes) @show_close_button = super(**attributes) end |
Instance Attribute Details
#show_close_button ⇒ Object (readonly)
Returns the value of attribute show_close_button.
32 33 34 |
# File 'app/components/shadcn/dialog/content/component.rb', line 32 def @show_close_button end |
Instance Method Details
#call ⇒ Object
shadcn wraps the overlay and the content in a DialogPortal. Radix
relocates that element to document.body; here it stays put (see
the shadcn--dialog controller for why) and is display: contents,
so it adds no box of its own.
54 55 56 57 58 59 60 61 |
# File 'app/components/shadcn/dialog/content/component.rb', line 54 def call tag.div("data-slot": "dialog-portal", style: CONTENTS_STYLE) do safe_join([ render(Overlay::Component.new), render_element(body: safe_join([ header, content, , ].compact)) ]) end end |
#element_attributes(**defaults) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'app/components/shadcn/dialog/content/component.rb', line 39 def element_attributes(**defaults) super(**{ role: "dialog", "aria-modal" => "true", tabindex: "-1", "data-state" => "closed", hidden: true, "data-shadcn--dialog-target" => "content" }.merge(defaults)) end |