Class: NitroKit::ResponsiveValue

Inherits:
Object
  • Object
show all
Defined in:
app/components/nitro_kit/responsive_value.rb

Constant Summary collapse

BREAKPOINTS =
{
  "sm" => "40rem",
  "md" => "48rem",
  "lg" => "64rem",
  "xl" => "80rem",
  "2xl" => "96rem"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(property:, value:, allowed:) ⇒ ResponsiveValue

Returns a new instance of ResponsiveValue.



13
14
15
16
17
18
# File 'app/components/nitro_kit/responsive_value.rb', line 13

def initialize(property:, value:, allowed:)
  @property = property
  @allowed = allowed.map { |candidate| normalize(candidate) }.freeze
  @values = parse(value).freeze
  freeze
end

Instance Method Details

#to_sObject



20
21
22
23
24
25
26
27
# File 'app/components/nitro_kit/responsive_value.rb', line 20

def to_s
  [ nil, *BREAKPOINTS.keys ].filter_map do |breakpoint|
    value = @values[breakpoint]
    next unless value

    breakpoint ? "#{breakpoint}:#{value}" : value
  end.join(" ")
end