feat: enhance fullscreen mode slide and hide able slide

This commit is contained in:
a2nr 2026-05-14 20:25:21 +07:00
parent bc49877123
commit 120a1338c0
1 changed files with 264 additions and 109 deletions

View File

@ -3,6 +3,7 @@
let activeIndex = $state(0);
let isFullscreen = $state(false);
let isExpanded = $state(false); // Default to hidden (collapsed)
let carouselEl = $state<HTMLElement | null>(null);
function next() {
@ -33,8 +34,13 @@
}
}
function toggleExpand() {
isExpanded = !isExpanded;
}
// Keyboard navigation
function handleKeydown(e: KeyboardEvent) {
if (!isExpanded && !isFullscreen) return;
if (e.key === 'ArrowRight') next();
if (e.key === 'ArrowLeft') prev();
if (e.key === 'f' || e.key === 'F') toggleFullscreen();
@ -45,20 +51,40 @@
if (typeof document !== 'undefined') {
document.addEventListener('fullscreenchange', () => {
isFullscreen = !!document.fullscreenElement;
if (isFullscreen) isExpanded = true;
});
}
</script>
<svelte:window onkeydown={handleKeydown} />
<div class="slide-carousel-wrapper" class:collapsed={!isExpanded && !isFullscreen}>
{#if !isExpanded && !isFullscreen}
<button class="expand-toggle-btn" onclick={toggleExpand}>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>
Tampilkan Slide Materi ({slides.length} Slide)
</button>
{:else}
<div class="slide-carousel" class:is-fullscreen={isFullscreen} bind:this={carouselEl}>
<div class="carousel-header">
<button class="collapse-btn" onclick={toggleExpand} aria-label="Sembunyikan slide">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 15-6-6-6 6"/></svg>
Sembunyikan Slide
</button>
<div class="slide-counter-top">
{activeIndex + 1} / {slides.length}
</div>
</div>
<div class="slide-container">
{#each slides as slide, i}
<div class="slide" class:active={i === activeIndex}>
<div class="slide-inner">
<div class="slide-content prose">
{@html slide}
</div>
</div>
</div>
{/each}
</div>
@ -98,23 +124,64 @@
</button>
</div>
</div>
<div class="slide-counter">
{activeIndex + 1} / {slides.length}
{/if}
</div>
{/if}
</div>
<style>
.slide-carousel {
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 12px;
:root {
--slide-bg: #f8fafc;
--slide-controls-bg: #ffffff;
--slide-border: #e2e8f0;
--slide-primary: #3b82f6;
--slide-text: #1e293b;
--slide-header-bg: #f1f5f9;
}
.slide-carousel-wrapper {
margin: 1.5rem 0;
transition: all 0.3s ease;
}
.slide-carousel-wrapper.collapsed {
border: 1px dashed var(--slide-border);
border-radius: 12px;
background: var(--slide-bg);
}
.expand-toggle-btn {
width: 100%;
padding: 1.25rem;
background: transparent;
border: none;
color: #64748b;
font-weight: 600;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 0.75rem;
transition: color 0.2s, background 0.2s;
border-radius: 12px;
}
.expand-toggle-btn:hover {
color: var(--slide-primary);
background: rgba(59, 130, 246, 0.05);
}
.slide-carousel {
background: var(--slide-bg);
border: 1px solid var(--slide-border);
border-radius: 12px;
position: relative;
overflow: hidden;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
color: var(--slide-text);
height: 500px; /* Slightly taller default */
}
.slide-carousel.is-fullscreen {
@ -129,16 +196,54 @@
background: #ffffff;
}
.carousel-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.5rem 1rem;
background: var(--slide-header-bg);
border-bottom: 1px solid var(--slide-border);
}
.is-fullscreen .carousel-header {
display: none; /* Hide top header in fullscreen */
}
.collapse-btn {
background: transparent;
border: none;
color: #64748b;
font-size: 0.85rem;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
padding: 0.25rem 0.5rem;
border-radius: 6px;
}
.collapse-btn:hover {
background: rgba(0,0,0,0.05);
color: var(--slide-text);
}
.slide-counter-top {
font-size: 0.75rem;
font-weight: 700;
color: #94a3b8;
background: white;
padding: 2px 8px;
border-radius: 10px;
border: 1px solid var(--slide-border);
}
.slide-container {
display: grid;
grid-template-areas: "stack";
flex-grow: 1;
min-height: 300px;
background: inherit;
}
.is-fullscreen .slide-container {
flex: 1;
min-height: 0;
background: inherit;
}
.slide {
@ -147,18 +252,12 @@
visibility: hidden;
transition: opacity 0.4s ease, transform 0.4s ease;
transform: translateX(20px);
padding: 2.5rem;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
background: inherit;
overflow-y: auto;
}
.is-fullscreen .slide {
padding: 4rem;
height: 100%;
scrollbar-width: thin;
}
.slide.active {
@ -167,41 +266,67 @@
transform: translateX(0);
}
.slide-content {
max-width: 100%;
.slide-inner {
display: flex;
flex-direction: column;
align-items: center;
padding: clamp(1rem, 5vw, 3rem);
min-height: 100%;
width: 100%;
box-sizing: border-box;
text-align: center;
}
.slide-inner::before,
.slide-inner::after {
content: "";
margin: auto;
}
.slide-content {
max-width: 1000px !important;
font-size: clamp(0.95rem, 1.5vw, 1.25rem);
}
.slide-content :global(h1) { font-size: clamp(1.8rem, 5vw, 3rem); line-height: 1.2; margin-top: 0; }
.slide-content :global(h2) { font-size: clamp(1.5rem, 4vw, 2.25rem); }
.slide-content :global(h3) { font-size: clamp(1.2rem, 3vw, 1.75rem); }
.slide-content :global(p) { line-height: 1.6; }
.slide-content :global(img) {
max-height: 50vh;
width: auto;
max-width: 100%;
object-fit: contain;
border-radius: 8px;
margin: 1rem auto;
}
.is-fullscreen .slide-inner {
padding: clamp(1.5rem, 8vw, 6rem);
}
.is-fullscreen .slide-content {
font-size: 1.5rem;
max-width: 900px;
font-size: clamp(1.1rem, 2vw, 1.6rem);
}
.is-fullscreen .slide-content :global(h1) { font-size: 3.5rem; }
.is-fullscreen .slide-content :global(h2) { font-size: 2.5rem; }
.is-fullscreen .slide-content :global(h3) { font-size: 2rem; }
.slide-content :global(h1),
.slide-content :global(h2),
.slide-content :global(h3),
.slide-content :global(p) {
margin-left: auto;
margin-right: auto;
}
.is-fullscreen .slide-content :global(h1) { font-size: clamp(2.5rem, 8vw, 5rem); }
.is-fullscreen .slide-content :global(h2) { font-size: clamp(2rem, 6vw, 3.5rem); }
.is-fullscreen .slide-content :global(h3) { font-size: clamp(1.5rem, 4vw, 2.5rem); }
.slide-controls {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem 1.5rem;
background: #ffffff;
border-top: 1px solid #e2e8f0;
padding: 0.75rem 1.25rem;
background: var(--slide-controls-bg);
border-top: 1px solid var(--slide-border);
user-select: none;
z-index: 10;
}
.is-fullscreen .slide-controls {
padding: 1.5rem 3rem;
background: #f8fafc;
background: var(--slide-bg);
}
.left-controls, .right-controls {
@ -211,10 +336,10 @@
}
.btn-nav, .btn-fullscreen {
background: #3b82f6;
background: var(--slide-primary);
color: white;
border: none;
border-radius: 8px;
border-radius: 10px;
width: 44px;
height: 44px;
display: flex;
@ -223,6 +348,7 @@
cursor: pointer;
font-size: 1.25rem;
transition: all 0.2s;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn-fullscreen {
@ -231,7 +357,8 @@
.btn-nav:hover:not(:disabled), .btn-fullscreen:hover {
filter: brightness(1.1);
transform: translateY(-1px);
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.btn-nav:active:not(:disabled), .btn-fullscreen:active {
@ -241,11 +368,12 @@
.btn-nav:disabled {
background: #cbd5e1;
cursor: not-allowed;
box-shadow: none;
}
.slide-dots {
display: flex;
gap: 0.5rem;
gap: 0.6rem;
}
.dot {
@ -256,44 +384,71 @@
border: none;
padding: 0;
cursor: pointer;
transition: background 0.2s, transform 0.2s;
transition: all 0.2s;
}
.dot.active {
background: #3b82f6;
transform: scale(1.2);
background: var(--slide-primary);
transform: scale(1.3);
width: 24px;
border-radius: 5px;
}
.slide-counter {
position: absolute;
top: 1rem;
right: 1rem;
background: rgba(0, 0, 0, 0.05);
padding: 0.25rem 0.75rem;
border-radius: 20px;
font-size: 0.875rem;
/* Desktop Counter moved to controls if not fullscreen */
:not(.is-fullscreen) .slide-counter-bottom {
font-size: 0.85rem;
font-weight: 600;
color: #64748b;
font-weight: 500;
}
.is-fullscreen .slide-counter {
top: 2rem;
right: 2rem;
font-size: 1.1rem;
padding: 0.5rem 1rem;
}
/* Mobile Optimizations */
@media (max-width: 768px) {
.slide {
padding: 1.5rem;
.slide-carousel {
height: auto;
min-height: 400px;
}
.slide-container {
min-height: 250px;
.slide-inner {
padding: 1.5rem 1rem;
}
.is-fullscreen .slide {
padding: 2rem 1rem;
.slide-controls {
padding: 0.75rem;
}
.btn-nav, .btn-fullscreen {
width: 40px;
height: 40px;
}
.slide-dots {
display: none;
}
}
/* Landscape specific fixes */
@media (max-height: 500px) and (orientation: landscape) {
.is-fullscreen .slide-inner {
padding: 1rem 3rem;
display: block;
text-align: left;
}
.is-fullscreen .slide-inner::before,
.is-fullscreen .slide-inner::after {
display: none;
}
.is-fullscreen .slide-content :global(h1) { font-size: 2rem; }
.is-fullscreen .slide-content :global(img) { max-height: 60vh; width: auto; float: right; margin: 0 0 1rem 1.5rem; }
.is-fullscreen .slide-controls {
padding: 0.5rem 2rem;
}
.btn-nav, .btn-fullscreen {
height: 36px;
width: 36px;
}
}
</style>