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



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

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



236
237
238
239
240
241
242
243
244
245
# File 'app/helpers/coco/components_helper.rb', line 236

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



281
282
283
# File 'app/helpers/coco/components_helper.rb', line 281

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



267
268
269
# File 'app/helpers/coco/components_helper.rb', line 267

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, **kwargs) ⇒ Object



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

def coco_icon(icon_name = nil, **kwargs, &)
  kwargs[:name] = icon_name if icon_name.present?
  render(Coco::Icon.new(**kwargs), &)
end

#coco_icon_sprite(*extra_icons) ⇒ Object



110
111
112
113
# File 'app/helpers/coco/components_helper.rb', line 110

def coco_icon_sprite(*extra_icons)
  icons = [*Coco::IconSet.icons, *extra_icons]
  Coco::IconSprite.new(icons).to_svg
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



209
210
211
212
213
214
215
216
217
218
219
220
# File 'app/helpers/coco/components_helper.rb', line 209

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


222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'app/helpers/coco/components_helper.rb', line 222

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



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

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

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



201
202
203
204
205
# File 'app/helpers/coco/components_helper.rb', line 201

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



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

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



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

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



163
164
165
# File 'app/helpers/coco/components_helper.rb', line 163

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



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

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

#coco_pager_button(direction) ⇒ Object



247
248
249
# File 'app/helpers/coco/components_helper.rb', line 247

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

#coco_panelObject



149
150
151
# File 'app/helpers/coco/components_helper.rb', line 149

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

#coco_placeholder(text_content = nil) ⇒ Object



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

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

#coco_popoverObject



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

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

#coco_proseObject

Typography



257
258
259
# File 'app/helpers/coco/components_helper.rb', line 257

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

#coco_seamless_textareaObject



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

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

#coco_snackbarObject



167
168
169
# File 'app/helpers/coco/components_helper.rb', line 167

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

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

Layout



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

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

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



145
146
147
# File 'app/helpers/coco/components_helper.rb', line 145

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

#coco_stamp(type = nil) ⇒ Object

Indicators



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/helpers/coco/components_helper.rb', line 117

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



175
176
177
# File 'app/helpers/coco/components_helper.rb', line 175

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

#coco_tabsObject



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

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

#coco_tagObject

General



277
278
279
# File 'app/helpers/coco/components_helper.rb', line 277

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

#coco_toastObject



171
172
173
# File 'app/helpers/coco/components_helper.rb', line 171

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



159
160
161
# File 'app/helpers/coco/components_helper.rb', line 159

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

#resolve_componentObject



285
286
287
# File 'app/helpers/coco/components_helper.rb', line 285

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