Sha256: a425c01a7d85756c45a5291069a02e602b36e990895d3f07a85f801640c7ae96
Contents?: true
Size: 1.68 KB
Versions: 4
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true module FComponents module Button class Component < FComponents::Base TYPE_CLASSES = { primary: 'bt--primary', secondary: 'bt--primary bt--outlined', tertiary: 'bt--tertiary', custom: '' }.freeze MODIFIERS = { success: 'bt--success', secondary: 'bt--secondary', error: 'bt--error', white: 'bt--white', warning: 'bt--warning', fit: 'w--fit max-w--fit', full: 'bt--full', outlined: 'bt--outlined', small: 'bt--smr', large: 'bt--lg', centered: 'mx--auto' }.freeze MODS = MODIFIERS.to_h.deep_dup MODS.default_proc = proc { |_hash, key| "bt--#{key}" } attr_reader :href, :options def initialize(title, href = nil, **options) @title = title @href = href || 'javascript: void(0);' @modifiers = options.delete(:mods) @type = options.delete(:type) || :primary @tag = options.delete(:tag) || :a @class = options.delete(:class) || '' @left_icon = options.delete(:left_icon) @options = options end private def button_tag? @tag == :button end def title @left_icon.present? ? fa_icon(@left_icon, class: 'bt-leftIcon', text: @title) : @title end def classes "bt bt--round #{button_type_class} #{modifiers} #{@class}" end def button_type_class raise 'Unkown button type' unless TYPE_CLASSES.has_key?(@type) TYPE_CLASSES[@type] end def modifiers MODS.values_at(*@modifiers).compact.join(' ') end end end end
Version data entries
4 entries across 4 versions & 1 rubygems