Toast

<main class="main-wrapper mt40">
    <button type="button" id="js-toast-trigger" class="toast-trigger">
        トースト(ポップアップ通知)<br>
        トリガーボタン
    </button>
    <div class="selectbox-container -pulldown mt40" style="max-width: 55%; margin: auto;">
        <label for="selectbox" class="selectbox-label">出現パターン :</label>
        <select id="appearance-pattern" class="selectbox -single-select" name="subject" required>
            <option label="以下選択してボタンを押してください" selected disabled></option>
            <option value="default">初期設定</option>
            <option value="in-the-bottom-right">右下にアニメーション出現</option>
            <option value="in-the-bottom-left">左下にアニメーション出現</option>
            <option value="in-the-upper-right">右上にアニメーション出現</option>
            <option value="in-the-upper-left">左上にアニメーション出現</option>
        </select>
    </div>
    <div id="js-toast-popup" class="toast" role="status" aria-live="polite" aria-atomic="false" aria-hidden="true">
        <button id="js-toast-close" type="button" class="close-button">
            <!-- 通知テキストをここにJSで追加・表示 -->
    </div>
</main>
<main class="main-wrapper mt40">
  <button type="button" id="js-toast-trigger" class="toast-trigger">
    トースト(ポップアップ通知)<br>
    トリガーボタン
  </button>
  <div class="selectbox-container -pulldown mt40" style="max-width: 55%; margin: auto;">
    <label for="selectbox" class="selectbox-label">出現パターン :</label>
    <select id="appearance-pattern" class="selectbox -single-select" name="subject" required >
      <option label="以下選択してボタンを押してください" selected disabled></option>
      <option value="default">初期設定</option>
      <option value="in-the-bottom-right">右下にアニメーション出現</option>
      <option value="in-the-bottom-left">左下にアニメーション出現</option>
      <option value="in-the-upper-right">右上にアニメーション出現</option>
      <option value="in-the-upper-left">左上にアニメーション出現</option>
    </select>
  </div>
  <div id="js-toast-popup" class="toast" role="status" aria-live="polite" aria-atomic="false" aria-hidden="true">
    <button id="js-toast-close" type="button" class="close-button">
    <!-- 通知テキストをここにJSで追加・表示 -->
  </div>
</main>
/* No context defined. */
  • Content:
    /* /js/modules/Toast.js */
    
    /**
     * Toast UI class
     */
    export class Toast {
      constructor(id1, id2, insertElem, id3, id4) {
        this.trigger = document.getElementById(id1);
        this.toastBody = document.getElementById(id2);
        this.toastBodyText = document.querySelector(insertElem);
        this.close = document.getElementById(id3);
        this.pattern = document.getElementById('id4');
        this.timerId;
      }
      showToast() {
        if (this.toastBody) {
          this.trigger.addEventListener('click', () => {
            this.toastBody.setAttribute('aria-atomic', 'true');
            this.toastBody.setAttribute('aria-hidden', 'false');
            this.toastBody.classList.remove('is-invisible');
            !this.toastBodyText ?
              this.toastBody.innerHTML = '<button id="js-toast-close" type="button" class="close-button">×</button><p class="text">notification!<span class="supplement-line">1件の通知があります</span></p>' :
              false;
            this.stopDisappearing();
            this.timerId = setTimeout(() => {
              setTimeout(() => {
                this.toastBody.setAttribute('aria-atomic', 'false');
                this.toastBody.setAttribute('aria-hidden', 'true');
              }, 500);
                this.toastBody.classList.add('is-invisible');
            }, 5500);
          });
        }
      }
      removeToast() {
        this.toastBody.addEventListener('click', (e) => {
          const target = e.target || e.srcElement;
          if (target.id == this.close.id) {
            this.toastBody.setAttribute('aria-atomic', 'false');
            this.toastBody.setAttribute('aria-hidden', 'true');
          }
        });
      }
      stopDisappearing() {
        clearTimeout(this.timerId);
      }
    
      addAppearancePattern() {
        this.pattern.addEventListener('change', () => {
          const value = this.patter.value;
          for (let index = 0; index < array.length; index++) {
            const element = array[index];
          }
        });
      }
    }
    
    /* /js/main.js */
    
    import { Toast } from './modules/Toast.js';
    
    const toast = new Toast('js-toast-trigger', 'js-toast-popup', '.toast > .text', 'js-toast-close');
    toast.showToast();
    toast.removeToast();
  • URL: /components/raw/toast/index.js
  • Filesystem Path: src/components/2-dynamic-ui/toast/index.js
  • Size: 2.1 KB
  • Content:
    .toast-trigger {
      display: block;
      width: 100%;
      max-width: 300px;
      min-width: fit-content;
      margin: 4rem auto;
      padding: .85rem 1rem .75rem;
      border: 1px solid var(--border-color);
      text-align: center;
      line-height: 1.6;
      font-size: 1.15rem;
      border-radius: 10rem;
    }
    .toast-trigger:hover, [data-whatintent="keyboard"] .toast-trigger:focus {
      background-color: #777;
      color: var(--white);
    }
    
    .toast[aria-hidden="false"] {
      display: block;
      position: relative;
      top: 10vh;
      right: 0;
      width: fit-content;
      max-width: 90%;
      margin: auto;
      border: 1px solid var(--border-color);
      background-color: var(--white);
      border-radius: .25rem;
      animation: fade-in .25s var(--ease-in-cubic);
    }
    .toast[aria-hidden="true"] {
      display: none;
    }
    .toast.is-invisible {
      animation: fade-out .5s var(--ease-in-cubic);
    }
    .toast > .text {
      padding: .5rem 1rem .45rem;
      text-align: center;
      font-weight: bold;
    }
    .toast .supplement-line {
      display: inline-block;
      width: 100%;
      margin-top: 3px;
      padding-top: 2px;
      border-top: 1px solid var(--border-color);
    }
    .toast .close-button {
      position: absolute;
      top: 0;
      right: 0;
      padding: .15rem .6rem 1.2rem 1.4rem;
      font-size: 1.2rem;
    }
    .toast .close-button:hover, .toast .close-button:focus {
      font-weight: bold;
    }
  • URL: /components/raw/toast/style.css
  • Filesystem Path: src/components/2-dynamic-ui/toast/style.css
  • Size: 1.3 KB

No notes defined.