@manufosela/modal-dialog
Modal dialog web component with Lit
Demo code (CodePen-ready HTML, CSS, JS)
HTML (html)
<div class="container">
<div class="demo-card">
<h2>Basic Modal</h2>
<p>Simple modal with title and content</p>
<div class="buttons">
<button class="btn-primary" onclick="document.getElementById('basic').show()">Open Modal</button>
</div>
<div class="code-block"><modal-dialog title="Welcome">
<p>This is a basic modal dialog.</p>
<p>Click outside or press Escape to close.</p>
</modal-dialog></div>
</div>
<div class="demo-card">
<h2>Confirmation Dialog</h2>
<p>Modal with confirm and cancel actions</p>
<div class="buttons">
<button class="btn-primary" onclick="document.getElementById('confirm').show()">Delete Item</button>
</div>
<div class="code-block"><modal-dialog id="confirm" title="Delete Item?" size="small">
<p>Are you sure? This action cannot be undone.</p>
<button slot="footer" onclick="confirm.cancel()">Cancel</button>
<button slot="footer" onclick="confirm.confirm()">Delete</button>
</modal-dialog>
<script>
confirm.addEventListener('modal-confirm', () => {
alert('Item deleted!');
});
</script></div>
</div>
<div class="demo-card">
<h2>Size Variants</h2>
<p>Small, medium, large, full width, and fullscreen</p>
<div class="buttons">
<button class="btn-secondary" onclick="showSize('small')">Small</button>
<button class="btn-secondary" onclick="showSize('medium')">Medium</button>
<button class="btn-secondary" onclick="showSize('large')">Large</button>
<button class="btn-secondary" onclick="showSize('full')">Full Width</button>
<button class="btn-secondary" onclick="showSize('fullscreen')">Fullscreen</button>
</div>
<div class="code-block" id="size-code"><modal-dialog size="small" title="Small Modal">
<p>This is a small modal with limited width (360px).</p>
</modal-dialog></div>
</div>
<div class="demo-card">
<h2>Custom Size</h2>
<p>Set exact dimensions with width and height attributes</p>
<div class="buttons">
<button class="btn-secondary" onclick="showCustom('50vw', '70vh')">50vw × 70vh</button>
<button class="btn-secondary" onclick="showCustom('80%', '400px')">80% × 400px</button>
<button class="btn-secondary" onclick="showCustom('600px', '50vh')">600px × 50vh</button>
</div>
<div class="code-block" id="custom-code"><modal-dialog width="50vw" height="70vh" title="Custom Size">
<p>Modal with custom dimensions: 50vw × 70vh</p>
</modal-dialog></div>
</div>
<div class="demo-card">
<h2>Form Modal</h2>
<p>Modal containing a form</p>
<div class="buttons">
<button class="btn-primary" onclick="document.getElementById('form').show()">Open Form</button>
</div>
<div class="code-block"><modal-dialog id="form" title="Contact Form">
<form>
<input type="text" placeholder="Name" />
<input type="email" placeholder="Email" />
<textarea placeholder="Message"></textarea>
</form>
<button slot="footer" onclick="form.cancel()">Cancel</button>
<button slot="footer" onclick="form.confirm()">Submit</button>
</modal-dialog></div>
</div>
</div>
<!-- Basic Modal -->
<modal-dialog id="basic" title="Welcome">
<p>This is a basic modal dialog.</p>
<p>Click outside or press Escape to close.</p>
</modal-dialog>
<!-- Confirmation Modal -->
<modal-dialog id="confirm" title="Delete Item?" size="small">
<p>Are you sure you want to delete this item? This action cannot be undone.</p>
<button slot="footer" class="btn-cancel" onclick="document.getElementById('confirm').cancel()">Cancel</button>
<button slot="footer" class="btn-danger" onclick="document.getElementById('confirm').confirm()">Delete</button>
</modal-dialog>
<!-- Size Variants - Single modal that changes size -->
<modal-dialog id="size-modal" title="Small Modal" size="small">
<p id="size-content">This is a small modal with limited width (360px).</p>
</modal-dialog>
<!-- Custom Size Modal -->
<modal-dialog id="custom-modal" title="Custom Size">
<p id="custom-content">Modal with custom dimensions: 50vw × 70vh</p>
</modal-dialog>
<!-- Form Modal -->
<modal-dialog id="form" title="Contact Form">
<form id="contact-form" style="display: flex; flex-direction: column; gap: 1rem;">
<label style="display: flex; flex-direction: column; gap: 0.25rem;">
Name
<input type="text" placeholder="Your name" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 6px;">
</label>
<label style="display: flex; flex-direction: column; gap: 0.25rem;">
Email
<input type="email" placeholder="your@email.com" style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 6px;">
</label>
<label style="display: flex; flex-direction: column; gap: 0.25rem;">
Message
<textarea rows="3" placeholder="Your message..." style="padding: 0.5rem; border: 1px solid #d1d5db; border-radius: 6px;"></textarea>
</label>
</form>
<button slot="footer" class="btn-cancel" onclick="document.getElementById('form').cancel()">Cancel</button>
<button slot="footer" class="btn-confirm" onclick="document.getElementById('form').confirm()">Submit</button>
</modal-dialog> CSS (css)
:root {
--bg: #0c0f14;
--bg-elevated: #141923;
--bg-panel: #171d28;
--border: #262f3f;
--text: #f4f6fb;
--text-muted: #a7b0c2;
--text-dim: #7d879b;
--accent: #ff8a3d;
--accent-strong: #ff6a00;
--accent-soft: rgba(255, 138, 61, 0.16);
--shadow: 0 20px 50px rgba(5, 8, 14, 0.45);
--radius-lg: 22px;
--radius-md: 14px;
--radius-sm: 10px;
--max-width: 1160px;
}
* { box-sizing: border-box; }
.container { max-width: 800px; margin: 0 auto; }
header { text-align: center; margin-bottom: 3rem; }
h1 { font-size: 2.5rem; margin-bottom: 0.5rem; }
.subtitle { color: #86868b; }
.demo-card { background: #fff; border-radius: 16px; padding: 2rem; margin-bottom: 2rem; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
.demo-card h2 { margin: 0 0 0.5rem 0; }
.demo-card p { color: #86868b; margin: 0 0 1.5rem 0; }
.buttons { display: flex; gap: 1rem; flex-wrap: wrap; }
button { padding: 0.75rem 1.5rem; border: none; border-radius: 8px; font-size: 1rem; cursor: pointer; transition: background 0.2s; }
.btn-primary { background: #3b82f6; color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-secondary { background: #6b7280; color: #fff; }
.btn-secondary:hover { background: #4b5563; }
.code-block { background: #1d1d1f; color: #f5f5f7; padding: 1rem; border-radius: 8px; font-family: monospace; font-size: 0.8rem; margin-top: 1rem; overflow-x: auto; white-space: pre; }
/* Custom modal button styles */
modal-dialog button { padding: 0.5rem 1rem; border: none; border-radius: 6px; cursor: pointer; }
modal-dialog .btn-cancel { background: #e5e7eb; color: #374151; }
modal-dialog .btn-confirm { background: #3b82f6; color: #fff; }
modal-dialog .btn-danger { background: #dc2626; color: #fff; }
footer {
text-align: center;
margin-top: 3rem;
padding-top: 2rem;
border-top: 1px solid #d2d2d7;
color: #86868b;
font-size: 0.9rem;
}
footer a { color: #1d1d1f; text-decoration: none; }
footer a:hover { text-decoration: underline; }
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600;700&display=swap');
:root {
--bg: #f5f5f7;
--bg-2: #ffffff;
--bg-spot-1: #f8e9d0;
--bg-spot-2: #e8eef8;
--card: #ffffff;
--text: #1d1d1f;
--muted: #6b7280;
--line: #e5e7eb;
--accent: #ffb000;
--accent-2: #00a7d6;
--accent-soft: rgba(255, 176, 0, 0.18);
--surface-1: #f3f4f6;
--surface-2: #eef2f7;
--code-bg: #111827;
--code-text: #f9fafb;
--panel-bg: rgba(255, 255, 255, 0.85);
--overlay-bg: rgba(255, 255, 255, 0.98);
}
:root.dark {
--bg: #0f1117;
--bg-2: #151a26;
--bg-spot-1: #1a2136;
--bg-spot-2: #1d1b34;
--card: #1c2233;
--text: #f3f6ff;
--muted: #b8c0d9;
--line: #2b3247;
--accent: #ffb000;
--accent-2: #00d0ff;
--accent-soft: rgba(255, 176, 0, 0.25);
--surface-1: #0b0f1a;
--surface-2: #263046;
--code-bg: #0b0f1a;
--code-text: #d6d9e6;
--panel-bg: rgba(28, 34, 51, 0.8);
--overlay-bg: rgba(15, 17, 23, 0.98);
}
* {
box-sizing: border-box;
}
a {
color: var(--accent);
}
h1 {
color: var(--accent);
}
.demo-links {
margin-top: 12px;
display: flex;
gap: 12px;
justify-content: center;
flex-wrap: wrap;
}
.demo-links a {
border: 1px solid var(--line);
border-radius: 999px;
padding: 6px 12px;
color: var(--muted);
text-decoration: none;
font-size: 0.85rem;
transition: border-color 0.2s ease, color 0.2s ease;
}
.demo-links a:hover {
color: var(--text);
border-color: var(--accent-2);
}
.demo-theme-toggle {
margin-top: 12px;
display: flex;
justify-content: center;
}
header {
border-bottom: 1px solid var(--line);
}
.demo-card,
.section,
.demo-section,
.panel,
.card {
background: var(--card);
border: 1px solid var(--line);
border-radius: 16px;
color: var(--text);
box-shadow: 0 18px 36px rgba(6, 10, 24, 0.45);
}
.demo-card {
display: flex;
flex-direction: column;
gap: 12px;
}
.demo-card .code-block {
margin-top: auto;
}
.demo-grid,
.grid {
align-items: stretch;
}
.demo-card h2,
.demo-card h3,
.section h2,
.demo-section h2,
.panel-header {
color: var(--text);
}
.label,
.stat-label,
.category-title,
.subtitle,
.hint,
.note {
color: var(--muted);
}
.info-item,
.capability,
.preference,
.option-group,
.output,
.current-url,
.event-log,
.result-card,
.log,
.stat {
background: var(--surface-1);
border: 1px solid var(--line);
color: var(--text);
}
.info-item .label,
.capability .name {
color: var(--muted);
}
.panel-header,
.options,
.topbar,
.top-links {
background: var(--panel-bg);
border-bottom: 1px solid var(--line);
color: var(--text);
}
.subtitle,
.hint,
.note,
.demo-card p,
.section p,
.demo-section p {
color: var(--muted);
}
.code-block,
pre,
code {
background: var(--code-bg);
color: var(--code-text);
border-radius: 8px;
}
.value-display,
.output,
.result,
.demo-output {
background: var(--surface-1);
border: 1px solid var(--line);
color: var(--text);
}
button {
background: linear-gradient(120deg, var(--accent), #ff6a00);
color: #111;
border: none;
}
button:hover {
filter: brightness(1.05);
}
input,
select,
textarea {
background: var(--surface-1);
color: var(--text);
border: 1px solid var(--line);
}
footer {
color: var(--muted);
}
footer a {
color: var(--text);
}
arc-slider {
--arc-slider-text-color: var(--text);
--arc-slider-value-bg: var(--surface-1);
--arc-slider-value-border: var(--line);
--arc-slider-value-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}
rich-select {
--caller-background: var(--card);
--caller-color: var(--text);
--caller-border: 1px solid var(--line);
--caller-hover-background: var(--surface-2);
--caller-hover-color: var(--text);
--caller-hover-border-color: var(--line);
--caller-focus-border-color: var(--accent-2);
--caller-focus-shadow: 0 0 0 3px rgba(0, 208, 255, 0.25);
--caller-disabled-background: var(--surface-1);
--caller-disabled-color: #6b7280;
--caller-disabled-border-color: var(--line);
--arrow-color: var(--muted);
--selectOptions-background: var(--card);
--selectOptions-border: 1px solid var(--line);
--selectOptions-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
--input-background: var(--surface-1);
--input-border: 1px solid var(--line);
--input-color: var(--text);
--input-placeholder-color: #6b7280;
--option-color: var(--text);
--option-hover-background: var(--surface-2);
--option-hover-color: var(--text);
--option-active-background: var(--accent);
--option-active-color: #111;
--option-selected-background: var(--accent-soft);
--option-selected-color: var(--text);
--option-disabled-background: var(--surface-1);
--option-disabled-color: #6b7280;
}
multi-select {
--multi-select-bg: var(--card);
--multi-select-border-color: var(--line);
--multi-select-border-hover: var(--line);
--multi-select-border-focus: var(--accent-2);
--multi-select-text-color: var(--text);
--multi-select-placeholder-color: #6b7280;
--multi-select-arrow-color: var(--muted);
--multi-select-dropdown-bg: var(--card);
--multi-select-shadow: 0 10px 22px rgba(0, 0, 0, 0.45);
--multi-select-option-hover-bg: var(--surface-2);
--multi-select-option-selected-bg: var(--accent-soft);
}
tab-nav {
--tab-bg: var(--card);
--tab-border: var(--line);
--tab-text: var(--muted);
--tab-active-text: var(--text);
--tab-hover-bg: var(--surface-2);
--tab-active-border: var(--accent);
--tab-disabled: #9ca3af;
}
slider-underline {
--slider-track: var(--surface-2);
--slider-fill: var(--accent);
--slider-thumb: var(--accent);
--slider-label-color: var(--text);
--slider-tick-color: #9ca3af;
--slider-tick-value-color: var(--muted);
}
header-nav {
--header-bg: var(--card);
--header-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
--header-link-color: var(--text);
--header-link-hover: var(--accent);
--header-mobile-hover-bg: var(--surface-2);
}
calendar-inline {
--calendar-bg: var(--card);
--calendar-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
--calendar-text: var(--text);
--calendar-accent: var(--accent);
--calendar-today: var(--accent-soft);
--calendar-selected: var(--accent);
--calendar-hover-bg: var(--surface-2);
--calendar-muted: var(--muted);
--calendar-muted-strong: #9ca3af;
--calendar-other-month: #9ca3af;
--calendar-disabled: #cbd5e1;
--calendar-holiday: #ef4444;
--calendar-holiday-selected: #111;
}
marked-calendar {
--calendar-bg: var(--card);
--calendar-border: var(--line);
--calendar-title: var(--text);
--calendar-muted: var(--muted);
--calendar-surface: var(--surface-1);
--calendar-accent: var(--accent);
--calendar-accent-hover: #ff7a1a;
--calendar-border-strong: var(--line);
--calendar-contrast: #111;
--calendar-nav-bg: var(--surface-1);
--calendar-nav-hover: var(--surface-2);
}
radar-chart {
--radar-bg: var(--card);
--radar-grid-color: var(--line);
--radar-axis-color: #94a3b8;
--radar-label-color: var(--muted);
}
multi-carousel {
--carousel-bg: var(--card);
--carousel-arrow-bg: var(--surface-1);
--carousel-arrow-color: var(--text);
--carousel-arrow-hover-bg: var(--surface-2);
--carousel-arrow-hover-color: var(--text);
--carousel-nav-bg: var(--surface-1);
--carousel-nav-color: var(--muted);
--carousel-nav-hover: #9ca3af;
--carousel-nav-active: var(--accent);
--carousel-focus-color: var(--accent-2);
}
nav-list {
--nav-list-bg: var(--card);
--nav-list-border-color: var(--line);
--nav-list-selected-border-color: var(--accent);
--nav-list-selected-bg: var(--surface-2);
--nav-list-hover-bg: var(--surface-2);
--nav-list-selected-color: var(--text);
}
theme-toggle {
--theme-toggle-bg: var(--card);
--theme-toggle-icon-color: var(--muted);
--theme-toggle-hover-bg: var(--surface-2);
--theme-toggle-active-bg: var(--surface-1);
--theme-toggle-active-color: var(--text);
--theme-toggle-dark-bg: var(--card);
--theme-toggle-dark-border: var(--line);
--theme-toggle-dark-icon-color: var(--muted);
--theme-toggle-dark-active-bg: var(--surface-1);
--theme-toggle-dark-active-color: var(--text);
--theme-toggle-dark-hover-bg: var(--surface-2);
}
qr-code {
--qr-fg: #0f1117;
--qr-bg: #f3f6ff;
}
click-clock {
--clock-color: var(--text);
--clock-bg: var(--card);
--clock-muted-color: var(--muted);
}
historical-line {
--title-color: var(--text);
--border-color: var(--line);
--year-bg: var(--surface-1);
}
circle-steps {
--steps-muted: var(--muted);
--steps-text: var(--text);
--steps-pending: var(--surface-2);
}
rich-inputfile {
--input-border: var(--line);
--input-border-focus: var(--accent-2);
--input-bg: var(--card);
--input-label-color: var(--text);
--input-hover-bg: var(--surface-2);
--input-drag-bg: var(--accent-soft);
--input-disabled-bg: var(--surface-1);
--input-success-border: #22c55e;
--input-success-bg: rgba(34, 197, 94, 0.12);
--input-icon-color: #94a3b8;
--input-text-color: var(--muted);
--input-accent-color: var(--accent-2);
--input-file-bg: var(--surface-1);
--input-preview-bg: var(--surface-1);
--input-file-name-color: var(--text);
--input-file-size-color: var(--muted);
--input-error-color: #ef4444;
--input-hint-color: var(--muted);
}
data-card {
--data-card-bg: var(--card);
--data-card-border-color: var(--line);
--data-card-title-color: var(--text);
--data-card-desc-color: var(--muted);
--data-card-info-bg: var(--overlay-bg);
--data-card-info-close-bg: var(--surface-2);
--data-card-info-close-color: var(--text);
--data-card-info-close-hover-bg: var(--surface-1);
--data-card-info-text: var(--text);
--data-card-loading-color: var(--muted);
--data-card-info-trigger-hover: var(--accent);
}
app-modal {
--app-modal-bg: var(--card);
--app-modal-body-color: var(--text);
--app-modal-standalone-bg: rgba(255, 176, 0, 0.35);
--app-modal-standalone-color: #111;
--app-modal-standalone-hover-bg: rgba(255, 176, 0, 0.6);
} JS (js)
document.querySelectorAll('.footer-year').forEach(el => el.textContent = new Date().getFullYear());
import "https://esm.sh/@manufosela/modal-dialog";
const sizeConfig = {
small: {
title: 'Small Modal',
content: 'This is a small modal with limited width (360px).',
code: `<modal-dialog size="small" title="Small Modal">
<p>This is a small modal with limited width (360px).</p>
</modal-dialog>`
},
medium: {
title: 'Medium Modal',
content: 'This is the default medium-sized modal (500px).',
code: `<modal-dialog size="medium" title="Medium Modal">
<p>This is the default medium-sized modal (500px).</p>
</modal-dialog>`
},
large: {
title: 'Large Modal',
content: 'This is a large modal for more complex content (720px).',
code: `<modal-dialog size="large" title="Large Modal">
<p>This is a large modal for more complex content (720px).</p>
</modal-dialog>`
},
full: {
title: 'Full Width Modal',
content: 'This modal takes the full width but adapts height to content.',
code: `<modal-dialog size="full" title="Full Width Modal">
<p>This modal takes the full width but adapts height to content.</p>
</modal-dialog>`
},
fullscreen: {
title: 'Fullscreen Modal',
content: 'This modal takes up the entire screen (width and height). Perfect for complex interfaces, editors, or immersive content.',
code: `<modal-dialog size="fullscreen" title="Fullscreen Modal">
<p>This modal takes up the entire screen (width and height).</p>
<p>Perfect for complex interfaces, editors, or immersive content.</p>
</modal-dialog>`
}
};
window.showSize = (size) => {
const modal = document.getElementById('size-modal');
const config = sizeConfig[size];
modal.size = size;
modal.title = config.title;
document.getElementById('size-content').textContent = config.content;
document.getElementById('size-code').innerHTML = config.code;
modal.show();
};
window.showCustom = (width, height) => {
const modal = document.getElementById('custom-modal');
modal.width = width;
modal.height = height;
document.getElementById('custom-content').textContent = `Modal with custom dimensions: ${width} × ${height}`;
document.getElementById('custom-code').innerHTML = `<modal-dialog width="${width}" height="${height}" title="Custom Size">
<p>Modal with custom dimensions: ${width} × ${height}</p>
</modal-dialog>`;
modal.show();
};
document.getElementById('confirm').addEventListener('modal-confirm', () => {
alert('Item deleted!');
});
document.getElementById('form').addEventListener('modal-confirm', () => {
alert('Form submitted!');
});
import '../../theme-toggle/src/theme-toggle.js';
const root = document.documentElement;
root.classList.add('dark');
const toggle = document.querySelector('theme-toggle');
if (toggle) {
toggle.theme = root.classList.contains('dark') ? 'dark' : 'light';
toggle.addEventListener('theme-changed', (event) => {
const theme = event.detail?.theme;
if (!theme) return;
root.classList.toggle('dark', theme === 'dark');
});
}