Class: Shadcn::ThemeSelector::Component
- Inherits:
-
ApplicationViewComponent
- Object
- ViewComponent::Base
- ApplicationViewComponent
- Shadcn::ThemeSelector::Component
- Defined in:
- app/components/shadcn/theme_selector/component.rb
Overview
Port of apps/v4/components/theme-selector.tsx — the select that swaps the colour palette.
In React this reads useThemeConfig(); here each option hands its value
to the shadcn--theme Stimulus controller, which swaps the theme-*
class the way shadcn's ActiveThemeProvider does.
Constant Summary
Constants inherited from ApplicationViewComponent
ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS
Instance Attribute Summary collapse
-
#themes ⇒ Object
readonly
Returns the value of attribute themes.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(themes: ShadcnViewComponent::Themes::BASE_COLORS, value: ShadcnViewComponent::Themes::DEFAULT, label: nil, **attributes) ⇒ Component
constructor
A new instance of Component.
- #label ⇒ Object
- #label_id ⇒ Object
Methods inherited from ApplicationViewComponent
#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name
Constructor Details
#initialize(themes: ShadcnViewComponent::Themes::BASE_COLORS, value: ShadcnViewComponent::Themes::DEFAULT, label: nil, **attributes) ⇒ Component
Returns a new instance of Component.
22 23 24 25 26 27 28 29 30 |
# File 'app/components/shadcn/theme_selector/component.rb', line 22 def initialize(themes: ShadcnViewComponent::Themes::BASE_COLORS, value: ShadcnViewComponent::Themes::DEFAULT, label: nil, **attributes) @themes = themes @value = value.to_s @label = label super(**attributes) end |
Instance Attribute Details
#themes ⇒ Object (readonly)
Returns the value of attribute themes.
18 19 20 |
# File 'app/components/shadcn/theme_selector/component.rb', line 18 def themes @themes end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
18 19 20 |
# File 'app/components/shadcn/theme_selector/component.rb', line 18 def value @value end |
Instance Method Details
#call ⇒ Object
44 45 46 |
# File 'app/components/shadcn/theme_selector/component.rb', line 44 def call render_element(body: safe_join([ hidden_label, select ])) end |
#element_attributes(**defaults) ⇒ Object
40 41 42 |
# File 'app/components/shadcn/theme_selector/component.rb', line 40 def element_attributes(**defaults) super(**{ "data-controller" => "shadcn--theme" }.merge(defaults)) end |
#label ⇒ Object
32 33 34 |
# File 'app/components/shadcn/theme_selector/component.rb', line 32 def label @label || shadcn_t("theme.label") end |
#label_id ⇒ Object
36 37 38 |
# File 'app/components/shadcn/theme_selector/component.rb', line 36 def label_id @label_id ||= "shadcn-theme-selector-#{SecureRandom.hex(4)}" end |