This commit is contained in:
skkim committed 2026-09-22 08:53:53 +09:00
commit 81a61b50f5
26 files changed
+480 -447

No files matched your search

+19 -4
View File
@@ -13,7 +13,7 @@
* `data-slider="on"` 이 걸리며 드래그로 바뀐다. 이 사이트의 존재 이유가 인용이라
* **모든 슬라이드는 항상 HTML 에 있다** — 지금 보이는 한 장만 그리지 않는다.
*/
import {useCallback, useEffect, useId, useRef, useState, type ReactNode} from 'react';
import {createContext, useCallback, useContext, useEffect, useId, useRef, useState, type ReactNode} from 'react';
import useEmblaCarousel from 'embla-carousel-react';
import {AUTOPLAY_MS, useRailAutoplay} from './use-rail-autoplay';
import {ChevronLeft, ChevronRight} from 'lucide-react';
@@ -52,6 +52,14 @@ interface CarouselProps {
* 그렇게 옮겨진 슬라이드에는 트랙의 flex `gap` 이 적용되지 않는다 — 이음매에서만
* 카드 둘이 딱 붙는다. 간격을 아무리 맞춰도 그 자리는 안 고쳐진다.
* 되감기를 없애면 슬라이드는 늘 flex 흐름 안에 있고, 간격은 한 값으로 유지된다.
* ★ `loop` 을 다시 쓰는 자리(미니 블로그, 2026-09-18)에서 위 증상을 실측으로 재현했다 —
* Playwright 로 좌표를 재 보니 이음매(마지막→첫 장)에서만 간격이 정확히 0px 였다.
* flex `gap` 은 **컨테이너** 속성이라 DOM 순서로만 계산되는데, embla 의 loop 보정
* transform 은 슬라이드를 시각적으로만 반대편에 옮겨 놓아 그 이웃 관계를 못 본다.
* 그래서 `loop` 일 때는 트랙의 `gap` 을 0 으로 끄고, 대신 **슬라이드 자신의
* `margin-inline-end`** 로 간격을 준다(`CarouselSlide` 의 `SlideGapContext`) — margin 은
* 슬라이드 자기 박스에 붙어 있어 embla 가 loop 거리를 잴 때 그 크기에 포함된다.
* `loop=false`(기본값)인 다른 모든 레일은 이 경로를 안 타서 예전 그대로다.
*/
autoplay?: number | false;
/**
@@ -66,6 +74,8 @@ interface CarouselProps {
className?: string;
}
/** `loop` 일 때만 값이 선다(간격을 rem 값으로) — `CarouselSlide` 가 자기 margin 으로 대신 낸다. */
const SlideGapContext = createContext<number | null>(null);
export function Carousel({
label,
@@ -212,8 +222,8 @@ export function Carousel({
}
}}
>
<div className="slider-track" style={{gap: `${gap}rem`}} id={id}>
{children}
<div className="slider-track" style={{gap: loop ? 0 : `${gap}rem`}} id={id}>
<SlideGapContext.Provider value={loop ? gap : null}>{children}</SlideGapContext.Provider>
</div>
</div>
@@ -264,8 +274,13 @@ export function Carousel({
* "옆으로 더 있다"는 유일한 시각 신호다** — 딱 맞게 자르면 아무도 밀지 않는다.
*/
export function CarouselSlide({basis, children}: {basis: string; children: ReactNode}) {
const loopGap = useContext(SlideGapContext);
return (
<div className={`min-w-0 shrink-0 grow-0 ${basis}`} aria-roledescription="슬라이드">
<div
className={`min-w-0 shrink-0 grow-0 ${basis}`}
style={loopGap != null ? {marginInlineEnd: `${loopGap}rem`} : undefined}
aria-roledescription="슬라이드"
>
{children}
</div>
);
+30 -23
View File
@@ -1,6 +1,7 @@
import {useEffect} from 'react';
import {useEffect, useRef} from 'react';
import type {ReactNode} from 'react';
import {X} from 'lucide-react';
import {useScrollLock} from './use-scroll-lock';
/**
* 바텀시트(모바일) · 가운데 카드(데스크톱) 모달 한 장.
@@ -13,29 +14,32 @@ export function Modal({
open,
onClose,
label,
title,
children,
wide,
}: {
open: boolean;
onClose: () => void;
label: string;
/** 닫기 버튼과 한 줄에 놓일 제목. 없으면 닫기 버튼만 뜬다. */
title?: ReactNode;
children: ReactNode;
/** 안이 2열(정보+예약)로 갈리는 경우처럼 lg 폭이 필요할 때. */
wide?: boolean;
}) {
const onCloseRef = useRef(onClose);
onCloseRef.current = onClose;
useScrollLock(open);
useEffect(() => {
if (!open) return;
const onKey = (event: KeyboardEvent) => {
if (event.key === 'Escape') onClose();
if (event.key === 'Escape') onCloseRef.current();
};
const previous = document.body.style.overflow;
document.body.style.overflow = 'hidden';
window.addEventListener('keydown', onKey);
return () => {
document.body.style.overflow = previous;
window.removeEventListener('keydown', onKey);
};
}, [open, onClose]);
return () => window.removeEventListener('keydown', onKey);
}, [open]);
if (!open) return null;
@@ -51,24 +55,27 @@ export function Modal({
role="dialog"
aria-modal="true"
aria-label={label}
className={`absolute inset-x-0 bottom-0 max-h-[88svh] overflow-auto rounded-t-2xl px-5 pb-8 pt-14 sm:bottom-auto sm:left-1/2 sm:top-1/2 sm:max-h-[85vh] sm:w-full sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl ${
className={`absolute inset-x-0 bottom-0 flex max-h-[88svh] flex-col overflow-hidden rounded-t-2xl sm:bottom-auto sm:left-1/2 sm:top-1/2 sm:max-h-[85vh] sm:w-full sm:-translate-x-1/2 sm:-translate-y-1/2 sm:rounded-2xl ${
wide ? 'sm:max-w-3xl' : 'sm:max-w-lg'
}`}
style={{backgroundColor: 'var(--color-surface)'}}
>
<button
type="button"
onClick={onClose}
aria-label="닫기"
className="tap absolute right-3 top-3 z-10 flex size-10 items-center justify-center rounded-full shadow-md"
style={{
backgroundColor: 'var(--color-surface)',
boxShadow: '0 1px 2px rgba(0,0,0,.18), 0 0 0 1px color-mix(in oklab, currentColor 12%, transparent)',
}}
>
<X className="size-5" />
</button>
{children}
<div className="border-line flex shrink-0 items-center justify-between gap-3 border-b p-5 pb-4">
{title && <h3 className="h3 min-w-0 truncate">{title}</h3>}
<button
type="button"
onClick={onClose}
aria-label="닫기"
className="tap ml-auto flex size-10 shrink-0 items-center justify-center rounded-full shadow-md"
style={{
backgroundColor: 'var(--color-surface)',
boxShadow: '0 1px 2px rgba(0,0,0,.18), 0 0 0 1px color-mix(in oklab, currentColor 12%, transparent)',
}}
>
<X className="size-5" />
</button>
</div>
<div className="overflow-y-auto p-5 pb-8">{children}</div>
</div>
</div>
);
+1
View File
@@ -3,3 +3,4 @@ export {Carousel, CarouselSlide} from './Carousel';
export {Card, Chip, Field, ActionLink} from './primitives';
export {ShowMore} from './ShowMore';
export {Modal} from './Modal';
export {useScrollLock} from './use-scroll-lock';
@@ -0,0 +1,39 @@
/**
* 모달·오버레이가 열려 있는 동안 배경 스크롤을 잠근다 — **한 벌만 둔다.**
*
* ★ 왜 훅으로 뺐나 (2026-09-21, 사장님: "이거 목업 하나만 해결하면 끝이야? 훅으로 만들어놓던가")
* 같은 잠금·복귀 코드가 Modal · GallerySection · EventSection 세 곳에 따로 박혀 있었다.
* 모달 하나만 고치고 나니 나머지 둘은 그대로 남아 같은 스크롤 버그가 다시 났다 —
* 복사한 코드는 복사한 곳마다 따로 고쳐야 한다.
* ★ 복귀는 즉시 이동이어야 한다. `index.css` 의 전역 `html { scroll-behavior: smooth }` 때문에
* `window.scrollTo` 가 애니메이션으로 움직이며 "위로 튀었다 내려오는" 것처럼 보인다 —
* 이 한 번만 `scroll-behavior: auto` 로 강제한다.
*/
import {useEffect} from 'react';
export function useScrollLock(active: boolean) {
useEffect(() => {
if (!active) return;
const scrollY = window.scrollY;
const body = document.body;
const prevPosition = body.style.position;
const prevTop = body.style.top;
const prevWidth = body.style.width;
const prevOverflow = body.style.overflow;
body.style.position = 'fixed';
body.style.top = `-${scrollY}px`;
body.style.width = '100%';
body.style.overflow = 'hidden';
return () => {
body.style.position = prevPosition;
body.style.top = prevTop;
body.style.width = prevWidth;
body.style.overflow = prevOverflow;
const root = document.documentElement;
const prevScrollBehavior = root.style.scrollBehavior;
root.style.scrollBehavior = 'auto';
window.scrollTo(0, scrollY);
root.style.scrollBehavior = prevScrollBehavior;
};
}, [active]);
}