-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreactive-test.stx
More file actions
245 lines (227 loc) · 8.29 KB
/
reactive-test.stx
File metadata and controls
245 lines (227 loc) · 8.29 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<script server>
import { defineProps, withDefaults } from 'stx'
interface ReactiveTestProps {
title?: string
items?: string[]
}
const { title, items } = withDefaults(
defineProps<ReactiveTestProps>(),
{
title: 'STX Reactive Directives Test',
items: ['Apple', 'Banana', 'Cherry']
}
)
</script>
<!DOCTYPE html>
<html>
<head>
<title>{{ title }}</title>
<style>
* { box-sizing: border-box; }
body {
font-family: system-ui, -apple-system, sans-serif;
padding: 2rem;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
color: #eee;
min-height: 100vh;
margin: 0;
}
.container { max-width: 900px; margin: 0 auto; }
h1 { color: #e94560; margin-bottom: 2rem; }
h2 {
color: #4ecca3;
background: rgba(78, 204, 163, 0.1);
padding: 0.75rem 1rem;
border-radius: 6px;
border-left: 4px solid #4ecca3;
margin-top: 2rem;
}
.panel {
padding: 1.5rem;
background: rgba(255, 255, 255, 0.05);
margin: 1rem 0;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
}
button {
padding: 0.6rem 1.2rem;
margin: 0.25rem;
cursor: pointer;
background: #e94560;
color: white;
border: none;
border-radius: 6px;
font-size: 0.95rem;
transition: all 0.2s;
}
button:hover { background: #ff6b88; transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
input, select {
padding: 0.6rem;
margin: 0.25rem;
border-radius: 6px;
border: 1px solid rgba(255, 255, 255, 0.2);
background: rgba(255, 255, 255, 0.1);
color: white;
font-size: 0.95rem;
}
input::placeholder { color: rgba(255, 255, 255, 0.5); }
input:focus { outline: none; border-color: #4ecca3; }
ul { padding-left: 1.5rem; }
li { margin: 0.5rem 0; }
.positive { color: #4ecca3; }
.negative { color: #e94560; }
.zero { color: #ffcc00; }
.log-area {
background: rgba(0, 0, 0, 0.3);
padding: 1rem;
margin-top: 1rem;
font-family: 'Fira Code', monospace;
font-size: 0.85rem;
border-radius: 6px;
max-height: 150px;
overflow-y: auto;
}
hr { margin: 2rem 0; border: none; border-top: 1px solid rgba(255, 255, 255, 0.1); }
/* Custom transition classes */
.fade-in { opacity: 0; }
.fade-in-active { transition: opacity 300ms ease-out; }
.fade-in-to { opacity: 1; }
.fade-out { opacity: 1; }
.fade-out-active { transition: opacity 200ms ease-in; }
.fade-out-to { opacity: 0; }
.slide-up { transform: translateY(10px); opacity: 0; }
.slide-up-active { transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1); }
.slide-up-to { transform: translateY(0); opacity: 1; }
.slide-down { transform: translateY(0); opacity: 1; }
.slide-down-active { transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1); }
.slide-down-to { transform: translateY(-10px); opacity: 0; }
</style>
</head>
<body>
<div class="container">
<h1>{{ title }}</h1>
<div x-data="{
count: 0,
name: 'World',
showPanel: true,
showDropdown: false,
logs: [],
addLog(msg) { this.logs.unshift(new Date().toLocaleTimeString() + ' - ' + msg); }
}" x-cloak>
<!-- Test 1: x-text and x-model -->
<h2>1. Two-way Binding (x-model + x-text)</h2>
<div class="panel">
<input x-model="name" type="text" placeholder="Enter your name" style="width: 250px;">
<p>Hello, <strong x-text="name"></strong>!</p>
</div>
<!-- Test 2: Counter with @click -->
<h2>2. Event Handling (@click)</h2>
<div class="panel">
<p style="font-size: 2rem; margin: 0 0 1rem 0;">
Counter: <strong x-text="count"></strong>
</p>
<button @click="count++">+ Increment</button>
<button @click="count--">- Decrement</button>
<button @click="count = 0">Reset</button>
</div>
<!-- Test 3: x-show with default x-transition -->
<h2>3. Show/Hide with Default Transition</h2>
<div class="panel">
<button @click="showPanel = !showPanel">
<span x-text="showPanel ? 'Hide Panel' : 'Show Panel'"></span>
</button>
<div x-show="showPanel" x-transition
style="margin-top: 1rem; padding: 1rem; background: rgba(78, 204, 163, 0.2); border-radius: 6px;">
This panel uses the default x-transition (scale + fade)
</div>
</div>
<!-- Test 4: Custom transitions -->
<h2>4. Custom Transition Classes</h2>
<div class="panel">
<button @click="showDropdown = !showDropdown">Toggle Dropdown Menu</button>
<div x-show="showDropdown"
x-transition:enter="slide-up-active"
x-transition:enter-start="slide-up"
x-transition:enter-end="slide-up-to"
x-transition:leave="slide-down-active"
x-transition:leave-start="slide-down"
x-transition:leave-end="slide-down-to"
style="margin-top: 1rem; padding: 1rem; background: rgba(233, 69, 96, 0.2); border-radius: 6px;">
This uses custom slide-up/slide-down transition classes!
</div>
</div>
<!-- Test 5: x-hide (inverse of x-show) -->
<h2>5. Hide Directive (x-hide)</h2>
<div class="panel">
<p>x-hide is the opposite of x-show:</p>
<div x-hide="showPanel" style="padding: 0.5rem; background: rgba(233, 69, 96, 0.2); border-radius: 6px;">
This is hidden when the panel above is visible (x-hide="showPanel")
</div>
</div>
<!-- Test 6: @mounted lifecycle -->
<h2>6. Lifecycle Hooks (@mounted)</h2>
<div class="panel">
<div @mounted="addLog('Main component mounted!')">
<p>This component logs when it mounts.</p>
<button @click="addLog('Button clicked!')">Add Log Entry</button>
</div>
<div class="log-area">
<p style="color: #888;">Logs appear here when you interact with the component.</p>
</div>
</div>
<!-- Test 7: Attribute binding -->
<h2>7. Attribute Binding (:disabled, :class)</h2>
<div class="panel">
<button :disabled="count >= 5" @click="count++">
Increment (disabled at 5+)
</button>
<button :disabled="count <= -5" @click="count--">
Decrement (disabled at -5)
</button>
<p style="margin-top: 1rem;">
Status:
<span :class="{ positive: count > 0, negative: count < 0, zero: count === 0 }">
<strong x-text="count > 0 ? 'Positive' : count < 0 ? 'Negative' : 'Zero'"></strong>
</span>
</p>
</div>
<!-- Test 8: x-ref -->
<h2>8. Element References (x-ref)</h2>
<div class="panel">
<input x-ref="testInput" type="text" placeholder="I can be focused programmatically" style="width: 300px;">
<div style="margin-top: 0.5rem;">
<button @click="$refs.testInput.focus()">Focus Input</button>
<button @click="$refs.testInput.value = 'Hello from x-ref!'">Set Value</button>
<button @click="$refs.testInput.value = ''; $refs.testInput.focus()">Clear & Focus</button>
</div>
</div>
<!-- Test 9: x-cloak demo -->
<h2>9. x-cloak (Prevents Flash)</h2>
<div class="panel">
<p>The x-cloak attribute on the parent div prevents a flash of uninitialized content.</p>
<p>Elements with x-cloak are hidden until the reactive system initializes, then x-cloak is removed.</p>
<div style="padding: 0.5rem; background: rgba(255, 204, 0, 0.2); border-radius: 6px;">
If you see this, the reactive system has initialized and x-cloak has been removed!
</div>
</div>
</div>
<!-- Server-side rendering with @if and @foreach (Blade-style) -->
<h2>Server-Side Directives (@if, @foreach)</h2>
<div class="panel">
<p>These are rendered on the server using STX Blade-style directives:</p>
<ul>
@foreach(items as item)
<li>{{ item }}</li>
@endforeach
</ul>
@if(items.length > 0)
<p class="positive">Total: {{ items.length }} items (server-rendered)</p>
@else
<p class="negative">No items</p>
@endif
</div>
</div>
</body>
</html>