Rebel Artimus commited on
Commit
6aacd12
·
1 Parent(s): 3265146

Add 3 files

Browse files
Files changed (3) hide show
  1. index.html +1 -19
  2. main.js +90 -0
  3. style.css +70 -26
index.html CHANGED
@@ -1,19 +1 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
1
+ <html><head><link href="https://cdn.jsdelivr.net/npm/daisyui@3.1.6/dist/full.css" rel="stylesheet" type="text/css" /><script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script><script src="https://cdn.tailwindcss.com?plugins=forms,typography,aspect-ratio"></script><script defer src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.156.1/three.min.js"></script><script type="module" src="main.js"></script><title>Page Builder</title></head><body></body></html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.js ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Grab and store references to frequently used elements.
3
+ * These are used throughout the app.
4
+ */
5
+ const swapTemplate = document.querySelector('template');
6
+ const draggableItems = document.querySelectorAll('[data-draggable]');
7
+ const draggableItemsStore = [];
8
+ const toolbarBtns = document.querySelectorAll('.toolbar-btn');
9
+ const widgetsBtns = document.querySelectorAll('.widgets .btn');
10
+ const widgetHolder = document.querySelector('.widgets');
11
+ const widgetsCounter = document.querySelector('.widgets-counter');
12
+ const popupContainer = document.querySelector('.popup-container');
13
+ const popup = document.querySelector('.popup');
14
+ /**
15
+ * Event listeners
16
+ */
17
+ // Draggable items
18
+ draggableItems.forEach((item) => {
19
+ new Drag(item);
20
+ });
21
+ // Toolbar buttons
22
+ toolbarBtns.forEach((btn) => {
23
+ btn.addEventListener('click', (e) => {
24
+ e.stopPropagation();
25
+ toggleEditMode();
26
+ });
27
+ });
28
+ // Widget buttons
29
+ widgetsBtns.forEach((btn) => {
30
+ btn.addEventListener('click', (e) => {
31
+ e.preventDefault();
32
+ addWidget(btn.dataset.widget);
33
+ });
34
+ });
35
+ // Click event to close popup
36
+ document.addEventListener('click', (e) => {
37
+ const target = e.target;
38
+ if (e.target.classList.contains('icon-remove')) {
39
+ const popup = target.closest('.popup');
40
+ popup.classList.remove('show');
41
+ }
42
+ });
43
+ // Add widget to widgetHolder
44
+ const addWidget = (widget) => {
45
+ const el = swapTemplate.content.cloneNode(true);
46
+ el.querySelector('h2').textContent = widget.name;
47
+ el.querySelector('p').innerHTML = widget.description;
48
+ widgetHolder.appendChild(el);
49
+ draggableItemsStore.push(new Drag(el));
50
+ updateWidgetsCounter();
51
+ };
52
+ // Update widgets counter
53
+ const updateWidgetsCounter = () => {
54
+ const counter = widgetsCounter.querySelector('span');
55
+ counter.textContent = `${widgetHolder.children.length || ''} Widgets`;
56
+ };
57
+ // Toggle Edit Mode
58
+ const toggleEditMode = () => {
59
+ popupContainer.classList.toggle('show');
60
+ document.body.classList.toggle('edit');
61
+ };
62
+ /**
63
+ * Init
64
+ */
65
+ const init = () => {
66
+ // Add widgets from array
67
+ const widgets = [
68
+ {
69
+ name: 'Text widget',
70
+ description: 'This is a text widget',
71
+ icon: 'fa-pencil-alt',
72
+ },
73
+ {
74
+ name: 'Photo widget',
75
+ description: 'This is a photo widget',
76
+ icon: 'fa-images',
77
+ },
78
+ {
79
+ name: 'Chart widget',
80
+ description: 'This is a chart widget',
81
+ icon: 'fa-chart-pie',
82
+ },
83
+ ];
84
+
85
+ // Call addWidget() for each widget
86
+ widgets.forEach((widget) => addWidget(widget));
87
+ };
88
+ init();
89
+
90
+ </script>
style.css CHANGED
@@ -1,28 +1,72 @@
 
 
 
 
 
 
 
1
  body {
2
- padding: 2rem;
3
- font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
4
- }
5
-
6
- h1 {
7
- font-size: 16px;
8
- margin-top: 0;
9
- }
10
-
11
- p {
12
- color: rgb(107, 114, 128);
13
- font-size: 15px;
14
- margin-bottom: 10px;
15
- margin-top: 5px;
16
- }
17
-
18
- .card {
19
- max-width: 620px;
20
- margin: 0 auto;
21
- padding: 16px;
22
- border: 1px solid lightgray;
23
- border-radius: 16px;
24
- }
25
-
26
- .card p:last-child {
27
- margin-bottom: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
 
 
 
1
+ @import url('https://fonts.googleapis.com/css?family=Roboto:400,700,900&display=swap');
2
+ /** GLOBAL CSS **/
3
+ *,
4
+ *::before,
5
+ *::after {
6
+ box-sizing: border-box;
7
+ }
8
  body {
9
+ padding: 2rem;
10
+ max-width: 500px;
11
+ margin: 0 auto;
12
+ text-align: center;
13
+ font-family: 'Roboto', sans-serif;
14
+ background-color: #f5f5f5;
15
+ }
16
+ .main-container {
17
+ background-color: #fff;
18
+ padding: 2rem;
19
+ border-radius: 12px;
20
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.12);
21
+ }
22
+ /** POPUP CSS **/
23
+ .popup-container {
24
+ position: fixed;
25
+ top: 0;
26
+ left: 0;
27
+ width: 100%;
28
+ height: 100%;
29
+ background-color: rgba(0, 0, 0, 0.3);
30
+ display: flex;
31
+ justify-content: center;
32
+ align-items: center;
33
+ z-index: 10;
34
+ }
35
+ .popup {
36
+ width: 500px;
37
+ padding: 2rem;
38
+ border-radius: 12px;
39
+ background-color: #fff;
40
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.12);
41
+ }
42
+ .popup-btn-close {
43
+ position: absolute;
44
+ top: 1rem;
45
+ right: 1rem;
46
+ }
47
+ /** DRAGGABLE CSS **/
48
+ .widget {
49
+ padding: 1rem;
50
+ border: 1px solid #ccc;
51
+ border-radius: 12px;
52
+ background-color: #fff;
53
+ cursor: move;
54
+ }
55
+ /** TOOLBAR CSS **/
56
+ .toolbar {
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: space-between;
60
+ }
61
+ .toolbar-btn {
62
+ background-color: #fff;
63
+ border: 1px solid #ccc;
64
+ border-radius: 12px;
65
+ padding: 0.5rem 1rem;
66
+ cursor: pointer;
67
+ }
68
+ .toolbar-btn-active {
69
+ background-color: #aee4f0;
70
  }
71
+ /** FONT AWESOME Icons **/
72
+ @import "https://kit.fontawesome.com/72adea038a.js";