@gov-cy/govcy-frontend-renderer 1.7.0 → 1.8.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.
@@ -1844,6 +1844,150 @@ root: root
1844
1844
  })();
1845
1845
  })();
1846
1846
 
1847
+ (function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["elements/errorSummary.njk"] = (function() {
1848
+ function root(env, context, frame, runtime, cb) {
1849
+ var lineno = 0;
1850
+ var colno = 0;
1851
+ var output = "";
1852
+ try {
1853
+ var parentTemplate = null;
1854
+ output += "\r\n";
1855
+ var macro_t_1 = runtime.makeMacro(
1856
+ ["params"],
1857
+ [],
1858
+ function (l_params, kwargs) {
1859
+ var callerFrame = frame;
1860
+ frame = new runtime.Frame();
1861
+ kwargs = kwargs || {};
1862
+ if (Object.prototype.hasOwnProperty.call(kwargs, "caller")) {
1863
+ frame.set("caller", kwargs.caller); }
1864
+ frame.set("params", l_params);
1865
+ var t_2 = "";env.getTemplate("utilities/govcyUtilities.njk", false, "elements/errorSummary.njk", false, function(t_4,t_3) {
1866
+ if(t_4) { cb(t_4); return; }
1867
+ t_3.getExported(function(t_5,t_3) {
1868
+ if(t_5) { cb(t_5); return; }
1869
+ if(Object.prototype.hasOwnProperty.call(t_3, "govcyLocalizeContent")) {
1870
+ var t_6 = t_3.govcyLocalizeContent;
1871
+ } else {
1872
+ cb(new Error("cannot import 'govcyLocalizeContent'")); return;
1873
+ }
1874
+ context.setVariable("govcyLocalizeContent", t_6);
1875
+ if(Object.prototype.hasOwnProperty.call(t_3, "govcyLangAttribute")) {
1876
+ var t_7 = t_3.govcyLangAttribute;
1877
+ } else {
1878
+ cb(new Error("cannot import 'govcyLangAttribute'")); return;
1879
+ }
1880
+ context.setVariable("govcyLangAttribute", t_7);
1881
+ if(runtime.memberLookup((l_params),"header")) {
1882
+ var t_8;
1883
+ t_8 = (function() {
1884
+ var output = "";
1885
+ output += runtime.suppressValue((lineno = 29, colno = 47, runtime.callWrap(t_6, "govcyLocalizeContent", context, [runtime.memberLookup((l_params),"header"),runtime.memberLookup((l_params),"lang")])), env.opts.autoescape);
1886
+ ;
1887
+ return output;
1888
+ })()
1889
+ ;
1890
+ frame.set("header", t_8, true);
1891
+ if(frame.topLevel) {
1892
+ context.setVariable("header", t_8);
1893
+ }
1894
+ if(frame.topLevel) {
1895
+ context.addExport("header", t_8);
1896
+ }
1897
+ ;
1898
+ }
1899
+ else {
1900
+ var t_9;
1901
+ t_9 = (function() {
1902
+ var output = "";
1903
+ output += runtime.suppressValue((lineno = 31, colno = 47, runtime.callWrap(t_6, "govcyLocalizeContent", context, [{"en": "There is a problem","el": "Υπάρχει πρόβλημα"},runtime.memberLookup((l_params),"lang")])), env.opts.autoescape);
1904
+ ;
1905
+ return output;
1906
+ })()
1907
+ ;
1908
+ frame.set("header", t_9, true);
1909
+ if(frame.topLevel) {
1910
+ context.setVariable("header", t_9);
1911
+ }
1912
+ if(frame.topLevel) {
1913
+ context.addExport("header", t_9);
1914
+ }
1915
+ ;
1916
+ }
1917
+ if(runtime.memberLookup((l_params),"id") && runtime.memberLookup((l_params),"errors")) {
1918
+ t_2 += "\r\n<div id=\"";
1919
+ t_2 += runtime.suppressValue(runtime.memberLookup((l_params),"id"), env.opts.autoescape);
1920
+ t_2 += "\" class=\"govcy-alert-error govcy-br-5 govcy-br-danger govcy-p-3\"";
1921
+ t_2 += runtime.suppressValue((lineno = 35, colno = 109, runtime.callWrap(t_7, "govcyLangAttribute", context, [runtime.memberLookup((l_params),"lang")])), env.opts.autoescape);
1922
+ t_2 += ">\r\n <h2 role=\"alert\" id=\"";
1923
+ t_2 += runtime.suppressValue(runtime.memberLookup((l_params),"id"), env.opts.autoescape);
1924
+ t_2 += "-title\">";
1925
+ t_2 += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "header"), env.opts.autoescape);
1926
+ t_2 += "</h2>\r\n <p>";
1927
+ frame = frame.push();
1928
+ var t_12 = runtime.memberLookup((l_params),"errors");
1929
+ if(t_12) {t_12 = runtime.fromIterator(t_12);
1930
+ var t_11 = t_12.length;
1931
+ for(var t_10=0; t_10 < t_12.length; t_10++) {
1932
+ var t_13 = t_12[t_10];
1933
+ frame.set("error", t_13);
1934
+ frame.set("loop.index", t_10 + 1);
1935
+ frame.set("loop.index0", t_10);
1936
+ frame.set("loop.revindex", t_11 - t_10);
1937
+ frame.set("loop.revindex0", t_11 - t_10 - 1);
1938
+ frame.set("loop.first", t_10 === 0);
1939
+ frame.set("loop.last", t_10 === t_11 - 1);
1940
+ frame.set("loop.length", t_11);
1941
+ t_2 += "\r\n <a href=\"";
1942
+ t_2 += runtime.suppressValue(runtime.memberLookup((t_13),"link"), env.opts.autoescape);
1943
+ t_2 += "\">";
1944
+ t_2 += runtime.suppressValue((lineno = 39, colno = 62, runtime.callWrap(t_6, "govcyLocalizeContent", context, [runtime.memberLookup((t_13),"text"),runtime.memberLookup((l_params),"lang")])), env.opts.autoescape);
1945
+ t_2 += "</a>";
1946
+ ;
1947
+ }
1948
+ }
1949
+ frame = frame.pop();
1950
+ t_2 += "\r\n </p>";
1951
+ if(runtime.memberLookup((l_params),"body")) {
1952
+ t_2 += "\r\n <p>";
1953
+ t_2 += runtime.suppressValue((lineno = 43, colno = 30, runtime.callWrap(t_6, "govcyLocalizeContent", context, [runtime.memberLookup((l_params),"body"),runtime.memberLookup((l_params),"lang")])), env.opts.autoescape);
1954
+ t_2 += "</p>";
1955
+ ;
1956
+ }
1957
+ if(runtime.memberLookup((l_params),"linkToContinue")) {
1958
+ t_2 += "\r\n <a href=\"";
1959
+ t_2 += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((l_params),"linkToContinue")),"link"), env.opts.autoescape);
1960
+ t_2 += "\">";
1961
+ t_2 += runtime.suppressValue((lineno = 46, colno = 70, runtime.callWrap(t_6, "govcyLocalizeContent", context, [runtime.memberLookup((runtime.memberLookup((l_params),"linkToContinue")),"text"),runtime.memberLookup((l_params),"lang")])), env.opts.autoescape);
1962
+ t_2 += "</a>";
1963
+ ;
1964
+ }
1965
+ t_2 += "\r\n</div>";
1966
+ ;
1967
+ }
1968
+ })});
1969
+ frame = callerFrame;
1970
+ return new runtime.SafeString(t_2);
1971
+ });
1972
+ context.addExport("errorSummary");
1973
+ context.setVariable("errorSummary", macro_t_1);
1974
+ if(parentTemplate) {
1975
+ parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);
1976
+ } else {
1977
+ cb(null, output);
1978
+ }
1979
+ ;
1980
+ } catch (e) {
1981
+ cb(runtime.handleError(e, lineno, colno));
1982
+ }
1983
+ }
1984
+ return {
1985
+ root: root
1986
+ };
1987
+
1988
+ })();
1989
+ })();
1990
+
1847
1991
  (function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["elements/fieldset.njk"] = (function() {
1848
1992
  function root(env, context, frame, runtime, cb) {
1849
1993
  var lineno = 0;
@@ -6138,7 +6282,7 @@ var output = "";
6138
6282
  try {
6139
6283
  var parentTemplate = null;
6140
6284
  var t_1;
6141
- t_1 = ["label","legend","hint","button","errorMessage","select","textElement","htmlElement","textInput","radios","checkboxes","fileInput","fileView","backLink","tag","table","summaryList","textArea","markdown","panel","datePicker","dateInput","taskList"];
6285
+ t_1 = ["label","legend","hint","button","errorMessage","select","textElement","htmlElement","textInput","radios","checkboxes","fileInput","fileView","backLink","tag","table","summaryList","textArea","markdown","panel","datePicker","dateInput","taskList","errorSummary"];
6142
6286
  frame.set("macroSimpleBlocks", t_1, true);
6143
6287
  if(frame.topLevel) {
6144
6288
  context.setVariable("macroSimpleBlocks", t_1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gov-cy/govcy-frontend-renderer",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "Render html for design elements of the Unified design system using njk or json template.",
5
5
  "author": "DMRID - DSF Team",
6
6
  "license": "MIT",
@@ -0,0 +1,51 @@
1
+ {# errorSummary
2
+ @param {string} lang The language used. Can be 'en','el'. Optional.
3
+ @param {object} header if defined, will rendered the `<h2>` inside the Error Summary. Will escape text. Default value `{"en":"There is a problem","el":"Υπάρχει πρόβλημα"}`. Optional
4
+ @param {object} body if defined, will rendered the body in a `<p>` after the errors. Will escape text. Example `{"en":"Content","el":"Περιεχομένο"}`. Optional
5
+ @param {object} linkToContinue if defined, will rendered it after the errors and the body in a. Will escape text. Optional
6
+ i.e. ` {
7
+ "link":"#",
8
+ "text":{"en":"Back to home page","el":"Επιστροφή στην αρχική σελίδα"}
9
+ }`
10
+ @param {string} id The of the error summary. Will also be used in the as {{id}}-title in the header. Will escape text
11
+ @param {array} errors The errors array.
12
+ i.e. `[
13
+ {
14
+ "link":"#input1",
15
+ "text":{"en":"Enter your full name","el":"Εισαγάγετε το πλήρες όνομά σας"}
16
+ },
17
+ {
18
+ "link":"#input2",
19
+ "text":{"en":"Enter your mobile number","el":"Εισαγάγετε τον αριθμο κινητού τηλεφωνου σας"}
20
+ }
21
+ ]`
22
+ @param {string} classes Additional classes to add to the outer div. Optional
23
+ @returns govcy error Summary html
24
+ #}
25
+ {% macro errorSummary(params) -%}
26
+ {#- Import localizer from utilities -#}
27
+ {%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
28
+ {#- set 'or' labels -#}
29
+ {%- if params.header -%}
30
+ {%- set header -%} {{- govcyLocalizeContent(params.header, params.lang) -}}{%- endset -%}
31
+ {%- else -%}
32
+ {%- set header -%} {{- govcyLocalizeContent({en:"There is a problem",el:"Υπάρχει πρόβλημα"}, params.lang) -}}{%- endset -%}
33
+ {%- endif -%}
34
+ {#- id and errors are mandatory -#}
35
+ {%- if params.id and params.errors %}
36
+ <div id="{{ params.id }}" class="govcy-alert-error govcy-br-5 govcy-br-danger govcy-p-3{% if params.classes %} {{ params.classes }}{% endif %}"{{ govcyLangAttribute(params.lang) }}>
37
+ <h2 role="alert" id="{{ params.id }}-title">{{ header }}</h2>
38
+ <p>
39
+ {%- for error in params.errors %}
40
+ <a href="{{ error.link }}">{{ govcyLocalizeContent(error.text, params.lang) }}</a>
41
+ {%- endfor %}
42
+ </p>
43
+ {%- if params.body %}
44
+ <p>{{ govcyLocalizeContent(params.body, params.lang) }}</p>
45
+ {%- endif %}
46
+ {%- if params.linkToContinue %}
47
+ <a href="{{ params.linkToContinue.link }}">{{ govcyLocalizeContent(params.linkToContinue.text, params.lang) }}</a>
48
+ {%- endif %}
49
+ </div>
50
+ {%- endif %}
51
+ {%- endmacro %}
@@ -25,7 +25,7 @@ To use:
25
25
  {%- set macroSimpleBlocks = ['label', 'legend', 'hint', 'button',
26
26
  'errorMessage','select','textElement','htmlElement','textInput','radios','checkboxes',
27
27
  'fileInput','fileView','backLink','tag','table', 'summaryList', 'textArea','markdown',
28
- 'panel', 'datePicker','dateInput', 'taskList'] -%}
28
+ 'panel', 'datePicker','dateInput', 'taskList', 'errorSummary'] -%}
29
29
  {%- set macroCallerBlocks = ['formControl','form','fieldset'] -%}
30
30
  {%- macro govcyElement(component, params) -%}
31
31
  {#- Simple blocks -#}