Class: Rolemodel::Optics::IconBuilder
- Inherits:
-
Object
- Object
- Rolemodel::Optics::IconBuilder
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/rolemodel/optics/icon_builder.rb
Direct Known Subclasses
CustomIconBuilder, FeatherIconBuilder, LucideIconBuilder, MaterialIconBuilder, PhosphorIconBuilder, TablerIconBuilder
Constant Summary collapse
- DEFAULT_SIZE =
'medium'- DEFAULT_WEIGHT =
'normal'- DEFAULT_EMPHASIS =
'normal'
Instance Attribute Summary collapse
-
#additional_classes ⇒ Object
readonly
Returns the value of attribute additional_classes.
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#duotone ⇒ Object
readonly
Returns the value of attribute duotone.
-
#emphasis ⇒ Object
readonly
Returns the value of attribute emphasis.
-
#filled ⇒ Object
readonly
Returns the value of attribute filled.
-
#hover_text ⇒ Object
(also: #title)
readonly
Returns the value of attribute hover_text.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(name, filled: false, size: DEFAULT_SIZE, weight: DEFAULT_WEIGHT, emphasis: DEFAULT_EMPHASIS, duotone: false, additional_classes: '', color: '', hover_text: name) ⇒ IconBuilder
constructor
TODO: consider Data.define a custom options object if all of these parameters are indeed necessary.
Constructor Details
#initialize(name, filled: false, size: DEFAULT_SIZE, weight: DEFAULT_WEIGHT, emphasis: DEFAULT_EMPHASIS, duotone: false, additional_classes: '', color: '', hover_text: name) ⇒ IconBuilder
TODO: consider Data.define a custom options object if all of these parameters are indeed necessary.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 14 def initialize( # rubocop:disable Metrics/ParameterLists name, filled: false, size: DEFAULT_SIZE, weight: DEFAULT_WEIGHT, emphasis: DEFAULT_EMPHASIS, duotone: false, additional_classes: '', color: '', hover_text: name ) @name = name @filled = filled @size = size @weight = weight @emphasis = emphasis @duotone = duotone @additional_classes = additional_classes @color = color @hover_text = hover_text end |
Instance Attribute Details
#additional_classes ⇒ Object (readonly)
Returns the value of attribute additional_classes.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def additional_classes @additional_classes end |
#color ⇒ Object (readonly)
Returns the value of attribute color.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def color @color end |
#duotone ⇒ Object (readonly)
Returns the value of attribute duotone.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def duotone @duotone end |
#emphasis ⇒ Object (readonly)
Returns the value of attribute emphasis.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def emphasis @emphasis end |
#filled ⇒ Object (readonly)
Returns the value of attribute filled.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def filled @filled end |
#hover_text ⇒ Object (readonly) Also known as: title
Returns the value of attribute hover_text.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def hover_text @hover_text end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def size @size end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
6 7 8 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 6 def weight @weight end |
Class Method Details
.flash_icon(type) ⇒ Object
36 37 38 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 36 def self.flash_icon(type, **) new(flash_icons[type.to_sym], **) end |
.flash_icons ⇒ Object
40 41 42 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 40 def self.flash_icons raise NotImplementedError end |
Instance Method Details
#build ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rolemodel/optics/icon_builder.rb', line 44 def build = { class: tag_classes.compact_blank.join(' '), title: hover_text, # color: primary, neutral, alerts-notice, alerts-warning, alerts-danger, alerts-info style: ("#{color_attribute}: var(--op-color-#{color}-base);" if color.present?) }.compact_blank tag.public_send(tag_method, tag_contents, **) end |