-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawer.twig
More file actions
92 lines (84 loc) · 2.67 KB
/
drawer.twig
File metadata and controls
92 lines (84 loc) · 2.67 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
{#
/**
* @component Wudo Drawer
*
* A universal drawer / modal container implemented as a Web Component.
* Can be used as an off-canvas panel (left/right) or as a centered modal.
*
* Behavior:
* - Opens and closes via global Custom Events (`drawer:open`, `drawer:close`).
* - Automatically manages focus using a focus-trap utility.
* - Locks background interaction using the `inert` attribute.
*
* Available variables:
* - id (string, required): Unique identifier used for event targeting.
* - position (string): Drawer position (`left`, `right`, `center`).
* - size (string): Maximum width of the drawer (e.g. `400px`, `100%`).
* - title (string): Accessible title rendered in the drawer header.
* - content (string|render array): Main drawer content.
* - footer (string|render array, optional): Optional footer content.
*
* Accessibility:
* - Uses role="dialog" with aria-modal="true".
* - The drawer title is referenced via aria-labelledby.
* - Focus is moved into the drawer on open and restored on close.
* - Background content is made inert while the drawer is active.
*
* Notes:
* - The overlay and close button both call `.close()` on the nearest
* <wudo-drawer> instance.
* - The `content` block can be overridden by extending templates.
*/
#}
{{ attach_library('wudo/focus-trap') }}
{%
set classes = [
'drawer',
'drawer--' ~ (position|default('right')),
modifier_class ? modifier_class : '',
]
%}
<wudo-drawer
id="{{ id }}"
{{ attributes.addClass(classes) }}
style="--drawer-max-width: {{ size }};"
role="dialog"
aria-modal="true"
aria-labelledby="{{ id }}-title"
{% if portal %}
source-selector="{{ portal.source }}"
wrapper-selector="{{ portal.wrapper }}"
slot-id="{{ portal.slot }}"
{% endif %}
>
<div class="drawer__overlay" onclick="this.closest('wudo-drawer').close()"></div>
<div class="drawer__inner">
<header class="drawer__header">
<h2 id="{{ id }}-title" class="drawer__title">{{ title }}</h2>
{% set button_attributes = create_attribute({
'class': 'drawer__close',
'data-flyout-open-trigger': '',
'aria-expanded': 'false',
'onclick': "this.closest('wudo-drawer').close()"
}) %}
{{ include('wudo:button', {
text: 'Close drawer',
icon: 'close',
size: 'large',
icon_only: true,
icon_size: 'large',
attributes: button_attributes,
}, with_context = false) }}
</header>
<div class="drawer__body">
{% block content %}
{{ content|raw }}
{% endblock %}
</div>
{% if footer %}
<footer class="drawer__footer">
{{ footer }}
</footer>
{% endif %}
</div>
</wudo-drawer>