Module: Coco::SharedHelper
- Included in:
- App::Fields::ButtonComponent, App::Fields::SubmitComponent, Button, ComponentHelper, Link
- Defined in:
- app/helpers/coco/shared_helper.rb
Instance Method Summary collapse
- #coco_avatar(src, name = nil) ⇒ Object
- #coco_badge(text) ⇒ Object
- #coco_button(*args, **kwargs, &block) ⇒ Object
- #coco_button_group(&block) ⇒ Object
- #coco_embed(platform, url = nil) ⇒ Object
- #coco_icon(icon_name = nil, &block) ⇒ Object
- #coco_image(src = nil) ⇒ Object
- #coco_link_to_modal(data: {}, modal: nil, **kwargs) ⇒ Object
- #coco_modal(name = "default", &block) ⇒ Object
- #coco_modal_data_attributes(name = "default") ⇒ Object
- #coco_modal_dialog(name = "default", &block) ⇒ Object
- #coco_modal_frame_id(name = "default") ⇒ Object
- #coco_modal_lightbox(name = "default", scroll_top: nil, &block) ⇒ Object
- #coco_placeholder(text_content = nil, &block) ⇒ Object
- #coco_prose(&block) ⇒ Object
- #coco_spacer(size = Coco::Spacer::DEFAULT) ⇒ Object (also: #space)
- #coco_stack(spacing: Coco::Spacer::DEFAULT, &block) ⇒ Object
- #coco_svg(path = nil) ⇒ Object
- #coco_tag(&block) ⇒ Object
Instance Method Details
#coco_avatar(src, name = nil) ⇒ Object
28 29 30 |
# File 'app/helpers/coco/shared_helper.rb', line 28 def coco_avatar(src, name = nil, **) render Coco::Avatar.new(src: src, name: name, **) end |
#coco_badge(text) ⇒ Object
36 37 38 |
# File 'app/helpers/coco/shared_helper.rb', line 36 def coco_badge(text, **) render Coco::Badge.new(**).with_content(text) end |
#coco_button(*args, **kwargs, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/helpers/coco/shared_helper.rb', line 53 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
72 73 74 |
# File 'app/helpers/coco/shared_helper.rb', line 72 def (**, &block) render Coco::ButtonGroup.new(**), &block end |
#coco_embed(platform, url = nil) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/helpers/coco/shared_helper.rb', line 40 def (platform, url = nil, **) case platform when :youtube render Coco::Embeds::Youtube.new(url: url, **) else raise ArgumentError, "`#{platform}` is not a valid embed type" end end |
#coco_icon(icon_name = nil, &block) ⇒ Object
32 33 34 |
# File 'app/helpers/coco/shared_helper.rb', line 32 def coco_icon(icon_name = nil, **, &block) render Coco::Icon.new(name: icon_name, **), &block end |
#coco_image(src = nil) ⇒ Object
24 25 26 |
# File 'app/helpers/coco/shared_helper.rb', line 24 def coco_image(src = nil, **) render Coco::Image.new(src: src, **) end |
#coco_link_to_modal(data: {}, modal: nil, **kwargs) ⇒ Object
92 93 94 95 96 |
# File 'app/helpers/coco/shared_helper.rb', line 92 def coco_link_to_modal(*, data: {}, modal: nil, **kwargs, &) kwargs[:data] = coco_modal_data_attributes(modal || "default").merge(data) coco_link_to(*, **kwargs, &) end |
#coco_modal(name = "default", &block) ⇒ Object
76 77 78 |
# File 'app/helpers/coco/shared_helper.rb', line 76 def coco_modal(name = "default", **, &block) render(Coco::Modal.new(name: name, **), &block) end |
#coco_modal_data_attributes(name = "default") ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'app/helpers/coco/shared_helper.rb', line 102 def coco_modal_data_attributes(name = "default") return {} if name.nil? { turbo: true, turbo_frame: coco_modal_frame_id(name) } end |
#coco_modal_dialog(name = "default", &block) ⇒ Object
80 81 82 83 84 |
# File 'app/helpers/coco/shared_helper.rb', line 80 def coco_modal_dialog(name = "default", **, &block) render(Coco::Modal.new(name: name, **)) do |modal| modal.with_container_dialog(&block) end end |
#coco_modal_frame_id(name = "default") ⇒ Object
98 99 100 |
# File 'app/helpers/coco/shared_helper.rb', line 98 def coco_modal_frame_id(name = "default") "coco-modal-frame-#{name.to_s.dasherize}" end |
#coco_modal_lightbox(name = "default", scroll_top: nil, &block) ⇒ Object
86 87 88 89 90 |
# File 'app/helpers/coco/shared_helper.rb', line 86 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_placeholder(text_content = nil, &block) ⇒ Object
49 50 51 |
# File 'app/helpers/coco/shared_helper.rb', line 49 def coco_placeholder(text_content = nil, **, &block) render Coco::Placeholder.new(text_content:, **), &block end |
#coco_prose(&block) ⇒ Object
16 17 18 |
# File 'app/helpers/coco/shared_helper.rb', line 16 def coco_prose(**, &block) render Coco::Prose.new(**), &block end |
#coco_spacer(size = Coco::Spacer::DEFAULT) ⇒ Object Also known as: space
7 8 9 |
# File 'app/helpers/coco/shared_helper.rb', line 7 def coco_spacer(size = Coco::Spacer::DEFAULT, **) render Coco::Spacer.new(size:, **) end |
#coco_stack(spacing: Coco::Spacer::DEFAULT, &block) ⇒ Object
12 13 14 |
# File 'app/helpers/coco/shared_helper.rb', line 12 def coco_stack(spacing: Coco::Spacer::DEFAULT, **, &block) render Coco::Stack.new(spacing:, **), &block end |
#coco_svg(path = nil) ⇒ Object
20 21 22 |
# File 'app/helpers/coco/shared_helper.rb', line 20 def coco_svg(path = nil, **) render Coco::Svg.new(path: path, **) end |
#coco_tag(&block) ⇒ Object
3 4 5 |
# File 'app/helpers/coco/shared_helper.rb', line 3 def coco_tag(*, **, &block) render Coco::Tag.new(*, **), &block end |