Sha256: 1d53a7c82ce685a78575cc3720dbd2ec167bd40ea3926fcef8611063b9c8c381
Contents?: true
Size: 1.47 KB
Versions: 30
Compression:
Stored size: 1.47 KB
Contents
module Coco class Stack < Coco::Component include Concerns::AcceptsOptions accepts_option :spacing, from: Coco::Spacer::SIZES, default: Coco::Spacer::DEFAULT, private: true accepts_option :direction, from: %i[vertical], default: :vertical renders_many :items, types: { element: ->(tag_name = :div, **kwargs) do with_space if items.any? && !ends_with_spacer? @_last_item_type = :element kwargs[:class] = class_names(kwargs[:class], "stack-item") Coco::Tag.new(tag_name, **kwargs) end, stack: ->(size = spacing, **kwargs) do with_space if items.any? && !ends_with_spacer? @_last_item_type = :stack kwargs[:class] = class_names(kwargs[:class], "stack-substack") Coco::Stack.new(spacing: size, **kwargs) end, spacer: ->(size = spacing, **kwargs) do @_starts_with_spacer = true if items.none? @_last_item_type = :spacer kwargs[:class] = class_names(kwargs[:class], "stack-spacer") Coco::Spacer.new(size:, **kwargs) end } def initialize(**) @_items = [] @_starts_with_spacer = false @_last_item_type = nil end def spacing = get_option_value(:spacing) def starts_with_spacer? = @_starts_with_spacer def ends_with_spacer? = @_last_item_type == :spacer alias_method :with_item, :with_item_element alias_method :with_substack, :with_item_stack alias_method :with_space, :with_item_spacer end end
Version data entries
30 entries across 30 versions & 1 rubygems