Class: Shadcn::Carousel::Previous::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::Carousel::Previous::Component
- Defined in:
- app/components/shadcn/carousel/previous/component.rb
Overview
CarouselPrevious — the button's own variants, as pagination-link takes
them: upstream renders a <Button variant="outline" size="icon"> and
adds its placement on top, so the classes come from
Button.variant_classes rather than from a style block of this
component's own. Redefining style here would replace the button's
base rather than add to it, which is a round control with no round.
Constant Summary collapse
- PLACEMENT =
{ horizontal: "top-1/2 -left-12 -translate-y-1/2", vertical: "-top-12 left-1/2 -translate-x-1/2 rotate-90" }.freeze
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#orientation ⇒ Object
readonly
Returns the value of attribute orientation.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #css_classes(extra = nil) ⇒ Object
-
#element_attributes(**defaults) ⇒ Object
Disabled until the controller says otherwise: at rest a carousel is at one end, and which end has room is a question about a viewport the server has never measured.
-
#initialize(orientation: :horizontal, variant: :outline, size: :icon, **attributes) ⇒ Component
constructor
A new instance of Component.
Methods inherited from ApplicationViewComponent
default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(orientation: :horizontal, variant: :outline, size: :icon, **attributes) ⇒ Component
Returns a new instance of Component.
23 24 25 26 27 28 |
# File 'app/components/shadcn/carousel/previous/component.rb', line 23 def initialize(orientation: :horizontal, variant: :outline, size: :icon, **attributes) @orientation = orientation&.to_sym == :vertical ? :vertical : :horizontal @variant = variant&.to_sym || :outline @size = size&.to_sym || :icon super(**attributes) end |
Instance Attribute Details
#orientation ⇒ Object (readonly)
Returns the value of attribute orientation.
21 22 23 |
# File 'app/components/shadcn/carousel/previous/component.rb', line 21 def orientation @orientation end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
21 22 23 |
# File 'app/components/shadcn/carousel/previous/component.rb', line 21 def size @size end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
21 22 23 |
# File 'app/components/shadcn/carousel/previous/component.rb', line 21 def variant @variant end |
Instance Method Details
#call ⇒ Object
50 51 52 53 54 55 |
# File 'app/components/shadcn/carousel/previous/component.rb', line 50 def call render_element(body: safe_join([ render(Icon::Component.new("arrow-left")), tag.span(shadcn_t("carousel.previous"), class: "sr-only") ])) end |
#css_classes(extra = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/components/shadcn/carousel/previous/component.rb', line 42 def css_classes(extra = nil) Button::Component.variant_classes( variant:, size:, class: [ "absolute size-8 rounded-full", PLACEMENT.fetch(orientation), extra ].compact.join(" ") ) end |
#element_attributes(**defaults) ⇒ Object
Disabled until the controller says otherwise: at rest a carousel is at one end, and which end has room is a question about a viewport the server has never measured.
33 34 35 36 37 38 39 40 |
# File 'app/components/shadcn/carousel/previous/component.rb', line 33 def element_attributes(**defaults) super(**{ type: "button", disabled: true, "data-shadcn--carousel-target" => "previous", "data-action" => "click->shadcn--carousel#previous" }.merge(defaults)) end |