class React::Component::Styles

Public Class Methods

new(native, props_prop = false) click to toggle source
# File lib/react/component/styles.rb, line 5
def initialize(native, props_prop = false)
  @native = native
  @props_prop = props_prop
end

Public Instance Methods

[](prop) click to toggle source
# File lib/react/component/styles.rb, line 10
def [](prop)
  method_missing(prop)
end
[]=(prop, val) click to toggle source
# File lib/react/component/styles.rb, line 14
def []=(prop, val)
  method_missing(prop, val)
end
deep_merge(a_hash) click to toggle source
# File lib/react/component/styles.rb, line 18
def deep_merge(a_hash)
  native_hash = a_hash.to_n
  React::Component::Styles.new(`Opal.React.merge_deep(#@native, native_hash)`)
end
deep_merge!(a_hash) click to toggle source
# File lib/react/component/styles.rb, line 23
def deep_merge!(a_hash)
  native_hash = a_hash.to_n
  `#@native = Opal.React.merge_deep(#@native, native_hash)`
  self
end
method_missing(prop, *args, &block) click to toggle source
# File lib/react/component/styles.rb, line 29
def method_missing(prop, *args, &block)
  %x{
    let value;
    if (#@props_prop) {
      if (!#@native.props[#@props_prop] || typeof #@native.props[#@props_prop][prop] === 'undefined') {
        console.warn("Style/Theme key '" + prop + "' returning nil!");
        return #{nil};
      }
      value = #@native.props[#@props_prop][prop];
    } else {
      if (!#@native || typeof #@native[prop] === 'undefined') {
        console.warn("Style/Theme key '" + prop + "' returning nil!");
        return #{nil};
      }
      value = #@native[prop];
    }
    if (typeof value === 'string' || typeof value === 'number' || Array.isArray(value)) { return value; }
    if (typeof value === 'function') { return value.apply(#@native, args); }
    return Opal.React.Component.Styles.$new(value);
  }
end
to_h() click to toggle source
# File lib/react/component/styles.rb, line 51
def to_h
  %x{
    if (#@props_prop) { return Opal.Hash.$new(#@native.props[#@props_prop]); }
    else { return Opal.Hash.$new(#@native); }
  }
end
to_n() click to toggle source
# File lib/react/component/styles.rb, line 58
def to_n
  %x{
    if (#@props_prop) { return #@native.props[#@props_prop]; }
    else { return #@native; }
  }
end