Module: Coco::AppHelper

Instance Method Summary collapse

Instance Method Details

#coco_app_header(&block) ⇒ Object



124
125
126
# File 'app/helpers/coco/app_helper.rb', line 124

def coco_app_header(*, **, &block)
  render Coco::App::Blocks::Header.new(*, **), &block
end

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/coco/app_helper.rb', line 16

def coco_button(*args, **kwargs, &block)
  href, content = if block
    [args.first, nil]
  else
    (args.size == 1) ? [nil, args.first] : args[0..2].reverse!
  end

  button = if kwargs.key?(:action) || kwargs.key?(:method) || kwargs.key?(:params)
    "ButtonTo"
  else
    "Button"
  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



59
60
61
# File 'app/helpers/coco/app_helper.rb', line 59

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

#coco_color_picker_button(&block) ⇒ Object



43
44
45
# File 'app/helpers/coco/app_helper.rb', line 43

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

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



39
40
41
# File 'app/helpers/coco/app_helper.rb', line 39

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

#coco_dropdown_button(&block) ⇒ Object



55
56
57
# File 'app/helpers/coco/app_helper.rb', line 55

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

#coco_fields(&block) ⇒ Object



116
117
118
# File 'app/helpers/coco/app_helper.rb', line 116

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

#coco_form_for(&block) ⇒ Object



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

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

#coco_form_with(&block) ⇒ Object



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

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

#coco_image_picker_button(&block) ⇒ Object



47
48
49
# File 'app/helpers/coco/app_helper.rb', line 47

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

#coco_layout(name, &block) ⇒ Object



120
121
122
# File 'app/helpers/coco/app_helper.rb', line 120

def coco_layout(name, **, &block)
  render coco_component("app/layouts/#{name}", **), &block
end

#coco_layout_picker_button(&block) ⇒ Object



51
52
53
# File 'app/helpers/coco/app_helper.rb', line 51

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

def coco_link(*args, **, &block)
  href, content = if block
    [args.first, nil]
  else
    (args.size == 1) ? [nil, args.first] : args[0..2].reverse!
  end

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

  render(link, &block)
end

#coco_menu_button(&block) ⇒ Object



35
36
37
# File 'app/helpers/coco/app_helper.rb', line 35

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

#coco_menu_item(type, &block) ⇒ Object



136
137
138
# File 'app/helpers/coco/app_helper.rb', line 136

def coco_menu_item(type, **, &block)
  render coco_component("app/elements/menu_items/#{type}", **), &block
end

#coco_notice(&block) ⇒ Object



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

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

#coco_page(id, &block) ⇒ Object



140
141
142
# File 'app/helpers/coco/app_helper.rb', line 140

def coco_page(id, **, &block)
  render coco_component("app/layouts/page", id: id, **), &block
end

#coco_panel(&block) ⇒ Object



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

def coco_panel(**, &block)
  render Coco::Panel.new(**), &block
end

#coco_seamless_textarea(&block) ⇒ Object



67
68
69
# File 'app/helpers/coco/app_helper.rb', line 67

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

#coco_sidebar_nav(&block) ⇒ Object



128
129
130
# File 'app/helpers/coco/app_helper.rb', line 128

def coco_sidebar_nav(*, **, &block)
  render Coco::App::Blocks::SidebarNav::Navbar.new(*, **), &block
end

#coco_sidebar_nav_menu(&block) ⇒ Object



132
133
134
# File 'app/helpers/coco/app_helper.rb', line 132

def coco_sidebar_nav_menu(*, **, &block)
  render Coco::App::Blocks::SidebarNav::Menu.new(*, **), &block
end

#coco_snackbar(&block) ⇒ Object



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

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

#coco_stamp(type = nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/coco/app_helper.rb', line 71

def coco_stamp(type = nil, **)
  props = case type
  when :success, :positive
    {icon: :check_circle, theme: :positive}
  when :error, :negative
    {icon: :alert_circle, theme: :negative}
  when :warning
    {icon: :alert_triangle, theme: :warning}
  when :info
    {icon: :info, theme: :info}
  else
    {}
  end

  render Coco::App::Elements::Stamp.new(**props, **)
end

#coco_system_banner(&block) ⇒ Object



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

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

#coco_toast(&block) ⇒ Object



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

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

#coco_toolbar(&block) ⇒ Object



63
64
65
# File 'app/helpers/coco/app_helper.rb', line 63

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