@ongov/ontario-design-system-component-library 4.3.0 → 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.
Files changed (76) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/ontario-accordion_43.cjs.entry.js +404 -223
  3. package/dist/cjs/ontario-accordion_43.cjs.entry.js.map +1 -1
  4. package/dist/cjs/ontario-design-system-components.cjs.js +1 -1
  5. package/dist/collection/components/ontario-card/ontario-card.css +13 -5
  6. package/dist/collection/components/ontario-card/ontario-card.js +10 -10
  7. package/dist/collection/components/ontario-card/ontario-card.js.map +1 -1
  8. package/dist/collection/components/ontario-card/test/ontario-cards.spec.js +1 -1
  9. package/dist/collection/components/ontario-card/test/ontario-cards.spec.js.map +1 -1
  10. package/dist/collection/components/ontario-header/ontario-header.js +17 -3
  11. package/dist/collection/components/ontario-header/ontario-header.js.map +1 -1
  12. package/dist/collection/components/ontario-header/test/ontario-header.spec.js +3 -3
  13. package/dist/collection/components/ontario-header/test/ontario-header.spec.js.map +1 -1
  14. package/dist/collection/components/ontario-language-toggle/ontario-language-toggle.js +193 -47
  15. package/dist/collection/components/ontario-language-toggle/ontario-language-toggle.js.map +1 -1
  16. package/dist/collection/components/ontario-language-toggle/test/ontario-language-toggle.spec.js +16 -3
  17. package/dist/collection/components/ontario-language-toggle/test/ontario-language-toggle.spec.js.map +1 -1
  18. package/dist/collection/i18n/global.i18n.json +172 -162
  19. package/dist/collection/utils/common/language-types.js +1 -1
  20. package/dist/collection/utils/common/language-types.js.map +1 -1
  21. package/dist/collection/utils/helper/utils-types.js +2 -0
  22. package/dist/collection/utils/helper/utils-types.js.map +1 -0
  23. package/dist/collection/utils/helper/utils.js +26 -0
  24. package/dist/collection/utils/helper/utils.js.map +1 -1
  25. package/dist/components/global.i18n.js +184 -173
  26. package/dist/components/global.i18n.js.map +1 -1
  27. package/dist/components/ontario-card.js +11 -11
  28. package/dist/components/ontario-card.js.map +1 -1
  29. package/dist/components/ontario-header.js +11 -3
  30. package/dist/components/ontario-header.js.map +1 -1
  31. package/dist/components/ontario-language-toggle2.js +180 -37
  32. package/dist/components/ontario-language-toggle2.js.map +1 -1
  33. package/dist/components/utils.js +28 -0
  34. package/dist/components/utils.js.map +1 -1
  35. package/dist/esm/loader.js +1 -1
  36. package/dist/esm/ontario-accordion_43.entry.js +404 -223
  37. package/dist/esm/ontario-accordion_43.entry.js.map +1 -1
  38. package/dist/esm/ontario-design-system-components.js +1 -1
  39. package/dist/ontario-design-system-components/i18n/global.i18n.json +172 -162
  40. package/dist/ontario-design-system-components/ontario-design-system-components.esm.js +1 -1
  41. package/dist/ontario-design-system-components/ontario-design-system-components.esm.js.map +1 -1
  42. package/dist/ontario-design-system-components/{p-cff41424.entry.js → p-abe58ec9.entry.js} +697 -608
  43. package/dist/ontario-design-system-components/p-abe58ec9.entry.js.map +1 -0
  44. package/dist/types/components/ontario-header/ontario-header.d.ts +13 -2
  45. package/dist/types/components/ontario-language-toggle/ontario-language-toggle.d.ts +75 -8
  46. package/dist/types/components.d.ts +12 -6
  47. package/dist/types/utils/common/language-types.d.ts +2 -1
  48. package/dist/types/utils/helper/utils-types.d.ts +2 -0
  49. package/dist/types/utils/helper/utils.d.ts +21 -0
  50. package/package.json +3 -3
  51. package/src/components/ontario-card/ontario-card.scss +13 -6
  52. package/src/components/ontario-card/ontario-card.tsx +8 -6
  53. package/src/components/ontario-card/test/ontario-cards.spec.tsx +1 -1
  54. package/src/components/ontario-header/ontario-header.tsx +13 -4
  55. package/src/components/ontario-header/test/ontario-header.spec.tsx +3 -3
  56. package/src/components/ontario-language-toggle/ontario-language-toggle.tsx +192 -45
  57. package/src/components/ontario-language-toggle/readme.md +10 -10
  58. package/src/components/ontario-language-toggle/test/__snapshots__/ontario-language-toggle.spec.tsx.snap +1 -1
  59. package/src/components/ontario-language-toggle/test/ontario-language-toggle.spec.tsx +17 -3
  60. package/src/components.d.ts +12 -6
  61. package/src/french.html +37 -0
  62. package/src/index.html +19 -0
  63. package/src/translations/global.i18n.json +172 -162
  64. package/src/utils/common/language-types.ts +2 -1
  65. package/src/utils/helper/utils-types.ts +2 -0
  66. package/src/utils/helper/utils.ts +30 -0
  67. package/www/build/ontario-design-system-components.esm.js +1 -1
  68. package/www/build/ontario-design-system-components.esm.js.map +1 -1
  69. package/www/build/{p-cff41424.entry.js → p-abe58ec9.entry.js} +697 -608
  70. package/www/build/p-abe58ec9.entry.js.map +1 -0
  71. package/www/build/{p-b61db0f6.js → p-fdc9ab6d.js} +1 -1
  72. package/www/french.html +37 -0
  73. package/www/i18n/global.i18n.json +172 -162
  74. package/www/index.html +21 -2
  75. package/dist/ontario-design-system-components/p-cff41424.entry.js.map +0 -1
  76. package/www/build/p-cff41424.entry.js.map +0 -1
