Class: React::Component::Styles
Instance Method Summary
collapse
Constructor Details
#initialize(native, props_prop = false) ⇒ Styles
Returns a new instance of Styles.
4
5
6
7
|
# File 'lib/react/component/styles.rb', line 4
def initialize(native, props_prop = false)
@native = native
@props_prop = props_prop
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(prop, *args, &block) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/react/component/styles.rb', line 9
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 #{Proc.new { `value()` }} }
return Opal.React.Component.Styles.$new(value);
}
end
|
Instance Method Details
31
32
33
34
35
36
|
# File 'lib/react/component/styles.rb', line 31
def to_h
%x{
if (#@props_prop) { return Opal.Hash.$new(#@native.props[#@props_prop]); }
else { return Opal.Hash.$new(#@native); }
}
end
|
38
39
40
41
42
43
|
# File 'lib/react/component/styles.rb', line 38
def to_n
%x{
if (#@props_prop) { return #@native.props[#@props_prop]; }
else { return #@native; }
}
end
|