Class: HakumiComponents::FloatButton::PositionConfig
- Inherits:
-
Object
- Object
- HakumiComponents::FloatButton::PositionConfig
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/float_button/position_config.rb
Constant Summary collapse
- PLACEMENTS =
T.let({ bottom_right: { bottom: 24, right: 24 }, bottom_left: { bottom: 24, left: 24 }, top_right: { top: 24, right: 24 }, top_left: { top: 24, left: 24 } }.freeze, T::Hash[Symbol, T::Hash[Symbol, Integer]])
- OffsetValue =
T.type_alias { T.nilable(T.any(Integer, String)) }
- OffsetMap =
T.type_alias { T::Hash[Symbol, OffsetValue] }
Instance Attribute Summary collapse
-
#floating ⇒ Object
readonly
Returns the value of attribute floating.
-
#placement ⇒ Object
readonly
Returns the value of attribute placement.
Instance Method Summary collapse
-
#initialize(floating:, placement:, offset: nil) ⇒ PositionConfig
constructor
A new instance of PositionConfig.
- #resolved_offset ⇒ Object
- #style ⇒ Object
Constructor Details
#initialize(floating:, placement:, offset: nil) ⇒ PositionConfig
Returns a new instance of PositionConfig.
20 21 22 23 24 25 |
# File 'app/components/hakumi_components/float_button/position_config.rb', line 20 def initialize(floating:, placement:, offset: nil) @floating = T.let(floating, T::Boolean) @placement = T.let(placement, Symbol) @offset = T.let(offset, T.nilable(OffsetMap)) validate_placement! end |
Instance Attribute Details
#floating ⇒ Object (readonly)
Returns the value of attribute floating.
28 29 30 |
# File 'app/components/hakumi_components/float_button/position_config.rb', line 28 def floating @floating end |
#placement ⇒ Object (readonly)
Returns the value of attribute placement.
31 32 33 |
# File 'app/components/hakumi_components/float_button/position_config.rb', line 31 def placement @placement end |
Instance Method Details
#resolved_offset ⇒ Object
47 48 49 50 51 |
# File 'app/components/hakumi_components/float_button/position_config.rb', line 47 def resolved_offset base = T.let(PLACEMENTS.fetch(@placement).dup, OffsetMap) extra = @offset || {} base.merge(extra).compact end |
#style ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/components/hakumi_components/float_button/position_config.rb', line 34 def style return nil unless @floating segments = T.let([ "position: fixed", "z-index: 1000" ], T::Array[String]) resolved_offset.each do |key, value| next if value.nil? segments << "#{key}: #{dimension(value)}" end segments.join("; ") end |