@graupl/graupl 1.0.0-alpha.12 → 1.0.0-alpha.14

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 (180) hide show
  1. package/.github/workflows/codeql-analysis.yml +3 -3
  2. package/.husky/commit-msg +0 -1
  3. package/.husky/pre-commit +0 -1
  4. package/CHANGELOG.md +65 -0
  5. package/dist/base/button.css +1 -1
  6. package/dist/base/button.css.map +1 -1
  7. package/dist/base/form.css +1 -1
  8. package/dist/base/form.css.map +1 -1
  9. package/dist/base/link.css +1 -1
  10. package/dist/base/link.css.map +1 -1
  11. package/dist/base/table.css +1 -1
  12. package/dist/base/table.css.map +1 -1
  13. package/dist/base.css +1 -1
  14. package/dist/base.css.map +1 -1
  15. package/dist/component/alert.css +2 -0
  16. package/dist/component/alert.css.map +1 -0
  17. package/dist/component/card.css +2 -0
  18. package/dist/component/card.css.map +1 -0
  19. package/dist/component/carousel.css +2 -0
  20. package/dist/component/carousel.css.map +1 -0
  21. package/dist/component/input-group.css +1 -1
  22. package/dist/component/input-group.css.map +1 -1
  23. package/dist/component/menu.css +2 -0
  24. package/dist/component/menu.css.map +1 -0
  25. package/dist/component/navigation.css +2 -0
  26. package/dist/component/navigation.css.map +1 -0
  27. package/dist/component.css +1 -1
  28. package/dist/component.css.map +1 -1
  29. package/dist/graupl.css +1 -1
  30. package/dist/graupl.css.map +1 -1
  31. package/dist/layout/columns.css +1 -1
  32. package/dist/layout/columns.css.map +1 -1
  33. package/dist/layout/container.css.map +1 -1
  34. package/dist/layout/flex-columns.css +2 -0
  35. package/dist/layout/flex-columns.css.map +1 -0
  36. package/dist/layout.css +1 -1
  37. package/dist/layout.css.map +1 -1
  38. package/dist/normalize.css.map +1 -1
  39. package/dist/state/focus.css.map +1 -1
  40. package/dist/state.css.map +1 -1
  41. package/dist/theme/color.css.map +1 -1
  42. package/dist/theme/typography.css +1 -1
  43. package/dist/theme/typography.css.map +1 -1
  44. package/dist/theme.css +1 -1
  45. package/dist/theme.css.map +1 -1
  46. package/dist/utilities/alignment.css.map +1 -1
  47. package/dist/utilities/color.css.map +1 -1
  48. package/dist/utilities/display.css +1 -1
  49. package/dist/utilities/display.css.map +1 -1
  50. package/dist/utilities/flex.css.map +1 -1
  51. package/dist/utilities/height.css +2 -0
  52. package/dist/utilities/height.css.map +1 -0
  53. package/dist/utilities/inset.css.map +1 -1
  54. package/dist/utilities/justification.css.map +1 -1
  55. package/dist/utilities/list.css.map +1 -1
  56. package/dist/utilities/order.css +2 -0
  57. package/dist/utilities/order.css.map +1 -0
  58. package/dist/utilities/postion.css.map +1 -1
  59. package/dist/utilities/spacing.css +1 -1
  60. package/dist/utilities/spacing.css.map +1 -1
  61. package/dist/utilities/typography.css +1 -1
  62. package/dist/utilities/typography.css.map +1 -1
  63. package/dist/utilities/visibility.css.map +1 -1
  64. package/dist/utilities/width.css +2 -0
  65. package/dist/utilities/width.css.map +1 -0
  66. package/dist/utilities.css +1 -1
  67. package/dist/utilities.css.map +1 -1
  68. package/docs/.vitepress/config.js +39 -12
  69. package/docs/components/alert.md +130 -0
  70. package/docs/components/button.md +84 -0
  71. package/docs/components/card.md +369 -0
  72. package/docs/components/index.md +1 -0
  73. package/docs/components/inputgroup.md +159 -0
  74. package/docs/components/menu.md +326 -0
  75. package/docs/components/navigation.md +158 -0
  76. package/docs/content.md +237 -0
  77. package/docs/defaults.md +121 -0
  78. package/docs/forms.md +79 -0
  79. package/docs/functions.md +9 -0
  80. package/docs/getting-started.md +1 -0
  81. package/docs/index.md +1 -7
  82. package/docs/introduction.md +22 -2
  83. package/docs/layout.md +200 -0
  84. package/docs/mixins.md +47 -0
  85. package/docs/state.md +67 -0
  86. package/docs/theme.md +258 -0
  87. package/docs/utilities.md +357 -0
  88. package/eslint.config.js +1 -0
  89. package/index.html +760 -325
  90. package/package.json +5 -6
  91. package/scss/component/alert.scss +3 -0
  92. package/scss/component/card.scss +3 -0
  93. package/scss/component/carousel.scss +3 -0
  94. package/scss/component/menu.scss +3 -0
  95. package/scss/component/navigation.scss +3 -0
  96. package/scss/layout/flex-columns.scss +3 -0
  97. package/scss/utilities/height.scss +3 -0
  98. package/scss/utilities/order.scss +3 -0
  99. package/scss/utilities/width.scss +3 -0
  100. package/src/js/alert/Alert.js +511 -0
  101. package/src/js/alert/index.js +21 -0
  102. package/src/js/carousel/Carousel.js +1376 -0
  103. package/src/js/carousel/index.js +20 -0
  104. package/src/js/domHelpers.js +37 -0
  105. package/src/js/eventHandlers.js +32 -0
  106. package/src/js/navigation.js +34 -0
  107. package/src/js/validate.js +225 -0
  108. package/src/scss/_defaults.scss +15 -1
  109. package/src/scss/base/_index.scss +1 -1
  110. package/src/scss/base/button/_defaults.scss +15 -3
  111. package/src/scss/base/button/_index.scss +80 -120
  112. package/src/scss/base/button/_mixins.scss +164 -0
  113. package/src/scss/base/button/_variables.scss +43 -11
  114. package/src/scss/base/form/_index.scss +3 -5
  115. package/src/scss/base/form/_variables.scss +8 -0
  116. package/src/scss/base/link/_defaults.scss +37 -6
  117. package/src/scss/base/link/_index.scss +73 -13
  118. package/src/scss/base/link/_variables.scss +175 -18
  119. package/src/scss/base/table/_index.scss +3 -5
  120. package/src/scss/base/table/_variables.scss +8 -0
  121. package/src/scss/component/_index.scss +6 -1
  122. package/src/scss/component/alert/_defaults.scss +49 -0
  123. package/src/scss/component/alert/_index.scss +118 -0
  124. package/src/scss/component/alert/_variables.scss +170 -0
  125. package/src/scss/component/card/_defaults.scss +32 -0
  126. package/src/scss/component/card/_index.scss +177 -0
  127. package/src/scss/component/card/_variables.scss +185 -0
  128. package/src/scss/component/carousel/_defaults.scss +43 -0
  129. package/src/scss/component/carousel/_index.scss +182 -0
  130. package/src/scss/component/carousel/_variables.scss +104 -0
  131. package/src/scss/component/input-group/_index.scss +1 -1
  132. package/src/scss/component/menu/_defaults.scss +66 -0
  133. package/src/scss/component/menu/_index.scss +305 -0
  134. package/src/scss/component/menu/_variables.scss +495 -0
  135. package/src/scss/component/navigation/_defaults.scss +29 -0
  136. package/src/scss/component/navigation/_index.scss +189 -0
  137. package/src/scss/component/navigation/_variables.scss +237 -0
  138. package/src/scss/functions/_theme.scss +16 -0
  139. package/src/scss/layout/_index.scss +2 -1
  140. package/src/scss/layout/columns/_index.scss +23 -1
  141. package/src/scss/layout/container/_index.scss +1 -1
  142. package/src/scss/layout/flex-columns/_defaults.scss +18 -0
  143. package/src/scss/layout/flex-columns/_index.scss +77 -0
  144. package/src/scss/layout/flex-columns/_variables.scss +26 -0
  145. package/src/scss/mixins/_layer.scss +2 -4
  146. package/src/scss/mixins/_media-queries.scss +8 -0
  147. package/src/scss/mixins/_visually-hidden.scss +20 -0
  148. package/src/scss/state/_index.scss +1 -1
  149. package/src/scss/state/focus/_index.scss +1 -1
  150. package/src/scss/theme/_index.scss +1 -1
  151. package/src/scss/theme/color/_index.scss +1 -1
  152. package/src/scss/theme/typography/_defaults.scss +1 -1
  153. package/src/scss/theme/typography/_index.scss +1 -1
  154. package/src/scss/theme/typography/_variables.scss +5 -2
  155. package/src/scss/utilities/_index.scss +5 -1
  156. package/src/scss/utilities/alignment/_index.scss +1 -1
  157. package/src/scss/utilities/color/_index.scss +1 -1
  158. package/src/scss/utilities/display/_defaults.scss +2 -0
  159. package/src/scss/utilities/display/_index.scss +11 -1
  160. package/src/scss/utilities/flex/_index.scss +1 -1
  161. package/src/scss/utilities/height/_defaults.scss +38 -0
  162. package/src/scss/utilities/height/_index.scss +23 -0
  163. package/src/scss/utilities/height/_variables.scss +6 -0
  164. package/src/scss/utilities/inset/_index.scss +1 -1
  165. package/src/scss/utilities/justification/_index.scss +1 -1
  166. package/src/scss/utilities/list/_index.scss +1 -1
  167. package/src/scss/utilities/order/_defaults.scss +19 -0
  168. package/src/scss/utilities/order/_index.scss +35 -0
  169. package/src/scss/utilities/order/_variables.scss +6 -0
  170. package/src/scss/utilities/position/_index.scss +1 -1
  171. package/src/scss/utilities/ratio/_defaults.scss +25 -0
  172. package/src/scss/utilities/ratio/_index.scss +34 -0
  173. package/src/scss/utilities/ratio/_variables.scss +9 -0
  174. package/src/scss/utilities/spacing/_index.scss +34 -17
  175. package/src/scss/utilities/typography/_index.scss +1 -1
  176. package/src/scss/utilities/visibility/_index.scss +1 -1
  177. package/src/scss/utilities/width/_defaults.scss +38 -0
  178. package/src/scss/utilities/width/_index.scss +23 -0
  179. package/src/scss/utilities/width/_variables.scss +6 -0
  180. package/stylelint.config.js +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graupl/graupl",
