|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en" dir="ltr"> |
| 3 | + <head> |
| 4 | + <meta charset="UTF-8" /> |
| 5 | + <title>Toast - Hue</title> |
| 6 | + <meta |
| 7 | + name="viewport" |
| 8 | + content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" |
| 9 | + /> |
| 10 | + <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" /> |
| 11 | + <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" /> |
| 12 | + <script src="../../../../../scripts/testing/scripts.js"></script> |
| 13 | + <script nomodule src="../../../../../dist/ionic/ionic.js"></script> |
| 14 | + <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script> |
| 15 | + </head> |
| 16 | + |
| 17 | + <body> |
| 18 | + <ion-app> |
| 19 | + <ion-header> |
| 20 | + <ion-toolbar> |
| 21 | + <ion-title>Toast - Hue</ion-title> |
| 22 | + </ion-toolbar> |
| 23 | + </ion-header> |
| 24 | + |
| 25 | + <ion-content class="ion-padding" id="content"> |
| 26 | + <p> |
| 27 | + Toasts are presented indefinitely but can be closed by clicking the backdrop. The backdrop has been added for |
| 28 | + demo purposes only. |
| 29 | + </p> |
| 30 | + |
| 31 | + <button id="show-subtle-toasts" class="expand">Show All Subtle Toasts</button> |
| 32 | + <button id="show-bold-toasts" class="expand">Show All Bold Toasts</button> |
| 33 | + </ion-content> |
| 34 | + |
| 35 | + <div id="backdrop" class="backdrop"></div> |
| 36 | + |
| 37 | + <ion-toast position="top"></ion-toast> |
| 38 | + <ion-toast color="primary" position="top"></ion-toast> |
| 39 | + <ion-toast color="secondary" position="top"></ion-toast> |
| 40 | + <ion-toast color="tertiary" position="top"></ion-toast> |
| 41 | + <ion-toast color="success" position="top"></ion-toast> |
| 42 | + <ion-toast color="warning" position="top"></ion-toast> |
| 43 | + <ion-toast color="danger" position="top"></ion-toast> |
| 44 | + <ion-toast color="light" position="top"></ion-toast> |
| 45 | + <ion-toast color="medium" position="top"></ion-toast> |
| 46 | + <ion-toast color="dark" position="top"></ion-toast> |
| 47 | + </ion-app> |
| 48 | + |
| 49 | + <script type="module"> |
| 50 | + let lastToast = null; |
| 51 | + let toastOffset = 10; |
| 52 | + |
| 53 | + // Show all toasts when the button is clicked |
| 54 | + function openAllToasts(isBold) { |
| 55 | + toastOffset = 10; |
| 56 | + |
| 57 | + const toasts = document.querySelectorAll('ion-toast'); |
| 58 | + |
| 59 | + toasts.forEach((toast, index) => { |
| 60 | + toast.removeAttribute('hue'); |
| 61 | + toast.hue = isBold ? 'bold' : 'subtle'; |
| 62 | + const hue = toast.hue; |
| 63 | + |
| 64 | + const color = toast.color || 'default'; |
| 65 | + toast.message = `This is a ${color} toast.`; |
| 66 | + |
| 67 | + toast.icon = 'information-circle'; |
| 68 | + |
| 69 | + toast.buttons = [ |
| 70 | + { |
| 71 | + text: 'Action', |
| 72 | + }, |
| 73 | + { |
| 74 | + icon: 'close', |
| 75 | + role: 'cancel', |
| 76 | + }, |
| 77 | + ]; |
| 78 | + |
| 79 | + // Set dynamic position for each toast to ensure they don't overlap |
| 80 | + toast.style.position = 'absolute'; |
| 81 | + toast.style.top = `${toastOffset}px`; |
| 82 | + toast.style.left = '50%'; |
| 83 | + toast.style.transform = 'translateX(-50%)'; |
| 84 | + |
| 85 | + toast.present(); |
| 86 | + |
| 87 | + // Update the toastOffset for the next toast to ensure it's positioned below the previous one |
| 88 | + toastOffset += 60; |
| 89 | + }); |
| 90 | + |
| 91 | + document.getElementById('backdrop').style.display = 'block'; |
| 92 | + } |
| 93 | + |
| 94 | + // Dismiss all toasts when backdrop is clicked |
| 95 | + function dismissAllToasts() { |
| 96 | + const toasts = document.querySelectorAll('ion-toast'); |
| 97 | + toasts.forEach((toast) => toast.dismiss()); |
| 98 | + |
| 99 | + document.getElementById('backdrop').style.display = 'none'; |
| 100 | + } |
| 101 | + |
| 102 | + document.addEventListener('DOMContentLoaded', function () { |
| 103 | + document.getElementById('show-subtle-toasts').addEventListener('click', () => openAllToasts(false)); |
| 104 | + document.getElementById('show-bold-toasts').addEventListener('click', () => openAllToasts(true)); |
| 105 | + |
| 106 | + document.getElementById('backdrop').addEventListener('click', dismissAllToasts); |
| 107 | + }); |
| 108 | + </script> |
| 109 | + |
| 110 | + <style> |
| 111 | + .backdrop { |
| 112 | + position: fixed; |
| 113 | + top: 0; |
| 114 | + left: 0; |
| 115 | + right: 0; |
| 116 | + bottom: 0; |
| 117 | + background: rgba(0, 0, 0, 0.5); |
| 118 | + z-index: 1000; |
| 119 | + display: none; |
| 120 | + } |
| 121 | + </style> |
| 122 | + </body> |
| 123 | +</html> |
0 commit comments