Module: Coco::ComponentsHelper

Includes:
ActionView::Helpers::UrlHelper
Included in:
Component, Fields::ButtonComponent, Fields::SubmitComponent, Helpers, PresentedComponent
Defined in:
app/helpers/coco/components_helper.rb

Instance Method Summary collapse

Instance Method Details

#coco_avatar(src, name = nil) ⇒ Object



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

def coco_avatar(src, name = nil, **)
  render Coco::Avatar.new(src: src, name: name, **)
end

#coco_badge(text) ⇒ Object



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

def coco_badge(text, **)
  render Coco::Badge.new(**).with_content(text)
end

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

Buttons



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/coco/components_helper.rb', line 7

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)
    "Coco::ButtonTo"
  else
    "Coco::Button"
  end

  component = button.constantize.new(href: href, **kwargs)
  component = component.with_content(content) if !block && content.present?

  render(component, &block)
end

#coco_button_groupObject



26
27
28
# File 'app/helpers/coco/components_helper.rb', line 26

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

#coco_button_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object



230
231
232
233
234
235
236
237
238
239
# File 'app/helpers/coco/components_helper.rb', line 230

def coco_button_to(name = nil, options = nil, html_options = nil, &block)
  html_options, options = options, name if block
  options ||= {}
  html_options ||= {}
  html_options.symbolize_keys!

  button = Coco::ButtonTo.new(action: options, type: :submit, **html_options)
  button = button.with_content(name) unless block
  render(button, &block)
end

#coco_color_picker_buttonObject



46
47
48
# File 'app/helpers/coco/components_helper.rb', line 46

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

#coco_component(name) ⇒ Object



275
276
277
# File 'app/helpers/coco/components_helper.rb', line 275

def coco_component(name, *, **)
  resolve_component("coco/#{name}", *, **)
end

#coco_confirm_button(href = nil) ⇒ Object



42
43
44
# File 'app/helpers/coco/components_helper.rb', line 42

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

#coco_dropdownObject

Utilties



261
262
263
# File 'app/helpers/coco/components_helper.rb', line 261

def coco_dropdown(**, &)
  render(Coco::Dropdown.new(**), &)
end

#coco_embed(platform, url = nil) ⇒ Object

Embeds



68
69
70
71
72
73
74
75
# File 'app/helpers/coco/components_helper.rb', line 68

def coco_embed(platform, url = nil, **)
  case platform
  when :youtube
    render Coco::YoutubeEmbed.new(url: url, **)
  else
    raise ArgumentError, "`#{platform}` is not a valid embed type"
  end
end

#coco_fieldsObject



87
88
89
# File 'app/helpers/coco/components_helper.rb', line 87

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

#coco_form_forObject



83
84
85
# File 'app/helpers/coco/components_helper.rb', line 83

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

#coco_form_withObject

Forms (WIP)



79
80
81
# File 'app/helpers/coco/components_helper.rb', line 79

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

#coco_icon(icon_name = nil) ⇒ Object



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

def coco_icon(icon_name = nil, **, &)
  render(Coco::Icon.new(name: icon_name, **), &)
end

#coco_image(src = nil) ⇒ Object



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

def coco_image(src = nil, **)
  render Coco::Image.new(src: src, **)
end

#coco_image_picker_buttonObject



50
51
52
# File 'app/helpers/coco/components_helper.rb', line 50

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

#coco_layout_picker_buttonObject



54
55
56
# File 'app/helpers/coco/components_helper.rb', line 54

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

Navigation



203
204
205
206
207
208
209
210
211
212
213
214
# File 'app/helpers/coco/components_helper.rb', line 203

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::Link.new(href: href, **)
  link = link.with_content(content) if !block && content.present?

  render(link, &block)
end


216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'app/helpers/coco/components_helper.rb', line 216

def coco_link_to(name = nil, options = nil, html_options = nil, &block)
  html_options, options, name = options, name, block if block
  options ||= {}
  html_options = Coco::ActionViewHelper.convert_options_to_data_attributes(options, html_options)

  href = Coco::ActionViewHelper.url_target(name, options)

  if block
    coco_link(href, **html_options.symbolize_keys!, &block)
  else
    coco_link(name, href, **html_options.symbolize_keys!)
  end
end

#coco_menuObject



30
31
32
# File 'app/helpers/coco/components_helper.rb', line 30

def coco_menu(**, &)
  render(Coco::Menu.new(**), &)
end

#coco_menu_button(text = nil) ⇒ Object



34
35
36
# File 'app/helpers/coco/components_helper.rb', line 34

def coco_menu_button(text = nil, **, &)
  render(Coco::MenuButton.new(text: text, **), &)
end

#coco_menu_item(type) ⇒ Object



38
39
40
# File 'app/helpers/coco/components_helper.rb', line 38

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

#coco_modal(name = "default") ⇒ Object

Modals



179
180
181
# File 'app/helpers/coco/components_helper.rb', line 179

