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
- #coco_avatar(src, name = nil) ⇒ Object
- #coco_badge(text) ⇒ Object
-
#coco_button(*args, **kwargs, &block) ⇒ Object
Buttons.
- #coco_button_group ⇒ Object
- #coco_button_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #coco_color_picker_button ⇒ Object
- #coco_component(name) ⇒ Object
- #coco_confirm_button(href = nil) ⇒ Object
-
#coco_dropdown ⇒ Object
Utilties.
-
#coco_embed(platform, url = nil) ⇒ Object
Embeds.
- #coco_fields ⇒ Object
- #coco_form_for ⇒ Object
-
#coco_form_with ⇒ Object
Forms (WIP).
- #coco_icon(icon_name = nil) ⇒ Object
- #coco_image(src = nil) ⇒ Object
- #coco_image_picker_button ⇒ Object
- #coco_layout_picker_button ⇒ Object
-
#coco_link(*args, &block) ⇒ Object
Navigation.
- #coco_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
- #coco_menu ⇒ Object
- #coco_menu_button(text = nil) ⇒ Object
- #coco_menu_item(type) ⇒ Object
-
#coco_modal(name = "default") ⇒ Object
Modals.
- #coco_modal_canvas(name = "default", &block) ⇒ Object
- #coco_modal_dialog(name = "default", size: :md, &block) ⇒ Object
- #coco_modal_lightbox(name = "default", scroll_top: nil, &block) ⇒ Object
- #coco_notice ⇒ Object
- #coco_option_bar ⇒ Object
- #coco_page(id) ⇒ Object
- #coco_pager_button(direction) ⇒ Object
- #coco_panel ⇒ Object
- #coco_placeholder(text_content = nil) ⇒ Object
- #coco_popover ⇒ Object
-
#coco_prose ⇒ Object
Typography.
- #coco_seamless_textarea ⇒ Object
- #coco_snackbar ⇒ Object
-
#coco_spacer(size = Coco::Spacer::DEFAULT) ⇒ Object
(also: #space)
Layout.
- #coco_stack(spacing: Coco::Spacer::DEFAULT) ⇒ Object
-
#coco_stamp(type = nil) ⇒ Object
Indicators.
-
#coco_svg(path = nil) ⇒ Object
Images.
- #coco_system_banner ⇒ Object
- #coco_tabs ⇒ Object
-
#coco_tag ⇒ Object
General.
- #coco_toast ⇒ Object
- #coco_toolbar ⇒ Object
-
#coco_tooltip(text) ⇒ Object
Messaging.
- #resolve_component ⇒ Object
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 (*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 ⇒ Object
26 27 28 |
# File 'app/helpers/coco/components_helper.rb', line 26 def (**, &) 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 (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 ⇒ Object
46 47 48 |
# File 'app/helpers/coco/components_helper.rb', line 46 def (**, &) 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 (href = nil, **, &) render(Coco::ConfirmButton.new(href: href, **), &) end |
#coco_dropdown ⇒ Object
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 (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 ⇒ Object
87 88 89 |
# File 'app/helpers/coco/components_helper.rb', line 87 def coco_fields(**, &) fields(**, builder: Coco::AppFormBuilder, &) end |
#coco_form_for ⇒ Object
83 84 85 |
# File 'app/helpers/coco/components_helper.rb', line 83 def coco_form_for(*, **, &) form_for(*, **, builder: Coco::AppFormBuilder, &) end |
#coco_form_with ⇒ Object
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_button ⇒ Object
50 51 52 |
# File 'app/helpers/coco/components_helper.rb', line 50 def (**, &) render(Coco::ImagePickerButton.new(**), &) end |
#coco_layout_picker_button ⇒ Object
54 55 56 |
# File 'app/helpers/coco/components_helper.rb', line 54 def (**, &) render(Coco::LayoutPickerButton.new(**), &) end |
#coco_link(*args, &block) ⇒ Object
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 |
#coco_link_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object
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, = 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 ⇒ Object
30 31 32 |
# File 'app/helpers/coco/components_helper.rb', line 30 def (**, &) render(Coco::Menu.new(**), &) end |
#coco_menu_button(text = nil) ⇒ Object
34 35 36 |
# File 'app/helpers/coco/components_helper.rb', line 34 def (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 (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_notice ⇒ Object
157 158 159 |
# File 'app/helpers/coco/components_helper.rb', line 157 def coco_notice(**, &) render(Coco::Notice.new(**), &) end |
#coco_option_bar ⇒ Object
62 63 64 |
# File 'app/helpers/coco/components_helper.rb', line 62 def (**, &) 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 (direction, **, &) render(Coco::PagerButton.new(direction:, **), &) end |
#coco_panel ⇒ Object
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_popover ⇒ Object
173 174 175 |
# File 'app/helpers/coco/components_helper.rb', line 173 def coco_popover(**, &) render(Coco::Popover.new(**), &) end |
#coco_prose ⇒ Object
Typography
251 252 253 |
# File 'app/helpers/coco/components_helper.rb', line 251 def coco_prose(**, &) render(Coco::Prose.new(**), &) end |
#coco_seamless_textarea ⇒ Object
255 256 257 |
# File 'app/helpers/coco/components_helper.rb', line 255 def coco_seamless_textarea(**, &) render(Coco::SeamlessTextarea.new(**), &) end |
#coco_snackbar ⇒ Object
161 162 163 |
# File 'app/helpers/coco/components_helper.rb', line 161 def (**, &) 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_banner ⇒ Object
169 170 171 |
# File 'app/helpers/coco/components_helper.rb', line 169 def (**, &) render(Coco::SystemBanner.new(**), &) end |
#coco_tabs ⇒ Object
245 246 247 |
# File 'app/helpers/coco/components_helper.rb', line 245 def coco_tabs(**, &) render(Coco::Tabs.new(**), &) end |
#coco_tag ⇒ Object
General
271 272 273 |
# File 'app/helpers/coco/components_helper.rb', line 271 def coco_tag(*, **, &) render(Coco::Tag.new(*, **), &) end |
#coco_toast ⇒ Object
165 166 167 |
# File 'app/helpers/coco/components_helper.rb', line 165 def coco_toast(**, &) render(Coco::Toast.new(**), &) end |
#coco_toolbar ⇒ Object
58 59 60 |
# File 'app/helpers/coco/components_helper.rb', line 58 def (**, &) 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_component ⇒ Object
279 280 281 |
# File 'app/helpers/coco/components_helper.rb', line 279 def resolve_component(...) Coco::ComponentResolver.new(...) end |