-
Notifications
You must be signed in to change notification settings - Fork 690
Expand file tree
/
Copy pathglobal-sidebar.twig
More file actions
171 lines (158 loc) · 7.18 KB
/
global-sidebar.twig
File metadata and controls
171 lines (158 loc) · 7.18 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
{% import "_includes/links" as links %}
{% macro action(item, isSubnav, isSelected, showIcon) %}
{% set showIcon = showIcon ?? true %}
{% set selected = item.sel ?? isSelected ?? false %}
{% set badgeCount = item.badgeCount ?? false %}
{% set external = item.external ?? false %}
{% set linkAttributes = {
id: (item.id ?? null) ? "#{item.id}-link" : null,
href: (item.url ?? false) ? url(item.url) : null,
class: [
'sidebar-action',
(external ? 'external'),
(selected ? 'sel'),
],
target: external ? '_blank',
aria: {
label: item.ariaLabel ?? false,
},
}|merge(item.linkAttributes ?? {}, recursive=true) %}
{% tag 'a' with linkAttributes %}
<span class="sidebar-action__prefix">
<span class="nav-icon" aria-hidden="true">
{% set icon = item.icon ?? false %}
{%- if icon is not same as(false) and icon is not same as(null) and icon is not same as('') -%}
{{ iconSvg(item.icon) }}
{%- elseif item.fontIcon ?? false -%}
<span data-icon="{{ item.fontIcon }}"></span>
{%- else -%}
<span class="nav-indicator"></span>
{%- endif -%}
</span>
</span>
<span class="sidebar-action__label">
<span class="label">{{ item.label }}</span>
{% if external %}
{{ links.externalLinkIcon() }}
{% endif %}
</span>
<span class="sidebar-action__suffix">
{%- if badgeCount -%}
<span class="sidebar-action__badge">
<span class="badge" aria-hidden="true">{{ item.badgeCount|number(decimals=0) }}</span>
{{ tag('span', {
class: 'visually-hidden',
data: {
notification: true,
},
text: '{num, number} {num, plural, =1{notification} other{notifications}}'|t('app', {
num: item.badgeCount,
}),
}) }}
</span>
{%- endif -%}
{% if not isSubnav and (item.subnav ?? false) %}
<craft-disclosure
class="nav-item__trigger"
state="{{ item.sel ? 'expanded' : 'collapsed' }}"
>
<button
type="button"
class="btn menubtn hairline"
aria-controls="{{ item.id }}-subnav"
aria-describedby="{{ item.id }}-link"
aria-expanded="{{ item.sel ? 'true' : 'false' }}"
>
<span class="visually-hidden">{{ 'Open subnavigation' |t('app') }}</span>
</button>
</craft-disclosure>
{% endif %}
</span>
{% endtag %}
{% endmacro %}
<craft-global-sidebar>
<header id="global-sidebar" class="global-sidebar">
<div class="global-sidebar__header">
{% include '_layouts/components/system-info' %}
</div>
<div class="global-sidebar__nav">
<nav id="nav" class="global-nav" aria-label="{{ 'Primary'|t('app') }}">
<ul>
{% for item in craft.cp.nav() %}
{% set itemAttributes = {
id: item.id,
class: [
item.subnav ? 'has-subnav'
],
} %}
<li {{ attr(itemAttributes) }}>
<div class="nav-item {% if item.sel %}sel{% endif %}">
{{ _self.action(item, false) }}
</div>
{% if item.subnav %}
<ul
class="nav-item__subnav"
id="{{ item.id }}-subnav"
data-state="{{ item.sel ? 'expanded' : 'collapsed' }}"
>
{% for subItemId, subItem in item.subnav %}
{% set itemIsSelected = selectedSubnavItem is defined and selectedSubnavItem == subItemId and subItem.url in craft.app.request.fullPath -%}
<li>
<div class="nav-item nav-item--sub {% if itemIsSelected %}sel{% endif %}">
{{ _self.action(subItem|merge({
linkAttributes: {
class: ['sidebar-action--sub'],
aria: {
current: itemIsSelected ? 'page' : false,
},
}
}, recursive=true), true, itemIsSelected, false) }}
</div>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
</div>
<div class="global-sidebar__footer">
<div class="sidebar-actions">
{% set toggleContent %}
<span class="sidebar-action__prefix">
<span class="nav-icon" aria-hidden="true" id="sidebar-toggle-icon">
{% if craft.app.locale.getOrientation() == 'rtl' %}
{{ iconSvg('angle-left') }}
{% else %}
{{ iconSvg('angle-right') }}
{% endif %}
</span>
</span>
<span class="sidebar-action__label">
<span class="label">{{ 'Toggle sidebar'|t('app') }}</span>
</span>
{% endset %}
{% include '_includes/disclosure-toggle' with {
id: 'sidebar-trigger',
controls: 'global-sidebar',
state: sidebarState,
content: toggleContent,
attributes: {
class: 'sidebar-action',
},
} %}
</div>
{% if currentUser.admin and devMode %}
{% set devModeText = 'Craft CMS is running in Dev Mode.'|t('app') %}
<div id="devmode">
{% tag 'span' with {
class: 'visually-hidden',
} %}
{{ devModeText|raw }}
{% endtag %}
</div>
{% endif %}
</div>
</header>
</craft-global-sidebar>