188 lines
9.1 KiB
TypeScript
188 lines
9.1 KiB
TypeScript
import type { Ref } from 'react'
|
||
import { createPortal } from 'react-dom'
|
||
import { cx } from '../lib/utils'
|
||
import type { TopIndex } from '../api/client/types.gen'
|
||
import { LEAF_SHADOW, MAP_IMG, MAP_SRC, md, PROVINCE, PROVINCES, STAGE, type Spot } from './foliage'
|
||
import { MEDALS, type TimeKind } from './lib'
|
||
import { Ic } from './ui'
|
||
|
||
/** 공유 이미지 전용 틀. 화면 밖에 그려 두고 보내기 때 이것만 찍는다 (화면의 버튼은 이미지에서 빠지므로 글자만으로 만든다) */
|
||
function Offscreen({ children }: { children: React.ReactNode }) {
|
||
return createPortal(
|
||
<div aria-hidden="true" className="pointer-events-none fixed top-0 -left-[10000px] w-[380px]">
|
||
{children}
|
||
</div>,
|
||
document.body,
|
||
)
|
||
}
|
||
|
||
export type DayShare = {
|
||
kind: TimeKind
|
||
label: string
|
||
now: boolean
|
||
icon: string
|
||
temp: string
|
||
score?: number | null
|
||
gak?: { name: string; icon: string } | null
|
||
}
|
||
|
||
function DayLabel({ d, size }: { d: DayShare; size: string }) {
|
||
return (
|
||
<span className={cx('flex items-center gap-1.5 font-jua leading-none', size)}>
|
||
{d.label}
|
||
{d.now && <small className="rounded-full bg-[#ff7a45] px-2 py-0.5 font-sans text-[13px] font-extrabold text-white">지금</small>}
|
||
</span>
|
||
)
|
||
}
|
||
|
||
/** 히어로 공유: 아침·낮·저녁·밤 네 줄. 줄마다 그 시간대 하늘에 날씨·기온, 날씨 점수, 그 시간 1등 각. 로고·지역·날짜는 공유 틀이 그린다 */
|
||
export function DayShareCard({ days, ref }: { days: DayShare[]; ref: Ref<HTMLDivElement> }) {
|
||
return (
|
||
<Offscreen>
|
||
<div ref={ref} className="flex aspect-[4/5] flex-col">
|
||
{days.map((d) => (
|
||
<div key={d.kind} className="b-hero grid flex-1 grid-cols-[96px_1fr_auto] items-center gap-3 px-4" data-t={d.kind}>
|
||
<span className="flex flex-col gap-1.5">
|
||
<DayLabel d={d} size="text-[28px]" />
|
||
<span className="flex items-center gap-1 font-jua text-[22px] leading-none">
|
||
<Ic name={d.icon} className="h-7 w-7 object-contain" />
|
||
{d.temp}
|
||
</span>
|
||
</span>
|
||
<span className="flex min-w-0 items-center gap-2">
|
||
{d.gak && <Ic name={d.gak.icon} className="w-10 shrink-0" />}
|
||
<b className="font-jua text-[24px] leading-tight font-normal break-keep">{d.gak?.name ?? '쉬어 가요'}</b>
|
||
</span>
|
||
<span className="text-right">
|
||
<b className="block font-bagel text-[62px] leading-[0.9] font-normal">{d.score ?? '–'}</b>
|
||
<small className="text-[13px] font-bold opacity-75">날씨 점수</small>
|
||
</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</Offscreen>
|
||
)
|
||
}
|
||
|
||
/** 1:1 공유용: 같은 내용을 2×2 칸으로 */
|
||
export function DayShareGrid({ days, ref }: { days: DayShare[]; ref: Ref<HTMLDivElement> }) {
|
||
return (
|
||
<Offscreen>
|
||
<div ref={ref} className="grid aspect-square grid-cols-2 grid-rows-2">
|
||
{days.map((d) => (
|
||
<div key={d.kind} className="b-hero flex flex-col justify-between p-4" data-t={d.kind}>
|
||
<span className="flex items-center justify-between">
|
||
<DayLabel d={d} size="text-[26px]" />
|
||
<span className="flex items-center gap-1 font-jua text-[20px] leading-none">
|
||
<Ic name={d.icon} className="h-7 w-7 object-contain" />
|
||
{d.temp}
|
||
</span>
|
||
</span>
|
||
<span>
|
||
<b className="block font-bagel text-[64px] leading-[0.9] font-normal">{d.score ?? '–'}</b>
|
||
<small className="text-[12px] font-bold opacity-75">날씨 점수</small>
|
||
</span>
|
||
<span className="flex min-w-0 items-center gap-1.5">
|
||
{d.gak && <Ic name={d.gak.icon} className="w-8 shrink-0" />}
|
||
<b className="truncate font-jua text-[21px] font-normal">{d.gak?.name ?? '쉬어 가요'}</b>
|
||
</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</Offscreen>
|
||
)
|
||
}
|
||
|
||
export function GakShareCard({ items, title, ref }: { items: TopIndex[]; title: string; ref: Ref<HTMLDivElement> }) {
|
||
return (
|
||
<Offscreen>
|
||
<div ref={ref} className="b-band-2 flex aspect-[4/5] flex-col bg-white px-5 pt-5 pb-4">
|
||
<p className="m-0 font-jua text-[22px]">{title}</p>
|
||
<ol className="m-0 mt-3 grid list-none gap-2 p-0">
|
||
{items.map((g, i) => (
|
||
<li key={g.index_id} className="flex items-center gap-2.5 rounded-[18px] bg-white px-3 py-2.5 shadow-[inset_0_-4px_0_var(--shade)]">
|
||
{i < 3 ? <Ic name={MEDALS[i]} className="w-[24px] shrink-0" /> : <span className="w-[24px] shrink-0 text-center font-jua text-(--ink3)">{i + 1}</span>}
|
||
<Ic name={g.icon} className="w-[36px] shrink-0" />
|
||
<span className="min-w-0 flex-1">
|
||
<b className="block font-jua text-[17px] leading-tight font-normal">{g.name}</b>
|
||
{g.summary && <small className="block truncate text-xs font-semibold text-(--ink2)">{g.summary}</small>}
|
||
</span>
|
||
<em className="font-bagel text-[24px] leading-none text-(--orange) not-italic">{g.score}</em>
|
||
</li>
|
||
))}
|
||
</ol>
|
||
</div>
|
||
</Offscreen>
|
||
)
|
||
}
|
||
|
||
/** 단풍 명소 하나 공유: 그 명소를 가운데 둔 지도 조각(둘레 시·도 이름과 다른 절정 잎) 위에 큰 잎, 아래에 이름·지역·절정 예상일 */
|
||
export function FoliageSpotShare({ spot, peak, ref }: { spot: Spot | null; peak: Spot[]; ref: Ref<HTMLDivElement> }) {
|
||
if (!spot) return null
|
||
const near = peak.filter((m) => m.name !== spot.name)
|
||
return (
|
||
<Offscreen>
|
||
<div ref={ref} className="flex aspect-[4/5] flex-col bg-[#fff6ea] text-[#28304a]">
|
||
<div className="relative flex-1 overflow-hidden">
|
||
{/* 명소가 가운데 오게 지도 그림을 3배로 키워 옮긴다 */}
|
||
<div className="absolute top-1/2 left-1/2 aspect-square w-[220%] bg-[#fff6ea]" style={{ transform: `translate(-${spot.x * 100}%, -${spot.y * 100}%)` }}>
|
||
<img src={MAP_SRC} alt="" className={MAP_IMG} />
|
||
{PROVINCES.map((v) => (
|
||
<span key={v.name} className={cx(PROVINCE, 'text-[15px]')} style={{ left: `${v.x * 100}%`, top: `${v.y * 100}%` }}>
|
||
{v.name}
|
||
</span>
|
||
))}
|
||
{near.map((m) => (
|
||
<Ic key={m.name} name={m.kind} className={cx('absolute size-5 -translate-x-1/2 -translate-y-1/2', LEAF_SHADOW)} style={{ left: `${m.x * 100}%`, top: `${m.y * 100}%` }} />
|
||
))}
|
||
</div>
|
||
<span className="absolute top-1/2 left-1/2 grid size-[92px] -translate-x-1/2 -translate-y-1/2 place-items-center rounded-full border-[3px] border-[#28304a] bg-[#ffffff99]">
|
||
<Ic name={spot.kind} className={cx('w-[60px]', LEAF_SHADOW)} />
|
||
</span>
|
||
</div>
|
||
<div className="px-5 pt-3 pb-4">
|
||
<p className="m-0 flex items-center gap-2">
|
||
<b className="font-jua text-[34px] leading-tight font-normal">{spot.name}</b>
|
||
<span className={cx('rounded-full px-2 py-0.5 text-[14px] font-extrabold', spot.stage === 'peak' ? 'bg-[#ffe3db] text-[#b5321f]' : 'bg-[#efe6d8] text-[#5b6075]')}>{STAGE[spot.stage]}</span>
|
||
</p>
|
||
<p className="m-0 mt-0.5 text-[15px] font-bold text-[#6b7189]">{spot.region}</p>
|
||
<p className="m-0 mt-2 font-jua text-[22px]">절정 예상 {md(spot.peak)}</p>
|
||
</div>
|
||
</div>
|
||
</Offscreen>
|
||
)
|
||
}
|
||
|
||
/** 단풍 지도 전체 공유: 지금 절정 제목, 절정 잎만 찍힌 지도, 가기 좋은 곳 1~3위 */
|
||
export function FoliageMapShare({ title, peak, ranked, ref }: { title: string; peak: Spot[]; ranked: Spot[]; ref: Ref<HTMLDivElement> }) {
|
||
return (
|
||
<Offscreen>
|
||
<div ref={ref} className="flex aspect-[4/5] flex-col bg-[#fff6ea] px-4 pt-4 pb-3 text-[#28304a]">
|
||
<p className="m-0 font-jua text-[24px] leading-tight">{title}</p>
|
||
<div className="relative mx-auto mt-1 aspect-square w-[78%] bg-[#fff6ea]">
|
||
<img src={MAP_SRC} alt="" className={MAP_IMG} />
|
||
{PROVINCES.map((v) => (
|
||
<span key={v.name} className={PROVINCE} style={{ left: `${v.x * 100}%`, top: `${v.y * 100}%` }}>
|
||
{v.name}
|
||
</span>
|
||
))}
|
||
{peak.map((m) => (
|
||
<Ic key={m.name} name={m.kind} className={cx('absolute size-4 -translate-x-1/2 -translate-y-1/2', LEAF_SHADOW)} style={{ left: `${m.x * 100}%`, top: `${m.y * 100}%` }} />
|
||
))}
|
||
</div>
|
||
<ol className="m-0 mt-auto grid list-none gap-1.5 p-0">
|
||
{ranked.slice(0, 3).map((m, i) => (
|
||
<li key={m.name} className="flex items-center gap-2.5 rounded-[14px] bg-[#ffffff] px-3 py-1.5">
|
||
<Ic name={MEDALS[i]} className="w-[22px] shrink-0" />
|
||
<Ic name={m.kind} className="w-[22px] shrink-0" />
|
||
<b className="min-w-0 flex-1 truncate font-jua text-[17px] font-normal">{m.name}</b>
|
||
<span className="shrink-0 text-[13px] font-bold text-[#6b7189]">{m.region.split(' ')[0]}</span>
|
||
<span className="shrink-0 font-jua text-[16px] text-[#b5321f]">{md(m.peak)}</span>
|
||
</li>
|
||
))}
|
||
</ol>
|
||
</div>
|
||
</Offscreen>
|
||
)
|
||
}
|