-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-accordion-fixed.html
More file actions
112 lines (101 loc) · 4.41 KB
/
test-accordion-fixed.html
File metadata and controls
112 lines (101 loc) · 4.41 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accordion Test - Fixed</title>
<script src="https://cdn.tailwindcss.com"></script>
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="src/dry2/base.js"></script>
<script src="src/dry2/accordion.js"></script>
<script src="src/dry2/component-builder.js"></script>
</head>
<body class="bg-gray-50 p-8">
<div class="max-w-4xl mx-auto">
<h1 class="text-3xl font-bold text-gray-900 mb-8">Accordion Component Test</h1>
<!-- Test 1: Regular Accordion with items already present -->
<section class="mb-8">
<h2 class="text-xl font-semibold mb-4">Test 1: Pre-loaded Items</h2>
<dry-accordion>
<accordion-item title="Section 1" open>
<p>This is section 1 content</p>
</accordion-item>
<accordion-item title="Section 2">
<p>This is section 2 content</p>
</accordion-item>
</dry-accordion>
</section>
<!-- Test 2: Component Builder Test -->
<section class="mb-8">
<h2 class="text-xl font-semibold mb-4">Test 2: Component Builder</h2>
<div id="accordion-test-builder"></div>
</section>
<!-- Test 3: Dynamic Item Addition -->
<section class="mb-8">
<h2 class="text-xl font-semibold mb-4">Test 3: Dynamic Item Addition</h2>
<button id="add-item-btn" class="bg-blue-500 text-white px-4 py-2 rounded mb-4">
Add Item Dynamically
</button>
<dry-accordion id="dynamic-accordion">
<!-- Items will be added dynamically -->
</dry-accordion>
</section>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Test 2: Component Builder
new ComponentBuilder({
elementId: 'accordion-test-builder',
componentTag: 'dry-accordion',
title: 'Accordion Builder Test',
description: 'Testing the accordion component builder fixes.',
properties: {
multiple: {
type: 'checkbox',
label: 'Multiple Mode',
default: false
}
},
defaults: {
multiple: false
},
previewWrapper: function(componentHTML) {
const openingTag = componentHTML.replace('</dry-accordion>', '');
return `
<div class="w-full">
${openingTag}
<accordion-item title="Test Section 1">
<p>Test content 1</p>
</accordion-item>
<accordion-item title="Test Section 2" open>
<p>Test content 2</p>
</accordion-item>
</dry-accordion>
</div>
`;
},
contentGenerator: function(values) {
return '';
}
});
// Test 3: Dynamic item addition
let itemCount = 0;
document.getElementById('add-item-btn').addEventListener('click', function() {
itemCount++;
const accordion = document.getElementById('dynamic-accordion');
const newItem = document.createElement('accordion-item');
newItem.setAttribute('title', `Dynamic Item ${itemCount}`);
newItem.innerHTML = `<p>This is dynamically added item ${itemCount}</p>`;
accordion.appendChild(newItem);
});
// Log accordion events
document.addEventListener('accordion:change', function(event) {
console.log('Accordion change:', event.detail);
});
document.addEventListener('accordion:initialized', function(event) {
console.log('Accordion initialized:', event.detail);
});
});
</script>
</body>
</html>