Module: Coco::CoreComponentsHelper
- Includes:
- ActionView::Helpers::UrlHelper
- Included in:
- Component, ComponentsHelper, Fields::ButtonComponent, Fields::SubmitComponent
- Defined in:
- app/helpers/coco/core_components_helper.rb
Instance Method Summary collapse
- #coco_avatar(src, name = nil) ⇒ Object
- #coco_badge(text) ⇒ Object
-
#coco_button(*args, **kwargs, &block) ⇒ Object
Buttons.
- #coco_button_group(&block) ⇒ Object
- #coco_button_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #coco_color_picker_button(&block) ⇒ Object
- #coco_component(name) ⇒ Object
- #coco_confirm_button(href = nil, &block) ⇒ Object
-
#coco_embed(platform, url = nil) ⇒ Object
Embeds.
- #coco_fields(&block) ⇒ Object
- #coco_form_for(&block) ⇒ Object
-
#coco_form_with(&block) ⇒ Object
Forms (WIP).
- #coco_icon(icon_name = nil, &block) ⇒ Object
- #coco_image(src = nil) ⇒ Object
- #coco_image_picker_button(&block) ⇒ Object
- #coco_layout_picker_button(&block) ⇒ Object
-
#coco_link(*args, &block) ⇒ Object
Navigation.
- #coco_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #coco_menu_button(&block) ⇒ Object
- #coco_menu_item(type, &block) ⇒ Object
-
#coco_modal(name = "default", &block) ⇒ Object
Modals.
- #coco_modal_dialog(name = "default", &block) ⇒ Object
- #coco_modal_lightbox(name = "default", scroll_top: nil, &block) ⇒ Object
-
#coco_notice(&block) ⇒ Object
Messaging.
- #coco_option_bar(&block) ⇒ Object
- #coco_page(id, &block) ⇒ Object
- #coco_pager_button(direction, &block) ⇒ Object
- #coco_panel(&block) ⇒ Object
-
#coco_placeholder(text_content = nil, &block) ⇒ Object
Utilties (internal).
-
#coco_prose(&block) ⇒ Object
Typography.
- #coco_seamless_textarea(&block) ⇒ Object
- #coco_snackbar(&block) ⇒ Object
-
#coco_spacer(size = Coco::Spacer::DEFAULT) ⇒ Object
(also: #space)
Layout.
- #coco_stack(spacing: Coco::Spacer::DEFAULT, &block) ⇒ Object
-
#coco_stamp(type = nil) ⇒ Object
Indicators.
-
#coco_svg(path = nil) ⇒ Object
Images.
- #coco_system_banner(&block) ⇒ Object
-
#coco_tag(&block) ⇒ Object
General.
- #coco_toast(&block) ⇒ Object
- #coco_toolbar(&block) ⇒ Object
- #resolve_component ⇒ Object
Instance Method Details
#coco_avatar(src, name = nil) ⇒ Object
97 98 99 |
# File 'app/helpers/coco/core_components_helper.rb', line 97 def coco_avatar(src, name = nil, **) render Coco::Avatar.new(src: src, name: name, **) end |
#coco_badge(text) ⇒ Object
124 125 126 |
# File 'app/helpers/coco/core_components_helper.rb', line 124 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/core_components_helper.rb', line 7 def (*args, **kwargs, &block) href, content = if block [args.first, nil] else (args.size == 1) ? [nil, args.first] : args[0..2].reverse! end = if kwargs.key?(:action) || kwargs.key?(:method) || kwargs.key?(:params) "Coco::ButtonTo" else "Coco::Button" end component = .constantize.new(href: href, **kwargs) component = component.with_content(content) if !block && content.present? render(component, &block) end |
#coco_button_group(&block) ⇒ Object
26 27 28 |
# File 'app/helpers/coco/core_components_helper.rb', line 26 def (**, &block) render Coco::ButtonGroup.new(**), &block end |
#coco_button_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
212 213 214 215 216 217 218 219 220 221 |
# File 'app/helpers/coco/core_components_helper.rb', line 212 def (name = nil, = nil, = nil, &block) , = , name if block ||= {} ||= {} .symbolize_keys! = Coco::ButtonTo.new(action: , type: :submit, **) = .with_content(name) unless block render(, &block) end |
#coco_color_picker_button(&block) ⇒ Object
42 43 44 |
# File 'app/helpers/coco/core_components_helper.rb', line 42 def (**, &block) render Coco::ColorPickerButton.new(**), &block end |
#coco_component(name) ⇒ Object
249 250 251 |
# File 'app/helpers/coco/core_components_helper.rb', line 249 def coco_component(name, *, **) resolve_component("coco/#{name}", *, **) end |
#coco_confirm_button(href = nil, &block) ⇒ Object
38 39 40 |
# File 'app/helpers/coco/core_components_helper.rb', line 38 def (href = nil, **, &block) render Coco::ConfirmButton.new(href: href, **), &block end |
#coco_embed(platform, url = nil) ⇒ Object
Embeds
64 65 66 67 68 69 70 71 |
# File 'app/helpers/coco/core_components_helper.rb', line 64 def (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_fields(&block) ⇒ Object
83 84 85 |
# File 'app/helpers/coco/core_components_helper.rb', line 83 def coco_fields(**, &block) fields(**, builder: Coco::AppFormBuilder, &block) end |
#coco_form_for(&block) ⇒ Object
79 80 81 |
# File 'app/helpers/coco/core_components_helper.rb', line 79 def coco_form_for(*, **, &block) form_for(*, **, builder: Coco::AppFormBuilder, &block) end |
#coco_form_with(&block) ⇒ Object
Forms (WIP)
75 76 77 |
# File 'app/helpers/coco/core_components_helper.rb', line 75 def coco_form_with(**, &block) form_with(**, builder: Coco::AppFormBuilder, &block) end |
#coco_icon(icon_name = nil, &block) ⇒ Object
101 102 103 |
# File 'app/helpers/coco/core_components_helper.rb', line 101 def coco_icon(icon_name = nil, **, &block) render Coco::Icon.new(name: icon_name, **), &block end |
#coco_image(src = nil) ⇒ Object
93 94 95 |
# File 'app/helpers/coco/core_components_helper.rb', line 93 def coco_image(src = nil, **) render Coco::Image.new(src: src, **) end |
#coco_image_picker_button(&block) ⇒ Object
46 47 48 |
# File 'app/helpers/coco/core_components_helper.rb', line 46 def (**, &block) render Coco::ImagePickerButton.new(**), &block end |
#coco_layout_picker_button(&block) ⇒ Object
50 51 52 |
# File 'app/helpers/coco/core_components_helper.rb', line 50 def (**, &block) render Coco::LayoutPickerButton.new(**), &block end |
#coco_link(*args, &block) ⇒ Object
Navigation
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'app/helpers/coco/core_components_helper.rb', line 185 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 |
#coco_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'app/helpers/coco/core_components_helper.rb', line 198 def coco_link_to(name = nil, = nil, = nil, &block) , , name = , name, block if block ||= {} = Coco::ActionViewHelper.(, ) href = Coco::ActionViewHelper.url_target(name, ) if block coco_link(href, **.symbolize_keys!, &block) else coco_link(name, href, **.symbolize_keys!) end end |
#coco_menu_button(&block) ⇒ Object
30 31 32 |
# File 'app/helpers/coco/core_components_helper.rb', line 30 def (**, &block) render Coco::MenuButton.new(**), &block end |
#coco_menu_item(type, &block) ⇒ Object
34 35 36 |
# File 'app/helpers/coco/core_components_helper.rb', line 34 def (type, **, &block) render coco_component("menu_items/#{type}", **), &block end |
#coco_modal(name = "default", &block) ⇒ Object
Modals
167 168 169 |
# File 'app/helpers/coco/core_components_helper.rb', line 167 def coco_modal(name = "default", **, &block) render(Coco::Modal.new(name: name, **), &block) end |
#coco_modal_dialog(name = "default", &block) ⇒ Object
171 172 173 174 175 |
# File 'app/helpers/coco/core_components_helper.rb', line 171 def coco_modal_dialog(name = "default", **, &block) render(Coco::Modal.new(name: name, **)) do |modal| modal.with_container_dialog(&block) end end |
#coco_modal_lightbox(name = "default", scroll_top: nil, &block) ⇒ Object
177 178 179 180 181 |
# File 'app/helpers/coco/core_components_helper.rb', line 177 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_notice(&block) ⇒ Object
Messaging
149 150 151 |
# File 'app/helpers/coco/core_components_helper.rb', line 149 def coco_notice(**, &block) render Coco::Notice.new(**), &block end |
#coco_option_bar(&block) ⇒ Object
58 59 60 |
# File 'app/helpers/coco/core_components_helper.rb', line 58 def (**, &block) render Coco::OptionBar.new(**), &block end |
#coco_page(id, &block) ⇒ Object
143 144 145 |
# File 'app/helpers/coco/core_components_helper.rb', line 143 def coco_page(id, **, &block) render Coco::Page.new(id: id, **), &block end |
#coco_pager_button(direction, &block) ⇒ Object
223 224 225 |
# File 'app/helpers/coco/core_components_helper.rb', line 223 def (direction, **, &block) render Coco::PagerButton.new(direction:, **), &block end |
#coco_panel(&block) ⇒ Object
139 140 141 |
# File 'app/helpers/coco/core_components_helper.rb', line 139 def coco_panel(**, &block) render Coco::Panel.new(**), &block end |
#coco_placeholder(text_content = nil, &block) ⇒ Object
Utilties (internal)
239 240 241 |
# File 'app/helpers/coco/core_components_helper.rb', line 239 def coco_placeholder(text_content = nil, **, &block) render Coco::Placeholder.new(text_content:, **), &block end |
#coco_prose(&block) ⇒ Object
Typography
229 230 231 |
# File 'app/helpers/coco/core_components_helper.rb', line 229 def coco_prose(**, &block) render Coco::Prose.new(**), &block end |
#coco_seamless_textarea(&block) ⇒ Object
233 234 235 |
# File 'app/helpers/coco/core_components_helper.rb', line 233 def coco_seamless_textarea(**, &block) render Coco::SeamlessTextarea.new(**), &block end |
#coco_snackbar(&block) ⇒ Object
153 154 155 |
# File 'app/helpers/coco/core_components_helper.rb', line 153 def (**, &block) render Coco::.new(**), &block end |
#coco_spacer(size = Coco::Spacer::DEFAULT) ⇒ Object Also known as: space
Layout
130 131 132 |
# File 'app/helpers/coco/core_components_helper.rb', line 130 def coco_spacer(size = Coco::Spacer::DEFAULT, **) render Coco::Spacer.new(size:, **) end |
#coco_stack(spacing: Coco::Spacer::DEFAULT, &block) ⇒ Object
135 136 137 |
# File 'app/helpers/coco/core_components_helper.rb', line 135 def coco_stack(spacing: Coco::Spacer::DEFAULT, **, &block) render Coco::Stack.new(spacing:, **), &block end |
#coco_stamp(type = nil) ⇒ Object
Indicators
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/coco/core_components_helper.rb', line 107 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
89 90 91 |
# File 'app/helpers/coco/core_components_helper.rb', line 89 def coco_svg(path = nil, **) render Coco::Svg.new(path: path, **) end |
#coco_system_banner(&block) ⇒ Object
161 162 163 |
# File 'app/helpers/coco/core_components_helper.rb', line 161 def (**, &block) render Coco::SystemBanner.new(**), &block end |
#coco_tag(&block) ⇒ Object
General
245 246 247 |
# File 'app/helpers/coco/core_components_helper.rb', line 245 def coco_tag(*, **, &block) render Coco::Tag.new(*, **), &block end |
#coco_toast(&block) ⇒ Object
157 158 159 |
# File 'app/helpers/coco/core_components_helper.rb', line 157 def coco_toast(**, &block) render Coco::Toast.new(**), &block end |
#coco_toolbar(&block) ⇒ Object
54 55 56 |
# File 'app/helpers/coco/core_components_helper.rb', line 54 def (**, &block) render Coco::.new(**), &block end |
#resolve_component ⇒ Object
253 254 255 |
# File 'app/helpers/coco/core_components_helper.rb', line 253 def resolve_component(...) Coco::ComponentResolver.new(...) end |