Skip to content

Commit 6eed2cf

Browse files
authored
Create elements_docs.md
1 parent 0318493 commit 6eed2cf

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

src/gp2/elements_docs.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# 🛠 GP2 Elements Engine Documentation
2+
**Location:** `./src/gp2/elements.js`
3+
4+
This is the custom rendering engine for Random Rants +. It allows us to build the UI using lightweight JS objects (JSON) instead of heavy frameworks like React.
5+
6+
---
7+
8+
## 🚀 Basic Usage
9+
To create an element, pass an array of objects to elements.createElementsFromJSON().
10+
11+
const elements = require('./gp2/elements.js');
12+
13+
const myUI = elements.createElementsFromJSON([
14+
{
15+
element: "div",
16+
className: "rant-container",
17+
style: {
18+
padding: "10px",
19+
backgroundColor: "#222"
20+
},
21+
children: [
22+
{
23+
element: "h1",
24+
textContent: "Hello Rant World!",
25+
style: { color: "cyan" }
26+
}
27+
]
28+
}
29+
]);
30+
31+
document.body.append(...myUI);
32+
33+
---
34+
35+
## 🔑 Special Properties
36+
37+
- element: The HTML tag name (e.g., "div", "button", "input").
38+
- gid: Global ID. Stores the element in __GP_elements. Access it later via elements.getGPId("id").
39+
- children: An array of more element objects to nest inside this one.
40+
- style: An object of CSS properties (e.g., { color: "red" }).
41+
- styleProperties: Uses style.setProperty. Good for CSS variables like --user-color.
42+
- eventListeners: An array of objects: [{ event: "click", func: myFunc }].
43+
- GPWhenCreated: A function that runs as soon as the element is made. "this" refers to the element.
44+
- dangerouslySetInnerHTML: Used to inject raw HTML. (Replaces the deprecated innerHTML).
45+
46+
---
47+
48+
## 🛠 Advanced Example: Interactive Component
49+
Use GPWhenCreated and eventListeners to make things interactive.
50+
51+
const chatInput = elements.createElementsFromJSON([
52+
{
53+
element: "input",
54+
gid: "main-input",
55+
placeholder: "Type a rant...",
56+
eventListeners: [
57+
{
58+
event: "keydown",
59+
func: (e) => { if(e.key === "Enter") console.log("Sent!"); }
60+
}
61+
],
62+
GPWhenCreated: function(elm) {
63+
console.log("Input is ready!");
64+
elm.focus();
65+
}
66+
}
67+
]);
68+
69+
---
70+
71+
## ⚠️ Guidelines for Contributors
72+
1. No React: Use this engine. It's lighter for school Chromebooks.
73+
2. Render Free Tier: Keep the code light. Don't cause memory leaks.
74+
3. Cleaning Up: If you use a gid, use elements.disposeGPId("id") if the element is removed.

0 commit comments

Comments
 (0)