3
- "version": "1.0.0-alpha.12",
3
+ "version": "1.0.0-alpha.14",
4
4
  "description": "A modular and modern CSS framework.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -15,7 +15,7 @@
15
15
  }
16
16
  },
17
17
  "scripts": {
18
- "prepare": "husky install",
18
+ "prepare": "husky",
19
19
  "commit": "git cz",
20
20
  "eslint": "eslint .",
21
21
  "prettier": "prettier '**/*.{js,mjs,cjs,scss,sass}'",
@@ -49,10 +49,9 @@
49
49
  "commitizen": "^4.3.0",
50
50
  "cssnano": "^7.0.1",
51
51
  "cz-conventional-changelog": "^3.3.0",
52
- "eslint": "^8.57.0",
52
+ "eslint": "^9.11.1",
53
53
  "eslint-config-prettier": "^9.1.0",
54
- "eslint-config-standard": "^17.1.0",
55
- "eslint-plugin-jsdoc": "^48.2.3",
54
+ "eslint-plugin-jsdoc": "^50.2.4",
56
55
  "globals": "^15.0.0",
57
56
  "husky": "^9.0.11",
58
57
  "lint-staged": "^15.2.2",
@@ -65,7 +64,7 @@
65
64
  "standard-version": "^9.5.0",
66
65
  "stylelint": "^16.3.1",
67
66
  "stylelint-config-property-sort-order-smacss": "^10.0.0",
68
- "stylelint-config-sass-guidelines": "^11.1.0",
67
+ "stylelint-config-sass-guidelines": "^12.1.0",
69
68
  "stylelint-config-standard-scss": "^13.1.0",
70
69
  "stylelint-prettier": "^5.0.0",
71
70
  "vite": "^5.2.8",
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl alert component.
2
+
3
+ @forward "../../src/scss/component/alert";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl card component.
2
+
3
+ @forward "../../src/scss/component/card";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl carousel component.
2
+
3
+ @forward "../../src/scss/component/carousel";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl menu component.
2
+
3
+ @forward "../../src/scss/component/menu";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl navigation component.
2
+
3
+ @forward "../../src/scss/component/navigation";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl flex columns layout.
2
+
3
+ @forward "../../src/scss/layout/flex-columns";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl height utilities.
2
+
3
+ @forward "../../src/scss/utilities/height";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl order utilities.
2
+
3
+ @forward "../../src/scss/utilities/order";
@@ -0,0 +1,3 @@
1
+ // @graupl/graupl width utilities.
2
+
3
+ @forward "../../src/scss/utilities/width";
@@ -0,0 +1,511 @@
1
+ /**
2
+ * @file
3
+ * The alert class.
4
+ */
5
+
6
+ import { isValidClassList, isValidInstance, isValidType } from "../validate.js";
7
+ import { addClass, removeClass } from "../domHelpers.js";
8
+ import { keyPress, preventEvent } from "../eventHandlers.js";
9
+
10
+ class Alert {
11
+ /**
12
+ * The HTML elements for the alert in the DOM.
13
+ *
14
+ * @protected
15
+ *
16
+ * @type {Object<HTMLElement>}
17
+ */
18
+ _dom = {
19
+ alert: null,
20
+ controller: null,
21
+ };
22
+
23
+ /**
24
+ * A flag to determine if the alert is hidden.
25
+ *
26
+ * @protected
27
+ *
28
+ * @type {boolean}
29
+ */
30
+ _hidden = false;
31
+
32
+ /**
33
+ * The class to use to show the alert.
34
+ *
35
+ * @protected
36
+ *
37
+ * @type {string|string[]}
38
+ */
39
+ _showClass = "";
40
+
41
+ /**
42
+ * The class to use to hide the alert.
43
+ *
44
+ * @protected
45
+ *
46
+ * @type {string|string[]}
47
+ */
48
+ _hideClass = "";
49
+
50
+ /**
51
+ * The class to use when transitioning the alert.
52
+ *
53
+ * @protected
54
+ *
55
+ * @type {string|string[]}
56
+ */
57
+ _transitionClass = "";
58
+
59
+ /**
60
+ * The time in milliseconds the transition will take.
61
+ *
62
+ * @protected
63
+ *
64
+ * @type {number}
65
+ */
66
+ _transitionTimer = 150;
67
+
68
+ /**
69
+ * An array of error messages generated by the alert.
70
+ *
71
+ * @protected
72
+ *
73
+ * @type {string[]}
74
+ */
75
+ _errors = [];
76
+
77
+ /**
78
+ * The event that is triggered when the alert is shown.
79
+ *
80
+ * @protected
81
+ *
82
+ * @event grauplAlertShow
83
+ *
84
+ * @type {CustomEvent}
85
+ *
86
+ * @property {boolean} bubbles - A flag to buggle the event.
87
+ * @property {Object<Alert>} detail - The details object container the Alert itself.
88
+ */
89
+ _showEvent = new CustomEvent("grauplAlertShow", {
90
+ bubbles: true,
91
+ detail: { alert: this },
92
+ });
93
+
94
+ /**
95
+ * The event that is triggered when the alert is hidden.
96
+ *
97
+ * @protected
98
+ *
99
+ * @event grauplAlertHide
100
+ *
101
+ * @type {CustomEvent}
102
+ *
103
+ * @property {boolean} bubbles - A flag to bubble the event.
104
+ * @property {Object<Alert>} detail - The details object containing the Alert itself.
105
+ */
106
+ _hideEvent = new CustomEvent("grauplAlertHide", {
107
+ bubbles: true,
108
+ detail: { alert: this },
109
+ });
110
+
111
+ /**
112
+ * Constructs a new `Alert`.
113
+ *
114
+ * @param {object} options - The options object.
115
+ * @param {HTMLElement} options.alertElement - The alert element.
116
+ * @param {?HTMLElement} [options.controllerElement = null] - The controller element.
117
+ * @param {string|string[]|null} [options.showClass = show] - The class to add when the alert is shown.
118
+ * @param {string|string[]|null} [options.hideClass = hide] - The class to add when
119
+ * @param {string|string[]|null} [options.transitionClass = transitioning] - The class to add when the alert is transitioning between shown and hidden.
120
+ * @param {number} [options.transitionTimer = 150] - The time in milliseconds the transition will take.
121
+ * @param {boolean} [options.isHidden = false] - A flag to determine the initial state of the alert.
122
+ * @param {boolean} [options.initialize = false] - AA flag to initialize the alert immediately upon creation.
123
+ */
124
+ constructor({
125
+ alertElement,
126
+ controllerElement = null,
127
+ showClass = "show",
128
+ hideClass = "hide",
129
+ transitionClass = "transitioning",
130
+ transitionTimer = 150,
131
+ isHidden = false,
132
+ initialize = false,
133
+ }) {
134
+ this._dom.alert = alertElement;
135
+ this._dom.controller = controllerElement;
136
+ this._showClass = showClass || "";
137
+ this._hideClass = hideClass || "";
138
+ this._transitionClass = transitionClass || "";
139
+ this._transitionTimer = transitionTimer;
140
+ this._hidden = isHidden;
141
+
142
+ if (initialize) {
143
+ this.initialize();
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Initializes the alert.
149
+ */
150
+ initialize() {
151
+ try {
152
+ if (!this._validate()) {
153
+ throw new Error(
154
+ `Graupl Alert: cannot initialize alert. The following errors have been found:\n - ${this.errors.join(
155
+ "\n - "
156
+ )}`
157
+ );
158
+ }
159
+
160
+ this._handleClick();
161
+ this._handleKeydown();
162
+ this._handleKeyup();
163
+ } catch (error) {
164
+ console.error(error);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * The HTML elements for the alert in the DOM.
170
+ *
171
+ * @readonly
172
+ *
173
+ * @see _dom
174
+ *
175
+ * @type {object}
176
+ */
177
+ get dom() {
178
+ return this._dom;
179
+ }
180
+
181
+ /**
182
+ * The class to use the show the alert.
183
+ *
184
+ * @type {string|string[]}
185
+ *
186
+ * @see _showClass
187
+ */
188
+ get showClass() {
189
+ return this._showClass;
190
+ }
191
+
192
+ /**
193
+ * The class to use to hide the alert.
194
+ *
195
+ * @type {string|string[]}
196
+ *
197
+ * @see _hideClass
198
+ */
199
+ get hideClass() {
200
+ return this._hideClass;
201
+ }
202
+
203
+ /**
204
+ * The class to use when transitioning the alert.
205
+ *
206
+ * @type {string|string[]}
207
+ *
208
+ * @see _transitionClass
209
+ */
210
+ get transitionClass() {
211
+ return this._transitionClass;
212
+ }
213
+
214
+ /**
215
+ * The time in milliseconds the transition will take.
216
+ *
217
+ * @type {number}
218
+ *
219
+ * @see _transitionTimer
220
+ */
221
+ get transitionTimer() {
222
+ return this._transitionTimer;
223
+ }
224
+
225
+ set showClass(value) {
226
+ isValidClassList({ showClass: value });
227
+
228
+ if (this._showClass !== value) {
229
+ this._showClass = value;
230
+ }
231
+ }
232
+
233
+ set hideClass(value) {
234
+ isValidClassList({ hideClass: value });
235
+
236
+ if (this._hideClass !== value) {
237
+ this._hideClass = value;
238
+ }
239
+ }
240
+
241
+ set transitionClass(value) {
242
+ isValidClassList({ transitionClass: value });
243
+
244
+ if (this._transitionClass !== value) {
245
+ this._transitionClass = value;
246
+ }
247
+ }
248
+
249
+ set transitionTimer(value) {
250
+ isValidType("number", { transitionTimer: value });
251
+
252
+ if (this._transitionTimer !== value) {
253
+ this._transitionTimer = value;
254
+ }
255
+ }
256
+
257
+ /**
258
+ * Validates all aspects of the alert to ensure proper functionality.
259
+ *
260
+ * @protected
261
+ *
262
+ * @return {boolean} - The result of the validation.
263
+ */
264
+ _validate() {
265
+ let check = true;
266
+
267
+ // HTML element checks.
268
+ let htmlElementChecks;
269
+
270
+ if (this._dom.controller !== null) {
271
+ htmlElementChecks = isValidInstance(HTMLElement, {
272
+ alertElement: this._dom.alert,
273
+ controllerElement: this._dom.controller,
274
+ });
275
+ } else {
276
+ htmlElementChecks = isValidInstance(HTMLElement, {
277
+ alertElement: this._dom.alert,
278
+ });
279
+ }
280
+
281
+ if (!htmlElementChecks.status) {
282
+ this._errors.push(htmlElementChecks.message);
283
+ check = false;
284
+ }
285
+
286
+ // Class list checks.
287
+ if (this._showClass !== "") {
288
+ const showClassCheck = isValidClassList({ showClass: this._showClass });
289
+
290
+ if (!showClassCheck.status) {
291
+ this._errors.push(showClassCheck.message);
292
+ check = false;
293
+ }
294
+ }
295
+
296
+ if (this._hideClass !== "") {
297
+ const hideClassCheck = isValidClassList({ hideClass: this._hideClass });
298
+
299
+ if (!hideClassCheck.status) {
300
+ this._errors.push(hideClassCheck.message);
301
+ check = false;
302
+ }
303
+ }
304
+
305
+ if (this._transitionClass !== "") {
306
+ const transitionClassCheck = isValidClassList({
307
+ transitionClass: this._transitionClass,
308
+ });
309
+
310
+ if (!transitionClassCheck.status) {
311
+ this._errors.push(transitionClassCheck.message);
312
+ check = false;
313
+ }
314
+ }
315
+
316
+ // Transition timer check.
317
+ const transitionTimerCheck = isValidType("number", {
318
+ transitionTimer: this._transitionTimer,
319
+ });
320
+
321
+ if (!transitionTimerCheck.status) {
322
+ this._errors.push(transitionTimerCheck.message);
323
+ check = false;
324
+ }
325
+
326
+ // Hidden check.
327
+ const hiddenCheck = isValidType("boolean", { isHidden: this._hidden });
328
+
329
+ if (!hiddenCheck.status) {
330
+ this._errors.push(hiddenCheck.message);
331
+ check = false;
332
+ }
333
+
334
+ return check;
335
+ }
336
+
337
+ /**
338
+ * Shows the alert.
339
+ *
340
+ * @fires grauplAlertShow
341
+ *
342
+ * @param {boolean} [emit = true] - A toggle to emit the show event once shown.
343
+ */
344
+ show(emit = true) {
345
+ if (!this._hidden) {
346
+ return;
347
+ }
348
+
349
+ // If we're dealing with transition classes, then we need to utilize
350
+ // requestAnimationFrame to add the transition class, remove the hide class,
351
+ // add the show class, and finally remove the transition class.
352
+ if (this.transitionClass !== "") {
353
+ addClass(this.transitionClass, this.dom.alert);
354
+
355
+ requestAnimationFrame(() => {
356
+ if (this.hideClass !== "") {
357
+ removeClass(this.hideClass, this.dom.alert);
358
+ }
359
+
360
+ requestAnimationFrame(() => {
361
+ if (this.showClass !== "") {
362
+ addClass(this.showClass, this.dom.alert);
363
+ }
364
+
365
+ requestAnimationFrame(() => {
366
+ removeClass(this.transitionClass, this.dom.alert);
367
+ });
368
+ });
369
+ });
370
+ } else {
371
+ // Add the show class
372
+ if (this.showClass !== "") {
373
+ addClass(this.showClass, this.dom.alert);
374
+ }
375
+
376
+ // Remove the hide class.
377
+ if (this.hideClass !== "") {
378
+ removeClass(this.hideClass, this.dom.alert);
379
+ }
380
+ }
381
+
382
+ this._hidden = false;
383
+
384
+ if (emit) {
385
+ this.dom.alert.dispatchEvent(this._hideEvent);
386
+ }
387
+ }
388
+
389
+ /**
390
+ * Hides the alert.
391
+ *
392
+ * @fires grauplAlertHide
393
+ *
394
+ * @param {boolean} [emit = true] - A toggle to emit the hide event once shown.
395
+ */
396
+ hide(emit = true) {
397
+ if (this._hidden) {
398
+ return;
399
+ }
400
+ // If we're dealing with transition classes, then we need to utilize
401
+ // requestAnimationFrame to add the transition class, remove the show class,
402
+ // add the hide class, and finally remove the transition class.
403
+ if (this.transitionClass !== "") {
404
+ addClass(this.transitionClass, this.dom.alert);
405
+
406
+ requestAnimationFrame(() => {
407
+ if (this.showClass !== "") {
408
+ removeClass(this.showClass, this.dom.alert);
409
+ }
410
+
411
+ requestAnimationFrame(() => {
412
+ if (this.transitionTimer > 0) {
413
+ setTimeout(() => {
414
+ if (this.hideClass !== "") {
415
+ addClass(this.hideClass, this.dom.alert);
416
+ }
417
+
418
+ requestAnimationFrame(() => {
419
+ removeClass(this.transitionClass, this.dom.alert);
420
+ });
421
+ }, this.transitionTimer);
422
+ } else {
423
+ if (this.hideClass !== "") {
424
+ addClass(this.hideClass, this.dom.alert);
425
+ }
426
+
427
+ requestAnimationFrame(() => {
428
+ removeClass(this.transitionClass, this.dom.alert);
429
+ });
430
+ }
431
+ });
432
+ });
433
+ } else {
434
+ // Add the hide class
435
+ if (this.hideClass !== "") {
436
+ addClass(this.hideClass, this.dom.alert);
437
+ }
438
+
439
+ // Remove the show class.
440
+ if (this.showClass !== "") {
441
+ removeClass(this.showClass, this.dom.alert);
442
+ }
443
+ }
444
+
445
+ this._hidden = true;
446
+
447
+ if (emit) {
448
+ this.dom.alert.dispatchEvent(this._hideEvent);
449
+ }
450
+ }
451
+
452
+ /**
453
+ * Handles click events throughout the alert for proper use.
454
+ *
455
+ * - Adds a `pointerup` listener to the controller that will hide the alert.
456
+ *
457
+ * @protected
458
+ */
459
+ _handleClick() {
460
+ if (this.dom.controller === null) {
461
+ return;
462
+ }
463
+
464
+ this.dom.controller.addEventListener("pointerup", () => this.hide());
465
+ }
466
+
467
+ /**
468
+ * Handles keydown events throughout the alert for proper use.
469
+ *
470
+ * This method exists to assist the _handleKeyup method.
471
+ *
472
+ * - Adds a `keydown` listener to the controller (if it exists).
473
+ * - Blocks propagation on "Space" and "Enter" keys.
474
+ */
475
+ _handleKeydown() {
476
+ if (this.dom.controller === null) {
477
+ return;
478
+ }
479
+
480
+ this.dom.controller.addEventListener("keydown", (event) => {
481
+ const key = keyPress(event);
482
+
483
+ // Prevent default behavior for space and enter keys.
484
+ if (key === "Space" || key === "Enter") {
485
+ preventEvent(event);
486
+ }
487
+ });
488
+ }
489
+
490
+ /**
491
+ * Handles keyup events throughout the alert for proper use.
492
+ *
493
+ * - Adds a `keyup` listener to the controller (if it exists).
494
+ * - Hides the alert when the user hits "Space" or "Enter".
495
+ */
496
+ _handleKeyup() {
497
+ if (this.dom.controller === null) {
498
+ return;
499
+ }
500
+
501
+ this.dom.controller.addEventListener("keyup", (event) => {
502
+ const key = keyPress(event);
503
+
504
+ if (key === "Space" || key === "Enter") {
505
+ this.hide();
506
+ }
507
+ });
508
+ }
509
+ }
510
+
511
+ export default Alert;
@@ -0,0 +1,21 @@
1
+ import Alert from "./Alert.js";
2
+
3
+ document.addEventListener("DOMContentLoaded", () => {
4
+ const alerts = [];
5
+
6
+ document.querySelectorAll(".alert").forEach((alertElement) => {
7
+ const alert = new Alert({
8
+ alertElement,
9
+ controllerElement: alertElement.querySelector(".alert-dismisser") || null,
10
+ initialize: true,
11
+ });
12
+
13
+ alerts.push(alert);
14
+ });
15
+
16
+ const graupl = window.Graupl || {};
17
+
18
+ graupl.alerts = alerts;
19
+
20
+ window.Graupl = graupl;
21
+ });