@gov-cy/govcy-frontend-renderer 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +447 -0
- package/dist/index.cjs +13133 -0
- package/dist/index.mjs +13130 -0
- package/package.json +53 -0
- package/src/njk/elements/backLink.njk +15 -0
- package/src/njk/elements/button.njk +18 -0
- package/src/njk/elements/checkboxes.njk +143 -0
- package/src/njk/elements/errorMessage.njk +20 -0
- package/src/njk/elements/fieldset.njk +27 -0
- package/src/njk/elements/fileInput.njk +39 -0
- package/src/njk/elements/fileView.njk +34 -0
- package/src/njk/elements/form.njk +24 -0
- package/src/njk/elements/formControl.njk +29 -0
- package/src/njk/elements/hint.njk +12 -0
- package/src/njk/elements/htmlElement.njk +13 -0
- package/src/njk/elements/label.njk +24 -0
- package/src/njk/elements/legend.njk +22 -0
- package/src/njk/elements/radios.njk +182 -0
- package/src/njk/elements/select.njk +59 -0
- package/src/njk/elements/summaryList.njk +149 -0
- package/src/njk/elements/table.njk +134 -0
- package/src/njk/elements/tag.njk +14 -0
- package/src/njk/elements/textArea.njk +75 -0
- package/src/njk/elements/textElement.njk +23 -0
- package/src/njk/elements/textInput.njk +72 -0
- package/src/njk/govcyElement.njk +46 -0
- package/src/njk/layouts/govcyBase.njk +143 -0
- package/src/njk/utilities/govcyUtilities.njk +36 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{# text input
|
|
2
|
+
@param {object} label The label text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
3
|
+
@param {string} id The input id. Will escape text
|
|
4
|
+
@param {string} name The input name. Will escape text. Optional
|
|
5
|
+
@param {object} hint The hint text. Optional. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
6
|
+
@param {boolean} isPageHeading Is the label also the page heading? Optional, default is false. Can be true,false
|
|
7
|
+
@param {boolean} isSpellcheck true renders nothing, false renders spellcheck="false"? Optional, default is true. Can be true,false
|
|
8
|
+
@param {string} type The text input type. Optional, default is text. Can be text,numeric,email,name,tel
|
|
9
|
+
@param {string} autocomplete The autocomplete attribute. Optional. Can be email, name, ...
|
|
10
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
11
|
+
@param {object} error If not empty there is an error message and displays the error variant. Optional, default is ''. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
12
|
+
@param {boolean} hideFormControlError If true, hides the form control error (red line on the left). Mostly used in conditional radio elements. Optional
|
|
13
|
+
@param {string} fixedWidth width If not empty will add the fixed width class variant. Optional, default is ''. Can be 50,35,20,10,5,4,3,2
|
|
14
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
15
|
+
@returns govcy input html
|
|
16
|
+
#}
|
|
17
|
+
{% macro textInput(params) -%}
|
|
18
|
+
{#- Import localizer from utilities -#}
|
|
19
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
20
|
+
{%- from "./formControl.njk" import formControl -%}
|
|
21
|
+
{%- from "./hint.njk" import hint -%}
|
|
22
|
+
{%- from "./label.njk" import label -%}
|
|
23
|
+
{%- from "./errorMessage.njk" import errorMessage -%}
|
|
24
|
+
{#- set default values -#}
|
|
25
|
+
{%- set isPageHeading = params.isPageHeading | default(false) -%}
|
|
26
|
+
{%- set isSpellcheck = params.isSpellcheck | default(false) -%}
|
|
27
|
+
{%- set type = params.type | default("text") -%}
|
|
28
|
+
{%- set autocomplete = params.autocomplete | default('') -%}
|
|
29
|
+
{#- label and id are mandatory -#}
|
|
30
|
+
{%- if params.label and params.id -%}
|
|
31
|
+
{#- set hint label error ids -#}
|
|
32
|
+
{%- set hintId = [params.id, "-hint"] | join -%}
|
|
33
|
+
{%- set labelId = [params.id, "-label"] | join -%}
|
|
34
|
+
{%- set errorId = [params.id, "-error"] | join -%}
|
|
35
|
+
{#- set fixed width class -#}
|
|
36
|
+
{%- set fixedWidthClass = ["govcy-text-input-char_" , params.fixedWidth] | join -%}
|
|
37
|
+
{#- set the type of the input. Also overwrites autocomplete and spellcheck if needed -#}
|
|
38
|
+
{%- if type=='text' -%}
|
|
39
|
+
{%- set inputType = 'type="text"' -%}
|
|
40
|
+
{%- elif type=='email' -%}
|
|
41
|
+
{%- set inputType = 'type="email"' %}{% set isSpellcheck = false %}{% set autocomplete = 'email' -%}
|
|
42
|
+
{%- elif type=='tel' -%}
|
|
43
|
+
{%- set inputType = 'type="tel"' %}{% set isSpellcheck = false %}{% set autocomplete = 'tel' -%}
|
|
44
|
+
{%- elif type=='name' -%}
|
|
45
|
+
{%- set inputType = 'type="text"' %}{% set isSpellcheck = false %}{% set autocomplete = 'name' -%}
|
|
46
|
+
{%- elif type=='numeric' -%}
|
|
47
|
+
{%- set inputType = 'type="text" pattern="[0-9]*" inputmode="numeric"' %}{% set isSpellcheck = false -%}
|
|
48
|
+
{%- endif -%}
|
|
49
|
+
{#- set spellcheck to false if not empty -#}
|
|
50
|
+
{%- if isSpellcheck -%}
|
|
51
|
+
{%- set inputSpellcheck = 'spellcheck="true"' -%}
|
|
52
|
+
{%- else -%}
|
|
53
|
+
{%- set inputSpellcheck = 'spellcheck="false"' -%}
|
|
54
|
+
{%- endif -%}
|
|
55
|
+
{#- set autocomplete -#}
|
|
56
|
+
{%- if autocomplete -%}
|
|
57
|
+
{%- set inputAutocomplete %}autocomplete="{{ autocomplete | safe }}"{% endset -%}
|
|
58
|
+
{%- else -%}
|
|
59
|
+
{%- set inputAutocomplete = '' -%}
|
|
60
|
+
{%- endif -%}
|
|
61
|
+
{% call formControl({isError: false if params.hideFormControlError else params.error,classes:params.classes,lang:params.lang}) %}
|
|
62
|
+
{#- render label -#}
|
|
63
|
+
{% call label({label:params.label, id:labelId, for:params.id, isPageHeading:isPageHeading, lang:params.lang}) %}{% endcall %}
|
|
64
|
+
{#- render hint -#}
|
|
65
|
+
{% call hint({hint:params.hint,id:hintId, lang:params.lang}) %}{% endcall %}
|
|
66
|
+
{#- render error message -#}
|
|
67
|
+
{% call errorMessage({message:params.error,id:errorId, lang:params.lang}) %}{% endcall %}
|
|
68
|
+
{#- render input -#}
|
|
69
|
+
<input id="{{params.id}}"{% if params.name %} name="{{ params.name }}"{% endif %} {{ inputType | safe }} {{ inputSpellcheck | safe }} {{ inputAutocomplete | safe }} class="govcy-text-input{% if params.fixedWidth %} {{ fixedWidthClass }}{% endif %}{% if params.error %} govcy-text-input-error{% endif %}"{% if params.hint or params.error%} aria-describedby="{% if params.hint %}{{hintId}} {% endif %}{% if params.error %}{{errorId}} {% endif %}"{% endif %}>
|
|
70
|
+
{% endcall %}
|
|
71
|
+
{%- endif -%}
|
|
72
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{# Define the macro blocks to be imported for each component.
|
|
2
|
+
|
|
3
|
+
These macros imported must:
|
|
4
|
+
- be in the directory `elements`
|
|
5
|
+
- have the same name for file and macro
|
|
6
|
+
- be added in the `macroBlocks` or `callMacroBlocks` arrays
|
|
7
|
+
|
|
8
|
+
To use:
|
|
9
|
+
1. Import the macro for example `{% from "govcyElement.njk" import govcyElement %}`
|
|
10
|
+
2. call the macro using the name of the element and it's parameters. For example
|
|
11
|
+
```
|
|
12
|
+
{{ govcyElement(
|
|
13
|
+
'hint',
|
|
14
|
+
{
|
|
15
|
+
hint:{en:"Content",el:"Περιεχομένο"},
|
|
16
|
+
classes:'govcy-test-class',
|
|
17
|
+
id:'govcy-test-2'
|
|
18
|
+
lang: 'el'
|
|
19
|
+
}
|
|
20
|
+
)
|
|
21
|
+
}}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#}
|
|
25
|
+
{%- set macroSimpleBlocks = ['label', 'legend', 'hint', 'button',
|
|
26
|
+
'errorMessage','select','textElement','htmlElement','textInput','radios','checkboxes',
|
|
27
|
+
'fileInput','fileView','backLink','tag','table', 'summaryList', 'textArea'] -%}
|
|
28
|
+
{%- set macroCallerBlocks = ['formControl','form','fieldset'] -%}
|
|
29
|
+
{%- macro govcyElement(component, params) -%}
|
|
30
|
+
{#- Simple blocks -#}
|
|
31
|
+
{%- for c in macroSimpleBlocks -%}
|
|
32
|
+
{%- if c == component -%}
|
|
33
|
+
{%- import "./elements/" + c + ".njk" as comp -%}
|
|
34
|
+
{{ comp[c](params) }}
|
|
35
|
+
{%- endif -%}
|
|
36
|
+
{%- endfor -%}
|
|
37
|
+
{#- Caller blocks -#}
|
|
38
|
+
{%- for c in macroCallerBlocks -%}
|
|
39
|
+
{%- if c == component -%}
|
|
40
|
+
{%- import "./elements/" + c + ".njk" as compm -%}
|
|
41
|
+
{%- call compm[c](params) -%}
|
|
42
|
+
{{ caller() }}
|
|
43
|
+
{%- endcall -%}
|
|
44
|
+
{%- endif -%}
|
|
45
|
+
{%- endfor -%}
|
|
46
|
+
{%- endmacro -%}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
{# Page template as defined in UDS
|
|
2
|
+
To use this template you need to pass the following data:
|
|
3
|
+
|
|
4
|
+
```
|
|
5
|
+
{
|
|
6
|
+
site: {
|
|
7
|
+
"lang": "en",
|
|
8
|
+
"title" : {"en":"Service title", "el":"Τιτλός υπηρεσίας"},
|
|
9
|
+
"headerTitle" : {"en":"Header title", "el":"Τιτλός επικεφαλιδας"},
|
|
10
|
+
"description" : {"en":"Service description", "el":"Περιγραφή υπηρεσίας"},
|
|
11
|
+
"isTesting" : true,
|
|
12
|
+
"url": "https://gov.cy",
|
|
13
|
+
"cdn": {
|
|
14
|
+
"dist": "https://cdn.jsdelivr.net/gh/gov-cy/govcy-design-system@3.0.0/dist",
|
|
15
|
+
"cssIntegrity": 'sha384-1zLHWOtnS0hOIz5mVEPZp0UH5gUE6eo0CQcCGA3sF2TyYhHyKOd3Ni8Iy/NjEASU",
|
|
16
|
+
"jsIntegrity": "sha384-zOuDuogVaaTveh/Ou2iYwCk14zFiSmMk7Ax8yRnXDtOJMyKZH5+ZNibNVwZSKtw+"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"pageData": {
|
|
20
|
+
"title": {"en": "Page title", "el": "Τιτλός σελιδας"},
|
|
21
|
+
"layout": "layouts/govcyBase.njk",
|
|
22
|
+
"mainLayout": "max-width"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
#}
|
|
27
|
+
{#- Import localizer from utilities -#}
|
|
28
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
29
|
+
<!doctype html>
|
|
30
|
+
<html lang="{{ site.lang }}">
|
|
31
|
+
<head>
|
|
32
|
+
<!-- Required meta tags -->
|
|
33
|
+
<meta charset="utf-8">
|
|
34
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
35
|
+
<!-- Social -->
|
|
36
|
+
<meta property="og:description" content="{{ govcyLocalizeContent(site.description, site.lang) }}">
|
|
37
|
+
<meta property="og:title" content="{% if pageData.title %}{{ govcyLocalizeContent(pageData.title, site.lang) }} - {% endif %}{% if site.title %}{{ govcyLocalizeContent(site.title, site.lang) }} - {% endif %}gov.cy">
|
|
38
|
+
<meta property="og:url" content="{{ site.url }}">
|
|
39
|
+
<meta property="og:type" content="website">
|
|
40
|
+
<meta property="og:image" content="{{ site.cdn.dist }}/img/icons-512.png">
|
|
41
|
+
<meta property="og:site_name" content="gov.cy">
|
|
42
|
+
|
|
43
|
+
<meta property="twitter:card" content="summary_large_image">
|
|
44
|
+
<meta property="twitter:url" content="{{ site.url }}">
|
|
45
|
+
<meta property="twitter:title" content="{% if pageData.title %}{{ govcyLocalizeContent(pageData.title, site.lang) }} - {% endif %}{% if site.title %}{{ govcyLocalizeContent(site.title, site.lang) }} - {% endif %}gov.cy">
|
|
46
|
+
<meta property="twitter:description" content="{{ govcyLocalizeContent(site.description, site.lang) }}">
|
|
47
|
+
<meta property="twitter:image" content="{{ site.cdn.dist }}/img/icons-512.png">
|
|
48
|
+
|
|
49
|
+
<!-- Theme -->
|
|
50
|
+
{# <link rel="manifest" href="manifest.json"> #}
|
|
51
|
+
<meta name="theme-color" content="#31576F">
|
|
52
|
+
<link rel="icon" type="image/png" sizes="48x48" href="{{ site.cdn.dist }}/img/favicon-48x48.png">
|
|
53
|
+
<link rel="icon" type="image/png" sizes="32x32" href="{{ site.cdn.dist }}/img/favicon-32x32.png">
|
|
54
|
+
<link rel="icon" type="image/png" sizes="16x16" href="{{ site.cdn.dist }}/img/favicon-16x16.png">
|
|
55
|
+
|
|
56
|
+
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="{{ site.cdn.dist }}/img/apple-touch-icon-144x144-precomposed.png">
|
|
57
|
+
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="{{ site.cdn.dist }}/img/apple-touch-icon-120x120-precomposed.png">
|
|
58
|
+
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="{{ site.cdn.dist }}/img/apple-touch-icon-114x114-precomposed.png">
|
|
59
|
+
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="{{ site.cdn.dist }}/img/apple-touch-icon-72x72-precomposed.png">
|
|
60
|
+
<link rel="apple-touch-icon-precomposed" href="{{ site.cdn.dist }}/img/apple-touch-icon-57x57-precomposed.png">
|
|
61
|
+
|
|
62
|
+
<!-- CSS -->
|
|
63
|
+
<link rel="stylesheet" href="{{ site.cdn.dist }}/css/govcy.uds.min.css" integrity="{{ site.cdn.cssIntegrity }}" crossorigin="anonymous">
|
|
64
|
+
|
|
65
|
+
<title>{% if pageData.title %}{{ govcyLocalizeContent(pageData.title, site.lang) }} - {% endif %}{% if site.title %}{{ govcyLocalizeContent(site.title, site.lang) }} - {% endif %}gov.cy</title>
|
|
66
|
+
<meta name="description" content="{{ govcyLocalizeContent(site.description, site.lang) }}">
|
|
67
|
+
|
|
68
|
+
</head>
|
|
69
|
+
<body>
|
|
70
|
+
<!--bodyStart-->
|
|
71
|
+
<section class="govcy-container-fluid" id="bodyStartContainer">
|
|
72
|
+
<a href="#mainContainer" class="govcy-skip-link">{%- if site.lang=='el' -%}Μεταφορά στο κεντρικό περιεχόμενο{%- else -%}Skip to main content{%- endif -%}</a>
|
|
73
|
+
{% block bodyStart %}{% endblock %}
|
|
74
|
+
</section>
|
|
75
|
+
|
|
76
|
+
<!--Header-->
|
|
77
|
+
<header class="govcy-header govcy-d-print-none" id="headerContainer">
|
|
78
|
+
{% block header %}
|
|
79
|
+
<div class="govcy-header-main-area">
|
|
80
|
+
<div class="govcy-container govcy-main-area-items">
|
|
81
|
+
<div class="govcy-navigation-container">
|
|
82
|
+
<div class="govcy-service-container">
|
|
83
|
+
<a href="https://gov.cy" class="govcy-logo" title="Go to the gov.cy homepage"><img alt="gov.cy Logo"></a>
|
|
84
|
+
<span class="govcy-service-name">{{ govcyLocalizeContent(site.headerTitle, site.lang) }}</span>
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
{% endblock %}
|
|
90
|
+
</header>
|
|
91
|
+
|
|
92
|
+
<!--beforeMain-->
|
|
93
|
+
<section class="govcy-container" id="beforeMainContainer">
|
|
94
|
+
{% block beforeMain %}{% endblock %}
|
|
95
|
+
{% if site.isTesting %}
|
|
96
|
+
<div class="govcy-phase-banner">
|
|
97
|
+
<span class="govcy-tag">TESTING</span>
|
|
98
|
+
<span class="govcy-ml-2">{{ govcyLocalizeContent({"en": "This is not a real service. It is only used for testing purposes. Any submissions made through this service will be ignored", "el": "Αυτή δεν είναι πραγματική υπηρεσία. Χρησιμοποιείται μόνο για σκοπούς δοκιμών. Οποιεσδήποτε υποβολές γίνουν μέσω της υπηρεσίας αυτής θα αγνοηθούν."}, site.lang) }}</span>
|
|
99
|
+
</div>
|
|
100
|
+
{% endif %}
|
|
101
|
+
</section>
|
|
102
|
+
|
|
103
|
+
<!--main-->
|
|
104
|
+
<main class="govcy-container" id="mainContainer">
|
|
105
|
+
<div class="govcy-row">
|
|
106
|
+
<article class="govcy-col-{% if pageData.mainLayout=='max-width' %}12{% else %}8{% endif %}">
|
|
107
|
+
{% block main %}{% endblock %}
|
|
108
|
+
</article>
|
|
109
|
+
</div>
|
|
110
|
+
</main>
|
|
111
|
+
|
|
112
|
+
<!-- Footer -->
|
|
113
|
+
<footer class="govcy-footer govcy-d-print-none" id="footerContainer">
|
|
114
|
+
{% block footer %}
|
|
115
|
+
<div class="govcy-container">
|
|
116
|
+
<div class="govcy-d-flex govcy-justify-content-between govcy-align-items-end govcy-flex-wrap">
|
|
117
|
+
<div class="govcy-my-4">
|
|
118
|
+
<ul>
|
|
119
|
+
<li><a href="#">Privacy statement</a></li>
|
|
120
|
+
<li><a href="#">Cookies</a></li>
|
|
121
|
+
<li><a href="#">Accessibility</a></li>
|
|
122
|
+
<li><a href="#">Help us improve this service</a></li>
|
|
123
|
+
</ul>
|
|
124
|
+
<div class="govcy-d-flex govcy-align-items-center govcy-flex-wrap">
|
|
125
|
+
<span class="govcy-fs-2 govcy-fw-bold govcy-mr-6">gov.cy</span>
|
|
126
|
+
<span class="govcy-mr-6 govcy-mt-2 govcy-mb-2">© Republic of Cyprus, 2023</span>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
<div class="govcy-my-4">
|
|
130
|
+
<a href="https://gov.cy" class="govcy-footer-logo" title="Go to the gov.cy homepage"><img alt="gov.cy Logo"/></a>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
{% endblock %}
|
|
135
|
+
</footer>
|
|
136
|
+
|
|
137
|
+
<!--bodyEnd-->
|
|
138
|
+
<section class="govcy-container-fluid" id="bodyEndContainer">
|
|
139
|
+
{% block bodyEnd %}{% endblock %}
|
|
140
|
+
</section>
|
|
141
|
+
<script src="{{ site.cdn.dist }}/js/govcy.uds.min.js" integrity="{{ site.cdn.jsIntegrity }}" crossorigin="anonymous"></script>
|
|
142
|
+
</body>
|
|
143
|
+
</html>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{#- govcyLocalizeContent
|
|
2
|
+
@param {string} content The content
|
|
3
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
4
|
+
@param {boolean} isHTML Is the content an HTML and can be reproduced without escaping? Optional, default is false. Can be true,false
|
|
5
|
+
@returns localized content
|
|
6
|
+
-#}
|
|
7
|
+
{% macro govcyLocalizeContent(content,lang,isHTML) -%}
|
|
8
|
+
{#- set default values -#}
|
|
9
|
+
{#- Set the language with priority: lang > globalData.site.lang > 'el' -#}
|
|
10
|
+
{%- set inlang = lang | default(globalData.site.lang) | default('el') -%}
|
|
11
|
+
{# {%- set inlang = lang | default('el') -%} #}
|
|
12
|
+
{%- set inIsHTML = isHTML | default(false) -%}
|
|
13
|
+
{% if inIsHTML %}{{- content[inlang] | safe -}}{% else %}{{- content[inlang] -}}{% endif %}
|
|
14
|
+
{%- endmacro %}
|
|
15
|
+
{#- --------------------------------------- -#}
|
|
16
|
+
{#- govcyLangAttribute
|
|
17
|
+
@param {string} lang The language used. Can be 'en','el'
|
|
18
|
+
@returns lang attribute if lang is defined
|
|
19
|
+
-#}
|
|
20
|
+
{% macro govcyLangAttribute(lang) -%}
|
|
21
|
+
{# If lang is defined, use it #}
|
|
22
|
+
{%- if lang %} lang="{{ lang }}"{%- endif %}
|
|
23
|
+
{%- endmacro %}
|
|
24
|
+
{#- --------------------------------------- -#}
|
|
25
|
+
{#- render govcyElements from an array -#}
|
|
26
|
+
{%- macro govcyElementsFromArray(elements, lang) %}
|
|
27
|
+
{%- from "../govcyElement.njk" import govcyElement -%}
|
|
28
|
+
{%- for element in elements -%}
|
|
29
|
+
{%- if lang and not element.params.lang -%}
|
|
30
|
+
{%- set params = element.params | merge({lang: lang}) -%}
|
|
31
|
+
{%- else -%}
|
|
32
|
+
{%- set params = element.params -%}
|
|
33
|
+
{%- endif -%}
|
|
34
|
+
{%- call govcyElement(element.element, params) %}{% endcall -%}
|
|
35
|
+
{%- endfor -%}
|
|
36
|
+
{%- endmacro %}
|