Sha256: 1fc0a8a5f352748e90005eb49029691f38f6cd163d43d336145ead8e5dea405a
Contents?: true
Size: 1.85 KB
Versions: 6
Compression:
Stored size: 1.85 KB
Contents
module Coco module App module Elements class ImagePickerButton < Coco::Component include Concerns::WithDropdownOptions include Concerns::WrapsComponent include Coco::AppHelper wraps_component :button do |args| Coco::App::Elements::Button.new(icon: :image_plus, **args) end renders_one :text, Coco::Content renders_one :picker, ->(picker = nil, **kwargs, &block) do if picker.is_a?(Coco::App::Elements::ImagePicker) picker else picker&.to_s.presence || Coco::App::Elements::ImagePicker.new( size: @size, resize: @resize, src: @src, **kwargs ) end end before_render do with_picker(src: @src) unless picker? end attr_reader :src def initialize(src: nil, **kwargs) @src = src @size = kwargs.fetch(:size, :default)&.to_sym if @size.in?(Coco::App::Elements::Button::SIZE_ALIASES.keys) && !kwargs.key?(:resize) @size, @resize = Coco::App::Elements::Button::SIZE_ALIASES.fetch(@size) end end # def input # if input_name # kwargs = { # class: "picker-file-input", # "x-ref": "fileInput", # direct_upload: @direct_upload # } # if direct_upload? && !helpers.respond_to?(:rails_direct_uploads_url) # kwargs[:data] = {direct_upload_url: @direct_upload} # end # if @form_builder # @form_builder.file_field(input_name, **kwargs) # else # file_field_tag(input_name, **kwargs) # end # end # end def button_text text || content end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems