@govtechsg/sgds-web-component 1.3.0 → 1.4.0

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/index.umd.js CHANGED
@@ -3309,6 +3309,7 @@
3309
3309
 
3310
3310
  var css_248z$E = css`:host{--accordion-active-color:var(--sgds-primary)}`;
3311
3311
 
3312
+ const VALID_KEYS = ["Enter", "ArrowUp", "ArrowLeft", "ArrowDown", "ArrowRight"];
3312
3313
  /**
3313
3314
  * @summary A dropdown mechanism that allow users to either show or hide related content. `SgdsAccordion` is a wrapper to manage the behaviour for multiple `SgdsAccordionItems`
3314
3315
  * @slot default - slot for accordion-item
@@ -3343,10 +3344,8 @@
3343
3344
  }
3344
3345
  });
3345
3346
  }
3346
- async onToggle(event) {
3347
- // Let the event pass through the DOM so that it can be
3348
- // prevented from the outside if a user so desires.
3349
- if (this.allowMultiple || event.defaultPrevented) {
3347
+ async _onToggle(event) {
3348
+ if (this.allowMultiple) {
3350
3349
  // No toggling when `allowMultiple` or the user prevents it.
3351
3350
  return;
3352
3351
  }
@@ -3363,6 +3362,11 @@
3363
3362
  }
3364
3363
  });
3365
3364
  }
3365
+ async _onKeyboardToggle(event) {
3366
+ if (!VALID_KEYS.includes(event.key))
3367
+ return;
3368
+ return this._onToggle(event);
3369
+ }
3366
3370
  render() {
3367
3371
  return html$1 `
3368
3372
  <div
@@ -3371,7 +3375,7 @@
3371
3375
  [`${this.accordionClasses}`]: this.accordionClasses
3372
3376
  })}
3373
3377
  >
3374
- <slot @click=${this.onToggle}></slot>
3378
+ <slot @click=${this._onToggle} @keydown=${this._onKeyboardToggle}></slot>
3375
3379
  </div>
3376
3380
  `;
3377
3381
  }
@@ -3516,7 +3520,7 @@
3516
3520
  };
3517
3521
  }
3518
3522
 
3519
- var css_248z$D = css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){box-shadow:none;color:var(--accordion-active-color);font-weight:var(--accordion-item-font-weight)}:host([first-of-type]) .accordion-item{border-radius:var(--accordion-item-border-radius) var(--accordion-item-border-radius) 0 0}:host([nth-of-type]) .accordion-item{border-radius:0;border-top:0}:host([last-of-type]) .accordion-item{border-radius:0 0 var(--accordion-item-border-radius) var(--accordion-item-border-radius);border-top:0}`;
3523
+ var css_248z$D = css`:host{--accordion-item-padding-y:1rem;--accordion-item-padding-x:1.5rem;--accordion-item-border-radius:0.25rem;--accordion-item-font-weight:700;--accordion-item-line-height:2rem}.accordion-body{line-height:var(--accordion-item-line-height);overflow:hidden;padding:0}.accordion-content{display:block;padding:0 var(--accordion-item-padding-x) var(--accordion-item-padding-y)}.accordion-button{line-height:var(--accordion-item-line-height)}.accordion-button:not(.collapsed){color:var(--accordion-active-color,var(--sgds-primary))}.accordion-button svg.bi-chevron-down{height:1.3rem;margin-left:auto;transition:transform .2s ease-in-out;width:1.3rem}.accordion-button:not(.collapsed){box-shadow:none;font-weight:var(--accordion-item-font-weight)}.accordion-button:not(.collapsed) svg.bi-chevron-down{transform:rotate(-180deg)}.accordion-button:after{content:unset}:host([first-of-type]) .accordion-item{border-radius:var(--accordion-item-border-radius) var(--accordion-item-border-radius) 0 0}:host([nth-of-type]) .accordion-item{border-radius:0;border-top:0}:host([last-of-type]) .accordion-item{border-radius:0 0 var(--accordion-item-border-radius) var(--accordion-item-border-radius);border-top:0}.hidden{display:none}`;
3520
3524
 
3521
3525
  /**
3522
3526
  *
@@ -3545,8 +3549,8 @@
3545
3549
  this.open = false;
3546
3550
  }
3547
3551
  firstUpdated() {
3548
- this.body.hidden = !this.open;
3549
- this.body.style.height = this.open ? "auto" : "0";
3552
+ if (!this.open)
3553
+ this.body.classList.add("hidden");
3550
3554
  }
3551
3555
  handleSummaryClick() {
3552
3556
  if (this.open) {
@@ -3585,10 +3589,9 @@
3585
3589
  return;
3586
3590
  }
3587
3591
  await stopAnimations(this.body);
3588
- this.body.hidden = false;
3592
+ this.body.classList.remove("hidden");
3589
3593
  const { keyframes, options } = getAnimation(this, "accordion.show");
3590
3594
  await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
3591
- this.body.style.height = "auto";
3592
3595
  this.emit("sgds-after-show");
3593
3596
  }
3594
3597
  else {
@@ -3600,9 +3603,13 @@
3600
3603
  }
3601
3604
  await stopAnimations(this.body);
3602
3605
  const { keyframes, options } = getAnimation(this, "accordion.hide");
3606
+ const animationDuration = options.duration;
3607
+ // Workaround to fix GSIB delay after animateTo.
3608
+ //Setting a timeout of duration slightly less than animation's duraton to prevent case where animation runs faster than .hidden class is added
3609
+ setTimeout(() => {
3610
+ this.body.classList.add("hidden");
3611
+ }, animationDuration - 20);
3603
3612
  await animateTo(this.body, shimKeyframesHeightAuto(keyframes, this.body.scrollHeight), options);
3604
- this.body.hidden = true;
3605
- this.body.style.height = "auto";
3606
3613
  this.emit("sgds-after-hide");
3607
3614
  }
3608
3615
  }
@@ -3628,7 +3635,8 @@
3628
3635
  part="base"
3629
3636
  class=${classMap({
3630
3637
  "sgds accordion-item": true,
3631
- [`${this.accordionItemClasses}`]: this.accordionItemClasses
3638
+ [`${this.accordionItemClasses}`]: this.accordionItemClasses,
3639
+ show: this.open
3632
3640
  })}
3633
3641
  >
3634
3642
  <button
@@ -3645,8 +3653,25 @@
3645
3653
  @keydown=${this.handleSummaryKeyDown}
3646
3654
  >
3647
3655
  <slot name="accordion-header"></slot>
3656
+ <svg
3657
+ xmlns="http://www.w3.org/2000/svg"
3658
+ width="16"
3659
+ height="16"
3660
+ fill="currentColor"
3661
+ class="bi bi-chevron-down"
3662
+ viewBox="0 0 16 16"
3663
+ >
3664
+ <path
3665
+ fill-rule="evenodd"
3666
+ d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"
3667
+ />
3668
+ </svg>
3648
3669
  </button>
3649
- <div class="accordion-body">
3670
+ <div
3671
+ class=${classMap({
3672
+ "accordion-body": true
3673
+ })}
3674
+ >
3650
3675
  <slot name="accordion-content" class="accordion-content" role="region" aria-labelledby="header"></slot>
3651
3676
  </div>
3652
3677
  </div>
@@ -3677,14 +3702,14 @@
3677
3702
  { height: "0", opacity: "0" },
3678
3703
  { height: "auto", opacity: "1" }
3679
3704
  ],
3680
- options: { duration: 200, easing: "ease-in-out" }
3705
+ options: { duration: 350, easing: "ease-in-out" }
3681
3706
  });
3682
3707
  setDefaultAnimation("accordion.hide", {
3683
3708
  keyframes: [
3684
3709
  { height: "auto", opacity: "1" },
3685
3710
  { height: "0", opacity: "0" }
3686
3711
  ],
3687
- options: { duration: 200, easing: "ease-in-out" }
3712
+ options: { duration: 350, easing: "ease-in-out" }
3688
3713
  });
3689
3714
 
3690
3715
  customElements.define("sgds-accordion", SgdsAccordion);
@@ -21715,6 +21740,8 @@
21715
21740
  this.centeredAlignVariant = false;
21716
21741
  /** Removes the default animation when opening and closing of modal */
