Sha256: 022f315a720a779b6f1413092b54442454928444307a7bfd83498c4420abc2aa
Contents?: true
Size: 1.17 KB
Versions: 5
Compression:
Stored size: 1.17 KB
Contents
module Coco class Modal < Coco::Component include Concerns::AcceptsOptions include Turbo::FramesHelper accepts_option :dismissable, from: [true, false], default: true accepts_option :close_on_submit, from: [true, false], default: true renders_one :title renders_one :dialog, ->(**kwargs, &block) do @dialog_content = capture { block.call } Coco::ModalDialog.new(dismissable: get_option_value(:dismissable), **kwargs) end before_render do if dialog? && title? dialog.with_title { title.to_s } end end attr_reader :name, :show def initialize(name:, show: false, **kwargs) @name = name @show = show title { kwargs[:title] } if kwargs[:title] end def render_as_modal? request.headers["Turbo-Frame"].present? || show end def id "coco-modal-#{name.to_s.dasherize}" end def modal_content dialog? ? dialog : content end def content @dialog_content || super end def render_flash_messages if helpers.respond_to?(:render_turbo_stream_flash_messages) helpers.render_turbo_stream_flash_messages end end end end
Version data entries
5 entries across 5 versions & 1 rubygems