@@ -153,9 +153,20 @@ export declare class OntarioHeader {
153
153
  */
154
154
  handleClick(event: any): void;
155
155
  /**
156
- * This listens for the `setAppLanguage` event sent from the test language toggler when it is is connected to the DOM. It is used for the initial language when the input component loads.
156
+ * This listens for the `setAppLanguage` event sent from the language toggle when it is is connected to the DOM.
157
+ * It is used for the initial language when the input component loads.
157
158
  */
158
- handleSetAppLanguage(event: CustomEvent<Language>): void;
159
+ handleSetAppLanguage(event: CustomEvent<Language> | Language): void;
160
+ /**
161
+ * This listens for the `headerLanguageToggled` event sent from the language toggle when it is is connected to the DOM.
162
+ * It is used for changing the component language after the language toggle has been activated.
163
+ */
164
+ handleLanguageToggle(
165
+ event: CustomEvent<{
166
+ oldLanguage: Language;
167
+ newLanguage: Language;
168
+ }>,
169
+ ): void;
159
170
  /**
160
171
  * Logic to handle the menu toggling
161
172
  */
@@ -2,7 +2,14 @@ import { EventEmitter } from '../../stencil-public-runtime';
2
2
  import { Language } from '../../utils/common/language-types';
3
3
  import { HeaderLanguageToggleEventDetails } from '../../utils/events/common-events.interface';
4
4
  export declare class OntarioLanguageToggle {
5
- language: Language | string;
5
+ /**
6
+ * The language of the component.
7
+ *
8
+ * In most cases, the language toggle should be the source of truth for determining the site language.
9
+ *
10
+ * Only pass a language value here if necessary.
11
+ */
12
+ language?: Language;
6
13
  /**
7
14
  * The size of the language toggle button.
8
15
  *
@@ -23,17 +30,77 @@ export declare class OntarioLanguageToggle {
23
30
  customLanguageToggle?: (event: globalThis.Event) => void;
24
31
  translations: any;
25
32
  /**
26
- * An event to set the Document's HTML lang property, and emit the toggled language to other components.
33
+ * Internal state used as the source of truth for component language.
27
34
  */
28
- setAppLanguage: EventEmitter<string>;
29
- setAppLanguageHandler(): void;
35
+ private languageState;
30
36
  /**
31
- * An event that emits to other components that the language toggle button has been toggled.
37
+ * Internal state used to render the text on the language toggle UI.
38
+ */
39
+ private oppositeLanguageLabel;
40
+ /**
41
+ * Updates the language and languageState props when changes to the language prop are detected.
32
42
  */
33
- headerLanguageToggled: EventEmitter<HeaderLanguageToggleEventDetails>;
34
- handleHeaderLanguageToggled(language: string, event?: globalThis.Event): void;
35
43
  updateLanguage(): void;
36
- updateHTMLLang: (lang: string) => void;
44
+ /**
45
+ * Event that fires during the setAppLanguageHandler() method.
46
+ *
47
+ * The event contains the current language (after language logic has already occurred).
48
+ */
49
+ setAppLanguage: EventEmitter<Language>;
50
+ /**
51
+ * Event that fires when the language toggle is pressed/clicked.
52
+ *
53
+ * The event contains the oldLanguage along with the newLanguage.
54
+ */
55
+ headerLanguageToggled: EventEmitter<HeaderLanguageToggleEventDetails>;
56
+ /**
57
+ * This function sets the languageState (if not already set).
58
+ *
59
+ * It also emits the setAppLanguage() event, updates the component language label, and
60
+ * updates the <html> tag lang attribute with the languageState value.
61
+ *
62
+ * It gets called by the connectedCallback() component lifecycle hook, and by the
63
+ * updateLanguage() method, which is fired on the watch for the language prop.
64
+ */
65
+ private setAppLanguageHandler;
66
+ /**
67
+ * An event that emits to other components that the language toggle button has been toggled.
68
+ *
69
+ * @param {Language} oldLanguage - The language prior to the language toggle being pressed.
70
+ * @param {globalThis.Event} event - event that triggered the function (e.g. onclick).
71
+ */
72
+ private handleHeaderLanguageToggled;
73
+ /**
74
+ * Prints a warning message to the console about using an incorrect language for the component.
75
+ *
76
+ * @param {string} lang - The incorrect language that was received.
77
+ * @param {string} type - prop/document | Where the incorrect language is coming from.
78
+ */
79
+ private showLanguageWarning;
80
+ /**
81
+ * Returns abbreviated text for the opposite language.
82
+ *
83
+ * @returns {Language}
84
+ */
85
+ private getOppositeLanguageAbbrievation;
86
+ /**
87
+ * Returns full word text for the opposite language.
88
+ *
89
+ * @returns {string}
90
+ */
91
+ private getOppositeLanguageFullWord;
92
+ private updateHTMLLang;
93
+ /**
94
+ * Component life cycle hook.
95
+ *
96
+ * https://stenciljs.com/docs/component-lifecycle#connectedcallback
97
+ */
37
98
  connectedCallback(): void;
99
+ /**
100
+ * Component life cycle hook.
101
+ *
102
+ * https://stenciljs.com/docs/component-lifecycle#componentdidload
103
+ */
104
+ componentDidLoad(): void;
38
105
  render(): any;
39
106
  }
@@ -1725,7 +1725,10 @@ export namespace Components {
1725
1725
  * A custom function to pass to the language toggle button. This is optional.
1726
1726
  */
1727
1727
  customLanguageToggle?: (event: globalThis.Event) => void;
1728
- language: Language | string;
1728
+ /**
1729
+ * The language of the component. In most cases, the language toggle should be the source of truth for determining the site language. Only pass a language value here if necessary.
1730
+ */
1731
+ language?: Language;
1729
1732
  /**
1730
1733
  * The size of the language toggle button. If no prop is passed, it will be set to the `default` size.
1731
1734
  */
@@ -2893,7 +2896,7 @@ declare global {
2893
2896
  new (): HTMLOntarioInputElement;
2894
2897
  };
2895
2898
  interface HTMLOntarioLanguageToggleElementEventMap {
2896
- setAppLanguage: string;
2899
+ setAppLanguage: Language;
2897
2900
  headerLanguageToggled: HeaderLanguageToggleEventDetails;
2898
2901
  }
2899
2902
  interface HTMLOntarioLanguageToggleElement extends Components.OntarioLanguageToggle, HTMLStencilElement {
@@ -4923,15 +4926,18 @@ declare namespace LocalJSX {
4923
4926
  * A custom function to pass to the language toggle button. This is optional.
4924
4927
  */
4925
4928
  customLanguageToggle?: (event: globalThis.Event) => void;
4926
- language?: Language | string;
4927
4929
  /**
4928
- * An event that emits to other components that the language toggle button has been toggled.
4930
+ * The language of the component. In most cases, the language toggle should be the source of truth for determining the site language. Only pass a language value here if necessary.
4931
+ */
4932
+ language?: Language;
4933
+ /**
4934
+ * Event that fires when the language toggle is pressed/clicked. The event contains the oldLanguage along with the newLanguage.
4929
4935
  */
4930
4936
  onHeaderLanguageToggled?: (event: OntarioLanguageToggleCustomEvent<HeaderLanguageToggleEventDetails>) => void;
4931
4937
  /**
4932
- * An event to set the Document's HTML lang property, and emit the toggled language to other components.
4938
+ * Event that fires during the setAppLanguageHandler() method. The event contains the current language (after language logic has already occurred).
4933
4939
  */
4934
- onSetAppLanguage?: (event: OntarioLanguageToggleCustomEvent<string>) => void;
4940
+ onSetAppLanguage?: (event: OntarioLanguageToggleCustomEvent<Language>) => void;
4935
4941
  /**
4936
4942
  * The size of the language toggle button. If no prop is passed, it will be set to the `default` size.
4937
4943
  */
@@ -1 +1,2 @@
1
- export type Language = 'en' | 'fr';
1
+ export declare const supportedLanguages: readonly ['en', 'fr'];
2
+ export type Language = (typeof supportedLanguages)[number];
@@ -0,0 +1,2 @@
1
+ export declare const conjunctions: readonly ['and', 'or'];
2
+ export type Conjunction = (typeof conjunctions)[number];
@@ -1,3 +1,4 @@
1
+ import { Conjunction } from './utils-types';
1
2
  export declare function format(first: string | undefined, middle: string | undefined, last: string | undefined): string;
2
3
  export declare function hasMultipleTrueValues<T>(arr: T[], key: keyof T): boolean;
3
4
  export declare function extractValuesByKey<T>(objects: T[], key: keyof T): Array<T[keyof T]>;
@@ -20,3 +21,23 @@ export declare function isEmpty(str: string | undefined | null): boolean;
20
21
  * @returns {string[]}
21
22
  */
22
23
  export declare function retrieveEnumKeys(enumObject: object): string[];
24
+ /**
25
+ * Prints an array as a comma delimited list, with the last element being preceded by a conjunction.
26
+ * As per ontario.ca content guidelines, there is no Oxford comma.
27
+ *
28
+ * @param {Array<any>} arr - The array that you wish to print.
29
+ * @param {Conjunction} conjunctionType - Whether you want the sentence to end with 'and value.' or 'or value.'
30
+ *
31
+ * @returns {string}
32
+ */
33
+ export declare function printArray(arr: Array<any>, conjunctionType?: Conjunction): string;
34
+ /**
35
+ * Grabs the HTML element of the page.
36
+ *
37
+ * More targetted than document.documentElement as the documentElement could
38
+ * in theory be any element that is the top level. e.g. <div> if the page is not
39
+ * set up to be semantically correct.
40
+ *
41
+ * @returns {HTMLElement}
42
+ */
43
+ export declare function getRootHTMLElement(): HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ongov/ontario-design-system-component-library",
3
- "version": "4.3.0",
3
+ "version": "4.3.1-alpha.1",
4
4
  "private": false,
5
5
  "description": "Ontario Design System Component Library",
6
6
  "license": "Apache-2.0",
@@ -40,7 +40,7 @@
40
40
  "test:unit": "stencil test --spec"
41
41
  },
42
42
  "dependencies": {
43
- "@ongov/ontario-design-system-global-styles": "4.3.0",
43
+ "@ongov/ontario-design-system-global-styles": "4.3.1-alpha.1",
44
44
  "@stencil/core": "^4.12.2",
45
45
  "dotenv": "^16.3.1"
46
46
  },
@@ -102,5 +102,5 @@
102
102
  "collection:main": "dist/collection/index.js",
103
103
  "es2015": "dist/esm/index.mjs",
104
104
  "es2017": "dist/esm/index.mjs",
105
- "gitHead": "788db424e1fbcb72a4b9bf8da801da4765ab6154"
105
+ "gitHead": "ab7fc8a847e4155ec0ad01347484aaed6dc2d981"
106
106
  }
@@ -15,7 +15,7 @@
15
15
  border-radius: globalVariables.$global-radius;
16
16
  margin: spacing.$spacing-0 spacing.$spacing-7 spacing.$spacing-7 spacing.$spacing-0;
17
17
  padding: spacing.$spacing-0;
18
- /*
18
+ /*
19
19
  * Required for cards to stay the same height regardless of content size.
20
20
  * Without subtracting the margin-bottom amount the cards will be too large.
21
21
  */
@@ -47,6 +47,18 @@
47
47
  }
48
48
  }
