Class: Shadcn::ModeSwitcher::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::ModeSwitcher::Component
- Defined in:
- app/components/shadcn/mode_switcher/component.rb
Overview
Port of apps/v4/components/mode-switcher.tsx — the single button used in shadcn's own site header, which flips straight between light and dark rather than offering the three-way menu.
The icon is the same half-filled circle upstream draws inline.
Constant Summary collapse
- ICON =
%(<path stroke="none" d="M0 0h24v24H0z" fill="none"/>) + %(<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0"/>) + %(<path d="M12 3l0 18"/><path d="M12 9l4.65 -4.65"/>) + %(<path d="M12 14.3l7.37 -7.37"/><path d="M12 19.6l8.85 -8.85"/>)
- ICON_ATTRIBUTES =
{ "xmlns" => "http://www.w3.org/2000/svg", "width" => "24", "height" => "24", "viewBox" => "0 0 24 24", "fill" => "none", "stroke" => "currentColor", "stroke-width" => "2", "stroke-linecap" => "round", "stroke-linejoin" => "round", "class" => "size-4.5" }.freeze
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(variant: :ghost, **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(variant: :ghost, **attributes) ⇒ Component
Returns a new instance of Component.
33 34 35 36 |
# File 'app/components/shadcn/mode_switcher/component.rb', line 33 def initialize(variant: :ghost, **attributes) @variant = variant&.to_sym || :ghost super(**attributes) end |
Instance Attribute Details
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
31 32 33 |
# File 'app/components/shadcn/mode_switcher/component.rb', line 31 def variant @variant end |
Instance Method Details
#call ⇒ Object
45 46 47 |
# File 'app/components/shadcn/mode_switcher/component.rb', line 45 def call render_element(body: ) end |
#element_attributes(**defaults) ⇒ Object
38 39 40 41 42 43 |
# File 'app/components/shadcn/mode_switcher/component.rb', line 38 def element_attributes(**defaults) super(**{ style: merged_style(CONTENTS_STYLE), "data-controller" => "shadcn--theme" }.merge(defaults)) end |