@cagovweb/state-template 1.1.0-beta.4 → 1.1.0-beta.5

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.
@@ -6358,91 +6358,94 @@ window.addEventListener("load", () => {
6358
6358
  // retain scroll position
6359
6359
 
6360
6360
  //@ts-check
6361
- /**
6362
- * Accordion web component that collapses and expands content inside itself on click.
6363
- *
6364
- * @element cagov-accordion
6365
- *
6366
- *
6367
- * @fires click - Default events which may be listened to in order to discover most popular accordions
6368
- *
6369
- * @attr {string} open - set on the internal details element
6370
- * If this is true the accordion will be open before any user interaction.
6371
- *
6372
- * @cssprop --primary-700 - Default value of #165ac2, used for all colors of borders and fills
6373
- * @cssprop --primary-900 - Default value of #003588, used for background on hover
6374
- *
6375
- */
6376
- class CaGovAccordion extends HTMLElement {
6377
- connectedCallback() {
6378
- this.summaryEl = this.querySelector("summary");
6379
- // trigger the opening and closing height change animation on summary click
6380
-
6381
- this.setHeight();
6382
- this.summaryEl.addEventListener("click", this.listen.bind(this));
6383
- this.summaryEl.insertAdjacentHTML(
6384
- "beforeend",
6385
- `<div class="cagov-open-indicator" aria-hidden="true" />`
6386
- );
6387
- this.detailsEl = this.querySelector("details");
6388
- this.bodyEl = this.querySelector(".accordion-body");
6389
6361
 
6390
- window.addEventListener("resize", this.debounce(this.setHeight).bind(this));
6391
- }
6362
+ window.addEventListener("load", () => {
6363
+ /**
6364
+ * Accordion web component that collapses and expands content inside itself on click.
6365
+ *
6366
+ * @element cagov-accordion
6367
+ *
6368
+ *
6369
+ * @fires click - Default events which may be listened to in order to discover most popular accordions
6370
+ *
6371
+ * @attr {string} open - set on the internal details element
6372
+ * If this is true the accordion will be open before any user interaction.
6373
+ *
6374
+ * @cssprop --primary-700 - Default value of #165ac2, used for all colors of borders and fills
6375
+ * @cssprop --primary-900 - Default value of #003588, used for background on hover
6376
+ *
6377
+ */
6378
+ class CaGovAccordion extends HTMLElement {
6379
+ connectedCallback() {
6380
+ this.summaryEl = this.querySelector("summary");
6381
+ // trigger the opening and closing height change animation on summary click
6382
+
6383
+ this.setHeight();
6384
+ this.summaryEl.addEventListener("click", this.listen.bind(this));
6385
+ this.summaryEl.insertAdjacentHTML(
6386
+ "beforeend",
6387
+ `<div class="cagov-open-indicator" aria-hidden="true" />`
6388
+ );
6389
+ this.detailsEl = this.querySelector("details");
6390
+ this.bodyEl = this.querySelector(".accordion-body");
6392
6391
 
6393
- setHeight() {
6394
- window.requestAnimationFrame(() => {
6395
- // delay so the desired height is readable in all browsers
6396
- this.closedHeightInt = this.summaryEl.scrollHeight + 2;
6397
- this.closedHeight = `${this.closedHeightInt}px`;
6392
+ window.addEventListener(
6393
+ "resize",
6394
+ this.debounce(this.setHeight).bind(this)
6395
+ );
6396
+ }
6398
6397
 
6399
- // apply initial height
6398
+ setHeight() {
6399
+ window.requestAnimationFrame(() => {
6400
+ // delay so the desired height is readable in all browsers
6401
+ this.closedHeightInt = this.summaryEl.scrollHeight + 2;
6402
+ this.closedHeight = `${this.closedHeightInt}px`;
6403
+
6404
+ // apply initial height
6405
+ if (this.detailsEl.hasAttribute("open")) {
6406
+ // if open get scrollHeight
6407
+ this.detailsEl.style.height = `${
6408
+ this.bodyEl.scrollHeight + this.closedHeightInt
6409
+ }px`;
6410
+ } else {
6411
+ // else apply closed height
6412
+ this.detailsEl.style.height = this.closedHeight;
6413
+ }
6414
+ });
6415
+ }
6416
+
6417
+ listen() {
6400
6418
  if (this.detailsEl.hasAttribute("open")) {
6401
- // if open get scrollHeight
6402
- this.detailsEl.style.height = `${
6403
- this.bodyEl.scrollHeight + this.closedHeightInt
6404
- }px`;
6405
- } else {
6406
- // else apply closed height
6419
+ // was open, now closing
6407
6420
  this.detailsEl.style.height = this.closedHeight;
6421
+ } else {
6422
+ // was closed, opening
6423
+ window.requestAnimationFrame(() => {
6424
+ // delay so the desired height is readable in all browsers
6425
+ this.detailsEl.style.height = `${
6426
+ this.bodyEl.scrollHeight + this.closedHeightInt
6427
+ }px`;
6428
+ });
6408
6429
  }
6409
- });
6410
- }
6430
+ }
6411
6431
 
6412
- listen() {
6413
- if (this.detailsEl.hasAttribute("open")) {
6414
- // was open, now closing
6415
- this.detailsEl.style.height = this.closedHeight;
6416
- } else {
6417
- // was closed, opening
6418
- window.requestAnimationFrame(() => {
6419
- // delay so the desired height is readable in all browsers
6420
- this.detailsEl.style.height = `${
6421
- this.bodyEl.scrollHeight + this.closedHeightInt
6422
- }px`;
6423
- });
6432
+ /**
6433
+ * @param {function} func
6434
+ */
6435
+ debounce(func, timeout = 300) {
6436
+ let timer;
6437
+ return (/** @type {any} */ ...args) => {
6438
+ window.clearTimeout(timer);
6439
+ timer = window.setTimeout(() => {
6440
+ func.apply(this, args);
6441
+ }, timeout);
6442
+ };
6424
6443
  }
6425
6444
  }
6426
6445
 
6427
- /**
6428
- * @param {function} func
6429
- */
6430
- debounce(func, timeout = 300) {
6431
- let timer;
6432
- return (/** @type {any} */ ...args) => {
6433
- window.clearTimeout(timer);
6434
- timer = window.setTimeout(() => {
6435
- func.apply(this, args);
6436
- }, timeout);
6437
- };
6438
- }
6439
- }
6440
- window.addEventListener("load", () => {
6441
6446
  window.customElements.define("cagov-accordion", CaGovAccordion);
6442
6447
  });
6443
6448
 
6444
- //document.querySelector('head').appendChild(style);
6445
-
6446
6449
  //@ts-check
6447
6450
  window.addEventListener("load", () => {
6448
6451
  const w = window;
@@ -8046,56 +8049,56 @@ window.addEventListener("load", () => {
8046
8049
  document.body.scrollTop = 0; // For Safari
8047
8050
  document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
8048
8051
  };
8049
- });
8050
8052
 
8051
- // If an user scrolls down the page for more than 400px activate back to top button
8052
- // othervise keep it invisible
8053
- let timer = 0;
8053
+ // If an user scrolls down the page for more than 400px activate back to top button
8054
+ // othervise keep it invisible
8055
+ let timer = 0;
8054
8056
 
8055
- let lastScrollTop = 0;
8057
+ let lastScrollTop = 0;
8056
8058
 
8057
- window.addEventListener(
8058
- "scroll",
8059
- () => {
8060
- const returnTopButton = document.querySelector(".return-top");
8061
- if (!returnTopButton) return;
8059
+ window.addEventListener(
8060
+ "scroll",
8061
+ () => {
8062
+ const returnTopButton = document.querySelector(".return-top");
8063
+ if (!returnTopButton) return;
8062
8064
 
8063
- const st = window.pageYOffset || document.documentElement.scrollTop;
8064
- if (st > lastScrollTop) {
8065
- // downscroll code
8066
- returnTopButton.classList.remove("is-visible");
8067
- } else if (
8068
- document.body.scrollTop >= 400 ||
8069
- document.documentElement.scrollTop >= 400
8070
- ) {
8071
- // upscroll code
8065
+ const st = window.pageYOffset || document.documentElement.scrollTop;
8066
+ if (st > lastScrollTop) {
8067
+ // downscroll code
8068
+ returnTopButton.classList.remove("is-visible");
8069
+ } else if (
8070
+ document.body.scrollTop >= 400 ||
8071
+ document.documentElement.scrollTop >= 400
8072
+ ) {
8073
+ // upscroll code
8072
8074
 
8073
- if (timer) {
8074
- window.clearTimeout(timer);
8075
- }
8076
- returnTopButton.classList.add("is-visible");
8075
+ if (timer) {
8076
+ window.clearTimeout(timer);
8077
+ }
8078
+ returnTopButton.classList.add("is-visible");
8077
8079
 
8078
- timer = window.setTimeout(() => {
8080
+ timer = window.setTimeout(() => {
8081
+ returnTopButton.classList.remove("is-visible");
8082
+ }, 2000); //Back to top removes itself after 2 sec of inactivity
8083
+ }
8084
+ // bottom of the page
8085
+ else {
8079
8086
  returnTopButton.classList.remove("is-visible");
8080
- }, 2000); //Back to top removes itself after 2 sec of inactivity
8081
- }
8082
- // bottom of the page
8083
- else {
8084
- returnTopButton.classList.remove("is-visible");
8085
- }
8087
+ }
8086
8088
 
8087
- lastScrollTop = st <= 0 ? 0 : st; // For Mobile or negative scrolling
8088
- },
8089
- false
8090
- );
8089
+ lastScrollTop = st <= 0 ? 0 : st; // For Mobile or negative scrolling
8090
+ },
8091
+ false
8092
+ );
8091
8093
 
8092
- // Hittin' rock bottom
8093
- window.addEventListener("scroll", () => {
8094
- const returnTopButton = document.querySelector(".return-top");
8095
- if (!returnTopButton) return;
8096
- if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
8097
- returnTopButton.classList.add("is-visible");
8098
- }
8094
+ // Hittin' rock bottom
8095
+ window.addEventListener("scroll", () => {
8096
+ const returnTopButton = document.querySelector(".return-top");
8097
+ if (!returnTopButton) return;
8098
+ if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
8099
+ returnTopButton.classList.add("is-visible");
8100
+ }
8101
+ });
8099
8102
  });
8100
8103
 
8101
8104
  //@ts-check
@@ -8377,13 +8380,13 @@ window.addEventListener("load", () => {
8377
8380
  /* -----------------------------------------
8378
8381
  PAGINATION - /src/js/cagov/pagination.js
8379
8382
  ----------------------------------------- */
8380
-
8381
- /**
8382
- * @param {string} label
8383
- * @param {number} number
8384
- */
8385
- function pageListItem(label, number) {
8386
- return `<li class="cagov-pagination__item">
8383
+ window.addEventListener("load", () => {
8384
+ /**
8385
+ * @param {string} label
8386
+ * @param {number} number
8387
+ */
8388
+ function pageListItem(label, number) {
8389
+ return `<li class="cagov-pagination__item">
8387
8390
  <a
8388
8391
  href="javascript:void(0);"
8389
8392
  class="cagov-pagination__button"
@@ -8393,27 +8396,27 @@ function pageListItem(label, number) {
8393
8396
  ${number}
8394
8397
  </a>
8395
8398
  </li>`;
8396
- }
8399
+ }
8397
8400
 
8398
- function pageOverflow() {
8399
- return `<li
8401
+ function pageOverflow() {
8402
+ return `<li
8400
8403
  class="cagov-pagination__item cagov-pagination__overflow"
8401
8404
  role="presentation"
8402
8405
  >
8403
8406
  <span> … </span>
8404
8407
  </li>`;
8405
- }
8408
+ }
8406
8409
 
8407
- /**
8408
- * @param {string} next
8409
- * @param {string} previous
8410
- * @param {string} page
8411
- * @param {number} currentPage
8412
- * @param {number} totalPages
8413
- */
8414
- function templateHTML(next, previous, page, currentPage, totalPages) {
8415
- const unbounded = totalPages == -1;
8416
- return `<nav aria-label="Pagination" class="cagov-pagination">
8410
+ /**
8411
+ * @param {string} next
8412
+ * @param {string} previous
8413
+ * @param {string} page
8414
+ * @param {number} currentPage
8415
+ * @param {number} totalPages
8416
+ */
8417
+ function templateHTML(next, previous, page, currentPage, totalPages) {
8418
+ const unbounded = totalPages == -1;
8419
+ return `<nav aria-label="Pagination" class="cagov-pagination">
8417
8420
  <ul class="cagov-pagination__list">
8418
8421
  <li class="cagov-pagination__item">
8419
8422
  <a
@@ -8472,9 +8475,9 @@ function templateHTML(next, previous, page, currentPage, totalPages) {
8472
8475
  </li>
8473
8476
  </ul>
8474
8477
  </nav>`;
8475
- }
8478
+ }
8476
8479
 
8477
- const styles = `
8480
+ const styles = `
8478
8481
  cagov-pagination {
8479
8482
  white-space: nowrap;
8480
8483
  font-size: .9rem;
@@ -8518,148 +8521,147 @@ cagov-pagination .cagov-pagination__item:has(.cagov-pagination__link-inactive) {
8518
8521
  }
8519
8522
  `;
8520
8523
 
8521
- /**
8522
- * Pagination web component
8523
- *
8524
- * @element cagov-pagination
8525
- *
8526
- * @fires paginationClick - custom event with object with detail value of current page: {detail: 1}
8527
- *
8528
- * @attr {string} [data-yes] - "Yes";
8529
- * @attr {string} [data-no] - "No";
8530
- *
8531
- * @cssprop --primary-700 - Default value of #165ac2, used for text, border color
8532
- */
8533
- class CAGovPagination extends HTMLElement {
8534
- constructor() {
8535
- super();
8524
+ /**
8525
+ * Pagination web component
8526
+ *
8527
+ * @element cagov-pagination
8528
+ *
8529
+ * @fires paginationClick - custom event with object with detail value of current page: {detail: 1}
8530
+ *
8531
+ * @attr {string} [data-yes] - "Yes";
8532
+ * @attr {string} [data-no] - "No";
8533
+ *
8534
+ * @cssprop --primary-700 - Default value of #165ac2, used for text, border color
8535
+ */
8536
+ class CAGovPagination extends HTMLElement {
8537
+ constructor() {
8538
+ super();
8536
8539
 
8537
- if (!document.querySelector("#cagov-pagination-styles")) {
8538
- const style = document.createElement("style");
8539
- style.id = "cagov-pagination-styles";
8540
- style.textContent = styles;
8541
- document.head.appendChild(style);
8540
+ if (!document.querySelector("#cagov-pagination-styles")) {
8541
+ const style = document.createElement("style");
8542
+ style.id = "cagov-pagination-styles";
8543
+ style.textContent = styles;
8544
+ document.head.appendChild(style);
8545
+ }
8542
8546
  }
8543
- }
8544
-
8545
- connectedCallback() {
8546
- this.currentPage = parseInt(
8547
- this.dataset.currentPage ? this.dataset.currentPage : "1",
8548
- 10
8549
- );
8550
- this.render();
8551
- }
8552
8547
 
8553
- render() {
8554
- //console.log(this.dataset);
8555
- const previous = this.dataset.previous
8556
- ? this.dataset.previous
8557
- : '<span class="ca-gov-icon-arrow-prev" aria-hidden="true"></span> Previous';
8558
- const next = this.dataset.next
8559
- ? this.dataset.next
8560
- : 'Next <span class="ca-gov-icon-arrow-next" aria-hidden="true"></span>';
8561
- const page = this.dataset.page ? this.dataset.page : "Page";
8562
- this.totalPages = this.dataset.totalPages
8563
- ? Number(this.dataset.totalPages)
8564
- : 1;
8565
- if (this.totalPages < 0 || this.totalPages > 1) {
8566
- const html = templateHTML(
8567
- next,
8568
- previous,
8569
- page,
8570
- this.currentPage,
8571
- this.totalPages
8548
+ connectedCallback() {
8549
+ this.currentPage = parseInt(
8550
+ this.dataset.currentPage ? this.dataset.currentPage : "1",
8551
+ 10
8572
8552
  );
8573
- this.innerHTML = html;
8574
- this.applyListeners();
8575
- } else {
8576
- this.innerHTML = "";
8553
+ this.render();
8577
8554
  }
8578
- }
8579
8555
 
8580
- static get observedAttributes() {
8581
- return ["data-current-page", "data-total-pages"];
8582
- }
8556
+ render() {
8557
+ //console.log(this.dataset);
8558
+ const previous = this.dataset.previous
8559
+ ? this.dataset.previous
8560
+ : '<span class="ca-gov-icon-arrow-prev" aria-hidden="true"></span> Previous';
8561
+ const next = this.dataset.next
8562
+ ? this.dataset.next
8563
+ : 'Next <span class="ca-gov-icon-arrow-next" aria-hidden="true"></span>';
8564
+ const page = this.dataset.page ? this.dataset.page : "Page";
8565
+ this.totalPages = this.dataset.totalPages
8566
+ ? Number(this.dataset.totalPages)
8567
+ : 1;
8568
+ if (this.totalPages < 0 || this.totalPages > 1) {
8569
+ const html = templateHTML(
8570
+ next,
8571
+ previous,
8572
+ page,
8573
+ this.currentPage,
8574
+ this.totalPages
8575
+ );
8576
+ this.innerHTML = html;
8577
+ this.applyListeners();
8578
+ } else {
8579
+ this.innerHTML = "";
8580
+ }
8581
+ }
8583
8582
 
8584
- attributeChangedCallback(name, oldValue, newValue) {
8585
- if (name === "data-current-page") {
8586
- this.currentPage = parseInt(newValue, 10);
8587
- this.render();
8583
+ static get observedAttributes() {
8584
+ return ["data-current-page", "data-total-pages"];
8588
8585
  }
8589
- if (name === "data-total-pages") {
8590
- this.totalPages = parseInt(newValue, 10);
8591
- this.render();
8586
+
8587
+ attributeChangedCallback(name, oldValue, newValue) {
8588
+ if (name === "data-current-page") {
8589
+ this.currentPage = parseInt(newValue, 10);
8590
+ this.render();
8591
+ }
8592
+ if (name === "data-total-pages") {
8593
+ this.totalPages = parseInt(newValue, 10);
8594
+ this.render();
8595
+ }
8592
8596
  }
8593
- }
8594
8597
 
8595
- applyListeners() {
8596
- const pageLinks = this.querySelectorAll(".cagov-pagination__button");
8597
- pageLinks.forEach(pl => {
8598
- pl.addEventListener("click", event => {
8599
- this.currentPage = parseInt(
8600
- /** @type {CAGovPagination} */ (event.target).dataset.pageNum,
8601
- 10
8602
- );
8603
- this.dispatchEvent(
8604
- new CustomEvent("paginationClick", {
8605
- detail: this.currentPage
8606
- })
8607
- );
8608
- this.dataset.currentPage = this.currentPage.toString();
8609
- });
8610
- });
8611
- this.querySelector(".cagov-pagination__previous-page").addEventListener(
8612
- "click",
8613
- event => {
8614
- if (
8615
- !(
8616
- /** @type {Element} */ (event.target).classList.contains(
8617
- "cagov-pagination__link-inactive"
8618
- )
8619
- )
8620
- ) {
8621
- this.currentPage -= 1;
8622
- if (this.currentPage < 1) {
8623
- this.currentPage = 1;
8624
- }
8598
+ applyListeners() {
8599
+ const pageLinks = this.querySelectorAll(".cagov-pagination__button");
8600
+ pageLinks.forEach(pl => {
8601
+ pl.addEventListener("click", event => {
8602
+ this.currentPage = parseInt(
8603
+ /** @type {CAGovPagination} */ (event.target).dataset.pageNum,
8604
+ 10
8605
+ );
8625
8606
  this.dispatchEvent(
8626
8607
  new CustomEvent("paginationClick", {
8627
8608
  detail: this.currentPage
8628
8609
  })
8629
8610
  );
8630
8611
  this.dataset.currentPage = this.currentPage.toString();
8612
+ });
8613
+ });
8614
+ this.querySelector(".cagov-pagination__previous-page").addEventListener(
8615
+ "click",
8616
+ event => {
8617
+ if (
8618
+ !(
8619
+ /** @type {Element} */ (event.target).classList.contains(
8620
+ "cagov-pagination__link-inactive"
8621
+ )
8622
+ )
8623
+ ) {
8624
+ this.currentPage -= 1;
8625
+ if (this.currentPage < 1) {
8626
+ this.currentPage = 1;
8627
+ }
8628
+ this.dispatchEvent(
8629
+ new CustomEvent("paginationClick", {
8630
+ detail: this.currentPage
8631
+ })
8632
+ );
8633
+ this.dataset.currentPage = this.currentPage.toString();
8634
+ }
8631
8635
  }
8632
- }
8633
- );
8634
- this.querySelector(".cagov-pagination__next-page").addEventListener(
8635
- "click",
8636
- event => {
8637
- if (
8638
- !(
8639
- /** @type {Element} */ (event.target).classList.contains(
8640
- "cagov-pagination__link-inactive"
8636
+ );
8637
+ this.querySelector(".cagov-pagination__next-page").addEventListener(
8638
+ "click",
8639
+ event => {
8640
+ if (
8641
+ !(
8642
+ /** @type {Element} */ (event.target).classList.contains(
8643
+ "cagov-pagination__link-inactive"
8644
+ )
8641
8645
  )
8642
- )
8643
- ) {
8644
- this.currentPage += 1;
8645
- if (this.totalPages != -1 && this.currentPage > this.totalPages) {
8646
- this.currentPage = this.totalPages;
8646
+ ) {
8647
+ this.currentPage += 1;
8648
+ if (this.totalPages != -1 && this.currentPage > this.totalPages) {
8649
+ this.currentPage = this.totalPages;
8650
+ }
8651
+ this.dispatchEvent(
8652
+ new CustomEvent("paginationClick", {
8653
+ detail: this.currentPage
8654
+ })
8655
+ );
8656
+ this.dataset.currentPage = this.currentPage.toString();
8647
8657
  }
8648
- this.dispatchEvent(
8649
- new CustomEvent("paginationClick", {
8650
- detail: this.currentPage
8651
- })
8652
- );
8653
- this.dataset.currentPage = this.currentPage.toString();
8654
8658
  }
8655
- }
8656
- );
8659
+ );
8660
+ }
8657
8661
  }
8658
- }
8659
- window.addEventListener("load", () => {
8662
+
8660
8663
  window.customElements.define("cagov-pagination", CAGovPagination);
8661
8664
  });
8662
- //export { CAGovPagination };
8663
8665
 
8664
8666
  //@ts-check
8665
8667