File size: 2,950 Bytes
b8d400c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a515efb
b8d400c
 
 
a515efb
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
// FlexDroid - Android Flex Design Studio

let currentClasses = ['flex', 'flex-col', 'items-center', 'justify-center', 'gap-4'];
let itemCount = 2;
let itemHeight = 'h-24';

function updateFlex(className) {
    // Remove existing flex classes
    const flexPrefixes = ['flex-', 'justify-', 'items-', 'gap-'];
    currentClasses = currentClasses.filter(cls => 
        !flexPrefixes.some(prefix => cls.startsWith(prefix))
    );
    
    // Add new class
    currentClasses.push(className);
    
    // Update preview
    updatePreview();
    
    // Update active buttons
    document.querySelectorAll('.flex-btn').forEach(btn => {
        btn.classList.remove('bg-indigo-100', 'text-indigo-800');
        btn.classList.add('bg-gray-100', 'text-gray-800');
    });
    
    const activeBtn = document.querySelector(`.flex-btn[onclick="updateFlex('${className}')"]`);
    if (activeBtn) {
        activeBtn.classList.remove('bg-gray-100', 'text-gray-800');
        activeBtn.classList.add('bg-indigo-100', 'text-indigo-800');
    }
}

function updateItemCount(count) {
    itemCount = parseInt(count);
    updatePreview();
}

function updateItemHeight(height) {
    itemHeight = height;
    updatePreview();
}

function updatePreview() {
    const previewContent = document.getElementById('previewContent');
    previewContent.className = currentClasses.join(' ');
    
    // Generate items
    let itemsHTML = '';
    for (let i = 0; i < itemCount; i++) {
        itemsHTML += `
            <div class="bg-indigo-100 p-4 rounded-lg ${itemHeight} flex items-center justify-center">
                <p class="text-indigo-800">Flex Item ${i+1}</p>
            </div>
        `;
    }
    
    previewContent.innerHTML = itemsHTML;
    
    // Update code output
    updateCodeOutput();
}

function updateCodeOutput() {
    const codeOutput = document.getElementById('codeOutput');
    let itemsCode = '';
    
    for (let i = 0; i < itemCount; i++) {
        itemsCode += `
    &lt;div class="bg-indigo-100 p-4 rounded-lg ${itemHeight} flex items-center justify-center"&gt;
        &lt;p class="text-indigo-800"&gt;Flex Item ${i+1}&lt;/p&gt;
    &lt;/div&gt;`;
    }
    
    const classesStr = currentClasses.map(c => c.replace(/-/g, '\\-')).join(' ');
    codeOutput.textContent = `&lt;div class="${classesStr}"&gt;${itemsCode}
&lt;/div&gt;`;
}

function copyCode() {
    const code = document.getElementById('codeOutput').textContent;
    navigator.clipboard.writeText(code.replace(/&lt;/g, '<').replace(/&gt;/g, '>'));
    
    // Show copied notification
    const btn = document.querySelector('[onclick="copyCode()"]');
    const originalText = btn.innerHTML;
    btn.innerHTML = '<i data-feather="check"></i> Copied!';
    feather.replace();
    
    setTimeout(() => {
        btn.innerHTML = originalText;
        feather.replace();
    }, 2000);
}

// Initialize
document.addEventListener('DOMContentLoaded', () => {
    updatePreview();
});