@qld-gov-au/qgds-bootstrap5 2.0.5 → 2.0.7

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.
Files changed (142) hide show
  1. package/.esbuild/plugins/qgds-plugin-build-log.js +2 -2
  2. package/.esbuild/plugins/qgds-plugin-copy-assets.js +0 -3
  3. package/.storybook/README.md +10 -0
  4. package/.storybook/dynamicThemeDecorator.js +28 -24
  5. package/.storybook/{main.js → main.mjs} +8 -7
  6. package/.storybook/modes.js +3 -12
  7. package/.storybook/preview.js +14 -11
  8. package/dist/assets/components/bs5/head/head.hbs +1 -1
  9. package/dist/assets/css/qld.bootstrap.css +1 -1
  10. package/dist/assets/css/qld.bootstrap.css.map +3 -3
  11. package/dist/assets/css/qld.bootstrap.legacy.css +2 -0
  12. package/dist/assets/css/qld.bootstrap.legacy.css.map +7 -0
  13. package/dist/assets/js/handlebars.init.min.js +1 -1
  14. package/dist/assets/js/handlebars.partials.js +2398 -136
  15. package/dist/assets/js/handlebars.partials.js.map +7 -0
  16. package/dist/assets/node/handlebars.init.min.js +1 -1
  17. package/dist/components/bs5/head/head.hbs +1 -1
  18. package/dist/package.json +25 -27
  19. package/dist/sample-data/correctincorrect/correctincorrect.data.json +1 -0
  20. package/dist/sample-data/tabs/tabs.data.json +1 -2
  21. package/dist/sample-data/typography/typography.data.json +1 -0
  22. package/esbuild.js +22 -5
  23. package/package.json +25 -27
  24. package/pom.xml +3 -3
  25. package/src/components/bs5/accordion/Accordion.mdx +1 -1
  26. package/src/components/bs5/accordion/accordion.scss +3 -3
  27. package/src/components/bs5/accordion/accordion.stories.js +17 -22
  28. package/src/components/bs5/backToTop/backToTop.mdx +1 -1
  29. package/src/components/bs5/banner/Banner.mdx +1 -1
  30. package/src/components/bs5/blockquote/Blockquote.mdx +1 -1
  31. package/src/components/bs5/blockquote/manifest.json +1 -0
  32. package/src/components/bs5/breadcrumbs/Breadcrumbs.mdx +1 -1
  33. package/src/components/bs5/breadcrumbs/breadcrumbs.stories.js +19 -10
  34. package/src/components/bs5/breadcrumbs/manifest.json +1 -0
  35. package/src/components/bs5/breadcumbsWrapper/manifest.json +1 -0
  36. package/src/components/bs5/button/Button.mdx +1 -1
  37. package/src/components/bs5/button/button.scss +25 -45
  38. package/src/components/bs5/button/manifest.json +1 -0
  39. package/src/components/bs5/callToAction/callToAction.mdx +1 -1
  40. package/src/components/bs5/callToAction/callToAction.stories.js +15 -50
  41. package/src/components/bs5/callout/Callout.mdx +1 -1
  42. package/src/components/bs5/callout/callout.stories.js +14 -39
  43. package/src/components/bs5/callout/manifest.json +1 -0
  44. package/src/components/bs5/card/Card.mdx +1 -1
  45. package/src/components/bs5/card/card.scss +5 -5
  46. package/src/components/bs5/card/manifest.json +1 -0
  47. package/src/components/bs5/contentFooter/manifest.json +1 -0
  48. package/src/components/bs5/contentFooterWrapper/manifest.json +1 -0
  49. package/src/components/bs5/contentWrapper/manifest.json +1 -0
  50. package/src/components/bs5/correctincorrect/correctincorrect.data.json +1 -0
  51. package/src/components/bs5/correctincorrect/manifest.json +1 -0
  52. package/src/components/bs5/dateinput/Dateinput.stories.js +23 -31
  53. package/src/components/bs5/dateinput/manifest.json +1 -0
  54. package/src/components/bs5/directionLinks/DirectionLinks.mdx +1 -1
  55. package/src/components/bs5/directionLinks/directionLinks.stories.js +14 -12
  56. package/src/components/bs5/footer/Footer.mdx +1 -1
  57. package/src/components/bs5/footer/footer.scss +3 -7
  58. package/src/components/bs5/formcheck/manifest.json +1 -0
  59. package/src/components/bs5/formcheck/stories/checkbox/Checkbox.mdx +1 -1
  60. package/src/components/bs5/formcheck/stories/checkbox/checkbox.stories.js +44 -87
  61. package/src/components/bs5/formcheck/stories/radio/Radio.mdx +1 -1
  62. package/src/components/bs5/formcheck/stories/radio/radio.stories.js +9 -36
  63. package/src/components/bs5/fullPageWrapper/manifest.json +1 -0
  64. package/src/components/bs5/globalAlert/GlobalAlert.mdx +1 -1
  65. package/src/components/bs5/globalAlert/globalAlert.test.js +3 -3
  66. package/src/components/bs5/globalAlert/manifest.json +1 -0
  67. package/src/components/bs5/head/manifest.json +1 -0
  68. package/src/components/bs5/header/Header.mdx +1 -1
  69. package/src/components/bs5/header/header.stories.js +1 -30
  70. package/src/components/bs5/header/manifest.json +1 -0
  71. package/src/components/bs5/icons/Icons.mdx +1 -1
  72. package/src/components/bs5/icons/manifest.json +1 -0
  73. package/src/components/bs5/icons/mdx/_IconsSizes.mdx +1 -1
  74. package/src/components/bs5/image/Image.mdx +1 -1
  75. package/src/components/bs5/inpageAlert/InpageAlert.mdx +1 -1
  76. package/src/components/bs5/inpageAlert/inpageAlert.stories.js +7 -23
  77. package/src/components/bs5/inpageAlert/manifest.json +1 -0
  78. package/src/components/bs5/inpagenav/Inpagenav.mdx +1 -1
  79. package/src/components/bs5/inpagenav/inpagenav.stories.js +4 -6
  80. package/src/components/bs5/inpagenav/manifest.json +1 -0
  81. package/src/components/bs5/link/link.mdx +1 -1
  82. package/src/components/bs5/link/link.stories.js +4 -6
  83. package/src/components/bs5/linkColumns/linkColumns.mdx +1 -1
  84. package/src/components/bs5/logo/Logo.mdx +1 -1
  85. package/src/components/bs5/mainContainerWrapper/manifest.json +1 -0
  86. package/src/components/bs5/metaDcTerms/manifest.json +1 -0
  87. package/src/components/bs5/metaOpenGraph/manifest.json +1 -0
  88. package/src/components/bs5/modal/Modal.mdx +1 -1
  89. package/src/components/bs5/modal/manifest.json +1 -0
  90. package/src/components/bs5/pagination/Pagination.mdx +1 -1
  91. package/src/components/bs5/pagination/manifest.json +1 -0
  92. package/src/components/bs5/pagination/pagination.scss +290 -274
  93. package/src/components/bs5/pagination/pagination.stories.js +22 -46
  94. package/src/components/bs5/promotionalPanel/PromotionalPanel.mdx +1 -1
  95. package/src/components/bs5/quickexit/manifest.json +1 -0
  96. package/src/components/bs5/searchInput/SearchInput.mdx +1 -1
  97. package/src/components/bs5/searchInput/manifest.json +1 -0
  98. package/src/components/bs5/searchInput/searchInput.stories.js +10 -12
  99. package/src/components/bs5/select/manifest.json +1 -0
  100. package/src/components/bs5/sidenav/Sidenav.mdx +1 -1
  101. package/src/components/bs5/sidenav/manifest.json +1 -0
  102. package/src/components/bs5/sidenav/sidenav.stories.js +4 -7
  103. package/src/components/bs5/sidenavWrapper/manifest.json +1 -0
  104. package/src/components/bs5/skiplinks/SkipLinks.mdx +1 -1
  105. package/src/components/bs5/spinner/manifest.json +1 -0
  106. package/src/components/bs5/table/Table.mdx +1 -1
  107. package/src/components/bs5/table/manifest.json +1 -0
  108. package/src/components/bs5/tabs/Tabs.mdx +1 -1
  109. package/src/components/bs5/tabs/tabs.data.json +1 -2
  110. package/src/components/bs5/tabs/tabs.stories.js +38 -215
  111. package/src/components/bs5/tag/Tag.mdx +1 -1
  112. package/src/components/bs5/tag/manifest.json +1 -0
  113. package/src/components/bs5/textarea/manifest.json +1 -0
  114. package/src/components/bs5/textbox/manifest.json +1 -0
  115. package/src/components/bs5/textbox/textInput.scss +55 -39
  116. package/src/components/bs5/typography/Typography.mdx +1 -1
  117. package/src/components/bs5/typography/manifest.json +1 -0
  118. package/src/components/bs5/typography/typography.data.json +1 -0
  119. package/src/components/bs5/typography/typography.stories.js +6 -24
  120. package/src/components/bs5/video/Video.mdx +1 -1
  121. package/src/components/bs5/video/manifest.json +1 -0
  122. package/src/components/bs5/video/video.scss +41 -27
  123. package/src/components/bs5/video/video.stories.js +6 -24
  124. package/src/css/main.legacy.scss +19 -0
  125. package/src/css/main.scss +17 -0
  126. package/src/css/qld-print.scss +426 -304
  127. package/src/css/qld-tokens-legacy.scss +94 -0
  128. package/src/css/qld-tokens.scss +92 -77
  129. package/src/css/qld-variables.scss +37 -30
  130. package/src/stories/Introduction.mdx +1 -1
  131. package/vite.config.js +17 -0
  132. package/.eslintrc.cjs +0 -52
  133. package/dist/assets/js/bootstrap.js +0 -6312
  134. package/dist/assets/js/handlebars.helpers.js +0 -292
  135. package/dist/assets/js/handlebars.init.cjs +0 -6
  136. package/dist/assets/js/handlebars.init.js +0 -34
  137. package/dist/components/handlebars.helpers.js +0 -292
  138. package/dist/components/handlebars.init.cjs +0 -6
  139. package/dist/components/handlebars.init.js +0 -34
  140. package/dist/components/handlebars.partials.js +0 -136
  141. package/src/css/main.masterbrand.scss +0 -137
  142. package/src/css/themes/masterbrand.scss +0 -109
