Module: Coco::AppHelper

Instance Method Summary collapse

Instance Method Details

#coco_button(*args, **kwargs, &block) ⇒ Object



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
# File 'app/helpers/coco/app_helper.rb', line 24

def coco_button(*args, **kwargs, &block)
  href, content = args[0..2].reverse!

  button = if kwargs.key?(:action) || kwargs.key?(:method) || kwargs.key?(:params)
    "ButtonTo"
  else
    "Button"
  end

  kwargs[:button_element] ||= {}

  if kwargs.key?(:modal)
    modal_name = (kwargs[:modal] == true) ? "default" : kwargs[:modal]
    kwargs[:button_element][:data] = kwargs[:button_element].fetch(:data, {}).merge(coco_modal_data_attributes(modal_name))
    kwargs.delete(:modal)
  end

  if kwargs.key?(:frame)
    turbo_data = {turbo: true, turbo_frame: kwargs[:frame]}
    kwargs[:button_element][:data] = kwargs[:button_element].fetch(:data, {}).merge(turbo_data)
    kwargs.delete(:frame)
  end

  component = "Coco::App::Elements::#{button}".constantize.new(href: href, **kwargs)
  component = component.with_content(content) if !block && content.present?

  render(component, &block)
end

#coco_button_group(&block) ⇒ Object



77
78
79
# File 'app/helpers/coco/app_helper.rb', line 77

def coco_button_group(**, &block)
  render Coco::App::Elements::ButtonGroup.new(**), &block
end

#coco_color_picker_button(&block) ⇒ Object



61
62
63
# File 'app/helpers/coco/app_helper.rb', line 61

def coco_color_picker_button(**, &block)
  render Coco::App::Elements::ColorPickerButton.new(**), &block
end

#coco_confirm_button(href = nil, &block) ⇒ Object



57
58
59
# File 'app/helpers/coco/app_helper.rb', line 57

def coco_confirm_button(href = nil, **, &block)
  render Coco::App::Elements::ConfirmButton.new(href: href, **), &block
end

#coco_dropdown_button(&block) ⇒ Object



73
74
75
# File 'app/helpers/coco/app_helper.rb', line 73

def coco_dropdown_button(**, &block)
  render Coco::App::Elements::DropdownButton.new(**), &block
end

#coco_fields(&block) ⇒ Object



113
114
115
# File 'app/helpers/coco/app_helper.rb', line 113

def coco_fields(**, &block)
  fields(**, builder: Coco::AppFormBuilder, &block)
end

#coco_form_for(&block) ⇒ Object



109
110
111
# File 'app/helpers/coco/app_helper.rb', line 109

def coco_form_for(*, **, &block)
  form_for(*, **, builder: Coco::AppFormBuilder, &block)
end

#coco_form_with(&block) ⇒ Object



105
106
107
# File 'app/helpers/coco/app_helper.rb', line 105

def coco_form_with(**, &block)
  form_with(**, builder: Coco::AppFormBuilder, &block)
end

#coco_image_picker_button(&block) ⇒ Object



65
66
67
# File 'app/helpers/coco/app_helper.rb', line 65

def coco_image_picker_button(**, &block)
  render Coco::App::Elements::ImagePickerButton.new(**), &block
end

#coco_layout_picker_button(&block) ⇒ Object



69
70
71
# File 'app/helpers/coco/app_helper.rb', line 69

def coco_layout_picker_button(**, &block)
  render Coco::App::Elements::LayoutPickerButton.new(**), &block
end


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/helpers/coco/app_helper.rb', line 3

def coco_link(*args, **kwargs, &block)
  href, content = args[0..2].reverse!

  if kwargs.key?(:modal)
    modal_name = (kwargs[:modal] == true) ? "default" : kwargs[:modal]
    kwargs[:data] = kwargs.fetch(:data, {}).merge(coco_modal_data_attributes(modal_name))
    kwargs.delete(:modal)
  end

  if kwargs.key?(:frame)
    turbo_data = {turbo: true, turbo_frame: kwargs[:frame]}
    kwargs[:data] = kwargs.fetch(:data, {}).merge(turbo_data)
    kwargs.delete(:frame)
  end

  link = Coco::App::Elements::Link.new(href: href, **kwargs)
  link = link.with_content(content) if !block && content.present?

  render(link, &block)
end

#coco_menu_button(&block) ⇒ Object



53
54
55
# File 'app/helpers/coco/app_helper.rb', line 53

def coco_menu_button(**, &block)
  render Coco::App::Elements::MenuButton.new(**), &block
end

#coco_notice(&block) ⇒ Object



93
94
95
# File 'app/helpers/coco/app_helper.rb', line 93

def coco_notice(**, &block)
  render Coco::App::Elements::Notice.new(**), &block
end

#coco_seamless_textarea(&block) ⇒ Object



85
86
87
# File 'app/helpers/coco/app_helper.rb', line 85

def coco_seamless_textarea(**, &block)
  render Coco::App::Elements::SeamlessTextarea.new(**), &block
end

#coco_snackbar(&block) ⇒ Object



89
90
91
# File 'app/helpers/coco/app_helper.rb', line 89

def coco_snackbar(**, &block)
  render Coco::App::Elements::Snackbar.new(**), &block
end

#coco_system_banner(&block) ⇒ Object



101
102
103
# File 'app/helpers/coco/app_helper.rb', line 101

def coco_system_banner(**, &block)
  render Coco::App::Elements::SystemBanner.new(**), &block
end

#coco_toast(&block) ⇒ Object



97
98
99
# File 'app/helpers/coco/app_helper.rb', line 97

def coco_toast(**, &block)
  render Coco::App::Elements::Toast.new(**), &block
end

#coco_toolbar(&block) ⇒ Object



81
82
83
# File 'app/helpers/coco/app_helper.rb', line 81

def coco_toolbar(**, &block)
  render Coco::App::Elements::Toolbar.new(**), &block
end