-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-custom-component-with-JSON.htm
150 lines (111 loc) · 4.44 KB
/
02-custom-component-with-JSON.htm
1
2
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<title>Custom Component, based on JSON data</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<!-- LIBRARY FILES -->
<link rel="stylesheet" type="text/css" href="basic/basic.min.css">
<script src="basic/basic.min.js" type="text/javascript" charset="utf-8"></script>
<script>
const itemDataList = [
{ id: "1", label: "Broccoli", desc: "Vegetable", icon: "assets/broccoli.png" },
{ id: "2", label: "Strawberry", desc: "Fruit", icon: "assets/strawberry.png" },
{ id: "3", label: "Carrot", desc: "Vegetable", icon: "assets/carrot.png" },
{ id: "4", label: "Blueberries", desc: "Fruit", icon: "assets/blueberries.png" },
];
let itemList = [];
let containerBox;
window.onload = function() {
page.color = "whitesmoke";
// GROUP: Autolayout centered.
startFlexBox();
// BOX: Fruit items container box.
containerBox = startBox(40, 40, 300, "auto", {
color: "white",
round: 13,
});
for(let i = 0; i < itemDataList.length; i++) {
// PLANTITEM: Every item.
PlantItem(itemDataList[i]);
itemList.push(that);
const _item = that;
that.on("click", function(event) {
if (_item.selected == 1) {
_item.selected = 0;
_item.elem.style.filter = "none";
} else {
_item.selected = 1;
_item.elem.style.filter = "grayscale(100%)";
println(_item.id);
}
});
}
endBox(); // END containerBox
endFlexBox(); // END Autolayout
};
// CUSTOM COMPONENT:
const PlantItem = function(params = {}) {
// Default values:
const defaults = {
width: 300,
height: 94,
color: "transparent",
position: "relative",
};
// BOX: Component container box.
const box = startBox();
// Apply default values and params:
box.props(defaults, params);
// Private, public variables and functions:
const privateVariable = "";
box.publicVariable = "";
const privateFunction = function() {
};
box.publicFunction = function() {
};
// COMPONENT VIEW:
// BOX: Item background box.
box.backgroundBox = Box(4, 2, box.width - 8, 90, {
color: "rgba(0, 0, 0, 0.01)",
round: 13,
border: 1,
borderColor: "rgba(0, 0, 0, 0.04)",
});
that.setMotion("background-color 0.3s");
that.clickable = 1;
that.elem.style.cursor = "pointer";
// IMAGE: Item icon image.
Icon(30, 12, 70, 70, {
round: 4,
color: "transparent",
border: 0,
});
that.load(box.icon);
// LABEL: Item label text.
Label(120, 25, 280, "auto", {
text: box.label,
});
// LABEL: Item description text.
Label(120, 49, 280, "auto", {
text: box.desc,
textColor: "gray",
fontSize: 14,
});
// INIT CODE:
box.on("mouseover", function(event) {
box.backgroundBox.color = "rgba(90, 90, 0, 0.09)";
});
box.on("mouseout", function(event) {
box.backgroundBox.color = "rgba(0, 0, 0, 0.01)";
});
endBox();
makeBasicObject(box);
return box;
};
</script>
</head>
<body>
<!-- HTML content -->
</body>
</html>