def coco_modal(name = "default", **, &)
  render(Coco::Modal.new(name: name, **), &)
end

#coco_modal_canvas(name = "default", &block) ⇒ Object



195
196
197
198
199
# File 'app/helpers/coco/components_helper.rb', line 195

def coco_modal_canvas(name = "default", **, &block)
  render(Coco::Modal.new(name: name, **)) do |modal|
    modal.with_container_canvas(&block)
  end
end

#coco_modal_dialog(name = "default", size: :md, &block) ⇒ Object



183
184
185
186
187
# File 'app/helpers/coco/components_helper.rb', line 183

def coco_modal_dialog(name = "default", size: :md, **, &block)
  render(Coco::Modal.new(name: name, **)) do |modal|
    modal.with_container_dialog(size: size, &block)
  end
end

#coco_modal_lightbox(name = "default", scroll_top: nil, &block) ⇒ Object



189
190
191
192
193
# File 'app/helpers/coco/components_helper.rb', line 189

def coco_modal_lightbox(name = "default", scroll_top: nil, **, &block)
  render(Coco::Modal.new(name: name, scroll_top: scroll_top, **)) do |modal|
    modal.with_container_lightbox(&block)
  end
end

#coco_noticeObject



157
158
159
# File 'app/helpers/coco/components_helper.rb', line 157

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

#coco_option_barObject



62
63
64
# File 'app/helpers/coco/components_helper.rb', line 62

def coco_option_bar(**, &)
  render(Coco::OptionBar.new(**), &)
end

#coco_page(id) ⇒ Object



147
148
149
# File 'app/helpers/coco/components_helper.rb', line 147

def coco_page(id, **, &)
  render(Coco::Page.new(id: id, **), &)
end

#coco_pager_button(direction) ⇒ Object



241
242
243
# File 'app/helpers/coco/components_helper.rb', line 241

def coco_pager_button(direction, **, &)
  render(Coco::PagerButton.new(direction:, **), &)
end

#coco_panelObject



143
144
145
# File 'app/helpers/coco/components_helper.rb', line 143

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

#coco_placeholder(text_content = nil) ⇒ Object



265
266
267
# File 'app/helpers/coco/components_helper.rb', line 265

def coco_placeholder(text_content = nil, **, &)
  render(Coco::Placeholder.new(text_content:, **), &)
end

#coco_popoverObject



173
174
175
# File 'app/helpers/coco/components_helper.rb', line 173

def coco_popover(**, &)
  render(Coco::Popover.new(**), &)
end

#coco_proseObject

Typography



251
252
253
# File 'app/helpers/coco/components_helper.rb', line 251

def coco_prose(**, &)
  render(Coco::Prose.new(**), &)
end

#coco_seamless_textareaObject



255
256
257
# File 'app/helpers/coco/components_helper.rb', line 255

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

#coco_snackbarObject



161
162
163
# File 'app/helpers/coco/components_helper.rb', line 161

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

#coco_spacer(size = Coco::Spacer::DEFAULT) ⇒ Object Also known as: space

Layout



134
135
136
# File 'app/helpers/coco/components_helper.rb', line 134

def coco_spacer(size = Coco::Spacer::DEFAULT, **)
  render Coco::Spacer.new(size:, **)
end

#coco_stack(spacing: Coco::Spacer::DEFAULT) ⇒ Object



139
140
141
# File 'app/helpers/coco/components_helper.rb', line 139

def coco_stack(spacing: Coco::Spacer::DEFAULT, **, &)
  render(Coco::Stack.new(spacing:, **), &)
end

#coco_stamp(type = nil) ⇒ Object

Indicators



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/helpers/coco/components_helper.rb', line 111

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::Stamp.new(**props, **)
end

#coco_svg(path = nil) ⇒ Object

Images



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

def coco_svg(path = nil, **)
  render Coco::Svg.new(path: path, **)
end

#coco_system_bannerObject



169
170
171
# File 'app/helpers/coco/components_helper.rb', line 169

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

#coco_tabsObject



245
246
247
# File 'app/helpers/coco/components_helper.rb', line 245

def coco_tabs(**, &)
  render(Coco::Tabs.new(**), &)
end

#coco_tagObject

General



271
272
273
# File 'app/helpers/coco/components_helper.rb', line 271

def coco_tag(*, **, &)
  render(Coco::Tag.new(*, **), &)
end

#coco_toastObject



165
166
167
# File 'app/helpers/coco/components_helper.rb', line 165

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

#coco_toolbarObject



58
59
60
# File 'app/helpers/coco/components_helper.rb', line 58

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

#coco_tooltip(text) ⇒ Object

Messaging



153
154
155
# File 'app/helpers/coco/components_helper.rb', line 153

def coco_tooltip(text, **, &)
  render(Coco::Tooltip.new(text:, **), &)
end

#resolve_componentObject



279
280
281
# File 'app/helpers/coco/components_helper.rb', line 279

def resolve_component(...)
  Coco::ComponentResolver.new(...)
end