module Coco module SharedHelper def coco_tag(*, **, &block) render Coco::Tag.new(*, **), &block end def coco_spacer(size = Coco::Spacer::DEFAULT, **) render Coco::Spacer.new(size:, **) end alias_method :space, :coco_spacer def coco_stack(spacing: Coco::Spacer::DEFAULT, **, &block) render Coco::Stack.new(spacing:, **), &block end def coco_prose(**, &block) render Coco::Prose.new(**), &block end def coco_svg(path = nil, **) render Coco::Svg.new(path: path, **) end def coco_image(src = nil, **) render Coco::Image.new(src: src, **) end def coco_avatar(src, name = nil, **) render Coco::Avatar.new(src: src, name: name, **) end def coco_icon(icon_name = nil, **, &block) render Coco::Icon.new(name: icon_name, **), &block end def coco_badge(text, **) render Coco::Badge.new(**).with_content(text) end def coco_embed(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 def coco_placeholder(text_content = nil, **, &block) render Coco::Placeholder.new(text_content:, **), &block end 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 def coco_button_group(**, &block) render Coco::ButtonGroup.new(**), &block end def coco_modal(name = "default", **, &block) render(Coco::Modal.new(name: name, **), &block) end def coco_modal_dialog(name = "default", **, &block) render(Coco::Modal.new(name: name, **)) do |modal| modal.with_container_dialog(&block) end end 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 def coco_link_to_modal(*, data: {}, modal: nil, **kwargs, &) kwargs[:data] = coco_modal_data_attributes(modal || "default").merge(data) coco_link_to(*, **kwargs, &) end def coco_modal_frame_id(name = "default") "coco-modal-frame-#{name.to_s.dasherize}" end def coco_modal_data_attributes(name = "default") return {} if name.nil? { turbo: true, turbo_frame: coco_modal_frame_id(name) } end end end