forked from symfony/ux-twig-component
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwig_component.html.twig
304 lines (290 loc) · 11.1 KB
/
twig_component.html.twig
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
{% extends '@WebProfiler/Profiler/layout.html.twig' %}
{% block page_title 'Twig Components' %}
{% block head %}
{{ parent() }}
<style>
.twig-component-dump {
display: block;
background: rgba(0, 0, 0, .15);
--font-size-monospace: 12px;
font-weight: 400;
border-radius: 4px;
padding: 5px;
}
.twig-component-metrics {
margin-block-end: 3rem;
}
.twig-component-component {
margin-block-end: 3rem;
}
.twig-component-component th:first-child,
.twig-component-component td:first-child {
width: 25%;
}
.twig-component-component thead th {
font-weight: 200;
vertical-align: middle;
padding: .75rem 1rem;
}
.twig-component-component thead strong {
font-weight: 600;
display: block;
}
.twig-component-component td {
vertical-align: middle;
padding: .75rem 1rem;
}
.twig-component-component tbody td.metric {
text-align: right;
}
.twig-component-component thead small,
.twig-component-component thead strong {
display: block;
}
.twig-component-component .cell-right {
width: 4rem;
text-align: right;
}
.twig-component-renders {
margin-bottom: 2rem;
}
.twig-component-render {
margin-left: calc(var(--render-depth) * .5rem);
width: calc(100% - calc(var(--render-depth) * .5rem));
}
.twig-component-render thead th {
text-align: left;
border-bottom: none;
vertical-align: middle;
}
.twig-component-render thead tr {
vertical-align: middle;
opacity: .9;
}
.twig-component-render thead tr:hover {
opacity: 1;
cursor: pointer;
}
.twig-component-render .sf-toggle .toggle-button {
color: inherit;
}
.twig-component-render .sf-toggle-on .toggle-button {
transform: rotate(0deg);
opacity: 1;
transition: all 150ms ease-in-out;
}
.twig-component-render .sf-toggle-off .toggle-button {
transform: rotate(90deg);
opacity: .85;
transition: all 250ms ease-in-out;
}
.twig-component-render th:first-child,
.twig-component-render tr:first-child {
width: 25%;
}
.twig-component-render th,
.twig-component-render tbody th {
font-weight: normal;
}
.twig-component-render th:first-child {
font-weight: bolder;
}
.twig-component-render th:first-child svg {
transform: rotate(45deg);
transform-origin: inherit;
transform-style: initial;
width: 1.25rem;
vertical-align: inherit;
}
.twig-component-render th:last-child {
width: 2rem;
}
.twig-component-render th.renderTime {
width: 4rem;
font-weight: initial;
}
.twig-component-render tbody.sf-toggle-visible {
display: table-row-group;
width: inherit;
}
.twig-component-render tbody th {
font-weight: normal !important;
}
</style>
{% endblock %}
{% block toolbar %}
{% if collector.renderCount %}
{% set icon %}
{{ source('@TwigComponent/Collector/icon.svg') }}
<span class="sf-toolbar-value">{{ collector.renderCount }}</span>
<span class="sf-toolbar-info-piece-additional-detail">
<span class="sf-toolbar-label">in</span>
<span class="sf-toolbar-value">{{ collector.renderTime|round }}</span>
<span class="sf-toolbar-label">ms</span>
</span>
{% endset %}
{% set text %}
{% for _component in collector.components %}
<div class="sf-toolbar-info-piece">
<b class="label">{{ _component.name }}</b>
<span class="sf-toolbar-status">{{ _component.render_count }}</span>
</div>
{% endfor %}
{% endset %}
{{ include('@WebProfiler/Profiler/toolbar_item.html.twig', {link: profiler_url}) }}
{% endif %}
{% endblock %}
{% block menu %}
<span class="label{{ collector.components is empty ? ' disabled' }}">
<span class="icon">{{ source('@TwigComponent/Collector/icon.svg') }}</span>
<strong>Twig Components</strong>
</span>
{% endblock %}
{% block panel %}
<h2>Components</h2>
{% if not collector.componentCount|default %}
<div class="empty empty-panel">
<p>No component were rendered for this request.</p>
</div>
{% else %}
<section class="twig-component-metrics metrics">
<div class="metric-group">
{{ _self.metric(collector.componentCount, "Twig Components") }}
</div>
<div class="metric-divider"></div>
<div class="metric-group">
{{ _self.metric(collector.renderCount, "Render Count") }}
{{ _self.metric(collector.renderTime|round, "Render Time", "ms") }}
</div>
<div class="metric-divider"></div>
<div class="metric-group">
{{ _self.metric((collector.peakMemoryUsage / 1024 / 1024)|number_format(1), "Memory Usage", "MiB") }}
</div>
</section>
<section class="twig-component-components">
<h3>Components</h3>
{{ block('table_components') }}
</section>
<section class="twig-component-renders">
<h3>Render calls</h3>
{{ block('table_renders') }}
</section>
{% endif %}
{% endblock %}
{% macro metric(value, label, unit = '') %}
<div class="metric">
<span class="value">
{{ value }}
{% if unit %}
<span class="unit text-small">{{ unit }}</span>
{% endif %}
</span>
<span class="label">
{{- label -}}
</span>
</div>
{% endmacro %}
{% block table_components %}
<table class="twig-component-component">
<thead>
<tr>
<th class="key">
<strong>Name</strong>
</th>
<th>
<strong>Metadata</strong>
</th>
<th class="cell-right">
<small>Render</small>
<strong>Count</strong>
</th>
<th class="cell-right">
<small>Render</small>
<strong>Time</strong>
</th>
</tr>
</thead>
<tbody>
{% for component in collector.components %}
<tr>
<td>{{ component.name }}</td>
<td>
{% if component.class == 'Symfony\\UX\\TwigComponent\\AnonymousComponent' %}
<pre class="sf-dump"><span class="text-muted">[Anonymous]</span></pre>
{% else %}
{{ profiler_dump(component.class_stub) }}
{% endif %}
{% if component.template_path %}
<a class=text-muted" href="{{ component.template_path|file_link(1) }}">
{{- component.template -}}
</a>
{% else %}
<span class=text-muted">{{ component.template }}</span>
{% endif %}
</td>
<td class="cell-right">{{ component.render_count }}</td>
<td class="cell-right">
{{- component.render_time|number_format(2) -}}
<span class="text-muted text-small">ms</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{% block table_renders %}
<div class="twig-component-renders">
{% set _memory = null %}
{% for render in collector.renders %}
<table class="twig-component-render" style="--render-depth:{{ render.depth }};">
<thead
class="sf-toggle {{ loop.index == 1 ? 'sf-toggle-on' : 'sf-toggle-off' }}"
data-toggle-selector="#render-{{ loop.index }}--details"
data-toggle-initial="{{ loop.index == 1 ? 'display' }}"
>
<tr>
<th class="key">{{ render.depth ? source('@TwigComponent/Collector/chevron-down.svg') }}{{ render.name }}</th>
<th>
{% if render.class == 'Symfony\\UX\\TwigComponent\\AnonymousComponent' %}
<pre class="sf-dump"><span class="text-muted">[Anonymous]</span></pre>
{% else %}
{{ render.class }}
{% endif %}
</th>
<th class="cell-right renderTime">
{% set _render_memory = render.render_memory|default(0) / 1024 / 1024 %}
<span class="{{ _render_memory == _memory ? 'text-muted' }}">
{{- _render_memory|number_format(1) -}}
</span>
<span class="text-muted text-small">MiB</span>
{% set _memory = _render_memory %}
</th>
<th class="cell-right renderTime">
{{ render.render_time|number_format(2) }}
<span class="text-muted text-small">ms</span>
</th>
<th class="cell-right">
<button class="btn btn-link toggle-button" type="button" aria-label="Toggle details">
{{ source('@TwigComponent/Collector/chevron-down.svg') }}
</button>
</th>
</tr>
</thead>
<tbody id="render-{{ loop.index }}--details">
<tr class="{{ not render.input_props|default ? 'opacity-50' }}">
<th scope="row">Input props</th>
<td colspan="4">{{ profiler_dump(render.input_props) }}</td>
</tr>
<tr class="{{ not render.attributes|default ? 'opacity-50' }}">
<th scope="row">Attributes</th>
<td colspan="4">{{ profiler_dump(render.attributes) }}</td>
</tr>
<tr>
<th scope="row">Component</th>
<td colspan="4">{{ profiler_dump(render.component) }}</td>
</tr>
</tbody>
</table>
{% endfor %}
</div>
{% endblock %}