@ongov/ontario-design-system-component-library 4.3.0-alpha.3 → 4.3.1-alpha.1
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/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/ontario-accordion_43.cjs.entry.js +404 -223
- package/dist/cjs/ontario-accordion_43.cjs.entry.js.map +1 -1
- package/dist/cjs/ontario-design-system-components.cjs.js +1 -1
- package/dist/collection/components/ontario-card/ontario-card.css +13 -5
- package/dist/collection/components/ontario-card/ontario-card.js +10 -10
- package/dist/collection/components/ontario-card/ontario-card.js.map +1 -1
- package/dist/collection/components/ontario-card/test/ontario-cards.spec.js +1 -1
- package/dist/collection/components/ontario-card/test/ontario-cards.spec.js.map +1 -1
- package/dist/collection/components/ontario-header/ontario-header.js +17 -3
- package/dist/collection/components/ontario-header/ontario-header.js.map +1 -1
- package/dist/collection/components/ontario-header/test/ontario-header.spec.js +3 -3
- package/dist/collection/components/ontario-header/test/ontario-header.spec.js.map +1 -1
- package/dist/collection/components/ontario-language-toggle/ontario-language-toggle.js +193 -47
- package/dist/collection/components/ontario-language-toggle/ontario-language-toggle.js.map +1 -1
- package/dist/collection/components/ontario-language-toggle/test/ontario-language-toggle.spec.js +16 -3
- package/dist/collection/components/ontario-language-toggle/test/ontario-language-toggle.spec.js.map +1 -1
- package/dist/collection/i18n/global.i18n.json +172 -162
- package/dist/collection/utils/common/language-types.js +1 -1
- package/dist/collection/utils/common/language-types.js.map +1 -1
- package/dist/collection/utils/helper/utils-types.js +2 -0
- package/dist/collection/utils/helper/utils-types.js.map +1 -0
- package/dist/collection/utils/helper/utils.js +26 -0
- package/dist/collection/utils/helper/utils.js.map +1 -1
- package/dist/components/global.i18n.js +184 -173
- package/dist/components/global.i18n.js.map +1 -1
- package/dist/components/ontario-card.js +11 -11
- package/dist/components/ontario-card.js.map +1 -1
- package/dist/components/ontario-header.js +11 -3
- package/dist/components/ontario-header.js.map +1 -1
- package/dist/components/ontario-language-toggle2.js +180 -37
- package/dist/components/ontario-language-toggle2.js.map +1 -1
- package/dist/components/utils.js +28 -0
- package/dist/components/utils.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/ontario-accordion_43.entry.js +404 -223
- package/dist/esm/ontario-accordion_43.entry.js.map +1 -1
- package/dist/esm/ontario-design-system-components.js +1 -1
- package/dist/ontario-design-system-components/i18n/global.i18n.json +172 -162
- package/dist/ontario-design-system-components/ontario-design-system-components.esm.js +1 -1
- package/dist/ontario-design-system-components/ontario-design-system-components.esm.js.map +1 -1
- package/dist/ontario-design-system-components/{p-cff41424.entry.js → p-abe58ec9.entry.js} +697 -608
- package/dist/ontario-design-system-components/p-abe58ec9.entry.js.map +1 -0
- package/dist/types/components/ontario-header/ontario-header.d.ts +13 -2
- package/dist/types/components/ontario-language-toggle/ontario-language-toggle.d.ts +75 -8
- package/dist/types/components.d.ts +12 -6
- package/dist/types/utils/common/language-types.d.ts +2 -1
- package/dist/types/utils/helper/utils-types.d.ts +2 -0
- package/dist/types/utils/helper/utils.d.ts +21 -0
- package/package.json +3 -3
- package/src/components/ontario-card/ontario-card.scss +13 -6
- package/src/components/ontario-card/ontario-card.tsx +8 -6
- package/src/components/ontario-card/test/ontario-cards.spec.tsx +1 -1
- package/src/components/ontario-header/ontario-header.tsx +13 -4
- package/src/components/ontario-header/test/ontario-header.spec.tsx +3 -3
- package/src/components/ontario-language-toggle/ontario-language-toggle.tsx +192 -45
- package/src/components/ontario-language-toggle/readme.md +10 -10
- package/src/components/ontario-language-toggle/test/__snapshots__/ontario-language-toggle.spec.tsx.snap +1 -1
- package/src/components/ontario-language-toggle/test/ontario-language-toggle.spec.tsx +17 -3
- package/src/components.d.ts +12 -6
- package/src/french.html +37 -0
- package/src/index.html +19 -0
- package/src/translations/global.i18n.json +172 -162
- package/src/utils/common/language-types.ts +2 -1
- package/src/utils/helper/utils-types.ts +2 -0
- package/src/utils/helper/utils.ts +30 -0
- package/www/build/ontario-design-system-components.esm.js +1 -1
- package/www/build/ontario-design-system-components.esm.js.map +1 -1
- package/www/build/{p-cff41424.entry.js → p-abe58ec9.entry.js} +697 -608
- package/www/build/p-abe58ec9.entry.js.map +1 -0
- package/www/build/{p-b61db0f6.js → p-fdc9ab6d.js} +1 -1
- package/www/french.html +37 -0
- package/www/i18n/global.i18n.json +172 -162
- package/www/index.html +21 -2
- package/dist/ontario-design-system-components/p-cff41424.entry.js.map +0 -1
- package/www/build/p-cff41424.entry.js.map +0 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { proxyCustomElement, HTMLElement, createEvent, h, Fragment } from '@stencil/core/internal/client';
|
|
2
|
-
import { v as validateLanguage } from './validation-functions.js';
|
|
3
2
|
import { t as translations } from './global.i18n.js';
|
|
3
|
+
import { a as validateValueAgainstArray } from './validation-functions.js';
|
|
4
|
+
import { C as ConsoleMessageClass } from './console-message.js';
|
|
5
|
+
import { g as getRootHTMLElement, p as printArray } from './utils.js';
|
|
6
|
+
|
|
7
|
+
const supportedLanguages = ['en', 'fr'];
|
|
4
8
|
|
|
5
9
|
const ontarioLanguageToggleCss =
|
|
6
10
|
'.ontario-language-toggler:focus{box-shadow:0 0 0 4px #009ADB;outline:4px solid transparent;transition:box-shadow 0.1s ease-in-out}.ontario-hide{display:none !important}.ontario-invisible{visibility:hidden !important}@media screen and (max-width: 39.99875em){.ontario-hide-for-small-only{display:none !important}}@media screen and (max-width: 0em), screen and (min-width: 40em){.ontario-show-for-small-only{display:none !important}}@media print, screen and (min-width: 40em){.ontario-hide-for-medium{display:none !important}}@media screen and (max-width: 39.99875em){.ontario-show-for-medium{display:none !important}}@media screen and (min-width: 40em) and (max-width: 72.99875em){.ontario-hide-for-medium-only{display:none !important}}@media screen and (max-width: 39.99875em), screen and (min-width: 73em){.ontario-show-for-medium-only{display:none !important}}@media print, screen and (min-width: 73em){.ontario-hide-for-large{display:none !important}}@media screen and (max-width: 72.99875em){.ontario-show-for-large{display:none !important}}@media screen and (min-width: 73em) and (max-width: 95.99875em){.ontario-hide-for-large-only{display:none !important}}@media screen and (max-width: 72.99875em), screen and (min-width: 96em){.ontario-show-for-large-only{display:none !important}}.ontario-show-for-sr,.ontario-show-on-focus{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0, 0, 0, 0)}.ontario-show-on-focus:active,.ontario-show-on-focus:focus{position:static;width:auto;height:auto;overflow:visible;clip:auto}.ontario-show-for-landscape,.ontario-hide-for-portrait{display:block !important}@media screen and (orientation: landscape){.ontario-show-for-landscape,.ontario-hide-for-portrait{display:block !important}}@media screen and (orientation: portrait){.ontario-show-for-landscape,.ontario-hide-for-portrait{display:none !important}}.ontario-hide-for-landscape,.ontario-show-for-portrait{display:none !important}@media screen and (orientation: landscape){.ontario-hide-for-landscape,.ontario-show-for-portrait{display:none !important}}@media screen and (orientation: portrait){.ontario-hide-for-landscape,.ontario-show-for-portrait{display:block !important}}.ontario-language-toggler{background-color:#1a1a1a;border:none;border-radius:4px;box-sizing:border-box;box-shadow:none;color:#FFFFFF;cursor:pointer;display:flex;align-items:center;font-size:1.125rem;font-weight:600;font-family:"Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;height:48px;line-height:1.5555555556;text-align:center;text-decoration:none}.ontario-language-toggler:hover{background-color:#4d4d4d}.ontario-language-toggler:active{background-color:#666666;color:#FFFFFF}.ontario-language-toggler:focus{background-color:#4d4d4d;color:#FFFFFF}.ontario-language-toggler:visited{color:#FFFFFF}.ontario-language-toggler abbr[title]{text-decoration:none}.ontario-language-toggler--default{padding:0.75rem}.ontario-language-toggler--small{font-size:1rem;line-height:1.375rem;height:auto;outline:none;padding:0.5rem 0.75rem}';
|
|
@@ -14,74 +18,211 @@ const OntarioLanguageToggle = /*@__PURE__*/ proxyCustomElement(
|
|
|
14
18
|
this.__attachShadow();
|
|
15
19
|
this.setAppLanguage = createEvent(this, 'setAppLanguage', 7);
|
|
16
20
|
this.headerLanguageToggled = createEvent(this, 'headerLanguageToggled', 7);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
21
|
+
/*
|
|
22
|
+
* Updates the <html> lang attribute based on component languageState.
|
|
23
|
+
*/
|
|
24
|
+
this.updateHTMLLang = () => {
|
|
25
|
+
const htmlElement = getRootHTMLElement();
|
|
26
|
+
if (htmlElement) {
|
|
27
|
+
htmlElement.setAttribute('lang', this.languageState);
|
|
25
28
|
}
|
|
26
|
-
return;
|
|
27
29
|
};
|
|
28
30
|
this.language = undefined;
|
|
29
31
|
this.size = 'default';
|
|
30
32
|
this.url = undefined;
|
|
31
33
|
this.customLanguageToggle = undefined;
|
|
32
34
|
this.translations = translations;
|
|
35
|
+
this.languageState = undefined;
|
|
36
|
+
this.oppositeLanguageLabel = undefined;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Updates the language and languageState props when changes to the language prop are detected.
|
|
40
|
+
*/
|
|
41
|
+
updateLanguage() {
|
|
36
42
|
if (this.language) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
if (!validateValueAgainstArray(this.language, supportedLanguages)) {
|
|
44
|
+
this.showLanguageWarning(this.language);
|
|
45
|
+
this.language = this.translations.siteLanguage.abbreviation.en;
|
|
46
|
+
}
|
|
47
|
+
this.languageState = this.language;
|
|
48
|
+
}
|
|
49
|
+
this.setAppLanguageHandler();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* This function sets the languageState (if not already set).
|
|
53
|
+
*
|
|
54
|
+
* It also emits the setAppLanguage() event, updates the component language label, and
|
|
55
|
+
* updates the <html> tag lang attribute with the languageState value.
|
|
56
|
+
*
|
|
57
|
+
* It gets called by the connectedCallback() component lifecycle hook, and by the
|
|
58
|
+
* updateLanguage() method, which is fired on the watch for the language prop.
|
|
59
|
+
*/
|
|
60
|
+
setAppLanguageHandler() {
|
|
61
|
+
var _a;
|
|
62
|
+
const defaultLang = this.translations.siteLanguage.abbreviation.en;
|
|
63
|
+
const rootLang = (_a = getRootHTMLElement()) === null || _a === void 0 ? void 0 : _a.lang;
|
|
64
|
+
// If languageState is not set, set it equal to the following cadence:
|
|
65
|
+
// language prop value, <html> tag lang attribute, or default to "en"
|
|
66
|
+
if (!this.languageState) {
|
|
67
|
+
if (this.language) {
|
|
68
|
+
this.languageState = this.language;
|
|
69
|
+
} else if (rootLang) {
|
|
70
|
+
if (validateValueAgainstArray(rootLang, supportedLanguages)) {
|
|
71
|
+
this.languageState = rootLang;
|
|
72
|
+
} else {
|
|
73
|
+
this.showLanguageWarning(rootLang, 'document');
|
|
74
|
+
this.languageState = defaultLang;
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
this.languageState = defaultLang;
|
|
78
|
+
}
|
|
42
79
|
}
|
|
43
|
-
this.
|
|
44
|
-
this.
|
|
45
|
-
|
|
80
|
+
this.setAppLanguage.emit(this.languageState);
|
|
81
|
+
this.oppositeLanguageLabel = {
|
|
82
|
+
fullWord: this.getOppositeLanguageFullWord(),
|
|
83
|
+
abbreviation: this.getOppositeLanguageAbbrievation(),
|
|
84
|
+
};
|
|
85
|
+
this.updateHTMLLang();
|
|
46
86
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
87
|
+
/**
|
|
88
|
+
* An event that emits to other components that the language toggle button has been toggled.
|
|
89
|
+
*
|
|
90
|
+
* @param {Language} oldLanguage - The language prior to the language toggle being pressed.
|
|
91
|
+
* @param {globalThis.Event} event - event that triggered the function (e.g. onclick).
|
|
92
|
+
*/
|
|
93
|
+
handleHeaderLanguageToggled(oldLanguage, event) {
|
|
94
|
+
this.languageState =
|
|
95
|
+
oldLanguage === this.translations.siteLanguage.abbreviation.en
|
|
96
|
+
? this.translations.siteLanguage.abbreviation.fr
|
|
97
|
+
: this.translations.siteLanguage.abbreviation.en;
|
|
98
|
+
this.headerLanguageToggled.emit({ oldLanguage: oldLanguage, newLanguage: this.languageState });
|
|
99
|
+
this.updateHTMLLang();
|
|
52
100
|
if (this.customLanguageToggle && event) {
|
|
53
101
|
this.customLanguageToggle(event);
|
|
54
102
|
}
|
|
55
103
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Prints a warning message to the console about using an incorrect language for the component.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} lang - The incorrect language that was received.
|
|
108
|
+
* @param {string} type - prop/document | Where the incorrect language is coming from.
|
|
109
|
+
*/
|
|
110
|
+
showLanguageWarning(lang, type = 'prop') {
|
|
111
|
+
const propOrDocumentMessage =
|
|
112
|
+
type === 'prop' ? `The language prop value of ${lang} ` : `The HTML document lang attribute value of ${lang} `;
|
|
113
|
+
const message = new ConsoleMessageClass();
|
|
114
|
+
message
|
|
115
|
+
.addDesignSystemTag()
|
|
116
|
+
.addRegularText(propOrDocumentMessage)
|
|
117
|
+
.addRegularText('is not a valid language value for the ')
|
|
118
|
+
.addMonospaceText(' <ontario-language-toggle> ')
|
|
119
|
+
.addRegularText(`component. Valid language values are ${printArray([...supportedLanguages])}. `)
|
|
120
|
+
.addRegularText(
|
|
121
|
+
`A default language value of ${this.translations.siteLanguage.abbreviation.en} will be applied.`,
|
|
122
|
+
)
|
|
123
|
+
.printMessage();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Returns abbreviated text for the opposite language.
|
|
127
|
+
*
|
|
128
|
+
* @returns {Language}
|
|
129
|
+
*/
|
|
130
|
+
getOppositeLanguageAbbrievation() {
|
|
131
|
+
return this.languageState === this.translations.siteLanguage.abbreviation.en
|
|
132
|
+
? this.translations.siteLanguage.abbreviation.fr
|
|
133
|
+
: this.translations.siteLanguage.abbreviation.en;
|
|
59
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns full word text for the opposite language.
|
|
137
|
+
*
|
|
138
|
+
* @returns {string}
|
|
139
|
+
*/
|
|
140
|
+
getOppositeLanguageFullWord() {
|
|
141
|
+
return this.languageState === this.translations.siteLanguage.abbreviation.en
|
|
142
|
+
? this.translations.siteLanguage.fullWord.fr
|
|
143
|
+
: this.translations.siteLanguage.fullWord.en;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Component life cycle hook.
|
|
147
|
+
*
|
|
148
|
+
* https://stenciljs.com/docs/component-lifecycle#connectedcallback
|
|
149
|
+
*/
|
|
60
150
|
connectedCallback() {
|
|
61
|
-
this.
|
|
151
|
+
this.setAppLanguageHandler();
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Component life cycle hook.
|
|
155
|
+
*
|
|
156
|
+
* https://stenciljs.com/docs/component-lifecycle#componentdidload
|
|
157
|
+
*/
|
|
158
|
+
componentDidLoad() {
|
|
159
|
+
/**
|
|
160
|
+
* Creates a MutationObserver (a type of watch) on the <html> tag lang attribute.
|
|
161
|
+
*
|
|
162
|
+
* When changes occur, the oppositeLanguageLabel state variable regenerates.
|
|
163
|
+
*
|
|
164
|
+
* This is to act as a form of callback and create a subtle delay between page content
|
|
165
|
+
* updating and the language toggle label updating.
|
|
166
|
+
*/
|
|
167
|
+
const observer = new MutationObserver((mutations) => {
|
|
168
|
+
mutations.forEach((mutation) => {
|
|
169
|
+
switch (mutation.type) {
|
|
170
|
+
case 'attributes':
|
|
171
|
+
switch (mutation.attributeName) {
|
|
172
|
+
case 'lang':
|
|
173
|
+
this.oppositeLanguageLabel = {
|
|
174
|
+
fullWord: this.getOppositeLanguageFullWord(),
|
|
175
|
+
abbreviation: this.getOppositeLanguageAbbrievation(),
|
|
176
|
+
};
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
// Only create/trigger the MutationObserver if the <html> element exists.
|
|
184
|
+
if (getRootHTMLElement()) {
|
|
185
|
+
const options = { attributes: true };
|
|
186
|
+
observer.observe(getRootHTMLElement(), options);
|
|
187
|
+
}
|
|
62
188
|
}
|
|
63
189
|
render() {
|
|
64
|
-
|
|
65
|
-
const abbreviatedLanguage = this.language === 'en' ? 'FR' : 'EN';
|
|
190
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
66
191
|
return h(
|
|
67
192
|
'a',
|
|
68
193
|
{
|
|
69
|
-
'key': '
|
|
194
|
+
'key': 'f43e42110b4272a268801c310a8d14e31342f426',
|
|
195
|
+
'aria-label':
|
|
196
|
+
this.translations.languageToggle.ariaLabel[
|
|
197
|
+
`${(_a = this.oppositeLanguageLabel) === null || _a === void 0 ? void 0 : _a.abbreviation}`
|
|
198
|
+
],
|
|
70
199
|
'class':
|
|
71
200
|
this.size === 'default'
|
|
72
201
|
? 'ontario-language-toggler ontario-language-toggler--default'
|
|
73
202
|
: 'ontario-language-toggler ontario-language-toggler--small',
|
|
74
203
|
'href': this.url ? this.url : '#',
|
|
75
|
-
'
|
|
76
|
-
'
|
|
204
|
+
'hreflang': (_b = this.oppositeLanguageLabel) === null || _b === void 0 ? void 0 : _b.abbreviation,
|
|
205
|
+
'lang': (_c = this.oppositeLanguageLabel) === null || _c === void 0 ? void 0 : _c.abbreviation,
|
|
206
|
+
'onClick': (e) => this.handleHeaderLanguageToggled(this.languageState, e),
|
|
77
207
|
},
|
|
78
208
|
this.size === 'small'
|
|
79
|
-
? h('span', null,
|
|
209
|
+
? h('span', null, (_d = this.oppositeLanguageLabel) === null || _d === void 0 ? void 0 : _d.fullWord)
|
|
80
210
|
: h(
|
|
81
211
|
Fragment,
|
|
82
212
|
null,
|
|
83
|
-
h(
|
|
84
|
-
|
|
213
|
+
h(
|
|
214
|
+
'abbr',
|
|
215
|
+
{
|
|
216
|
+
title: (_e = this.oppositeLanguageLabel) === null || _e === void 0 ? void 0 : _e.fullWord,
|
|
217
|
+
class: 'ontario-show-for-small-only',
|
|
218
|
+
},
|
|
219
|
+
(_f = this.oppositeLanguageLabel) === null || _f === void 0 ? void 0 : _f.abbreviation.toUpperCase(),
|
|
220
|
+
),
|
|
221
|
+
h(
|
|
222
|
+
'span',
|
|
223
|
+
{ class: 'ontario-show-for-medium' },
|
|
224
|
+
(_g = this.oppositeLanguageLabel) === null || _g === void 0 ? void 0 : _g.fullWord,
|
|
225
|
+
),
|
|
85
226
|
),
|
|
86
227
|
);
|
|
87
228
|
}
|
|
@@ -103,6 +244,8 @@ const OntarioLanguageToggle = /*@__PURE__*/ proxyCustomElement(
|
|
|
103
244
|
url: [1025],
|
|
104
245
|
customLanguageToggle: [16],
|
|
105
246
|
translations: [32],
|
|
247
|
+
languageState: [32],
|
|
248
|
+
oppositeLanguageLabel: [32],
|
|
106
249
|
},
|
|
107
250
|
undefined,
|
|
108
251
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"ontario-language-toggle2.js","mappings":";;;;AAAA,MAAM,wBAAwB,GAAG,s9FAAs9F,CAAC;AACx/F,oCAAe,wBAAwB;;MCY1B,qBAAqB;;;;;;;QAqEjC,mBAAc,GAAG,CAAC,IAAY;YAC7B,MAAM,WAAW,GAAG,QAAQ,CAAC,iBAAiB,CAAC;YAE/C,IAAI,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,OAAO,CAAC,WAAW,EAAE,MAAK,MAAM,EAAE;gBAClD,IAAI,IAAI,EAAE;oBACT,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;iBACvC;qBAAM;oBACN,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;iBACvC;aACD;YAED,OAAO;SACP,CAAC;;oBAzEmC,SAAS;;;4BAgBjB,YAAY;;IAMzC,qBAAqB;QACpB,IAAI,IAAuB,CAAC;QAC5B,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC;SACrB;aAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,IAAI,EAAE;YACzC,IAAI,GAAG,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AC,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,EAC1E,OAAO,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,IAEjE,IAAI,CAAC,IAAI,KAAK,OAAO,IACrB,gBAAO,QAAQ,CAAQ,KAEvB,EAAC,QAAQ,QACR,YAAM,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAC,6BAA6B,IACxD,mBAAmB,CACd,EACP,YAAM,KAAK,EAAC,yBAAyB,IAAE,QAAQ,CAAQ,CAC7C,CACX,CACE,EACH;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/ontario-language-toggle/ontario-language-toggle.scss?tag=ontario-language-toggle&encapsulation=shadow","src/components/ontario-language-toggle/ontario-language-toggle.tsx"],"sourcesContent":["@use 'sass:math';\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/spacing.variables' as spacing;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/global.variables' as globalVariables;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/colours.variables' as colours;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/typography.variables' as typography;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/font-weights.variables' as fontWeights;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/2-tools/functions/global.functions' as globalFunctions;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/2-tools/placeholder/focus.placeholders' as\n\tfocusPlaceholders;\n\n@forward '@ongov/ontario-design-system-global-styles/dist/styles/scss/7-overrides/_visibility.overrides.scss';\n\n.ontario-language-toggler {\n\tbackground-color: colours.$ontario-colour-black;\n\tborder: none;\n\tborder-radius: globalVariables.$global-radius;\n\tbox-sizing: border-box;\n\tbox-shadow: none;\n\tcolor: colours.$ontario-colour-white;\n\tcursor: pointer;\n\tdisplay: flex;\n\talign-items: center;\n\tfont-size: 1.125rem;\n\tfont-weight: fontWeights.$ontario-font-weights-semi-bold;\n\tfont-family: typography.$ontario-font-open-sans;\n\theight: globalVariables.$standard-input-height;\n\tline-height: math.div(14, 9);\n\ttext-align: center;\n\ttext-decoration: none;\n\n\t&:hover {\n\t\tbackground-color: colours.$ontario-greyscale-70;\n\t}\n\n\t&:active {\n\t\tbackground-color: colours.$ontario-greyscale-60;\n\t\tcolor: colours.$ontario-colour-white;\n\t}\n\n\t&:focus {\n\t\tbackground-color: colours.$ontario-greyscale-70;\n\t\tcolor: colours.$ontario-colour-white;\n\t\t@extend %ontario-focus;\n\t}\n\n\t&:visited {\n\t\tcolor: colours.$ontario-colour-white;\n\t}\n\n\tabbr[title] {\n\t\ttext-decoration: none;\n\t}\n}\n\n.ontario-language-toggler--default {\n\tpadding: spacing.$spacing-3;\n}\n\n.ontario-language-toggler--small {\n\tfont-size: globalFunctions.px-to-rem(16);\n\tline-height: globalFunctions.px-to-rem(22);\n\theight: auto;\n\toutline: none;\n\tpadding: spacing.$spacing-2 spacing.$spacing-3;\n}\n","import { Component, Prop, State, Event, EventEmitter, Watch, h, Fragment } from '@stencil/core';\n\nimport { Language } from '../../utils/common/language-types';\nimport { validateLanguage } from '../../utils/validation/validation-functions';\n\nimport { default as translations } from '../../translations/global.i18n.json';\nimport { HeaderLanguageToggleEventDetails } from '../../utils/events/common-events.interface';\n\n@Component({\n\ttag: 'ontario-language-toggle',\n\tstyleUrl: 'ontario-language-toggle.scss',\n\tshadow: true,\n})\nexport class OntarioLanguageToggle {\n\t@Prop({ mutable: true }) language: Language | string;\n\n\t/**\n\t * The size of the language toggle button.\n\t *\n\t * If no prop is passed, it will be set to the `default` size.\n\t */\n\t@Prop() size?: 'default' | 'small' = 'default';\n\n\t/**\n\t * The URL to change to when the language toggle button is clicked.\n\t *\n\t * This is optional.\n\t */\n\t@Prop({ mutable: true }) url?: string;\n\n\t/**\n\t * A custom function to pass to the language toggle button.\n\t *\n\t * This is optional.\n\t */\n\t@Prop() customLanguageToggle?: (event: globalThis.Event) => void;\n\n\t@State() translations: any = translations;\n\n\t/**\n\t * An event to set the Document's HTML lang property, and emit the toggled language to other components.\n\t */\n\t@Event() setAppLanguage: EventEmitter<string>;\n\tsetAppLanguageHandler() {\n\t\tlet lang: string | Language;\n\t\tif (this.language) {\n\t\t\tlang = this.language;\n\t\t} else if (document.documentElement.lang) {\n\t\t\tlang = document.documentElement.lang;\n\t\t} else {\n\t\t\tlang = 'en';\n\t\t}\n\n\t\tthis.language = lang;\n\t\tthis.setAppLanguage.emit(lang);\n\n\t\tthis.updateHTMLLang(lang);\n\t}\n\n\t/**\n\t * An event that emits to other components that the language toggle button has been toggled.\n\t */\n\t@Event() headerLanguageToggled: EventEmitter<HeaderLanguageToggleEventDetails>;\n\thandleHeaderLanguageToggled(language: string, event?: globalThis.Event) {\n\t\tconst toggledLanguage = language === 'en' ? 'fr' : 'en';\n\t\tthis.language = toggledLanguage;\n\n\t\tthis.headerLanguageToggled.emit({ oldLanguage: language, newLanguage: toggledLanguage });\n\n\t\tthis.updateHTMLLang(toggledLanguage);\n\n\t\tif (this.customLanguageToggle && event) {\n\t\t\tthis.customLanguageToggle(event);\n\t\t}\n\t}\n\n\t@Watch('language')\n\tupdateLanguage() {\n\t\tthis.language = validateLanguage(this.language);\n\t\tthis.setAppLanguageHandler();\n\t}\n\n\tupdateHTMLLang = (lang: string) => {\n\t\tconst htmlElement = document.firstElementChild;\n\n\t\tif (htmlElement?.tagName.toLowerCase() === 'html') {\n\t\t\tif (lang) {\n\t\t\t\thtmlElement.setAttribute('lang', lang);\n\t\t\t} else {\n\t\t\t\thtmlElement.setAttribute('lang', 'en');\n\t\t\t}\n\t\t}\n\n\t\treturn;\n\t};\n\n\tconnectedCallback() {\n\t\tthis.updateLanguage();\n\t}\n\n\trender() {\n\t\tconst language = this.language === 'en' ? 'Français' : 'English';\n\t\tconst abbreviatedLanguage = this.language === 'en' ? 'FR' : 'EN';\n\n\t\treturn (\n\t\t\t<a\n\t\t\t\tclass={\n\t\t\t\t\tthis.size === 'default'\n\t\t\t\t\t\t? 'ontario-language-toggler ontario-language-toggler--default'\n\t\t\t\t\t\t: 'ontario-language-toggler ontario-language-toggler--small'\n\t\t\t\t}\n\t\t\t\thref={this.url ? this.url : '#'}\n\t\t\t\taria-label={this.translations.languageToggle.ariaLabel[`${this.language}`]}\n\t\t\t\tonClick={(e) => this.handleHeaderLanguageToggled(this.language, e)}\n\t\t\t>\n\t\t\t\t{this.size === 'small' ? (\n\t\t\t\t\t<span>{language}</span>\n\t\t\t\t) : (\n\t\t\t\t\t<Fragment>\n\t\t\t\t\t\t<abbr title={language} class=\"ontario-show-for-small-only\">\n\t\t\t\t\t\t\t{abbreviatedLanguage}\n\t\t\t\t\t\t</abbr>\n\t\t\t\t\t\t<span class=\"ontario-show-for-medium\">{language}</span>\n\t\t\t\t\t</Fragment>\n\t\t\t\t)}\n\t\t\t</a>\n\t\t);\n\t}\n}\n"],"version":3}
|
|
1
|
+
{"file":"ontario-language-toggle2.js","mappings":";;;;;;AAAO,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,IAAI,CAAU;;ACAvD,MAAM,wBAAwB,GAAG,s9FAAs9F,CAAC;AACx/F,oCAAe,wBAAwB;;MCc1B,qBAAqB;;;;;;;;;;QAkLzB,mBAAc,GAAG;YACxB,MAAM,WAAW,GAAG,kBAAkB,EAAE,CAAC;YAEzC,IAAI,WAAW,EAAE;gBAChB,WAAW,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;aACrD;SACD,CAAC;;oBAzKmC,SAAS;;;4BAgBjB,YAAY;;qCAU0D,SAAS;;;;;IAM5G,cAAc;QACb,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClB,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,CAAC,EAAE;gBAClE,IAAI,CAAC,mBAAmB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,CAAC,GAAG,GAAG,GAAG,EAC/B,QAAQ,EAAE,MAAA,IAAI,CAAC,qBAAqB,0CAAE,YAAY,EAClD,IAAI,EAAE,MAAA,IAAI,CAAC,qBAAqB,0CAAE,YAAY,EAC9C,OAAO,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,IAEtE,IAAI,CAAC,IAAI,KAAK,OAAO,IACrB,gBAAO,MAAA,IAAI,CAAC,qBAAqB,0CAAE,QAAQ,CAAQ,KAEnD,EAAC,QAAQ,QACR,YAAM,KAAK,EAAE,MAAA,IAAI,CAAC,qBAAqB,0CAAE,QAAQ,EAAE,KAAK,EAAC,6BAA6B,IACpF,MAAA,IAAI,CAAC,qBAAqB,0CAAE,YAAY,CAAC,WAAW,EAAE,CACjD,EACP,YAAM,KAAK,EAAC,yBAAyB,IAAE,MAAA,IAAI,CAAC,qBAAqB,0CAAE,QAAQ,CAAQ,CACzE,CACX,CACE,EACH;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/utils/common/language-types.ts","src/components/ontario-language-toggle/ontario-language-toggle.scss?tag=ontario-language-toggle&encapsulation=shadow","src/components/ontario-language-toggle/ontario-language-toggle.tsx"],"sourcesContent":["export const supportedLanguages = ['en', 'fr'] as const;\nexport type Language = (typeof supportedLanguages)[number];\n","@use 'sass:math';\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/spacing.variables' as spacing;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/global.variables' as globalVariables;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/colours.variables' as colours;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/typography.variables' as typography;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/1-variables/font-weights.variables' as fontWeights;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/2-tools/functions/global.functions' as globalFunctions;\n@use '@ongov/ontario-design-system-global-styles/dist/styles/scss/2-tools/placeholder/focus.placeholders' as\n\tfocusPlaceholders;\n\n@forward '@ongov/ontario-design-system-global-styles/dist/styles/scss/7-overrides/_visibility.overrides.scss';\n\n.ontario-language-toggler {\n\tbackground-color: colours.$ontario-colour-black;\n\tborder: none;\n\tborder-radius: globalVariables.$global-radius;\n\tbox-sizing: border-box;\n\tbox-shadow: none;\n\tcolor: colours.$ontario-colour-white;\n\tcursor: pointer;\n\tdisplay: flex;\n\talign-items: center;\n\tfont-size: 1.125rem;\n\tfont-weight: fontWeights.$ontario-font-weights-semi-bold;\n\tfont-family: typography.$ontario-font-open-sans;\n\theight: globalVariables.$standard-input-height;\n\tline-height: math.div(14, 9);\n\ttext-align: center;\n\ttext-decoration: none;\n\n\t&:hover {\n\t\tbackground-color: colours.$ontario-greyscale-70;\n\t}\n\n\t&:active {\n\t\tbackground-color: colours.$ontario-greyscale-60;\n\t\tcolor: colours.$ontario-colour-white;\n\t}\n\n\t&:focus {\n\t\tbackground-color: colours.$ontario-greyscale-70;\n\t\tcolor: colours.$ontario-colour-white;\n\t\t@extend %ontario-focus;\n\t}\n\n\t&:visited {\n\t\tcolor: colours.$ontario-colour-white;\n\t}\n\n\tabbr[title] {\n\t\ttext-decoration: none;\n\t}\n}\n\n.ontario-language-toggler--default {\n\tpadding: spacing.$spacing-3;\n}\n\n.ontario-language-toggler--small {\n\tfont-size: globalFunctions.px-to-rem(16);\n\tline-height: globalFunctions.px-to-rem(22);\n\theight: auto;\n\toutline: none;\n\tpadding: spacing.$spacing-2 spacing.$spacing-3;\n}\n","import { Component, Prop, State, Event, EventEmitter, Watch, h, Fragment } from '@stencil/core';\n\nimport { supportedLanguages, Language } from '../../utils/common/language-types';\n\nimport { default as translations } from '../../translations/global.i18n.json';\nimport { HeaderLanguageToggleEventDetails } from '../../utils/events/common-events.interface';\nimport { validateValueAgainstArray } from '../../utils/validation/validation-functions';\nimport { ConsoleMessageClass } from '../../utils/console-message/console-message';\nimport { printArray, getRootHTMLElement } from '../../utils/helper/utils';\n\n@Component({\n\ttag: 'ontario-language-toggle',\n\tstyleUrl: 'ontario-language-toggle.scss',\n\tshadow: true,\n})\nexport class OntarioLanguageToggle {\n\t/**\n\t * The language of the component.\n\t *\n\t * In most cases, the language toggle should be the source of truth for determining the site language.\n\t *\n\t * Only pass a language value here if necessary.\n\t */\n\t@Prop({ mutable: true }) language?: Language;\n\n\t/**\n\t * The size of the language toggle button.\n\t *\n\t * If no prop is passed, it will be set to the `default` size.\n\t */\n\t@Prop() size?: 'default' | 'small' = 'default';\n\n\t/**\n\t * The URL to change to when the language toggle button is clicked.\n\t *\n\t * This is optional.\n\t */\n\t@Prop({ mutable: true }) url?: string;\n\n\t/**\n\t * A custom function to pass to the language toggle button.\n\t *\n\t * This is optional.\n\t */\n\t@Prop() customLanguageToggle?: (event: globalThis.Event) => void;\n\n\t@State() translations: any = translations;\n\n\t/**\n\t * Internal state used as the source of truth for component language.\n\t */\n\t@State() private languageState: Language;\n\n\t/**\n\t * Internal state used to render the text on the language toggle UI.\n\t */\n\t@State() private oppositeLanguageLabel: { fullWord: string; abbreviation: Language } | undefined = undefined;\n\n\t/**\n\t * Updates the language and languageState props when changes to the language prop are detected.\n\t */\n\t@Watch('language')\n\tupdateLanguage() {\n\t\tif (this.language) {\n\t\t\tif (!validateValueAgainstArray(this.language, supportedLanguages)) {\n\t\t\t\tthis.showLanguageWarning(this.language);\n\t\t\t\tthis.language = this.translations.siteLanguage.abbreviation.en as Language;\n\t\t\t}\n\t\t\tthis.languageState = this.language;\n\t\t}\n\t\tthis.setAppLanguageHandler();\n\t}\n\n\t/**\n\t * Event that fires during the setAppLanguageHandler() method.\n\t *\n\t * The event contains the current language (after language logic has already occurred).\n\t */\n\t@Event() setAppLanguage: EventEmitter<Language>;\n\n\t/**\n\t * Event that fires when the language toggle is pressed/clicked.\n\t *\n\t * The event contains the oldLanguage along with the newLanguage.\n\t */\n\t@Event() headerLanguageToggled: EventEmitter<HeaderLanguageToggleEventDetails>;\n\n\t/**\n\t * This function sets the languageState (if not already set).\n\t *\n\t * It also emits the setAppLanguage() event, updates the component language label, and\n\t * updates the <html> tag lang attribute with the languageState value.\n\t *\n\t * It gets called by the connectedCallback() component lifecycle hook, and by the\n\t * updateLanguage() method, which is fired on the watch for the language prop.\n\t */\n\tprivate setAppLanguageHandler() {\n\t\tconst defaultLang = this.translations.siteLanguage.abbreviation.en;\n\t\tconst rootLang = getRootHTMLElement()?.lang;\n\n\t\t// If languageState is not set, set it equal to the following cadence:\n\t\t// language prop value, <html> tag lang attribute, or default to \"en\"\n\t\tif (!this.languageState) {\n\t\t\tif (this.language) {\n\t\t\t\tthis.languageState = this.language;\n\t\t\t} else if (rootLang) {\n\t\t\t\tif (validateValueAgainstArray(rootLang, supportedLanguages)) {\n\t\t\t\t\tthis.languageState = rootLang as Language;\n\t\t\t\t} else {\n\t\t\t\t\tthis.showLanguageWarning(rootLang, 'document');\n\t\t\t\t\tthis.languageState = defaultLang;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.languageState = defaultLang;\n\t\t\t}\n\t\t}\n\n\t\tthis.setAppLanguage.emit(this.languageState);\n\n\t\tthis.oppositeLanguageLabel = {\n\t\t\tfullWord: this.getOppositeLanguageFullWord(),\n\t\t\tabbreviation: this.getOppositeLanguageAbbrievation(),\n\t\t};\n\n\t\tthis.updateHTMLLang();\n\t}\n\n\t/**\n\t * An event that emits to other components that the language toggle button has been toggled.\n\t *\n\t * @param {Language} oldLanguage - The language prior to the language toggle being pressed.\n\t * @param {globalThis.Event} event - event that triggered the function (e.g. onclick).\n\t */\n\tprivate handleHeaderLanguageToggled(oldLanguage: Language, event?: globalThis.Event) {\n\t\tthis.languageState =\n\t\t\toldLanguage === this.translations.siteLanguage.abbreviation.en\n\t\t\t\t? this.translations.siteLanguage.abbreviation.fr\n\t\t\t\t: this.translations.siteLanguage.abbreviation.en;\n\n\t\tthis.headerLanguageToggled.emit({ oldLanguage: oldLanguage, newLanguage: this.languageState });\n\n\t\tthis.updateHTMLLang();\n\n\t\tif (this.customLanguageToggle && event) {\n\t\t\tthis.customLanguageToggle(event);\n\t\t}\n\t}\n\n\t/**\n\t * Prints a warning message to the console about using an incorrect language for the component.\n\t *\n\t * @param {string} lang - The incorrect language that was received.\n\t * @param {string} type - prop/document | Where the incorrect language is coming from.\n\t */\n\tprivate showLanguageWarning(lang: string, type: 'prop' | 'document' = 'prop') {\n\t\tconst propOrDocumentMessage =\n\t\t\ttype === 'prop' ? `The language prop value of ${lang} ` : `The HTML document lang attribute value of ${lang} `;\n\t\tconst message = new ConsoleMessageClass();\n\t\tmessage\n\t\t\t.addDesignSystemTag()\n\t\t\t.addRegularText(propOrDocumentMessage)\n\t\t\t.addRegularText('is not a valid language value for the ')\n\t\t\t.addMonospaceText(' <ontario-language-toggle> ')\n\t\t\t.addRegularText(`component. Valid language values are ${printArray([...supportedLanguages])}. `)\n\t\t\t.addRegularText(`A default language value of ${this.translations.siteLanguage.abbreviation.en} will be applied.`)\n\t\t\t.printMessage();\n\t}\n\n\t/**\n\t * Returns abbreviated text for the opposite language.\n\t *\n\t * @returns {Language}\n\t */\n\tprivate getOppositeLanguageAbbrievation(): Language {\n\t\treturn this.languageState === this.translations.siteLanguage.abbreviation.en\n\t\t\t? this.translations.siteLanguage.abbreviation.fr\n\t\t\t: this.translations.siteLanguage.abbreviation.en;\n\t}\n\n\t/**\n\t * Returns full word text for the opposite language.\n\t *\n\t * @returns {string}\n\t */\n\tprivate getOppositeLanguageFullWord(): string {\n\t\treturn this.languageState === this.translations.siteLanguage.abbreviation.en\n\t\t\t? this.translations.siteLanguage.fullWord.fr\n\t\t\t: this.translations.siteLanguage.fullWord.en;\n\t}\n\n\t/*\n\t * Updates the <html> lang attribute based on component languageState.\n\t */\n\tprivate updateHTMLLang = () => {\n\t\tconst htmlElement = getRootHTMLElement();\n\n\t\tif (htmlElement) {\n\t\t\thtmlElement.setAttribute('lang', this.languageState);\n\t\t}\n\t};\n\n\t/**\n\t * Component life cycle hook.\n\t *\n\t * https://stenciljs.com/docs/component-lifecycle#connectedcallback\n\t */\n\tconnectedCallback() {\n\t\tthis.setAppLanguageHandler();\n\t}\n\n\t/**\n\t * Component life cycle hook.\n\t *\n\t * https://stenciljs.com/docs/component-lifecycle#componentdidload\n\t */\n\tcomponentDidLoad() {\n\t\t/**\n\t\t * Creates a MutationObserver (a type of watch) on the <html> tag lang attribute.\n\t\t *\n\t\t * When changes occur, the oppositeLanguageLabel state variable regenerates.\n\t\t *\n\t\t * This is to act as a form of callback and create a subtle delay between page content\n\t\t * updating and the language toggle label updating.\n\t\t */\n\t\tconst observer = new MutationObserver((mutations) => {\n\t\t\tmutations.forEach((mutation) => {\n\t\t\t\tswitch (mutation.type) {\n\t\t\t\t\tcase 'attributes':\n\t\t\t\t\t\tswitch (mutation.attributeName) {\n\t\t\t\t\t\t\tcase 'lang':\n\t\t\t\t\t\t\t\tthis.oppositeLanguageLabel = {\n\t\t\t\t\t\t\t\t\tfullWord: this.getOppositeLanguageFullWord(),\n\t\t\t\t\t\t\t\t\tabbreviation: this.getOppositeLanguageAbbrievation(),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\t// Only create/trigger the MutationObserver if the <html> element exists.\n\t\tif (getRootHTMLElement()) {\n\t\t\tconst options = { attributes: true };\n\t\t\tobserver.observe(getRootHTMLElement(), options);\n\t\t}\n\t}\n\n\trender() {\n\t\treturn (\n\t\t\t<a\n\t\t\t\taria-label={this.translations.languageToggle.ariaLabel[`${this.oppositeLanguageLabel?.abbreviation}`]}\n\t\t\t\tclass={\n\t\t\t\t\tthis.size === 'default'\n\t\t\t\t\t\t? 'ontario-language-toggler ontario-language-toggler--default'\n\t\t\t\t\t\t: 'ontario-language-toggler ontario-language-toggler--small'\n\t\t\t\t}\n\t\t\t\thref={this.url ? this.url : '#'}\n\t\t\t\threflang={this.oppositeLanguageLabel?.abbreviation}\n\t\t\t\tlang={this.oppositeLanguageLabel?.abbreviation}\n\t\t\t\tonClick={(e) => this.handleHeaderLanguageToggled(this.languageState, e)}\n\t\t\t>\n\t\t\t\t{this.size === 'small' ? (\n\t\t\t\t\t<span>{this.oppositeLanguageLabel?.fullWord}</span>\n\t\t\t\t) : (\n\t\t\t\t\t<Fragment>\n\t\t\t\t\t\t<abbr title={this.oppositeLanguageLabel?.fullWord} class=\"ontario-show-for-small-only\">\n\t\t\t\t\t\t\t{this.oppositeLanguageLabel?.abbreviation.toUpperCase()}\n\t\t\t\t\t\t</abbr>\n\t\t\t\t\t\t<span class=\"ontario-show-for-medium\">{this.oppositeLanguageLabel?.fullWord}</span>\n\t\t\t\t\t</Fragment>\n\t\t\t\t)}\n\t\t\t</a>\n\t\t);\n\t}\n}\n"],"version":3}
|
package/dist/components/utils.js
CHANGED
|
@@ -68,14 +68,42 @@ function isEmpty(str) {
|
|
|
68
68
|
function retrieveEnumKeys(enumObject) {
|
|
69
69
|
return Object.keys(enumObject).filter(isNumber);
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Prints an array as a comma delimited list, with the last element being preceded by a conjunction.
|
|
73
|
+
* As per ontario.ca content guidelines, there is no Oxford comma.
|
|
74
|
+
*
|
|
75
|
+
* @param {Array<any>} arr - The array that you wish to print.
|
|
76
|
+
* @param {Conjunction} conjunctionType - Whether you want the sentence to end with 'and value.' or 'or value.'
|
|
77
|
+
*
|
|
78
|
+
* @returns {string}
|
|
79
|
+
*/
|
|
80
|
+
function printArray(arr, conjunctionType = 'and') {
|
|
81
|
+
return [...arr].reduce(
|
|
82
|
+
(text, value, i, array) => text + (i < array.length - 1 ? ', ' : ` ${conjunctionType} `) + value,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Grabs the HTML element of the page.
|
|
87
|
+
*
|
|
88
|
+
* More targetted than document.documentElement as the documentElement could
|
|
89
|
+
* in theory be any element that is the top level. e.g. <div> if the page is not
|
|
90
|
+
* set up to be semantically correct.
|
|
91
|
+
*
|
|
92
|
+
* @returns {HTMLElement}
|
|
93
|
+
*/
|
|
94
|
+
function getRootHTMLElement() {
|
|
95
|
+
return document.getElementsByTagName('html')[0];
|
|
96
|
+
}
|
|
71
97
|
|
|
72
98
|
export {
|
|
73
99
|
isNumber as a,
|
|
74
100
|
removeObjectsBySpecificKey as b,
|
|
75
101
|
extractValuesByKey as e,
|
|
102
|
+
getRootHTMLElement as g,
|
|
76
103
|
hasMultipleTrueValues as h,
|
|
77
104
|
isEmpty as i,
|
|
78
105
|
organizeObjectKeys as o,
|
|
106
|
+
printArray as p,
|
|
79
107
|
retrieveEnumKeys as r,
|
|
80
108
|
};
|
|
81
109
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"file":"utils.js","mappings":"
|
|
1
|
+
{"file":"utils.js","mappings":"SAMgB,qBAAqB,CAAI,GAAQ,EAAE,GAAY;IAC9D,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;QACtB,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,MAAM,EAAE;YAC7C,KAAK,EAAE,CAAC;YACR,IAAI,KAAK,GAAG,CAAC,EAAE;gBACd,OAAO,IAAI,CAAC;aACZ;SACD;KACD;IAED,OAAO,KAAK,CAAC;AACd,CAAC;SAEe,kBAAkB,CAAI,OAAY,EAAE,GAAY;IAC/D,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACvC,CAAC;SAEe,kBAAkB,CAAC,IAAW,EAAE,OAAiB;IAChE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI;QACpB,MAAM,OAAO,GAAQ,EAAE,CAAC;QACxB,MAAM,SAAS,GAAQ,E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,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;;;SASgB,UAAU,CAAC,GAAe,EAAE,kBAA+B,KAAK;IAC/E,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,MAAM,CACrB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,eAAe,GAAG,CAAC,GAAG,KAAK,CAChG,CAAC;AACH,CAAC;AAED;;;;;;;;;SASgB,kBAAkB;IACjC,OAAO,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD;;;;","names":[],"sources":["src/utils/helper/utils.ts"],"sourcesContent":["import { Conjunction } from './utils-types';\n\nexport function format(first: string | undefined, middle: string | undefined, last: string | undefined): string {\n\treturn (first || '') + (middle ? ` ${middle}` : '') + (last ? ` ${last}` : '');\n}\n\nexport function hasMultipleTrueValues<T>(arr: T[], key: keyof T): boolean {\n\tlet count = 0;\n\n\tfor (const obj of arr) {\n\t\tif (obj[key] === true || obj[key] === 'true') {\n\t\t\tcount++;\n\t\t\tif (count > 1) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn false;\n}\n\nexport function extractValuesByKey<T>(objects: T[], key: keyof T): Array<T[keyof T]> {\n\treturn objects.map((obj) => obj[key]);\n}\n\nexport function organizeObjectKeys(data: any[], columns: string[]): any[] {\n\treturn data.map((item) => {\n\t\tconst newData: any = {};\n\t\tconst otherKeys: any = {};\n\n\t\t// Iterate through each key in the item\n\t\tObject.keys(item).forEach((key) => {\n\t\t\tif (key === 'data') {\n\t\t\t\t// Organize keys in the 'data' object\n\t\t\t\tcolumns.forEach((column) => {\n\t\t\t\t\tif (column in item.data) {\n\t\t\t\t\t\tnewData[column] = item.data[column];\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\t// Preserve other keys\n\t\t\t\totherKeys[key] = item[key];\n\t\t\t}\n\t\t});\n\n\t\treturn { data: newData, ...otherKeys };\n\t});\n}\n\nexport function removeObjectsBySpecificKey<T>(objects: T[], key: keyof T, value: boolean | 'true'): [T[], T[]] {\n\tconst removedObjects: T[] = [];\n\tconst filteredObjects = objects.filter((obj) => {\n\t\tif (obj[key] === value) {\n\t\t\tremovedObjects.push(obj);\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t});\n\treturn [filteredObjects, removedObjects];\n}\n\n/**\n * Takes an input value and determines whether or not it is a number.\n *\n * @param {string | number} value - The value you would like to test against.\n *\n * @returns {boolean}\n */\nexport function isNumber(value: string | number): boolean {\n\treturn isNaN(Number(value)) === true;\n}\n\nexport function isEmpty(str: string | undefined | null): boolean {\n\treturn !str || str?.length <= 0;\n}\n\n/**\n * Retrieves the keys from an enum and lists them in an array.\n *\n * @param {object} enumObject - The enum you wish to get the keys of.\n *\n * @returns {string[]}\n */\nexport function retrieveEnumKeys(enumObject: object): string[] {\n\treturn Object.keys(enumObject).filter(isNumber);\n}\n\n/**\n * Prints an array as a comma delimited list, with the last element being preceded by a conjunction.\n * As per ontario.ca content guidelines, there is no Oxford comma.\n *\n * @param {Array<any>} arr - The array that you wish to print.\n * @param {Conjunction} conjunctionType - Whether you want the sentence to end with 'and value.' or 'or value.'\n *\n * @returns {string}\n */\nexport function printArray(arr: Array<any>, conjunctionType: Conjunction = 'and'): string {\n\treturn [...arr].reduce(\n\t\t(text, value, i, array) => text + (i < array.length - 1 ? ', ' : ` ${conjunctionType} `) + value,\n\t);\n}\n\n/**\n * Grabs the HTML element of the page.\n *\n * More targetted than document.documentElement as the documentElement could\n * in theory be any element that is the top level. e.g. <div> if the page is not\n * set up to be semantically correct.\n *\n * @returns {HTMLElement}\n */\nexport function getRootHTMLElement(): HTMLElement {\n\treturn document.getElementsByTagName('html')[0];\n}\n"],"version":3}
|