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
|
# File 'app/helpers/wilday_ui/components/button/features/tooltip.rb', line 19
def setup_tooltip_options(options, additional_classes, tooltip, wrapper_data)
tooltip_config = normalize_tooltip_options(tooltip)
has_dropdown = wrapper_data[:controller]&.include?("dropdown")
has_clipboard = wrapper_data[:controller]&.include?("clipboard")
trigger_type = (has_dropdown || has_clipboard) ? :hover : tooltip_config[:trigger].to_sym
tooltip_action = FEATURE_CONFIG[:default_stimulus_action][trigger_type]
existing_controller = wrapper_data[:controller]
wrapper_data[:controller] = [
existing_controller,
FEATURE_CONFIG[:stimulus_controller]
].compact.join(" ")
existing_action = wrapper_data[:action]
if has_dropdown
wrapper_data[:action] = [
"click->dropdown#toggle", tooltip_action
].compact.join(" ")
elsif has_clipboard
wrapper_data[:action] = [
"click->clipboard#copy click->button#toggleLoading",
tooltip_action
].compact.join(" ")
else
wrapper_data[:action] = [
existing_action,
tooltip_action
].compact.join(" ")
end
theme = tooltip_config[:theme]
theme_name = theme.is_a?(Hash) ? theme[:name] : theme
wrapper_data.merge!(
tooltip_content_value: tooltip_config[:content],
tooltip_position_value: tooltip_config[:position],
tooltip_align_value: tooltip_config[:align],
tooltip_trigger_value: trigger_type,
tooltip_show_delay_value: tooltip_config[:delay][:show],
tooltip_hide_delay_value: tooltip_config[:delay][:hide],
tooltip_offset_value: tooltip_config[:offset],
tooltip_theme_value: theme_name,
tooltip_size_value: tooltip_config[:size],
tooltip_arrow_value: tooltip_config[:arrow]
)
if theme.is_a?(Hash) && theme[:custom]
custom_styles = []
custom_styles << "--tooltip-text-color: #{theme[:custom][:color]}" if theme[:custom][:color]
custom_styles << "--tooltip-bg-color: #{theme[:custom][:background]}" if theme[:custom][:background]
wrapper_data[:tooltip_custom_style_value] = custom_styles.join(";")
end
options[:data][:tooltip_target] = "trigger"
options[:aria] ||= {}
options[:aria][:describedby] = "tooltip-#{SecureRandom.hex(4)}"
end
|