Confirm Dialog
確認ダイアログ。削除操作の前に表示する用途に。
HTML
<button class="cd-trigger" id="cd-open">Delete Item</button>
<div class="cd-overlay" id="cd-overlay">
<div class="cd-box">
<div class="cd-icon">⚠</div>
<div class="cd-title">Delete this item?</div>
<div class="cd-desc">This action cannot be undone.</div>
<div class="cd-actions">
<button class="cd-cancel" id="cd-cancel">Cancel</button>
<button class="cd-confirm">Delete</button>
</div>
</div>
</div>
CSS
.cd-trigger {
padding: 10px 22px;
background: #fff;
color: #dc2626;
border: 1px solid #fecaca;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
}
.cd-overlay {
position: absolute;
inset: 0;
background: rgba(0,0,0,.25);
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
pointer-events: none;
transition: opacity .2s;
z-index: 10;
}
.cd-overlay.open {
opacity: 1;
pointer-events: auto;
}
.cd-box {
background: #fff;
border-radius: 14px;
padding: 28px;
width: 300px;
text-align: center;
transform: scale(.92);
transition: transform .25s cubic-bezier(.16,1,.3,1);
}
.cd-overlay.open .cd-box { transform: scale(1); }
.cd-icon { font-size: 28px; margin-bottom: 8px; }
.cd-title { font-size: 16px; font-weight: 700; color: #1a1a1a; margin-bottom: 4px; }
.cd-desc { font-size: 13px; color: #666; margin-bottom: 20px; }
.cd-actions { display: flex; gap: 8px; justify-content: center; }
.cd-cancel {
padding: 8px 18px;
background: #f5f5f5;
border: none;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
color: #1a1a1a;
}
.cd-confirm {
padding: 8px 18px;
background: #dc2626;
color: #fff;
border: none;
border-radius: 6px;
font-size: 13px;
font-weight: 600;
font-family: inherit;
cursor: pointer;
}
JavaScript
const overlay = document.getElementById('cd-overlay');
document.getElementById('cd-open').addEventListener('click', () => {
overlay.classList.add('open');
});
document.getElementById('cd-cancel').addEventListener('click', () => {
overlay.classList.remove('open');
});
overlay.addEventListener('click', (e) => {
if (e.target === overlay) overlay.classList.remove('open');
});