-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy path_macro.njk
154 lines (147 loc) · 10.5 KB
/
_macro.njk
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
{% macro onsSummary(params) %}
{% set className = "ons-summary" %}
{% set headingLevel = "2" %}
{% if params.variant == "hub" %}
{% set variantHub = true %}
{% set className = className + " ons-summary--hub" %}
{% elif params.variant %}
{% set variantClasses = " ons-summary__group--" + params.variant %}
{% endif %}
{% if params.classes %}
{% set className = className + " " + params.classes %}
{% endif %}
<div class="{{ className }}">
{% for summary in params.summaries %}
{% if summary.title %}
<h2 class="ons-summary__title ons-u-mb-l{{ ' ons-u-mt-l' if loop.index > 1 else "" }}">{{ summary.title }}</h2>
{% set headingLevel = "3" %}
{% endif %}
{% for group in summary.groups %}
<div {% if group.id %}id="{{ group.id }}"{% endif %} class="ons-summary__group{{ variantClasses }}">
{% if group.title %}
{% set openingHeadingTag = "<h" ~ headingLevel %}
{% set closingHeadingTag = "</h" ~ headingLevel ~ ">" %}
{{ openingHeadingTag | safe }}
class="ons-summary__group-title">{{ group.title }}{{ closingHeadingTag | safe }}
{% endif %}
{% if group.rows %}
<dl class="ons-summary__items">
{% for row in group.rows %}
{% set itemClass = "" %}
{% if row.error %}{% set itemClass = " ons-summary__item--error" %}{% endif %}
{% if row.total %}{% set itemClass = itemClass + " ons-summary__item--total" %}{% endif %}
<div {% if row.id %}id="{{ row.id }}"{% endif %}class="ons-summary__item{{ itemClass }}">
{% if row.errorMessage %}
<dt class="ons-summary__row-title--error ons-u-fs-r">{{ row.errorMessage }}</dt>
{% endif %}
{% if row.itemsList | length > 1 and row.title %}
<dt class="ons-summary__row-title ons-summary__row-title--no-group-title ons-u-fs-r">
{{- row.title -}}
</dt>
{% endif %}
{% for item in row.itemsList %}
<dt
class="ons-summary__item-title"
{% if item.titleAttributes %}{% for attribute, value in (item.titleAttributes.items() if item.titleAttributes is mapping and item.titleAttributes.items else item.titleAttributes) %}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
>
{% if item.iconType %}
{% from "components/icon/_macro.njk" import onsIcon %}
<span
class="ons-summary__item-title-icon{{ ' ons-summary__item-title-icon--check' if item.iconType == 'check' else "" }}"
>
{{-
onsIcon({
"iconType": item.iconType
})
-}}
{% if item.iconVisuallyHiddenText %}
<span class="ons-u-vh">{{ item.iconVisuallyHiddenText }}</span>
{% endif %}
</span>
{% endif %}
<div
class="ons-summary__item--text{{ ' ons-summary__item-title--text' if item.iconType else "" }}"
>
{{- item.title | default(row.title) | safe -}}
</div>
{# Render section status for mobile if is hub #}
{% if variantHub and item.valueList %}
<span class="ons-u-d-no@m ons-u-fs-r"> — {{ item.valueList[0].text | safe }}</span>
{% endif %}
</dt>
{% if item.valueList %}
<dd
class="ons-summary__values{{ ' ons-summary__values--2' if not item.actions }}"
{% if item.attributes %}{% for attribute, value in (item.attributes.items() if item.attributes is mapping and item.attributes.items else item.attributes) %}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
>
{% if item.valueList | length == 1 %}
<span class="ons-summary__text">{{ item.valueList[0].text | safe }}</span>
{% if item.valueList[0].other or item.valueList[0].other == 0 %}
<ul class="ons-u-mb-no">
<li>{{ item.valueList[0].other | safe }}</li>
</ul>
{% endif %}
{% else %}
<ul class="ons-u-mb-no">
{% for value in item.valueList %}
<li>
<span class="ons-summary__text">{{ value.text | safe }}</span>
{% if value.other or value.other == 0 %}
<ul class="ons-u-mb-no">
<li>{{ value.other | safe }}</li>
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
</dd>
{% endif %}
{% if item.actions %}
<dd class="ons-summary__actions" {% if item.id %}id="{{ item.id }}"{% endif %}>
{% for action in item.actions %}
{% if loop.index > 1 %}<span class="ons-summary__spacer"></span>{% endif %}
<a
href="{{ action.url }}"
class="ons-summary__button"
{% if action.attributes %}{% for attribute, value in (action.attributes.items() if action.attributes is mapping and action.attributes.items else action.attributes) %}{{ ' ' }}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
>
<span class="ons-summary__button-text" aria-hidden="true">{{- action.text -}}</span>
<span class="ons-u-vh"
>{{ action.visuallyHiddenText | default (action.text) }}</span
>
</a>
{% endfor %}
</dd>
{% endif %}
{% endfor %}
</div>
{% endfor %}
</dl>
{% elif group.placeholderText %}
<span class="ons-summary__placeholder">{{ group.placeholderText }}</span>
{% endif %}
{% if group.summaryLink %}
<div
class="ons-summary__link{{ ' ons-u-pt-s' if params.variant != 'card' and (group.placeholderText or group.rows) }}{{ ' ons-u-bt' if group.placeholderText is not defined and group.rows | length > 1 and params.variant != 'card' }}{{ ' ons-u-mb-3xl' if not group.last }}"
>
{% set link %}
<a
{% if group.summaryLink.attributes %}{% for attribute, value in (group.summaryLink.attributes.items() if group.summaryLink.attributes is mapping and group.summaryLink.attributes.items else group.summaryLink.attributes) %}{{ ' ' }}{{ attribute }}="{{ value }}"{% endfor %}{% endif %}
href="{{ group.summaryLink.url }}"
>
{{ group.summaryLink.text }}
</a>
{% endset %}
{% if params.variant == 'card' %}
<div class="ons-summary__link-container">{{ link | safe }}</div>
{% else %}
{{ link | safe }}
{% endif %}
</div>
{% endif %}
</div>
{% endfor %}
{% endfor %}
</div>
{% endmacro %}