3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/lucid_component/api.rb', line 3
def self.included(base)
base.instance_exec do
def prop(name, options = `null`)
name = `Opal.React.lower_camelize(name)`
if options
if options.key?(:default)
%x{
if (typeof self.lucid_react_component.defaultProps == "undefined") {
self.lucid_react_component.defaultProps = { isomorfeus_store: Opal.Hash.$new() };
}
self.lucid_react_component.defaultProps[name] = options.$fetch("default");
}
end
if options.key?(:class)
%x{
if (typeof self.lucid_react_component.propTypes == "undefined") {
self.lucid_react_component.propTypes = {};
self.lucid_react_component.propValidations = {};
self.lucid_react_component.propValidations[name] = {};
}
self.lucid_react_component.propTypes[name] = self.lucid_react_component.prototype.validateProp;
self.lucid_react_component.propValidations[name].ruby_class = options.$fetch("class");
}
elsif options.key?(:is_a)
%x{
if (typeof self.lucid_react_component.propTypes == "undefined") {
self.lucid_react_component.propTypes = {};
self.lucid_react_component.propValidations = {};
self.lucid_react_component.propValidations[name] = {};
}
self.lucid_react_component.propTypes[name] = self.lucid_react_component.prototype.validateProp;
self.lucid_react_component.propValidations[name].is_a = options.$fetch("is_a");
}
end
if options.key?(:required)
%x{
if (typeof self.lucid_react_component.propTypes == "undefined") {
self.lucid_react_component.propTypes = {};
self.lucid_react_component.propValidations = {};
self.lucid_react_component.propValidations[name] = {};
}
self.lucid_react_component.propTypes[name] = self.lucid_react_component.prototype.validateProp;
self.lucid_react_component.propValidations[name].required = options.$fetch("required");
}
elsif !options.key?(:default)
%x{
if (typeof self.lucid_react_component.propTypes == "undefined") {
self.lucid_react_component.propTypes = {};
self.lucid_react_component.propValidations = {};
}
self.lucid_react_component.propTypes[name] = self.lucid_react_component.prototype.validateProp;
self.lucid_react_component.propValidations[name].required = true;
}
end
else
%x{
if (typeof self.lucid_react_component.propTypes == "undefined") {
self.lucid_react_component.propTypes = {};
self.lucid_react_component.propValidations = {};
self.lucid_react_component.propValidations[name] = {};
}
self.lucid_react_component.propTypes[name] = self.lucid_react_component.prototype.validateProp;
self.lucid_react_component.propValidations[name].required = options.$fetch("required");
}
end
end
def default_props
return @default_props if @default_props
%x{
if (typeof self.lucid_react_component.defaultProps == "undefined") {
self.lucid_react_component.defaultProps = { isomorfeus_store: Opal.Hash.$new() };
}
}
@default_props = React::Component::Props.new(`{props: self.lucid_react_component.defaultProps}`)
end
end
end
|