Files
o2o-weather/frontend/src/b/weatherWhy.tsx
T

89 lines
4.4 KiB
TypeScript

import type { WeatherWhy } from '@nalssigak/shared/api/client/types.gen'
import { cx } from '../lib/utils'
/** status: 히어로 상태 줄 그대로 (단계 이름, 실제 값) */
export type WeatherWhyPayload = { label: string; score: number; why: WeatherWhy[]; status?: { label: string; value: string; tone?: string; detail?: string | null }[] }
// 조건마다 같은 색을 막대 칸과 아래 줄 점에 같이 써서 이어 보이게
const COLOR: Record<string, string> = {
기온: '#ff7a45',
비: '#4f97e3',
햇볕: '#ffb02e',
바람: '#5fb8b0',
습도: '#8e8cf0',
미세먼지: '#b59a86',
}
const colorOf = (label: string) => COLOR[label] ?? '#9aa3b8'
// 상태 줄 항목마다 단계를 나누는 기준 (backend/services/hero_stats.py 와 같은 값)
const RULE: Record<string, string> = {
습도: '30% 아래는 건조, 60% 넘으면 습함이에요',
불쾌지수: '68 아래는 쾌적, 75부터 불쾌예요',
자외선: '3 아래는 낮음, 6부터 높음이에요',
미세먼지: '에어코리아 기준 등급이에요',
}
/** 날씨 점수 근거: 비중만큼 나눈 막대(채운 만큼 얻은 점수)와 조건별 지금 값 */
export function WeatherWhySheet({ d }: { d: WeatherWhyPayload }) {
return (
<div className="flex-1 overflow-auto overscroll-contain px-4 pt-4 pb-[18px]">
<p className="m-0 flex items-baseline gap-2">
<b className="font-bagel text-[44px] leading-none font-normal">{d.score}</b>
<span className="font-jua text-[17px] text-(--ink2)">{d.label} 날씨 점수</span>
</p>
<div className="mt-3 flex h-7 gap-[3px] overflow-hidden rounded-[10px]" role="img" aria-label={d.why.map((w) => `${w.label} 비중 ${w.weight}% 중 ${w.score}점`).join(', ')}>
{d.why.map((w) => (
<span key={w.label} className="relative h-full bg-[#eef2f8]" style={{ width: `${w.weight}%` }}>
<span className="absolute inset-y-0 left-0" style={{ width: `${w.score}%`, background: colorOf(w.label) }} />
</span>
))}
</div>
<p className="m-0 mt-1.5 text-[12.5px] font-semibold text-(--ink3)">칸 넓이는 비중, 채운 만큼이 얻은 점수예요</p>
<ul className="m-0 mt-3 flex list-none flex-col gap-1.5 p-0">
{d.why.map((w) => (
<li key={w.label} className="flex items-center gap-3 rounded-2xl bg-[#f5f8fc] px-3.5 py-2.5">
<i className="size-3 shrink-0 rounded-full" style={{ background: colorOf(w.label) }} aria-hidden="true" />
<span className="min-w-0 flex-1">
<b className="block font-jua text-[16px] leading-tight font-normal">
{w.label} <small className="font-sans text-[12px] font-bold text-(--ink3)">비중 {w.weight}%</small>
</b>
<small className="block text-[13px] font-semibold text-(--ink2)">{w.note}</small>
</span>
<b className="font-jua text-[20px] font-normal tabular-nums">{w.score}</b>
</li>
))}
</ul>
{d.status && d.status.length > 0 && (
<>
<h4 className="m-0 mt-5 font-jua text-[17px] font-normal">지금 상태</h4>
<ul className="m-0 mt-2 flex list-none flex-col gap-1.5 p-0">
{d.status.map((s) => (
<li key={s.label} className="flex items-center gap-3 rounded-2xl bg-[#f5f8fc] px-3.5 py-2.5">
<span className="min-w-0 flex-1">
<b className="block font-jua text-[16px] leading-tight font-normal">{s.label}</b>
{RULE[s.label] && <small className="block text-[12.5px] font-semibold text-(--ink3)">{RULE[s.label]}</small>}
</span>
<span className="shrink-0 text-right">
<b className={cx('block font-jua text-[18px] leading-tight font-normal', s.tone === 'warn' && 'b-warn')}>{s.value}</b>
{s.detail?.split(' · ').map((x) => (
<small key={x} className="block text-[12px] font-bold whitespace-nowrap text-(--ink2) tabular-nums">
{x}
</small>
))}
</span>
</li>
))}
</ul>
</>
)}
<p className="m-0 mt-3 text-[13px] leading-relaxed font-semibold text-(--ink2)">
조건마다 점수를 매겨 비중대로 합쳐요. 유난히 아쉬운 조건이 있으면 조금 더 깎고, 모든 조건이 완벽할 때만 만점이 나와요.
</p>
</div>
)
}