@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
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gov-cy/govcy-frontend-renderer",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Render html for design elements of the Unified design system using njk or json template.",
|
|
5
|
+
"author": "DMRID - DSF Team",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.cjs",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"exports": {
|
|
10
|
+
"require": "./dist/index.cjs",
|
|
11
|
+
"import": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"src/njk"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"govcy",
|
|
19
|
+
"cyprus",
|
|
20
|
+
"unified design system",
|
|
21
|
+
"uds",
|
|
22
|
+
"dsf",
|
|
23
|
+
"digital service framework",
|
|
24
|
+
"template",
|
|
25
|
+
"renderer",
|
|
26
|
+
"frontend",
|
|
27
|
+
"builder"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/gov-cy/govcy-frontend-renderer.git"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/gov-cy/govcy-frontend-renderer",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"express": "^4.19.2",
|
|
36
|
+
"nunjucks": "^3.2.4",
|
|
37
|
+
"semver": ">=7.5.2"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"test": "mocha --timeout 60000 ./test/**/*.test.mjs",
|
|
41
|
+
"build": "rollup -c",
|
|
42
|
+
"start": "nodemon app.mjs"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
46
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
47
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
48
|
+
"chai": "^5.1.0",
|
|
49
|
+
"mocha": "^10.4.0",
|
|
50
|
+
"nodemon": "^3.1.4",
|
|
51
|
+
"rollup": "^4.21.2"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{# Back link
|
|
2
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
3
|
+
@param {object} text The button text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
4
|
+
@param {string} classes Additional classes to add to the button. Optional
|
|
5
|
+
@param {string} href The URL to navigate when clicked. Optional, default is 'javascript:history.back()'
|
|
6
|
+
@returns govcy back link html
|
|
7
|
+
#}
|
|
8
|
+
{% macro backLink(params) -%}
|
|
9
|
+
{#- Import localizer from utilities -#}
|
|
10
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
11
|
+
{# set default values #}
|
|
12
|
+
{%- set text = govcyLocalizeContent(params.text, params.lang) if params.text else govcyLocalizeContent({en:'Back',el:'Πίσω'}, params.lang) -%}
|
|
13
|
+
{%- set href = params.href | default('javascript:history.back()') -%}
|
|
14
|
+
<a class="govcy-back-link{% if params.classes %} {{ params.classes }}{% endif %}" href="{{ href }}"{{ govcyLangAttribute(params.lang) }}>{{ text}}</a>
|
|
15
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{# Button
|
|
2
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
3
|
+
@param {object} text The button text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
4
|
+
@param {string} variant The button variant. Optional, default is 'primary'. Can be 'primary', 'secondary', 'warning', 'success'
|
|
5
|
+
@param {string} id The id of the button. Optional
|
|
6
|
+
@param {string} type The button input type. Optional, default is button. Can be button or submit
|
|
7
|
+
@param {string} classes Additional classes to add to the button. Optional
|
|
8
|
+
@param {string} prototypeNavigate WARNING Only to be used for prototypes. the URL to navigate when clicked Optional
|
|
9
|
+
@returns govcy button html
|
|
10
|
+
#}
|
|
11
|
+
{% macro button(params) -%}
|
|
12
|
+
{#- Import localizer from utilities -#}
|
|
13
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
14
|
+
{# set default values #}
|
|
15
|
+
{%- set variant = params.variant | default('primary') -%}
|
|
16
|
+
{%- set type = params.type | default('button') -%}
|
|
17
|
+
<button type="{{ type }}"{% if params.id %} id="{{ params.id }}" {% endif %}class="govcy-btn-{{ variant }}{% if params.classes %} {{ params.classes }}{% endif %}"{% if params.prototypeNavigate %} onclick="location.href='{{ params.prototypeNavigate }}'"{% endif %}{{ govcyLangAttribute(params.lang) }}>{{ govcyLocalizeContent(params.text, params.lang) }}</button>
|
|
18
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
{# checkbox item
|
|
2
|
+
@param {object} params The parent parameters
|
|
3
|
+
@param {int} index The index number in the items array
|
|
4
|
+
@param {string} lang The language used. Can be 'en','el'.
|
|
5
|
+
@param {object} item The item object
|
|
6
|
+
i.e.
|
|
7
|
+
item : {
|
|
8
|
+
type: "or",
|
|
9
|
+
altOrText: {en:"If not",el:"Αν όχι"},
|
|
10
|
+
value: "maybe",
|
|
11
|
+
hint: {en:"We want you to be absolutely sure",el:"Θέλουμε να είστε απολύτως σίγουροι"},
|
|
12
|
+
text: {en:"Maybe",el:"Ίσως"}
|
|
13
|
+
}
|
|
14
|
+
@param {string} item.type The item type. Can be empty,'or','and'. Optional, default is empty
|
|
15
|
+
@param {string} item.value The value of the checkbox.
|
|
16
|
+
@param {object} item.text The label of the checkbox. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
17
|
+
@param {object} item.hint The hint of the checkbox. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
18
|
+
@param {object} item.altAndText The and text. Optional, default is `{en:"And",el:"Και"}
|
|
19
|
+
@param {object} item.altOrText The or text. Optional, default is `{en:"Or",el:"Ή"}
|
|
20
|
+
@returns govcy checkbox item html
|
|
21
|
+
#}
|
|
22
|
+
{%- macro _checkboxItem(params, item, index, lang) %}
|
|
23
|
+
{#- Import localizer from utilities -#}
|
|
24
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
25
|
+
{%- from "./hint.njk" import hint -%}
|
|
26
|
+
{%- from "./label.njk" import label -%}
|
|
27
|
+
{#- set language labels -#}
|
|
28
|
+
{#- set 'or' labels -#}
|
|
29
|
+
{%- if item.altOrText -%}
|
|
30
|
+
{%- set orText -%} {{- govcyLocalizeContent(item.altOrText, lang) -}}{%- endset -%}
|
|
31
|
+
{%- else -%}
|
|
32
|
+
{%- set orText -%} {{- govcyLocalizeContent({en:'Or',el:'Ή'}, lang) -}}{%- endset -%}
|
|
33
|
+
{%- endif -%}
|
|
34
|
+
{#- set 'and' labels -#}
|
|
35
|
+
{%- if item.altAndText -%}
|
|
36
|
+
{%- set andText -%} {{- govcyLocalizeContent(item.altAndText, lang) -}}{%- endset -%}
|
|
37
|
+
{%- else -%}
|
|
38
|
+
{%- set andText -%} {{- govcyLocalizeContent({en:'And',el:'Και'}, lang) -}}{%- endset -%}
|
|
39
|
+
{%- endif -%}
|
|
40
|
+
{#- set option id -#}
|
|
41
|
+
{% set optionId = params.id ~ '-option-' ~ index %}
|
|
42
|
+
{#- set hint id -#}
|
|
43
|
+
{%- if item.hint -%}
|
|
44
|
+
{%- set hintId = [optionId, "-hint"] | join -%}
|
|
45
|
+
{%- else -%}
|
|
46
|
+
{%- set hintId = '' -%}
|
|
47
|
+
{%- endif -%}
|
|
48
|
+
{# depending on the type, render html and set label#}
|
|
49
|
+
{%- if item.type == 'or' -%}
|
|
50
|
+
<p class="govcy-ml-3 govcy-mb-3">{{ orText }}</p>
|
|
51
|
+
{%- set label -%}
|
|
52
|
+
<span class="govcy-visually-hidden-error">{{ orText }}, </span> {{- govcyLocalizeContent(item.text, lang) -}}
|
|
53
|
+
{%- endset -%}
|
|
54
|
+
{%- elif item.type == 'and' -%}
|
|
55
|
+
<p class="govcy-ml-3 govcy-mb-3">{{ andText }}</p>
|
|
56
|
+
{%- set label -%}
|
|
57
|
+
<span class="govcy-visually-hidden-error">{{ andText }}, </span> {{- govcyLocalizeContent(item.text, lang) -}}
|
|
58
|
+
{%- endset -%}
|
|
59
|
+
{% else %}
|
|
60
|
+
{%- set label -%}{{- govcyLocalizeContent(item.text, lang) -}}{%- endset -%}
|
|
61
|
+
{%- endif -%}
|
|
62
|
+
{#- render checkbox -#}
|
|
63
|
+
<div class="govcy-checkbox">
|
|
64
|
+
<input class="govcy-checkbox-input" name="{{ params.name }}" value="{{item.value}}" type="checkbox" id="{{ optionId }}" {% if item.hint%} aria-describedby="{{hintId}}"{% endif %}>
|
|
65
|
+
<label class="govcy-label" for="{{ optionId }}">{{ label | safe }}</label>
|
|
66
|
+
{#- {% call govcyLabel({label:label, for:optionId, isPrimary:false, isHTML:true, lang:lang}) %}{% endcall %} -#}
|
|
67
|
+
{% call hint({hint:item.hint, id:hintId, lang:lang}) %}{% endcall %}
|
|
68
|
+
</div>
|
|
69
|
+
{%- endmacro %}
|
|
70
|
+
{# checkbox
|
|
71
|
+
@param {object} legend The legend text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
72
|
+
@param {string} id The id prefix for the options. Will escape text.
|
|
73
|
+
@param {string} name The name used in checkbox. Will escape text.
|
|
74
|
+
@param {string} hint The hint text. Optional. Will escape text
|
|
75
|
+
@param {boolean} isPageHeading Is the label also the page heading? Optional, default is false. Can be true,false
|
|
76
|
+
@param {string} classes Additional classes to add to the outer fieldset. Optional
|
|
77
|
+
@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:"Περιεχομένο"}`
|
|
78
|
+
@param {boolean} hideFormControlError If true, hides the form control error (red line on the left). Mostly used in conditional radio elements. Optional
|
|
79
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
80
|
+
@param {array} items The array of items to turn onto checkbox
|
|
81
|
+
i.e. `[
|
|
82
|
+
{
|
|
83
|
+
value: "yes",
|
|
84
|
+
text: {en:"Yes",el:"Ναι"}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
value: "no",
|
|
88
|
+
text: {en:"No",el:"Όχι"}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: "or",
|
|
92
|
+
altOrText: {en:"If not",el:"Αν όχι"},
|
|
93
|
+
value: "maybe",
|
|
94
|
+
hint: {en:"We want you to be absolutely sure",el:"Θέλουμε να είστε απολύτως σίγουροι"},
|
|
95
|
+
text: {en:"Maybe",el:"Ίσως"}
|
|
96
|
+
}
|
|
97
|
+
]`
|
|
98
|
+
@returns govcy checkboxes html
|
|
99
|
+
#}
|
|
100
|
+
{% macro checkboxes(params) -%}
|
|
101
|
+
{#- set default values -#}
|
|
102
|
+
{%- set isPageHeading = params.isPageHeading | default(false) -%}
|
|
103
|
+
{#- legend, id and name are mandatory -#}
|
|
104
|
+
{%- if params.legend and params.id and params.name -%}
|
|
105
|
+
{%- from "./fieldset.njk" import fieldset -%}
|
|
106
|
+
{%- from "./hint.njk" import hint -%}
|
|
107
|
+
{%- from "./legend.njk" import legend -%}
|
|
108
|
+
{%- from "./errorMessage.njk" import errorMessage -%}
|
|
109
|
+
{%- from "./formControl.njk" import formControl -%}
|
|
110
|
+
{#- set hint id -#}
|
|
111
|
+
{%- if params.hint -%}
|
|
112
|
+
{%- set hintId = [params.id, "-hint"] | join -%}
|
|
113
|
+
{%- else -%}
|
|
114
|
+
{%- set hintId = '' -%}
|
|
115
|
+
{%- endif -%}
|
|
116
|
+
{#- set error id -#}
|
|
117
|
+
{%- if params.error -%}
|
|
118
|
+
{%- set errorId = [params.id, "-error"] | join -%}
|
|
119
|
+
{%- else -%}
|
|
120
|
+
{%- set errorId = '' -%}
|
|
121
|
+
{%- endif -%}
|
|
122
|
+
{# set aria described by #}
|
|
123
|
+
{%- if params.error or params.hint -%}
|
|
124
|
+
{% set ariaDescribedBy = hintId ~ ' ' ~ errorId %}
|
|
125
|
+
{%- else -%}
|
|
126
|
+
{% set ariaDescribedBy = '' %}
|
|
127
|
+
{%- endif -%}
|
|
128
|
+
{% call fieldset({ariaDescribedby:ariaDescribedBy,classes:params.classes, lang:params.lang}) %}
|
|
129
|
+
{% call legend({legend:params.legend, isPageHeading:isPageHeading,lang:params.lang}) %}{% endcall %}
|
|
130
|
+
{% call formControl({isError: false if params.hideFormControlError else params.error}) %}
|
|
131
|
+
{% call hint({hint:params.hint, id:hintId,lang:params.lang}) %}{% endcall %}
|
|
132
|
+
{#- render error message -#}
|
|
133
|
+
{% call errorMessage({message:params.error,id:errorId,lang:params.lang}) %}{% endcall %}
|
|
134
|
+
{# for each item render checkbox item #}
|
|
135
|
+
{%- for item in params.items -%}
|
|
136
|
+
{%- if item -%}
|
|
137
|
+
{{- _checkboxItem(params, item, loop.index, params.lang) -}}
|
|
138
|
+
{%- endif -%}
|
|
139
|
+
{%- endfor -%}
|
|
140
|
+
{% endcall %}
|
|
141
|
+
{% endcall %}
|
|
142
|
+
{%- endif -%}
|
|
143
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{# error Message
|
|
2
|
+
@param {object} message The error message text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
3
|
+
@param {string} id The error message id. Will escape text
|
|
4
|
+
@param {string} lang The language used. Can be 'en','el'. Optional, default is 'el'.
|
|
5
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
6
|
+
@returns govcy error message html
|
|
7
|
+
#}
|
|
8
|
+
{% macro errorMessage(params) -%}
|
|
9
|
+
{#- Import localizer from utilities -#}
|
|
10
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
11
|
+
{#- set default values -#}
|
|
12
|
+
{%- set hiddenError -%}
|
|
13
|
+
{{- govcyLocalizeContent({en:'Error',el:'Σφάλμα'}, params.lang) -}}
|
|
14
|
+
{%- endset -%}
|
|
15
|
+
{%- if params.message -%}
|
|
16
|
+
<p {% if params.id %}id="{{ params.id }}"{% endif %} class="govcy-input-error-msg{% if params.classes %} {{ params.classes }}{% endif %}"{{ govcyLangAttribute(params.lang) }}>
|
|
17
|
+
<span class="govcy-visually-hidden-error">{{ hiddenError }}:</span>{{ govcyLocalizeContent(params.message, params.lang) }}
|
|
18
|
+
</p>
|
|
19
|
+
{%- endif -%}
|
|
20
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{# fieldset
|
|
2
|
+
@param {string} id The hint id. Will escape text. Optional
|
|
3
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
4
|
+
@param {string} ariaDescribedby Ids of aria-describedby. To be used for hints and errors. Optional
|
|
5
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
6
|
+
@param {array} elements If defined will be rendered elements inside the form.
|
|
7
|
+
i.e. `[
|
|
8
|
+
{element:"button",params:{text:{en:"Button 1",el:"Κουμπί 1"},lang:"en",id:"govcy-test-23b"} },
|
|
9
|
+
{element:"button",params:{text:{en:"Button 2",el:"Κουμπί 2"},variant:'secondary',lang:"en",id:"govcy-test-23c"} },
|
|
10
|
+
]`
|
|
11
|
+
@returns govcy fieldset html
|
|
12
|
+
#}
|
|
13
|
+
{% macro fieldset(params) -%}
|
|
14
|
+
{#- Import localizer from utilities -#}
|
|
15
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
16
|
+
<fieldset {% if params.id %}id="{{ params.id }}" {% endif %}class="govcy-fieldset{% if params.classes %} {{ params.classes }}{% endif %}"{% if params.ariaDescribedby %} aria-describedby="{{ params.ariaDescribedby }}"{% endif %}{{ govcyLangAttribute(params.lang) }}>
|
|
17
|
+
{{ caller() }}
|
|
18
|
+
{#- if it has elements to be called -#}
|
|
19
|
+
{%- if params.elements -%}
|
|
20
|
+
{#- Import localizer from utilities -#}
|
|
21
|
+
{%- from "../govcyElement.njk" import govcyElement -%}
|
|
22
|
+
{%- for element in params.elements -%}
|
|
23
|
+
{%- call govcyElement(element.element, element.params) %}{% endcall -%}
|
|
24
|
+
{%- endfor -%}
|
|
25
|
+
{%- endif -%}
|
|
26
|
+
</fieldset>
|
|
27
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{# file 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 {string} classes Additional classes to add to the outer div. Optional
|
|
8
|
+
@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:"Περιεχομένο"}`
|
|
9
|
+
@param {boolean} hideFormControlError If true, hides the form control error (red line on the left). Mostly used in conditional radio elements. Optional
|
|
10
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
11
|
+
@returns govcy file html
|
|
12
|
+
#}
|
|
13
|
+
{% macro fileInput(params) -%}
|
|
14
|
+
{#- Import localizer from utilities -#}
|
|
15
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
16
|
+
{%- from "./formControl.njk" import formControl -%}
|
|
17
|
+
{%- from "./hint.njk" import hint -%}
|
|
18
|
+
{%- from "./label.njk" import label -%}
|
|
19
|
+
{%- from "./errorMessage.njk" import errorMessage -%}
|
|
20
|
+
{#- set default values -#}
|
|
21
|
+
{%- set isPageHeading = params.isPageHeading | default(false) -%}
|
|
22
|
+
{#- label and id are mandatory -#}
|
|
23
|
+
{%- if params.label and params.id -%}
|
|
24
|
+
{#- set hint label error ids -#}
|
|
25
|
+
{%- set hintId = [params.id, "-hint"] | join -%}
|
|
26
|
+
{%- set labelId = [params.id, "-label"] | join -%}
|
|
27
|
+
{%- set errorId = [params.id, "-error"] | join -%}
|
|
28
|
+
{% call formControl({isError: false if params.hideFormControlError else params.error,classes:params.classe, lang:params.langs}) %}
|
|
29
|
+
{#- render label -#}
|
|
30
|
+
{% call label({label:params.label, id:labelId, for:params.id, isPageHeading:isPageHeading, lang:params.lang}) %}{% endcall %}
|
|
31
|
+
{#- render hint -#}
|
|
32
|
+
{% call hint({hint:params.hint,id:hintId, lang:params.lang}) %}{% endcall %}
|
|
33
|
+
{#- render error message -#}
|
|
34
|
+
{% call errorMessage({message:params.error,id:errorId, lang:params.lang}) %}{% endcall %}
|
|
35
|
+
{#- render input -#}
|
|
36
|
+
<input id="{{params.id}}"{% if params.name %} name="{{ params.name }}"{% endif %} type="file" class="govcy-file-upload"{% if params.hint or params.error%} aria-describedby="{% if params.hint %}{{hintId}} {% endif %}{% if params.error %}{{errorId}} {% endif %}"{% endif %}>
|
|
37
|
+
{% endcall %}
|
|
38
|
+
{%- endif -%}
|
|
39
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{# file view and delete
|
|
2
|
+
@param {object} label The label text. Will escape text. `{en:"Content",el:"Περιεχομένο"}`
|
|
3
|
+
@param {string} viewHref The view link's href. Will escape text
|
|
4
|
+
@param {string} deleteHref The delete link's href. Will escape text
|
|
5
|
+
@param {object} visuallyHiddenText The visuallyHiddenText text. Optional. Will escape text. `{en:"Content",el:"Περιεχομένο"}`
|
|
6
|
+
@param {object} hint The hint text. Optional. Will escape text. `{en:"Content",el:"Περιεχομένο"}`
|
|
7
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
8
|
+
@param {boolean} isPageHeading Is the label also the page heading? Optional, default is false. Can be true,false
|
|
9
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
10
|
+
@returns govcy file view and delete html
|
|
11
|
+
#}
|
|
12
|
+
{% macro fileView(params) -%}
|
|
13
|
+
{#- Import localizer from utilities -#}
|
|
14
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
15
|
+
{%- from "./formControl.njk" import formControl -%}
|
|
16
|
+
{%- from "./hint.njk" import hint -%}
|
|
17
|
+
{#- set language labels -#}
|
|
18
|
+
{%- set viewLabel -%} {{- govcyLocalizeContent({en:'View',el:'Προβολή'}, params.lang) -}}{%- endset -%}
|
|
19
|
+
{%- set deleteLabel -%} {{- govcyLocalizeContent({en:'Delete',el:'Διαγραφή'}, params.lang) -}}{%- endset -%}
|
|
20
|
+
{#- label, viewHref and deleteHref are mandatory -#}
|
|
21
|
+
{%- if params.label and params.viewHref and params.deleteHref -%}
|
|
22
|
+
<div class="govcy-form">
|
|
23
|
+
{% call formControl({classes:params.classes, lang:params.lang}) %}
|
|
24
|
+
{%- if params.isPageHeading -%}<h1>{%- else -%}<p class="govcy-label govcy-label-primary">{%- endif -%}{{- govcyLocalizeContent(params.label, params.lang) -}}{%- if params.isPageHeading -%}</h1>{%- else -%}</p>{%- endif -%}
|
|
25
|
+
{#- render hint -#}
|
|
26
|
+
{% call hint({hint:params.hint, lang:params.lang}) %}{% endcall %}
|
|
27
|
+
{#- render view -#}
|
|
28
|
+
<a href="{{ params.viewHref }}">{{viewLabel}}{%if params.visuallyHiddenText%}<span class="govcy-visually-hidden"> {{- govcyLocalizeContent(params.visuallyHiddenText, params.lang) -}}</span>{% endif %}</a>
|
|
29
|
+
{#- render delete -#}
|
|
30
|
+
<a class="govcy-ml-3" href="{{ params.deleteHref }}">{{deleteLabel}}{%if params.visuallyHiddenText%}<span class="govcy-visually-hidden"> {{- govcyLocalizeContent(params.visuallyHiddenText, params.lang) -}}</span>{% endif %}</a>
|
|
31
|
+
{% endcall %}
|
|
32
|
+
</div>
|
|
33
|
+
{%- endif -%}
|
|
34
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{# form
|
|
2
|
+
@param {string} action. Will escape text
|
|
3
|
+
@param {string} id The hint id. Will escape text
|
|
4
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
5
|
+
@param {array} elements If defined will be rendered elements inside the form.
|
|
6
|
+
i.e. `[
|
|
7
|
+
{element:"button",params:{text:{en:"Button 1",el:"Κουμπί 1"},lang:"en",id:"govcy-test-23b"} },
|
|
8
|
+
{element:"button",params:{text:{en:"Button 2",el:"Κουμπί 2"},variant:'secondary',lang:"en",id:"govcy-test-23c"} },
|
|
9
|
+
]`
|
|
10
|
+
@returns govcy form html
|
|
11
|
+
#}
|
|
12
|
+
{% macro form(params) -%}
|
|
13
|
+
<form {% if params.id %}id="{{ params.id }}" {% endif %}action="{{ params.action }}" class="govcy-form{% if params.classes %} {{ params.classes }}{% endif %}" novalidate="">
|
|
14
|
+
{{ caller() }}
|
|
15
|
+
{#- if it has elements to be called -#}
|
|
16
|
+
{%- if params.elements -%}
|
|
17
|
+
{#- Import localizer from utilities -#}
|
|
18
|
+
{%- from "../govcyElement.njk" import govcyElement -%}
|
|
19
|
+
{%- for element in params.elements -%}
|
|
20
|
+
{%- call govcyElement(element.element, element.params) %}{% endcall -%}
|
|
21
|
+
{%- endfor -%}
|
|
22
|
+
{%- endif -%}
|
|
23
|
+
</form>
|
|
24
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{# form control
|
|
2
|
+
@param {string} id The hint id. Will escape text. Optional
|
|
3
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
4
|
+
@param {string} isError Is there a validation error and need to render the errror variant? Optional, default is false. Can be true,false
|
|
5
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
6
|
+
@param {array} elements If defined will be rendered elements inside the form.
|
|
7
|
+
i.e. `[
|
|
8
|
+
{element:"button",params:{text:{en:"Button 1",el:"Κουμπί 1"},lang:"en",id:"govcy-test-23b"} },
|
|
9
|
+
{element:"button",params:{text:{en:"Button 2",el:"Κουμπί 2"},variant:'secondary',lang:"en",id:"govcy-test-23c"} },
|
|
10
|
+
]`
|
|
11
|
+
@returns govcy form control html
|
|
12
|
+
#}
|
|
13
|
+
{% macro formControl(params) -%}
|
|
14
|
+
{#- Import localizer from utilities -#}
|
|
15
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
16
|
+
{# set default values #}
|
|
17
|
+
{%- set isError = params.isError | default(false) -%}
|
|
18
|
+
<div {% if params.id %}id="{{ params.id }}" {% endif %}class="govcy-form-control{% if isError %} govcy-form-control-error{% endif %}{% if params.classes %} {{ params.classes }}{% endif %}"{{ govcyLangAttribute(params.lang) }}>
|
|
19
|
+
{{ caller() }}
|
|
20
|
+
{#- if it has elements to be called -#}
|
|
21
|
+
{%- if params.elements -%}
|
|
22
|
+
{#- Import localizer from utilities -#}
|
|
23
|
+
{%- from "../govcyElement.njk" import govcyElement -%}
|
|
24
|
+
{%- for element in params.elements -%}
|
|
25
|
+
{%- call govcyElement(element.element, element.params) %}{% endcall -%}
|
|
26
|
+
{%- endfor -%}
|
|
27
|
+
{%- endif -%}
|
|
28
|
+
</div>
|
|
29
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{# hint
|
|
2
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
3
|
+
@param {object} hint The label text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
4
|
+
@param {string} id The hint id. Will escape text
|
|
5
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
6
|
+
@returns govcy hint html
|
|
7
|
+
#}
|
|
8
|
+
{% macro hint(params) -%}
|
|
9
|
+
{#- Import localizer from utilities -#}
|
|
10
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
11
|
+
{% if params.hint %}<span {% if params.id %}id="{{ params.id }}"{% endif %} class="govcy-hint{% if params.classes %} {{ params.classes }}{% endif %}"{{ govcyLangAttribute(params.lang) }}>{{ govcyLocalizeContent(params.hint, params.lang) }}</span>{% endif %}
|
|
12
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{# htmlElement (use with caution - no escaping)
|
|
2
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
3
|
+
@param {object} text The text. Will not escape text, Example `{en:"Content",el:"Περιεχομένο"}`
|
|
4
|
+
@returns html Elements with sanitzed html
|
|
5
|
+
#}
|
|
6
|
+
{% macro htmlElement(params) -%}
|
|
7
|
+
{# text is mandatory #}
|
|
8
|
+
{%- if params.text -%}
|
|
9
|
+
{#- Import localizer from utilities -#}
|
|
10
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent -%}
|
|
11
|
+
{{ govcyLocalizeContent(params.text, params.lang, true) }}
|
|
12
|
+
{%- endif -%}
|
|
13
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{# label
|
|
2
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
3
|
+
@param {object} label The label text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
4
|
+
@param {string} id The label id. Will escape text
|
|
5
|
+
@param {string} for The input id used in `for`. Will escape text
|
|
6
|
+
@param {boolean} isPrimary Is the label a primary? Optional, default is true. Can be true,false
|
|
7
|
+
@param {boolean} isPageHeading Is the label also the page heading? Optional, default is false. Can be true,false
|
|
8
|
+
@param {boolean} isHTML Is the label an HTML and can be reproduced without escaping? Optional, default is false. Can be true,false
|
|
9
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
10
|
+
@returns govcy label html
|
|
11
|
+
#}
|
|
12
|
+
{% macro label(params) -%}
|
|
13
|
+
{#- Import localizer from utilities -#}
|
|
14
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
15
|
+
{#- set default values -#}
|
|
16
|
+
{%- set isPrimary = params.isPrimary | default(true) -%}
|
|
17
|
+
{%- set isHTML = params.isHTML | default(false) -%}
|
|
18
|
+
{# label and for are mandatory #}
|
|
19
|
+
{%- if params.label and params.for -%}
|
|
20
|
+
{%- if params.isPageHeading -%}<h1>{%- endif -%}
|
|
21
|
+
<label {% if params.id %}id="{{ params.id }}" {% endif %}class="govcy-label{% if isPrimary == true %} govcy-label-primary{% endif %}{% if params.classes %} {{ params.classes }}{% endif %}" for="{{ params.for }}"{{ govcyLangAttribute(params.lang) }}>{{ govcyLocalizeContent(params.label, params.lang, isHTML) }}</label>
|
|
22
|
+
{%- if params.isPageHeading -%}</h1>{%- endif -%}
|
|
23
|
+
{%- endif -%}
|
|
24
|
+
{%- endmacro %}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{# legend
|
|
2
|
+
@param {string} lang The language used. Can be 'en','el'. Optional.
|
|
3
|
+
@param {object} legend The legend text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
|
|
4
|
+
@param {string} id The legend id. Will escape text
|
|
5
|
+
@param {boolean} isPageHeading Is the legend also the page heading? Optional, default is false. Can be true,false
|
|
6
|
+
@param {string} classes Additional classes to add to the outer div. Optional
|
|
7
|
+
@returns govcy legend html
|
|
8
|
+
#}
|
|
9
|
+
{% macro legend(params) -%}
|
|
10
|
+
{#- Import localizer from utilities -#}
|
|
11
|
+
{%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
|
|
12
|
+
{# set default values #}
|
|
13
|
+
{%- set isPageHeading = params.isPageHeading | default(false) -%}
|
|
14
|
+
{# legend is mandatory #}
|
|
15
|
+
{%- if params.legend -%}
|
|
16
|
+
{%- if isPageHeading -%}
|
|
17
|
+
<legend {% if params.id %}id="{{ params.id }}" {% endif %}class="govcy-legend{% if params.classes %} {{ params.classes }}{% endif %}"{{ govcyLangAttribute(params.lang) }}><h1>{{ govcyLocalizeContent(params.legend , params.lang) }}</h1></legend>
|
|
18
|
+
{%- else -%}
|
|
19
|
+
<legend {% if params.id %}id="{{ params.id }}" {% endif %}class="govcy-legend{% if params.classes %} {{ params.classes }}{% endif %}"{{ govcyLangAttribute(params.lang) }}>{{ govcyLocalizeContent(params.legend , params.lang) }}</legend>
|
|
20
|
+
{%- endif -%}
|
|
21
|
+
{%- endif -%}
|
|
22
|
+
{%- endmacro %}
|