21717
21742
  this.noAnimation = false;
21743
+ /** Removes the close button from modal header */
21744
+ this.noCloseButton = false;
21718
21745
  }
21719
21746
  connectedCallback() {
21720
21747
  super.connectedCallback();
@@ -21871,16 +21898,18 @@
21871
21898
  >
21872
21899
  ${this.titleIcon ? withLabelIcon : ""} ${this.title}
21873
21900
  </h3>
21874
- <button
21875
- class=${classMap({
21876
- "modal-close": true,
21877
- "btn-sm": true,
21878
- "btn-close": true,
21879
- centered: this.centeredAlignVariant
21880
- })}
21881
- @click="${() => this.requestClose("close-button")}"
21882
- aria-label="close modal"
21883
- ></button>
21901
+ ${this.noCloseButton
21902
+ ? nothing
21903
+ : html$1 `<button
21904
+ class=${classMap({
21905
+ "modal-close": true,
21906
+ "btn-sm": true,
21907
+ "btn-close": true,
21908
+ centered: this.centeredAlignVariant
21909
+ })}
21910
+ @click="${() => this.requestClose("close-button")}"
21911
+ aria-label="close modal"
21912
+ ></button>`}
21884
21913
  </div>
21885
21914
  `
21886
21915
  : ""}
@@ -21943,6 +21972,9 @@
21943
21972
  __decorate([
21944
21973
  property({ type: Boolean, reflect: true })
21945
21974
  ], SgdsModal.prototype, "noAnimation", void 0);
21975
+ __decorate([
21976
+ property({ type: Boolean, reflect: true })
21977
+ ], SgdsModal.prototype, "noCloseButton", void 0);
21946
21978
  __decorate([
21947
21979
  watch("open", { waitUntilFirstUpdate: true })
21948
21980
  ], SgdsModal.prototype, "handleOpenChange", null);