mirror of
https://github.com/shadoll/sLogos.git
synced 2026-02-04 02:53:22 +00:00
Refactor Preview component for improved URL hash synchronization and responsive design
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
|
show = false;
|
||||||
dispatch('close');
|
dispatch('close');
|
||||||
// Remove preview anchor from URL
|
// Remove preview anchor from URL
|
||||||
if (window.location.hash.startsWith('#preview-')) {
|
if (window.location.hash.startsWith('#preview-')) {
|
||||||
@@ -31,6 +32,8 @@
|
|||||||
|
|
||||||
$: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme);
|
$: getLogoThemeColor = logo => getDefaultLogoColor(logo.colors, theme);
|
||||||
|
|
||||||
|
$: validColorConfig = logo && typeof logo.colorConfig === 'object' && logo.colorConfig.selector ? logo.colorConfig : undefined;
|
||||||
|
|
||||||
// Improved debug logging for color and theme
|
// Improved debug logging for color and theme
|
||||||
$: {
|
$: {
|
||||||
if (logo && logo.colors) {
|
if (logo && logo.colors) {
|
||||||
@@ -40,6 +43,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync show state with URL hash
|
||||||
|
$: {
|
||||||
|
if (typeof window !== 'undefined') {
|
||||||
|
if (window.location.hash.startsWith('#preview-')) {
|
||||||
|
show = true;
|
||||||
|
} else {
|
||||||
|
show = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update URL hash when opening/closing preview
|
// Update URL hash when opening/closing preview
|
||||||
$: if (show && logo) {
|
$: if (show && logo) {
|
||||||
const anchor = '#preview-' + encodeURIComponent(logo.name.replace(/\s+/g, '-').toLowerCase());
|
const anchor = '#preview-' + encodeURIComponent(logo.name.replace(/\s+/g, '-').toLowerCase());
|
||||||
@@ -48,6 +62,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch for show/close to update scroll lock
|
||||||
|
$: if (show && logo) {
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
} else {
|
||||||
|
document.body.style.overflow = '';
|
||||||
|
}
|
||||||
|
|
||||||
// On mount, check for preview anchor and open if present
|
// On mount, check for preview anchor and open if present
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
document.addEventListener('keydown', handleKeydown);
|
document.addEventListener('keydown', handleKeydown);
|
||||||
@@ -55,11 +76,17 @@
|
|||||||
openLogoByAnchor(window.location.hash);
|
openLogoByAnchor(window.location.hash);
|
||||||
}
|
}
|
||||||
window.addEventListener('hashchange', onHashChange);
|
window.addEventListener('hashchange', onHashChange);
|
||||||
|
// Lock background scroll when preview is open
|
||||||
|
if (show && logo) {
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
document.removeEventListener('keydown', handleKeydown);
|
document.removeEventListener('keydown', handleKeydown);
|
||||||
window.removeEventListener('hashchange', onHashChange);
|
window.removeEventListener('hashchange', onHashChange);
|
||||||
|
// Restore scroll when component is destroyed
|
||||||
|
document.body.style.overflow = '';
|
||||||
});
|
});
|
||||||
|
|
||||||
function onHashChange() {
|
function onHashChange() {
|
||||||
@@ -114,7 +141,7 @@
|
|||||||
<InlineSvg
|
<InlineSvg
|
||||||
path={logo.path}
|
path={logo.path}
|
||||||
color={logo.colors ? (logo._activeColor || getLogoThemeColor(logo)) : undefined}
|
color={logo.colors ? (logo._activeColor || getLogoThemeColor(logo)) : undefined}
|
||||||
colorConfig={logo.colors ? logo.colorConfig : undefined}
|
colorConfig={validColorConfig}
|
||||||
alt={logo.name}
|
alt={logo.name}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -182,7 +209,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
overflow: auto;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.modal-content.fullscreen-modal {
|
.modal-content.fullscreen-modal {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
@@ -196,6 +223,7 @@
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
border: none;
|
border: none;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.modal-header {
|
.modal-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -205,6 +233,7 @@
|
|||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
flex: 0 0 auto;
|
||||||
}
|
}
|
||||||
.modal-header h2 {
|
.modal-header h2 {
|
||||||
font-size: 2.2rem;
|
font-size: 2.2rem;
|
||||||
@@ -230,10 +259,11 @@
|
|||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
height: calc(100vh - 4.5rem);
|
height: 100%;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 0 2.5rem 2.5rem 2.5rem;
|
padding: 0;
|
||||||
gap: 2.5rem;
|
gap: 2.5rem;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.preview-container.fullscreen-preview {
|
.preview-container.fullscreen-preview {
|
||||||
flex: 2 1 0;
|
flex: 2 1 0;
|
||||||
@@ -245,7 +275,7 @@
|
|||||||
background: transparent;
|
background: transparent;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: auto;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.preview-media-wrapper {
|
.preview-media-wrapper {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -253,6 +283,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.preview-media-wrapper img,
|
.preview-media-wrapper img,
|
||||||
.preview-media-wrapper svg {
|
.preview-media-wrapper svg {
|
||||||
@@ -263,6 +294,8 @@
|
|||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
display: block;
|
display: block;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
}
|
}
|
||||||
.logo-details.fullscreen-details {
|
.logo-details.fullscreen-details {
|
||||||
flex: 1 1 350px;
|
flex: 1 1 350px;
|
||||||
@@ -272,11 +305,12 @@
|
|||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 2rem 2rem 1.5rem 2rem;
|
padding: 2rem 2rem 1.5rem 2rem;
|
||||||
margin: 2rem 0 2rem 0;
|
margin: 0;
|
||||||
box-shadow: 0 2px 16px 4px rgba(0,0,0,0.18);
|
box-shadow: 0 2px 16px 4px rgba(0,0,0,0.18);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
max-height: 100%;
|
||||||
}
|
}
|
||||||
.logo-tags {
|
.logo-tags {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
Reference in New Issue
Block a user