Skip to content

Commit

Permalink
Close #33
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohswedd committed Nov 12, 2024
1 parent 94f2303 commit 0e2d87b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 40 deletions.
55 changes: 16 additions & 39 deletions css/components/modal.css
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
/* Base Modal Styling */
/* Base Modal Overlay */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.6); /* Slightly deeper background for better contrast */
background-color: rgba(0, 0, 0, 0.6);
display: flex;
justify-content: center;
align-items: center;
z-index: var(--z-50);
opacity: 0;
visibility: hidden;
transition: opacity 0.35s ease, visibility 0.35s ease;
backdrop-filter: blur(4px); /* Adds a modern blur effect */
backdrop-filter: blur(4px);
}

.modal-overlay.active {
opacity: 1;
visibility: visible;
}

/* Modal Container */
.modal {
background-color: var(--neutral-50);
border-radius: var(--radius-2xl); /* Softer, rounded corners */
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3); /* Enhanced shadow for depth */
border-radius: var(--radius-2xl);
box-shadow: var(--shadow-xl);
max-width: clamp(20rem, 50vw, 40rem);
width: 100%;
position: relative;
Expand Down Expand Up @@ -53,15 +54,10 @@
align-items: center;
}

.modal-header.no-title {
display: none;
}

.modal-title {
font-size: clamp(1.125rem, 2vw, 1.5rem);
font-weight: 600;
color: var(--neutral-900);
letter-spacing: 0.5px; /* Slightly increased letter-spacing for elegance */
}

.modal-close {
Expand All @@ -75,7 +71,7 @@

.modal-close:hover {
color: var(--danger);
transform: scale(1.1); /* Slight enlargement for feedback */
transform: scale(1.1);
}

/* Modal Body */
Expand All @@ -87,7 +83,6 @@
scrollbar-width: thin;
}

/* Custom Scrollbar */
.modal-body::-webkit-scrollbar {
width: 8px;
background-color: var(--neutral-200);
Expand All @@ -98,10 +93,6 @@
border-radius: 4px;
}

.modal-body::-webkit-scrollbar-track {
background-color: var(--neutral-100);
}

/* Modal Footer */
.modal-footer {
padding: var(--space-4);
Expand All @@ -110,44 +101,30 @@
text-align: right;
}

/* Scrollable Modal */
.modal-scrollable .modal-body {
max-height: 70vh;
padding-right: 1rem; /* Ensures space for custom scrollbar */
}
/* Variants */
[data-variant="primary"] .modal { border-left: 5px solid var(--primary); }
[data-variant="secondary"] .modal { border-left: 5px solid var(--secondary); }
[data-variant="success"] .modal { border-left: 5px solid var(--success); }
[data-variant="danger"] .modal { border-left: 5px solid var(--danger); }
[data-variant="warning"] .modal { border-left: 5px solid var(--warning); }
[data-variant="info"] .modal { border-left: 5px solid var(--info); }

/* Fullscreen Modal */
.modal-fullscreen {
[data-size="fullscreen"] .modal {
width: 100%;
height: 100%;
border-radius: 0;
max-width: none;
max-height: none;
}

/* Variants */
.modal-primary { border-left: 5px solid var(--primary); }
.modal-secondary { border-left: 5px solid var(--secondary); }
.modal-success { border-left: 5px solid var(--success); }
.modal-danger { border-left: 5px solid var(--danger); }
.modal-warning { border-left: 5px solid var(--warning); }
.modal-info { border-left: 5px solid var(--info); }

/* Animation for Modal Close */
.modal-overlay.closing {
opacity: 0;
visibility: hidden;
transition: opacity 0.2s ease, visibility 0.2s ease;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
.modal {
max-width: 90vw;
padding: var(--space-2);
}

.modal-body {
max-height: 50vh; /* Adjust for smaller screens */
max-height: 50vh;
}
}
9 changes: 8 additions & 1 deletion js/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ export class Modal {
this.overlay = this.modal.closest('.modal-overlay');
this.closeButton = this.modal.querySelector('.modal-close');

// Close button in header
if (this.closeButton) {
this.closeButton.addEventListener('click', () => this.close());
}

// Close modal when clicking on overlay (if allowed)
this.overlay.addEventListener('click', (e) => {
if (e.target === this.overlay && !this.overlay.classList.contains('no-close-on-outside-click')) {
this.close();
}
});

// Close modal when clicking a button with the class "close-modal" inside the modal
this.modal.querySelectorAll('.close-modal').forEach((button) => {
button.addEventListener('click', () => this.close());
});
}

open() {
Expand All @@ -33,7 +40,7 @@ export class Modal {
}
}

// Initialize modals when the document is ready
// Initialize modals on document load
document.addEventListener('DOMContentLoaded', () => {
Modal.initAll();

Expand Down

0 comments on commit 0e2d87b

Please sign in to comment.