Module: WildayUi::Components::Button::ButtonHelper

Includes:
FeatureEngine
Included in:
ApplicationHelper
Defined in:
app/helpers/wilday_ui/components/button/button_helper.rb

Constant Summary

Constants included from FeatureEngine

FeatureEngine::BUTTON_FEATURES

Constants included from Features::Animation

Features::Animation::FEATURE_CONFIG

Constants included from Features::Tooltip

Features::Tooltip::FEATURE_CONFIG

Constants included from Features::ConfirmDialog

Features::ConfirmDialog::FEATURE_CONFIG

Constants included from Features::CopyToClipboard

Features::CopyToClipboard::FEATURE_CONFIG

Constants included from Features::Dropdown

Features::Dropdown::FEATURE_CONFIG

Constants included from Features::Loading

Features::Loading::FEATURE_CONFIG

Instance Method Summary collapse

Methods included from FeatureEngine

button_features, #determine_active_features, #setup_feature_controller, #setup_features

Methods included from Features::Animation

feature_config, #setup_animation_options

Methods included from Features::Tooltip

feature_config, #setup_tooltip_options

Methods included from Features::ConfirmDialog

feature_config, #normalize_confirmation_options, #setup_confirmation_options

Methods included from Features::CopyToClipboard

feature_config, #setup_clipboard_options

Methods included from Features::Dropdown

feature_config, #setup_dropdown_options

Methods included from Features::Loading

feature_config, #setup_loading_data_attributes, #setup_loading_options

Instance Method Details

#w_button(content, variant: :solid, size: :medium, radius: :rounded, gradient: nil, icon: nil, icon_position: :left, icon_only: false, loading: false, loading_text: nil, disabled: false, additional_classes: "", use_default_controller: true, href: nil, method: :get, target: nil, underline: true, dropdown: false, dropdown_items: nil, dropdown_icon: nil, theme: nil, copy_to_clipboard: nil, confirm: nil, tooltip: nil, animation: nil, **options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/helpers/wilday_ui/components/button/button_helper.rb', line 7

def w_button(
  content,
  variant: :solid,
  size: :medium,
  radius: :rounded,
  gradient: nil,
  icon: nil,
  icon_position: :left,
  icon_only: false,
  loading: false,
  loading_text: nil,
  disabled: false,
  additional_classes: "",
  use_default_controller: true,
  href: nil,
  method: :get,
  target: nil,
  underline: true,
  dropdown: false,
  dropdown_items: nil,
  dropdown_icon: nil,
  theme: nil,
  copy_to_clipboard: nil,
  confirm: nil,
  tooltip: nil,
  animation: nil,
  **options
)
  content_for(:head) { stylesheet_link_tag "wilday_ui/components/button/index", media: "all" }

  options[:data] ||= {}
  wrapper_data = {}
  wrapper_options = nil

  # Process gradient styles if present
  if gradient.present?
    gradient_styles = process_gradient(gradient)
    options[:style] = [ options[:style], gradient_styles ].compact.join(";") if gradient_styles.present?
  end

  # Process theme styles
  if theme.present?
    theme_styles = process_theme(variant, theme)
    options[:style] = theme_styles if theme_styles.present?
  end

  variant_class = get_variant_class(variant)
  size_class = get_size_class(size)
  radius_class = get_radius_class(radius)
  gradient_class = get_gradient_class(gradient)

  # Setup features that require Stimulus controllers
  active_features = determine_active_features(loading, dropdown, loading_text, copy_to_clipboard, confirm, tooltip, animation, use_default_controller)

  setup_features(active_features, options, use_default_controller)
  setup_loading_data_attributes(options, loading_text) if active_features[:loading]

  setup_link_options(options, href, target, method)

  if dropdown
    setup_dropdown_options(
      options,
      additional_classes,
      dropdown,
      dropdown_items,
      wrapper_data
    )
  end

  if copy_to_clipboard
    setup_clipboard_options(
      options,
      additional_classes,
      copy_to_clipboard,
      wrapper_data
    )
  end

  if confirm
    setup_confirmation_options(
      options,
      additional_classes,
      confirm,
      wrapper_data
    )
  end

  if tooltip
    setup_tooltip_options(
      options,
      additional_classes,
      tooltip,
      wrapper_data
    )
  end

  if animation
    additional_classes = setup_animation_options(
      options,
      additional_classes,
      animation,
      wrapper_data
    )
  end

  # Setup wrapper options if any feature requires it
  wrapper_options = setup_wrapper_options(
    active_features,
    additional_classes,
    wrapper_data
  )

  render_button(
    content,
    variant_class,
    size_class,
    radius_class,
    gradient_class,
    icon,
    icon_position,
    icon_only,
    loading,
    loading_text,
    additional_classes,
    disabled,
    options,
    href,
    underline,
    dropdown,
    dropdown_items,
    dropdown_icon,
    wrapper_options
  )
end