49
49
 
50
+ .ontario-card__header-type--dark.ontario-card__description-false {
51
+ background-color: colours.$ontario-colour-black;
52
+ }
53
+
54
+ .ontario-card__header-type--light.ontario-card__description-false {
55
+ background-color: colours.$ontario-greyscale-5;
56
+ }
57
+
58
+ .ontario-card--image-true {
59
+ margin-top: spacing.$spacing-2 * -1;
60
+ }
61
+
50
62
  .ontario-card__card-type--horizontal {
51
63
  display: flex;
52
64
 
@@ -114,11 +126,6 @@
114
126
  text-decoration-color: colours.$ontario-colour-white;
115
127
  }
116
128
 
117
- .ontario-card--no-description & {
118
- padding: spacing.$spacing-4 spacing.$spacing-5;
119
- border-radius: 0 0 globalVariables.$global-radius globalVariables.$global-radius;
120
- }
121
-
122
129
  a {
123
130
  color: colours.$ontario-colour-black;
124
131
  text-decoration: none;
@@ -199,12 +199,14 @@ export class OntarioCard {
199
199
  * @returns the classes of the ontario cards based off the `cardType` and `headerType`.
200
200
  */
201
201
  private getClass() {
202
- if (this.cardTypeState === 'horizontal') {
203
- return `ontario-card ontario-card__card-type--horizontal ontario-card__image-${this.horizontalImagePositionType} ontario-card__image-size-${this.horizontalImageSizeType}`;
204
- } else {
205
- // Return other classes when cardTypeState is not 'horizontal'
206
- return `ontario-card ontario-card__header-type--${this.headerTypeState} ontario-card__card-type--${this.cardTypeState}`;
207
- }
202
+ const baseClass =
203
+ this.cardTypeState === 'horizontal'
204
+ ? `ontario-card ontario-card__card-type--horizontal ontario-card__image-${this.horizontalImagePositionType} ontario-card__image-size-${this.horizontalImageSizeType}`
205
+ : `ontario-card ontario-card__header-type--${this.headerTypeState} ontario-card__card-type--${this.cardTypeState}`;
206
+
207
+ const descriptionClass = this.description ? '' : ' ontario-card__description-false';
208
+
209
+ return `${baseClass}${descriptionClass}`;
208
210
  }
209
211
 
210
212
  private getHref() {
@@ -10,7 +10,7 @@ describe('ontario-card', () => {
10
10
  expect(page.root).toEqualHtml(`
11
11
  <ontario-card>
12
12
  <mock:shadow-root>
13
- <li class="ontario-card ontario-card__card-type--basic ontario-card__header-type--default">
13
+ <li class="ontario-card ontario-card__card-type--basic ontario-card__header-type--default ontario-card__description-false">
14
14
  <div class="ontario-card__text-container">
15
15
  <h2 class="ontario-card__heading">
16
16
  <a href="#"></a>
@@ -250,11 +250,22 @@ export class OntarioHeader {
250
250
  }
251
251
 
252
252
  /**
253
- * This listens for the `setAppLanguage` event sent from the test language toggler when it is is connected to the DOM. It is used for the initial language when the input component loads.
253
+ * This listens for the `setAppLanguage` event sent from the language toggle when it is is connected to the DOM.
254
+ * It is used for the initial language when the input component loads.
254
255
  */
255
256
  @Listen('setAppLanguage', { target: 'window' })
256
- handleSetAppLanguage(event: CustomEvent<Language>) {
257
+ handleSetAppLanguage(event: CustomEvent<Language> | Language) {
257
258
  this.language = validateLanguage(event);
259
+ this.parseMenuItems();
260
+ }
261
+
262
+ /**
263
+ * This listens for the `headerLanguageToggled` event sent from the language toggle when it is is connected to the DOM.
264
+ * It is used for changing the component language after the language toggle has been activated.
265
+ */
266
+ @Listen('headerLanguageToggled', { target: 'window' })
267
+ handleLanguageToggle(event: CustomEvent<{ oldLanguage: Language; newLanguage: Language }>) {
268
+ this.handleSetAppLanguage(event.detail.newLanguage);
258
269
  }
259
270
 
260
271
  /**
@@ -573,7 +584,6 @@ export class OntarioHeader {
573
584
  url={this.language === 'en' ? this.languageState?.frenchLink : this.languageState?.englishLink}
574
585
  size="default"
575
586
  customLanguageToggle={this.customLanguageToggle}
576
- language={this.language}
577
587
  ></ontario-language-toggle>
578
588
  <button
579
589
  class="ontario-header__search-toggler ontario-header-button ontario-header-button--without-outline ontario-hide-for-large"
@@ -674,7 +684,6 @@ export class OntarioHeader {
674
684
  size="small"
675
685
  url={this.language === 'en' ? this.languageState?.frenchLink : this.languageState?.englishLink}
676
686
  customLanguageToggle={this.customLanguageToggle}
677
- language={this.language}
678
687
  ></ontario-language-toggle>
679
688
  </div>
680
689
  </div>
@@ -87,7 +87,7 @@ describe('ontario-header', () => {
87
87
  </a>
88
88
  </div>
89
89
  <div class="ontario-application-header__lang-toggle ontario-columns ontario-small-6">
90
- <ontario-language-toggle language="en" size="small" url="/fr"></ontario-language-toggle>
90
+ <ontario-language-toggle size="small" url="/fr"></ontario-language-toggle>
91
91
  </div>
92
92
  </div>
93
93
  </header>
@@ -370,7 +370,7 @@ describe('ontario-header', () => {
370
370
  </button>
371
371
  </form>
372
372
  <div class="ontario-columns ontario-header__nav-right-container ontario-large-3 ontario-medium-8 ontario-small-10">
373
- <ontario-language-toggle language="en" size="default" url="/fr"></ontario-language-toggle>
373
+ <ontario-language-toggle size="default" url="/fr"></ontario-language-toggle>
374
374
  <button aria-controls="ontario-search-form-container" class="ontario-header-button ontario-header-button--without-outline ontario-header__search-toggler ontario-hide-for-large" id="ontario-header-search-toggler">
375
375
  <span class="ontario-header__icon-container"></span>
376
376
  <span class="ontario-show ontario-show-for-medium">
@@ -532,7 +532,7 @@ describe('ontario-header', () => {
532
532
  </a>
533
533
  </div>
534
534
  <div class="ontario-application-header__lang-toggle ontario-columns ontario-small-6">
535
- <ontario-language-toggle language="en" size="small" url="/fr"></ontario-language-toggle>
535
+ <ontario-language-toggle size="small" url="/fr"></ontario-language-toggle>
536
536
  </div>
537
537
  </div>
538
538
  </header>