@gov-cy/govcy-frontend-renderer 1.2.1 → 1.3.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.
@@ -892,6 +892,277 @@ root: root
892
892
  })();
893
893
  })();
894
894
 
895
+ (function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["elements/datePicker.njk"] = (function() {
896
+ function root(env, context, frame, runtime, cb) {
897
+ var lineno = 0;
898
+ var colno = 0;
899
+ var output = "";
900
+ try {
901
+ var parentTemplate = null;
902
+ output += "\n";
903
+ output += "\n";
904
+ var macro_t_1 = runtime.makeMacro(
905
+ ["params"],
906
+ [],
907
+ function (l_params, kwargs) {
908
+ var callerFrame = frame;
909
+ frame = new runtime.Frame();
910
+ kwargs = kwargs || {};
911
+ if (Object.prototype.hasOwnProperty.call(kwargs, "caller")) {
912
+ frame.set("caller", kwargs.caller); }
913
+ frame.set("params", l_params);
914
+ var t_2 = "";var t_3;
915
+ t_3 = env.getFilter("default").call(context, runtime.memberLookup((l_params),"isPageHeading"),false);
916
+ frame.set("isPageHeading", t_3, true);
917
+ if(frame.topLevel) {
918
+ context.setVariable("isPageHeading", t_3);
919
+ }
920
+ if(frame.topLevel) {
921
+ context.addExport("isPageHeading", t_3);
922
+ }
923
+ if(runtime.memberLookup((l_params),"label") && runtime.memberLookup((l_params),"id") && runtime.memberLookup((l_params),"name")) {
924
+ env.getTemplate("utilities/govcyUtilities.njk", false, "elements/datePicker.njk", false, function(t_5,t_4) {
925
+ if(t_5) { cb(t_5); return; }
926
+ t_4.getExported(function(t_6,t_4) {
927
+ if(t_6) { cb(t_6); return; }
928
+ if(Object.prototype.hasOwnProperty.call(t_4, "govcyLocalizeContent")) {
929
+ var t_7 = t_4.govcyLocalizeContent;
930
+ } else {
931
+ cb(new Error("cannot import 'govcyLocalizeContent'")); return;
932
+ }
933
+ context.setVariable("govcyLocalizeContent", t_7);
934
+ if(Object.prototype.hasOwnProperty.call(t_4, "govcyLangAttribute")) {
935
+ var t_8 = t_4.govcyLangAttribute;
936
+ } else {
937
+ cb(new Error("cannot import 'govcyLangAttribute'")); return;
938
+ }
939
+ context.setVariable("govcyLangAttribute", t_8);
940
+ env.getTemplate("elements/hint.njk", false, "elements/datePicker.njk", false, function(t_10,t_9) {
941
+ if(t_10) { cb(t_10); return; }
942
+ t_9.getExported(function(t_11,t_9) {
943
+ if(t_11) { cb(t_11); return; }
944
+ if(Object.prototype.hasOwnProperty.call(t_9, "hint")) {
945
+ var t_12 = t_9.hint;
946
+ } else {
947
+ cb(new Error("cannot import 'hint'")); return;
948
+ }
949
+ context.setVariable("hint", t_12);
950
+ env.getTemplate("elements/label.njk", false, "elements/datePicker.njk", false, function(t_14,t_13) {
951
+ if(t_14) { cb(t_14); return; }
952
+ t_13.getExported(function(t_15,t_13) {
953
+ if(t_15) { cb(t_15); return; }
954
+ if(Object.prototype.hasOwnProperty.call(t_13, "label")) {
955
+ var t_16 = t_13.label;
956
+ } else {
957
+ cb(new Error("cannot import 'label'")); return;
958
+ }
959
+ context.setVariable("label", t_16);
960
+ env.getTemplate("elements/errorMessage.njk", false, "elements/datePicker.njk", false, function(t_18,t_17) {
961
+ if(t_18) { cb(t_18); return; }
962
+ t_17.getExported(function(t_19,t_17) {
963
+ if(t_19) { cb(t_19); return; }
964
+ if(Object.prototype.hasOwnProperty.call(t_17, "errorMessage")) {
965
+ var t_20 = t_17.errorMessage;
966
+ } else {
967
+ cb(new Error("cannot import 'errorMessage'")); return;
968
+ }
969
+ context.setVariable("errorMessage", t_20);
970
+ env.getTemplate("elements/formControl.njk", false, "elements/datePicker.njk", false, function(t_22,t_21) {
971
+ if(t_22) { cb(t_22); return; }
972
+ t_21.getExported(function(t_23,t_21) {
973
+ if(t_23) { cb(t_23); return; }
974
+ if(Object.prototype.hasOwnProperty.call(t_21, "formControl")) {
975
+ var t_24 = t_21.formControl;
976
+ } else {
977
+ cb(new Error("cannot import 'formControl'")); return;
978
+ }
979
+ context.setVariable("formControl", t_24);
980
+ if(runtime.memberLookup((l_params),"hint")) {
981
+ var t_25;
982
+ t_25 = env.getFilter("join").call(context, [runtime.memberLookup((l_params),"id"),"-hint"]);
983
+ frame.set("hintId", t_25, true);
984
+ if(frame.topLevel) {
985
+ context.setVariable("hintId", t_25);
986
+ }
987
+ if(frame.topLevel) {
988
+ context.addExport("hintId", t_25);
989
+ }
990
+ ;
991
+ }
992
+ else {
993
+ var t_26;
994
+ t_26 = "";
995
+ frame.set("hintId", t_26, true);
996
+ if(frame.topLevel) {
997
+ context.setVariable("hintId", t_26);
998
+ }
999
+ if(frame.topLevel) {
1000
+ context.addExport("hintId", t_26);
1001
+ }
1002
+ ;
1003
+ }
1004
+ if(runtime.memberLookup((l_params),"error")) {
1005
+ var t_27;
1006
+ t_27 = env.getFilter("join").call(context, [runtime.memberLookup((l_params),"id"),"-error"]);
1007
+ frame.set("errorId", t_27, true);
1008
+ if(frame.topLevel) {
1009
+ context.setVariable("errorId", t_27);
1010
+ }
1011
+ if(frame.topLevel) {
1012
+ context.addExport("errorId", t_27);
1013
+ }
1014
+ ;
1015
+ }
1016
+ else {
1017
+ var t_28;
1018
+ t_28 = "";
1019
+ frame.set("errorId", t_28, true);
1020
+ if(frame.topLevel) {
1021
+ context.setVariable("errorId", t_28);
1022
+ }
1023
+ if(frame.topLevel) {
1024
+ context.addExport("errorId", t_28);
1025
+ }
1026
+ ;
1027
+ }
1028
+ if(runtime.memberLookup((l_params),"error") || runtime.memberLookup((l_params),"hint")) {
1029
+ var t_29;
1030
+ t_29 = runtime.contextOrFrameLookup(context, frame, "hintId") + "" + " " + "" + runtime.contextOrFrameLookup(context, frame, "errorId");
1031
+ frame.set("ariaDescribedBy", t_29, true);
1032
+ if(frame.topLevel) {
1033
+ context.setVariable("ariaDescribedBy", t_29);
1034
+ }
1035
+ if(frame.topLevel) {
1036
+ context.addExport("ariaDescribedBy", t_29);
1037
+ }
1038
+ ;
1039
+ }
1040
+ else {
1041
+ var t_30;
1042
+ t_30 = "";
1043
+ frame.set("ariaDescribedBy", t_30, true);
1044
+ if(frame.topLevel) {
1045
+ context.setVariable("ariaDescribedBy", t_30);
1046
+ }
1047
+ if(frame.topLevel) {
1048
+ context.addExport("ariaDescribedBy", t_30);
1049
+ }
1050
+ ;
1051
+ }
1052
+ t_2 += runtime.suppressValue((lineno = 44, colno = 23, runtime.callWrap(t_24, "formControl", context, [{"isError": (runtime.memberLookup((l_params),"hideFormControlError")?false:runtime.memberLookup((l_params),"error")),"classes": runtime.memberLookup((l_params),"classes")},runtime.makeKeywordArgs({"caller": (function (){var macro_t_31 = runtime.makeMacro(
1053
+ [],
1054
+ [],
1055
+ function (kwargs) {
1056
+ var callerFrame = frame;
1057
+ frame = frame.push(true);
1058
+ kwargs = kwargs || {};
1059
+ if (Object.prototype.hasOwnProperty.call(kwargs, "caller")) {
1060
+ frame.set("caller", kwargs.caller); }
1061
+ var t_32 = "";t_32 += "\n ";
1062
+ t_32 += runtime.suppressValue((lineno = 45, colno = 21, runtime.callWrap(t_16, "label", context, [{"label": runtime.memberLookup((l_params),"label"),"id": runtime.contextOrFrameLookup(context, frame, "labelId"),"for": runtime.memberLookup((l_params),"id"),"isPageHeading": runtime.contextOrFrameLookup(context, frame, "isPageHeading"),"lang": runtime.memberLookup((l_params),"lang")},runtime.makeKeywordArgs({"caller": (function (){var macro_t_33 = runtime.makeMacro(
1063
+ [],
1064
+ [],
1065
+ function (kwargs) {
1066
+ var callerFrame = frame;
1067
+ frame = frame.push(true);
1068
+ kwargs = kwargs || {};
1069
+ if (Object.prototype.hasOwnProperty.call(kwargs, "caller")) {
1070
+ frame.set("caller", kwargs.caller); }
1071
+ var t_34 = "";;
1072
+ frame = frame.pop();
1073
+ return new runtime.SafeString(t_34);
1074
+ });
1075
+ return macro_t_33;})()})])), env.opts.autoescape);
1076
+ t_32 += "\n ";
1077
+ t_32 += runtime.suppressValue((lineno = 46, colno = 20, runtime.callWrap(t_12, "hint", context, [{"hint": runtime.memberLookup((l_params),"hint"),"id": runtime.contextOrFrameLookup(context, frame, "hintId"),"lang": runtime.memberLookup((l_params),"lang")},runtime.makeKeywordArgs({"caller": (function (){var macro_t_35 = runtime.makeMacro(
1078
+ [],
1079
+ [],
1080
+ function (kwargs) {
1081
+ var callerFrame = frame;
1082
+ frame = frame.push(true);
1083
+ kwargs = kwargs || {};
1084
+ if (Object.prototype.hasOwnProperty.call(kwargs, "caller")) {
1085
+ frame.set("caller", kwargs.caller); }
1086
+ var t_36 = "";;
1087
+ frame = frame.pop();
1088
+ return new runtime.SafeString(t_36);
1089
+ });
1090
+ return macro_t_35;})()})])), env.opts.autoescape);
1091
+ t_32 += runtime.suppressValue((lineno = 48, colno = 28, runtime.callWrap(t_20, "errorMessage", context, [{"message": runtime.memberLookup((l_params),"error"),"id": runtime.contextOrFrameLookup(context, frame, "errorId"),"lang": runtime.memberLookup((l_params),"lang")},runtime.makeKeywordArgs({"caller": (function (){var macro_t_37 = runtime.makeMacro(
1092
+ [],
1093
+ [],
1094
+ function (kwargs) {
1095
+ var callerFrame = frame;
1096
+ frame = frame.push(true);
1097
+ kwargs = kwargs || {};
1098
+ if (Object.prototype.hasOwnProperty.call(kwargs, "caller")) {
1099
+ frame.set("caller", kwargs.caller); }
1100
+ var t_38 = "";;
1101
+ frame = frame.pop();
1102
+ return new runtime.SafeString(t_38);
1103
+ });
1104
+ return macro_t_37;})()})])), env.opts.autoescape);
1105
+ t_32 += "\n <div class=\"govcy-date-picker\"";
1106
+ if(runtime.memberLookup((l_params),"dataMinDate")) {
1107
+ t_32 += " data-min-date=\"";
1108
+ t_32 += runtime.suppressValue(runtime.memberLookup((l_params),"dataMinDate"), env.opts.autoescape);
1109
+ t_32 += "\"";
1110
+ ;
1111
+ }
1112
+ if(runtime.memberLookup((l_params),"dataMaxDate")) {
1113
+ t_32 += " data-max-date=\"";
1114
+ t_32 += runtime.suppressValue(runtime.memberLookup((l_params),"dataMaxDate"), env.opts.autoescape);
1115
+ t_32 += "\"";
1116
+ ;
1117
+ }
1118
+ t_32 += ">\n <input type=\"text\" class=\"govcy-text-input ";
1119
+ if(runtime.memberLookup((l_params),"error")) {
1120
+ t_32 += " govcy-text-input-error";
1121
+ ;
1122
+ }
1123
+ t_32 += "\" \n id=\"";
1124
+ t_32 += runtime.suppressValue(runtime.memberLookup((l_params),"id"), env.opts.autoescape);
1125
+ t_32 += "\"\n name=\"";
1126
+ t_32 += runtime.suppressValue(runtime.memberLookup((l_params),"name"), env.opts.autoescape);
1127
+ t_32 += "\"\n ";
1128
+ if(runtime.contextOrFrameLookup(context, frame, "ariaDescribedBy")) {
1129
+ t_32 += " aria-describedby=\"";
1130
+ t_32 += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "ariaDescribedBy"), env.opts.autoescape);
1131
+ t_32 += "\"";
1132
+ ;
1133
+ }
1134
+ t_32 += runtime.suppressValue((lineno = 53, colno = 115, runtime.callWrap(t_8, "govcyLangAttribute", context, [runtime.memberLookup((l_params),"lang")])), env.opts.autoescape);
1135
+ t_32 += "/>\n </div>\n ";
1136
+ ;
1137
+ frame = frame.pop();
1138
+ return new runtime.SafeString(t_32);
1139
+ });
1140
+ return macro_t_31;})()})])), env.opts.autoescape);
1141
+ })})})})})})})})})});
1142
+ }
1143
+ ;
1144
+ frame = callerFrame;
1145
+ return new runtime.SafeString(t_2);
1146
+ });
1147
+ context.addExport("datePicker");
1148
+ context.setVariable("datePicker", macro_t_1);
1149
+ if(parentTemplate) {
1150
+ parentTemplate.rootRenderFunc(env, context, frame, runtime, cb);
1151
+ } else {
1152
+ cb(null, output);
1153
+ }
1154
+ ;
1155
+ } catch (e) {
1156
+ cb(runtime.handleError(e, lineno, colno));
1157
+ }
1158
+ }
1159
+ return {
1160
+ root: root
1161
+ };
1162
+
1163
+ })();
1164
+ })();
1165
+
895
1166
  (function() {(window.nunjucksPrecompiled = window.nunjucksPrecompiled || {})["elements/errorMessage.njk"] = (function() {
896
1167
  function root(env, context, frame, runtime, cb) {
897
1168
  var lineno = 0;
@@ -5087,7 +5358,7 @@ var output = "";
5087
5358
  try {
5088
5359
  var parentTemplate = null;
5089
5360
  var t_1;
5090
- t_1 = ["label","legend","hint","button","errorMessage","select","textElement","htmlElement","textInput","radios","checkboxes","fileInput","fileView","backLink","tag","table","summaryList","textArea","markdown","panel"];
5361
+ t_1 = ["label","legend","hint","button","errorMessage","select","textElement","htmlElement","textInput","radios","checkboxes","fileInput","fileView","backLink","tag","table","summaryList","textArea","markdown","panel","datePicker"];
5091
5362
  frame.set("macroSimpleBlocks", t_1, true);
5092
5363
  if(frame.topLevel) {
5093
5364
  context.setVariable("macroSimpleBlocks", t_1);
@@ -16451,7 +16451,7 @@ var GovcyFrontendRendererBrowser = (function () {
16451
16451
  /**
16452
16452
  * Returns the rendered html as string, based on the json templates
16453
16453
  *
16454
- * @param {onject} input The JSON input
16454
+ * @param {Object} input The JSON input
16455
16455
  * @param {Object} data The data
16456
16456
  * @returns {string} Rendered html as string
16457
16457
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gov-cy/govcy-frontend-renderer",
3
- "version": "1.2.1",
3
+ "version": "1.3.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,58 @@
1
+
2
+ {# datePicker
3
+ @param {object} label The label text. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
4
+ @param {string} id The id of the datePicker. Will escape text.
5
+ @param {string} name The name of the datePicker. Will escape text.
6
+ @param {object} hint The hint text. Optional. Will escape text. Example `{en:"Content",el:"Περιεχομένο"}`
7
+ @param {boolean} isPageHeading Is the label also the page heading? Optional, default is false. Can be true,false
8
+ @param {string} classes Additional classes to add to the outer `govcy-form-control` container. Optional
9
+ @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:"Περιεχομένο"}`
10
+ @param {boolean} hideFormControlError If true, hides the form control error (red line on the left). Mostly used in conditional radio elements. Optional
11
+ @param {string} dataMinDate The min date allowed in `YYYY-MM-DD` format. Optional.
12
+ @param {string} dataMaxDate The max date allowed in `YYYY-MM-DD` format. Optional.
13
+ @param {string} lang The language used. Can be 'en','el'. Optional.
14
+ @returns govcy datePicker html
15
+ #}
16
+ {% macro datePicker(params) -%}
17
+ {#- set default values -#}
18
+ {%- set isPageHeading = params.isPageHeading | default(false) -%}
19
+ {#- legend, id and name are mandatory -#}
20
+ {%- if params.label and params.id and params.name -%}
21
+ {#- Import localizer from utilities -#}
22
+ {%- from "../utilities/govcyUtilities.njk" import govcyLocalizeContent, govcyLangAttribute -%}
23
+ {%- from "./hint.njk" import hint -%}
24
+ {%- from "./label.njk" import label -%}
25
+ {%- from "./errorMessage.njk" import errorMessage -%}
26
+ {%- from "./formControl.njk" import formControl -%}
27
+ {#- set hint id -#}
28
+ {%- if params.hint -%}
29
+ {%- set hintId = [params.id, "-hint"] | join -%}
30
+ {%- else -%}
31
+ {%- set hintId = '' -%}
32
+ {%- endif -%}
33
+ {#- set error id -#}
34
+ {%- if params.error -%}
35
+ {%- set errorId = [params.id, "-error"] | join -%}
36
+ {%- else -%}
37
+ {%- set errorId = '' -%}
38
+ {%- endif -%}
39
+ {# set aria described by #}
40
+ {%- if params.error or params.hint -%}
41
+ {% set ariaDescribedBy = hintId ~ ' ' ~ errorId %}
42
+ {%- else -%}
43
+ {% set ariaDescribedBy = '' %}
44
+ {%- endif -%}
45
+ {% call formControl({isError: false if params.hideFormControlError else params.error,classes:params.classes}) %}
46
+ {% call label({label:params.label, id:labelId, for:params.id, isPageHeading:isPageHeading, lang:params.lang}) %}{% endcall %}
47
+ {% call hint({hint:params.hint, id:hintId, lang:params.lang}) %}{% endcall %}
48
+ {#- render error message -#}
49
+ {% call errorMessage({message:params.error,id:errorId,lang:params.lang}) %}{% endcall %}
50
+ <div class="govcy-date-picker"{% if params.dataMinDate %} data-min-date="{{ params.dataMinDate }}"{% endif %}{% if params.dataMaxDate %} data-max-date="{{ params.dataMaxDate }}"{% endif %}>
51
+ <input type="text" class="govcy-text-input {% if params.error %} govcy-text-input-error{% endif %}"
52
+ id="{{ params.id }}"
53
+ name="{{ params.name }}"
54
+ {%if ariaDescribedBy %} aria-describedby="{{ ariaDescribedBy }}"{% endif%}{{ govcyLangAttribute(params.lang) }}/>
55
+ </div>
56
+ {% endcall %}
57
+ {%- endif -%}
58
+ {%- 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'] -%}
28
+ 'panel', 'datePicker'] -%}
29
29
  {%- set macroCallerBlocks = ['formControl','form','fieldset'] -%}
30
30
  {%- macro govcyElement(component, params) -%}
31
31
  {#- Simple blocks -#}
@@ -137,7 +137,8 @@ To use this template you need to pass the following data:
137
137
  <!--bodyEnd-->
138
138
  <section class="govcy-container-fluid" id="bodyEndContainer">
139
139
  {% block bodyEnd %}{% endblock %}
140
- </section>
140
+ </section>
141
+ {%- if site.lang == 'en' -%}<script src="{{ site.cdn.dist }}/js/locales/govcy.datepicker.en.min.js"></script>{%- elseif site.lang == 'el' -%}<script src="{{ site.cdn.dist }}/js/locales/govcy.datepicker.el.min.js"></script>{%- endif -%}
141
142
  <script src="{{ site.cdn.dist }}/js/govcy.uds.min.js" integrity="{{ site.cdn.jsIntegrity }}" crossorigin="anonymous"></script>
142
143
  </body>
143
144
  </html>