module Coco class LayoutPickerButton < Coco::Component include Concerns::AcceptsOptions include Concerns::WithDropdownOptions include Concerns::WrapsComponent wraps_component :button do |args| args[:class] = [args[:class], "layout-picker-trigger"] Coco::Button.new(**args) end renders_many :layouts, ->(name:, thumbnail: nil, **layout_options, &block) do @layout_options << {name: name, thumbnail: thumbnail, **layout_options, icon: block&.call} end attr_reader :layout_options, :size, :resize def initialize(selected: nil, **kwargs) @selected = selected @layout_options = [] @resize = {} @size = kwargs.fetch(:size, :default)&.to_sym if @size.in?(Coco::Button::SIZE_ALIASES.keys) && !kwargs.key?(:resize) @size, @resize = Coco::Button::SIZE_ALIASES.fetch(@size) end end def selected @selected || @layout_options.first[:name] end end end