Module: WildayUi::Components::Button::FeatureEngine
- Includes:
- WildayUi::Components::Button::Features::Animation, WildayUi::Components::Button::Features::ConfirmDialog, WildayUi::Components::Button::Features::CopyToClipboard, WildayUi::Components::Button::Features::Dropdown, WildayUi::Components::Button::Features::Loading, WildayUi::Components::Button::Features::Tooltip
- Included in:
- ButtonHelper
- Defined in:
- app/helpers/wilday_ui/components/button/feature_engine.rb
Constant Summary collapse
- BUTTON_FEATURES =
begin {} .merge(Features::Loading.feature_config) .merge(Features::Tooltip.feature_config) .merge(Features::Dropdown.feature_config) .merge(Features::CopyToClipboard.feature_config) .merge(Features::ConfirmDialog.feature_config) .merge(Features::Animation.feature_config) .freeze end
Constants included from WildayUi::Components::Button::Features::Animation
WildayUi::Components::Button::Features::Animation::FEATURE_CONFIG
Constants included from WildayUi::Components::Button::Features::Tooltip
WildayUi::Components::Button::Features::Tooltip::FEATURE_CONFIG
Constants included from WildayUi::Components::Button::Features::ConfirmDialog
WildayUi::Components::Button::Features::ConfirmDialog::FEATURE_CONFIG
Constants included from WildayUi::Components::Button::Features::CopyToClipboard
WildayUi::Components::Button::Features::CopyToClipboard::FEATURE_CONFIG
Constants included from WildayUi::Components::Button::Features::Dropdown
WildayUi::Components::Button::Features::Dropdown::FEATURE_CONFIG
Constants included from WildayUi::Components::Button::Features::Loading
WildayUi::Components::Button::Features::Loading::FEATURE_CONFIG
Class Method Summary collapse
Instance Method Summary collapse
- #determine_active_features(loading, dropdown, loading_text = nil, copy_to_clipboard = nil, confirm = nil, tooltip = nil, animation = nil, use_default_controller = true) ⇒ Object
- #setup_feature_controller(options, feature_config) ⇒ Object
- #setup_features(active_features, options, use_default_controller) ⇒ Object
Methods included from WildayUi::Components::Button::Features::Animation
feature_config, #setup_animation_options
Methods included from WildayUi::Components::Button::Features::Tooltip
feature_config, #setup_tooltip_options
Methods included from WildayUi::Components::Button::Features::ConfirmDialog
feature_config, #normalize_confirmation_options, #setup_confirmation_options
Methods included from WildayUi::Components::Button::Features::CopyToClipboard
feature_config, #setup_clipboard_options
Methods included from WildayUi::Components::Button::Features::Dropdown
feature_config, #setup_dropdown_options
Methods included from WildayUi::Components::Button::Features::Loading
feature_config, #setup_loading_data_attributes, #setup_loading_options
Class Method Details
.button_features ⇒ Object
23 24 25 |
# File 'app/helpers/wilday_ui/components/button/feature_engine.rb', line 23 def self. BUTTON_FEATURES end |
Instance Method Details
#determine_active_features(loading, dropdown, loading_text = nil, copy_to_clipboard = nil, confirm = nil, tooltip = nil, animation = nil, use_default_controller = true) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/wilday_ui/components/button/feature_engine.rb', line 27 def determine_active_features(loading, dropdown, loading_text = nil, copy_to_clipboard = nil, confirm = nil, tooltip = nil, animation = nil, use_default_controller = true) features = {} features[:loading] = true if (loading || loading_text.present?) && use_default_controller features[:dropdown] = true if dropdown && use_default_controller features[:copy_to_clipboard] = true if copy_to_clipboard.present? && use_default_controller features[:confirm] = true if confirm.present? && use_default_controller features[:tooltip] = true if tooltip.present? && use_default_controller features[:animation] = true if animation.present? && use_default_controller features end |
#setup_feature_controller(options, feature_config) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/wilday_ui/components/button/feature_engine.rb', line 55 def setup_feature_controller(, feature_config) [:data] ||= {} existing_controller = .dig(:data, :controller) existing_action = .dig(:data, :action) [:data][:controller] = [ existing_controller, feature_config[:stimulus_controller] ].compact.join(" ") [:data][:action] = [ existing_action, feature_config[:default_stimulus_action] ].compact.join(" ") end |
#setup_features(active_features, options, use_default_controller) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/wilday_ui/components/button/feature_engine.rb', line 38 def setup_features(active_features, , use_default_controller) return unless use_default_controller && active_features.any? active_features.each do |feature, _value| feature_config = BUTTON_FEATURES[feature] next unless feature_config # Skip adding controller for dropdown feature since it's handled by wrapper if feature_config[:wrapper_required] # For dropdown, only set the action, not the controller [:data][:action] = feature_config[:default_stimulus_action] else setup_feature_controller(, feature_config) end end end |