@@ -1,292 +0,0 @@
1
- /* global Handlebars */
2
-
3
- /**
4
- *
5
- * @param {*} v1 The left value
6
- * @param { "==" | "===" | "!=" | "!==" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "contains"} operator the operator to handle comparison
7
- * @param {*} v2 The right value
8
- * @param {Object} options handlebars-provided options object
9
- * @returns {string} handlebars template block string
10
- * @example
11
- * {{#ifCond value1 "===" value2}}
12
- * <!-- Content to render if condition is true -->
13
- * <p>Value1 is strictly equal to Value2</p>
14
- * {{else}}
15
- * <!-- Content to render if condition is false -->
16
- * <p>Value1 is not strictly equal to Value2</p>
17
- * {{/ifCond}}
18
- */
19
- function ifCond(v1, operator, v2, options) {
20
- switch (operator) {
21
- case "==":
22
- return v1 == v2 ? options.fn(this) : options.inverse(this);
23
- case "===":
24
- return v1 === v2 ? options.fn(this) : options.inverse(this);
25
- case "!=":
26
- return v1 != v2 ? options.fn(this) : options.inverse(this);
27
- case "!==":
28
- return v1 !== v2 ? options.fn(this) : options.inverse(this);
29
- case "<":
30
- return v1 < v2 ? options.fn(this) : options.inverse(this);
31
- case "<=":
32
- return v1 <= v2 ? options.fn(this) : options.inverse(this);
33
- case ">":
34
- return v1 > v2 ? options.fn(this) : options.inverse(this);
35
- case ">=":
36
- return v1 >= v2 ? options.fn(this) : options.inverse(this);
37
- case "&&":
38
- return v1 && v2 ? options.fn(this) : options.inverse(this);
39
- case "||":
40
- return v1 || v2 ? options.fn(this) : options.inverse(this);
41
- case "contains":
42
- if (typeof v1 == "string" && typeof v2 == "string") {
43
- return v1.toLowerCase().indexOf(v2.toLowerCase()) >= 0
44
- ? options.fn(this)
45
- : options.inverse(this);
46
- } else return options.inverse(this);
47
- default:
48
- return options.inverse(this);
49
- }
50
- }
51
- /**
52
- * Registers Handlebars Helpers
53
- * @param {Handlebars} handlebars Templating engine
54
- * @returns {void} Result of the helper operation
55
- */
56
-
57
- export default function handlebarsHelpers(handlebars) {
58
- // contains - if first object is in collection (second object) to return true
59
- handlebars.registerHelper("contains", function (needle, haystack, options) {
60
- needle = handlebars.escapeExpression(needle);
61
- haystack = handlebars.escapeExpression(haystack);
62
- return haystack.indexOf(needle) > -1
63
- ? options.fn(this)
64
- : options.inverse(this);
65
- });
66
-
67
- handlebars.registerHelper("ifCond", ifCond);
68
-
69
- // isType - Checks is expected type
70
- handlebars.registerHelper("isType", function (value, expected, options) {
71
- if (value === expected) {
72
- return options.fn(this); // Render the block if condition is true
73
- } else {
74
- return options.inverse(this); // Render the else block if present
75
- }
76
- });
77
- // ifAny - {{{#ifAny variable1 variable2 variable3 variable4 etc}}, if any set then return true
78
- handlebars.registerHelper("ifAny", function (...args) {
79
- const options = args.pop(); // The last argument is the options object
80
- return args.some((arg) => !!arg) ? options.fn(this) : options.inverse(this);
81
- });
82
- // now - return current timestamp i.e {{now}}
83
- handlebars.registerHelper("now", function () {
84
- return new Date().toISOString();
85
- });
86
- // formatDate - Format Date, for footer meta data i.e {{formatDate '2023-06-23'}}
87
- handlebars.registerHelper(
88
- "formatDate",
89
- function (dateString, defaultDate, format) {
90
- // Use the dateString if provided, otherwise use the defaultDate, otherwise error
91
- let date;
92
- if (dateString) {
93
- date = new Date(dateString);
94
- }
95
- if (isNaN(date) && defaultDate) {
96
- date = new Date(defaultDate);
97
- }
98
-
99
- // Check if the date is valid
100
- if (isNaN(date)) {
101
- return "Invalid Date";
102
- }
103
-
104
- var monthNames = [
105
- "January",
106
- "February",
107
- "March",
108
- "April",
109
- "May",
110
- "June",
111
- "July",
112
- "August",
113
- "September",
114
- "October",
115
- "November",
116
- "December",
117
- ];
118
- var day = date.getDate();
119
- var month = monthNames[date.getMonth()];
120
- var year = date.getFullYear();
121
- // Format date based on the format string
122
- switch (format) {
123
- case "YYYY":
124
- return `${year}`;
125
- case "MMMM YYYY":
126
- return `${month} ${year}`;
127
- default:
128
- return `${day} ${month} ${year}`;
129
- }
130
- },
131
- );
132
-
133
- // formatDateOrToday - Format Date if passed or today i.e. {{formatDateOrToday '2023-06-23'}} or {{formatDateOrToday}} <!-- This will use the current date -->
134
- handlebars.registerHelper("formatDateOrToday", function (dateString, format) {
135
- // Use the current date if dateString is missing or invalid
136
- const dateToFormat = dateString || new Date().toISOString();
137
- // Call the formatDate helper with the determined date and format
138
- return handlebars.helpers.formatDate(dateString, dateToFormat, format);
139
- });
140
-
141
- /**
142
- * Format time duration into a string.
143
- *
144
- * Supports two formats: "short" and "long".
145
- * - Short format: Display the duration in simplified format of "HH:MM:SS". It is the default format.
146
- * - Long format: Display the duration in descriptive format of "X hours Y minutes Z seconds".
147
- *
148
- * @param {Object | String} duration - Duration object with properties: 'hours', 'minutes', and 'seconds'. Duration string: "HH:MM:SS".
149
- * @param {String} format - Option for format type 'short' or 'long'. If none provided, 'short' is the defaut value.
150
- *
151
- * @returns {String} Formatted duration
152
- * Examples:
153
- * - 03:00:00 - 3 hours
154
- * - 03:15:00 - 3 hours 15 minutes
155
- * - 01:30:45 - 1 hour 30 minutes 45 seconds
156
- * - 02:00:45 - 2 hours 45 seconds
157
- * - 07:12 - 7 minutes 12 seconds
158
- * - 00:45 - 45 seconds
159
- *
160
- * Usage:
161
- * {{formatDuration duration}}
162
- * {{formatDuration duration "long"}}
163
- */
164
- handlebars.registerHelper("formatDuration", function (duration, format) {
165
- // Return empty string when there is no duration.
166
- if (!duration) {
167
- return "";
168
- }
169
-
170
- // Nothing to process here when the duration is already in short format string
171
- // (to support existing CMS metadata).
172
- if (typeof duration === "string" && format !== "long") {
173
- return duration;
174
- }
175
-
176
- let durationString = "";
177
- let parts = [];
178
- let hours, minutes, seconds;
179
-
180
- // Support for string type 'duration'.
181
- if (typeof duration === "string") {
182
- const durationSplit = duration.split(":");
183
- seconds = durationSplit[0];
184
- if (durationSplit.length == 2) {
185
- [minutes = "", seconds = ""] = durationSplit;
186
- } else if (durationSplit.length == 3) {
187
- [hours = "", minutes = "", seconds = ""] = durationSplit;
188
- }
189
- } else {
190
- // Support for object type 'duration'.
191
- [hours = "", minutes = "", seconds = ""] = duration;
192
- }
193
-
194
- // Long format: "X hours Y minutes Z seconds"
195
- if (format === "long") {
196
- if (hours > 0) {
197
- parts.push(`${hours} hour${hours > 1 ? "s" : ""}`);
198
- }
199
- if (minutes > 0) {
200
- parts.push(`${minutes} minute${minutes > 1 ? "s" : ""}`);
201
- }
202
- if (seconds > 0) {
203
- parts.push(`${seconds} second${seconds > 1 ? "s" : ""}`);
204
- }
205
- durationString = parts.join(" ");
206
-
207
- // Short format: "HH:MM:SS"
208
- } else {
209
- // Omitting hours when zero
210
- if (hours > 0) {
211
- parts.push(hours.toString().padStart(2, 0));
212
- }
213
- parts.push(minutes.toString().padStart(2, 0));
214
- parts.push(seconds.toString().padStart(2, 0));
215
- durationString = parts.join(":");
216
- }
217
- return durationString;
218
- });
219
-
220
- /**
221
- * Helper for extending components to set overridable data values
222
- * If the value is not set in the component data.json, it will use the hds data value
223
- *
224
- * @param {string} value - The value to check if it is defined
225
- * @param {string} defaultValue - The default value to return if value is not defined
226
- * @returns {string} - The value if it is defined, otherwise the default value
227
- */
228
- handlebars.registerHelper("isdefined", function (value, defaultValue) {
229
- return value !== undefined && value !== "" ? value : defaultValue;
230
- });
231
-
232
- /**
233
- * Used to get class names added to an element based on their boolean values in an array
234
- *
235
- * @param {string} names - Comma-separated list of class names to check for
236
- * @param {array} array - Array of objects to check for true values
237
- * @returns {string} - Space-separated list of class names that have true values
238
- */
239
- handlebars.registerHelper("getClassNames", function (names, array) {
240
- // Split the comma-separated string of names into an array
241
- let nameList = names.split(",").map((name) => name.trim());
242
-
243
- // Create an array to hold the names that have true values
244
- let matchedItems = [];
245
-
246
- for (let i = 0; i < nameList.length; i++) {
247
- let name = nameList[i];
248
- // Check if any item in the array matches the name and is true
249
- if (array) {
250
- for (let j = 0; j < array.length; j++) {
251
- if (array[j][name] === true) {
252
- matchedItems.push(name); // Add to matchedItems if found and true
253
- break;
254
- }
255
- }
256
- }
257
- }
258
-
259
- // If we found any matched items, return them as a space-separated string
260
- if (matchedItems.length > 0) {
261
- return matchedItems.join(" ");
262
- } else {
263
- return "";
264
- }
265
- });
266
-
267
- handlebars.registerHelper("join", function (theArray, separator) {
268
- // Handle if a separator is not provided
269
- if (!separator || typeof separator !== "string") {
270
- separator = " ";
271
- }
272
-
273
- // If theArray is not an array, return it as is, otherwise join it
274
- return !Array.isArray(theArray) ? theArray : theArray.join(separator);
275
- });
276
-
277
- handlebars.registerHelper("toCamelCase", function (text) {
278
- if (typeof text !== "string") return text;
279
-
280
- // Remove whitespace and convert to camelCase
281
- return text
282
- .toLowerCase()
283
- .replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match, index) =>
284
- index === 0 ? match.toLowerCase() : match.toUpperCase(),
285
- )
286
- .replace(/\s+/g, ""); // Remove all spaces
287
- });
288
- }
289
-
290
- if (typeof Handlebars !== "undefined") {
291
- handlebarsHelpers(Handlebars);
292
- }
@@ -1,6 +0,0 @@
1
-
2
- import init from "./handlebars.init.js";
3
-
4
- module.exports = {
5
- init,
6
- };
@@ -1,34 +0,0 @@
1
- /* global Handlebars */
2
- import handlebarsHelpers from "./handlebars.helpers.js";
3
- import handlebarsPartials from "./handlebars.partials.js";
4
-
5
-
6
- let isHandlebarsHelpersAndPartialsRegistered = false;
7
-
8
- /*
9
- * init function to load all HandleBar partials and helpers into passed in handlebars
10
- * by default the helpers and partials will autoload if handleBars is found in environment
11
- *
12
- * @param {Handlebars} handlebars
13
- */
14
- export default function init(handlebars) {
15
- if (typeof(handlebars) === 'undefined') {
16
- console.error("Handlebars.init requires HandleBars");
17
- }
18
-
19
- if(typeof(handlebars) !== 'undefined') {
20
- if (!isHandlebarsHelpersAndPartialsRegistered) {
21
- isHandlebarsHelpersAndPartialsRegistered = true;
22
- } else {
23
- console.log("HandleBars Helpers And Partials already loaded, loading again")
24
- }
25
- handlebarsHelpers(handlebars);
26
-
27
- handlebarsPartials(handlebars);
28
- } else {
29
- console.log("Handlebars not found, init failed");
30
- }
31
- }
32
- if(typeof(Handlebars) !== 'undefined') {
33
- init(Handlebars);
34
- }
@@ -1,292 +0,0 @@
1
- /* global Handlebars */
2
-
3
- /**
4
- *
5
- * @param {*} v1 The left value
6
- * @param { "==" | "===" | "!=" | "!==" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "contains"} operator the operator to handle comparison
7
- * @param {*} v2 The right value
8
- * @param {Object} options handlebars-provided options object
9
- * @returns {string} handlebars template block string
10
- * @example
11
- * {{#ifCond value1 "===" value2}}
12
- * <!-- Content to render if condition is true -->
13
- * <p>Value1 is strictly equal to Value2</p>
14
- * {{else}}
15
- * <!-- Content to render if condition is false -->
16
- * <p>Value1 is not strictly equal to Value2</p>
17
- * {{/ifCond}}
18
- */
19
- function ifCond(v1, operator, v2, options) {
20
- switch (operator) {
21
- case "==":
22
- return v1 == v2 ? options.fn(this) : options.inverse(this);
23
- case "===":
24
- return v1 === v2 ? options.fn(this) : options.inverse(this);
25
- case "!=":
26
- return v1 != v2 ? options.fn(this) : options.inverse(this);
27
- case "!==":
28
- return v1 !== v2 ? options.fn(this) : options.inverse(this);
29
- case "<":
30
- return v1 < v2 ? options.fn(this) : options.inverse(this);
31
- case "<=":
32
- return v1 <= v2 ? options.fn(this) : options.inverse(this);
33
- case ">":
34
- return v1 > v2 ? options.fn(this) : options.inverse(this);
35
- case ">=":
36
- return v1 >= v2 ? options.fn(this) : options.inverse(this);
37
- case "&&":
38
- return v1 && v2 ? options.fn(this) : options.inverse(this);
39
- case "||":
40
- return v1 || v2 ? options.fn(this) : options.inverse(this);
41
- case "contains":
42
- if (typeof v1 == "string" && typeof v2 == "string") {
43
- return v1.toLowerCase().indexOf(v2.toLowerCase()) >= 0
44
- ? options.fn(this)
45
- : options.inverse(this);
46
- } else return options.inverse(this);
47
- default:
48
- return options.inverse(this);
49
- }
50
- }
51
- /**
52
- * Registers Handlebars Helpers
53
- * @param {Handlebars} handlebars Templating engine
54
- * @returns {void} Result of the helper operation
55
- */
56
-
57
- export default function handlebarsHelpers(handlebars) {
58
- // contains - if first object is in collection (second object) to return true
59
- handlebars.registerHelper("contains", function (needle, haystack, options) {
60
- needle = handlebars.escapeExpression(needle);
61
- haystack = handlebars.escapeExpression(haystack);
62
- return haystack.indexOf(needle) > -1
63
- ? options.fn(this)
64
- : options.inverse(this);
65
- });
66
-
67
- handlebars.registerHelper("ifCond", ifCond);
68
-
69
- // isType - Checks is expected type
70
- handlebars.registerHelper("isType", function (value, expected, options) {
71
- if (value === expected) {
72
- return options.fn(this); // Render the block if condition is true
73
- } else {
74
- return options.inverse(this); // Render the else block if present
75
- }
76
- });
77
- // ifAny - {{{#ifAny variable1 variable2 variable3 variable4 etc}}, if any set then return true
78
- handlebars.registerHelper("ifAny", function (...args) {
79
- const options = args.pop(); // The last argument is the options object
80
- return args.some((arg) => !!arg) ? options.fn(this) : options.inverse(this);
81
- });
82
- // now - return current timestamp i.e {{now}}
83
- handlebars.registerHelper("now", function () {
84
- return new Date().toISOString();
85
- });
86
- // formatDate - Format Date, for footer meta data i.e {{formatDate '2023-06-23'}}
87
- handlebars.registerHelper(
88
- "formatDate",
89
- function (dateString, defaultDate, format) {
90
- // Use the dateString if provided, otherwise use the defaultDate, otherwise error
91
- let date;
92
- if (dateString) {
93
- date = new Date(dateString);
94
- }
95
- if (isNaN(date) && defaultDate) {
96
- date = new Date(defaultDate);
97
- }
98
-
99
- // Check if the date is valid
100
- if (isNaN(date)) {
101
- return "Invalid Date";
102
- }
103
-
104
- var monthNames = [
105
- "January",
106
- "February",
107
- "March",
108
- "April",
109
- "May",
110
- "June",
111
- "July",
112
- "August",
113
- "September",
114
- "October",
115
- "November",
116
- "December",
117
- ];
118
- var day = date.getDate();
119
- var month = monthNames[date.getMonth()];
120
- var year = date.getFullYear();
121
- // Format date based on the format string
122
- switch (format) {
123
- case "YYYY":
124
- return `${year}`;
125
- case "MMMM YYYY":
126
- return `${month} ${year}`;
127
- default:
128
- return `${day} ${month} ${year}`;
129
- }
130
- },
131
- );
132
-
133
- // formatDateOrToday - Format Date if passed or today i.e. {{formatDateOrToday '2023-06-23'}} or {{formatDateOrToday}} <!-- This will use the current date -->
134
- handlebars.registerHelper("formatDateOrToday", function (dateString, format) {
135
- // Use the current date if dateString is missing or invalid
136
- const dateToFormat = dateString || new Date().toISOString();
137
- // Call the formatDate helper with the determined date and format
138
- return handlebars.helpers.formatDate(dateString, dateToFormat, format);
139
- });
140
-
141
- /**
142
- * Format time duration into a string.
143
- *
144
- * Supports two formats: "short" and "long".
145
- * - Short format: Display the duration in simplified format of "HH:MM:SS". It is the default format.
146
- * - Long format: Display the duration in descriptive format of "X hours Y minutes Z seconds".
147
- *
148
- * @param {Object | String} duration - Duration object with properties: 'hours', 'minutes', and 'seconds'. Duration string: "HH:MM:SS".
149
- * @param {String} format - Option for format type 'short' or 'long'. If none provided, 'short' is the defaut value.
150
- *
151
- * @returns {String} Formatted duration
152
- * Examples:
153
- * - 03:00:00 - 3 hours
154
- * - 03:15:00 - 3 hours 15 minutes
155
- * - 01:30:45 - 1 hour 30 minutes 45 seconds
156
- * - 02:00:45 - 2 hours 45 seconds
157
- * - 07:12 - 7 minutes 12 seconds
158
- * - 00:45 - 45 seconds
159
- *
160
- * Usage:
161
- * {{formatDuration duration}}
162
- * {{formatDuration duration "long"}}
163
- */
164
- handlebars.registerHelper("formatDuration", function (duration, format) {
165
- // Return empty string when there is no duration.
166
- if (!duration) {
167
- return "";
168
- }
169
-
170
- // Nothing to process here when the duration is already in short format string
171
- // (to support existing CMS metadata).
172
- if (typeof duration === "string" && format !== "long") {
173
- return duration;
174
- }
175
-
176
- let durationString = "";
177
- let parts = [];
178
- let hours, minutes, seconds;
179
-
180
- // Support for string type 'duration'.
181
- if (typeof duration === "string") {
182
- const durationSplit = duration.split(":");
183
- seconds = durationSplit[0];
184
- if (durationSplit.length == 2) {
185
- [minutes = "", seconds = ""] = durationSplit;
186
- } else if (durationSplit.length == 3) {
187
- [hours = "", minutes = "", seconds = ""] = durationSplit;
188
- }
189
- } else {
190
- // Support for object type 'duration'.
191
- [hours = "", minutes = "", seconds = ""] = duration;
192
- }
193
-
194
- // Long format: "X hours Y minutes Z seconds"
195
- if (format === "long") {
196
- if (hours > 0) {
197
- parts.push(`${hours} hour${hours > 1 ? "s" : ""}`);
198
- }
199
- if (minutes > 0) {
200
- parts.push(`${minutes} minute${minutes > 1 ? "s" : ""}`);
201
- }
202
- if (seconds > 0) {
203
- parts.push(`${seconds} second${seconds > 1 ? "s" : ""}`);
204
- }
205
- durationString = parts.join(" ");
206
-
207
- // Short format: "HH:MM:SS"
208
- } else {
209
- // Omitting hours when zero
210
- if (hours > 0) {
211
- parts.push(hours.toString().padStart(2, 0));
212
- }
213
- parts.push(minutes.toString().padStart(2, 0));
214
- parts.push(seconds.toString().padStart(2, 0));
215
- durationString = parts.join(":");
216
- }
217
- return durationString;
218
- });
219
-
220
- /**
221
- * Helper for extending components to set overridable data values
222
- * If the value is not set in the component data.json, it will use the hds data value
223
- *
224
- * @param {string} value - The value to check if it is defined
225
- * @param {string} defaultValue - The default value to return if value is not defined
226
- * @returns {string} - The value if it is defined, otherwise the default value
227
- */
228
- handlebars.registerHelper("isdefined", function (value, defaultValue) {
229
- return value !== undefined && value !== "" ? value : defaultValue;
230
- });
231
-
232
- /**
233
- * Used to get class names added to an element based on their boolean values in an array
234
- *
235
- * @param {string} names - Comma-separated list of class names to check for
236
- * @param {array} array - Array of objects to check for true values
237
- * @returns {string} - Space-separated list of class names that have true values
238
- */
239
- handlebars.registerHelper("getClassNames", function (names, array) {
240
- // Split the comma-separated string of names into an array
241
- let nameList = names.split(",").map((name) => name.trim());
242
-
243
- // Create an array to hold the names that have true values
244
- let matchedItems = [];
245
-
246
- for (let i = 0; i < nameList.length; i++) {
247
- let name = nameList[i];
248
- // Check if any item in the array matches the name and is true
249
- if (array) {
250
- for (let j = 0; j < array.length; j++) {
251
- if (array[j][name] === true) {
252
- matchedItems.push(name); // Add to matchedItems if found and true
253
- break;
254
- }
255
- }
256
- }
257
- }
258
-
259
- // If we found any matched items, return them as a space-separated string
260
- if (matchedItems.length > 0) {
261
- return matchedItems.join(" ");
262
- } else {
263
- return "";
264
- }
265
- });
266
-
267
- handlebars.registerHelper("join", function (theArray, separator) {
268
- // Handle if a separator is not provided
269
- if (!separator || typeof separator !== "string") {
270
- separator = " ";
271
- }
272
-
273
- // If theArray is not an array, return it as is, otherwise join it
274
- return !Array.isArray(theArray) ? theArray : theArray.join(separator);
275
- });
276
-
277
- handlebars.registerHelper("toCamelCase", function (text) {
278
- if (typeof text !== "string") return text;
279
-
280
- // Remove whitespace and convert to camelCase
281
- return text
282
- .toLowerCase()
283
- .replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, (match, index) =>
284
- index === 0 ? match.toLowerCase() : match.toUpperCase(),
285
- )
286
- .replace(/\s+/g, ""); // Remove all spaces
287
- });
288
- }
289
-
290
- if (typeof Handlebars !== "undefined") {
291
- handlebarsHelpers(Handlebars);
292
- }
@@ -1,6 +0,0 @@
1
-
2
- import init from "./handlebars.init.js";
3
-
4
- module.exports = {
5
- init,
6
- };
@@ -1,34 +0,0 @@
1
- /* global Handlebars */
2
- import handlebarsHelpers from "./handlebars.helpers.js";
3
- import handlebarsPartials from "./handlebars.partials.js";
4
-
5
-
6
- let isHandlebarsHelpersAndPartialsRegistered = false;
7
-
8
- /*
9
- * init function to load all HandleBar partials and helpers into passed in handlebars
10
- * by default the helpers and partials will autoload if handleBars is found in environment
11
- *
12
- * @param {Handlebars} handlebars
13
- */
14
- export default function init(handlebars) {
15
- if (typeof(handlebars) === 'undefined') {
16
- console.error("Handlebars.init requires HandleBars");
17
- }
18
-
19
- if(typeof(handlebars) !== 'undefined') {
20
- if (!isHandlebarsHelpersAndPartialsRegistered) {
21
- isHandlebarsHelpersAndPartialsRegistered = true;
22
- } else {
23
- console.log("HandleBars Helpers And Partials already loaded, loading again")
24
- }
25
- handlebarsHelpers(handlebars);
26
-
27
- handlebarsPartials(handlebars);
28
- } else {
29
- console.log("Handlebars not found, init failed");
30
- }
31
- }
32
- if(typeof(Handlebars) !== 'undefined') {
33
- init(Handlebars);
34
- }