Weather/app/components/WeatherDetailsGird.tsx

60 lines
3.1 KiB
TypeScript
Raw Normal View History

2025-11-17 17:55:01 +08:00
import { Cloud, Droplets, Gauge, ThermometerSun, Wind } from "lucide-react";
2025-11-17 19:10:41 +08:00
import { useWeatherStore } from "@/store/weatherStore";
2025-11-17 17:55:01 +08:00
2025-11-17 17:17:43 +08:00
interface WeatherDetailsGridProps {
icon: React.ReactNode;
label: string;
value: string;
subtitle?: string;
}
2025-11-17 17:55:01 +08:00
function WeatherInfoItem({ icon, label, value, subtitle }: WeatherDetailsGridProps) {
return(
<div className="group rounded-xl bg-slate-50/50 border border-slate-200 p-4 hover:bg-slate-100/80 hover:border-slate-300 transition-all duration-300">
<div className="flex items-start gap-2">
<div className="flex-shrink-0 w-9 h-9 rounded-full bg-white flex items-center justify-center group-hover:scale-100 transition-tramsform duration-300">
{icon}
</div>
<div className="flex-1 min-w-0">
<p className="text-sm text-slate-500">{label}</p>
<p className="text-slate-900 text-sm font-semibold">{value}</p>
{subtitle && <p className="text-xs text-slate-400 mt-1">{subtitle}</p>}
</div>
</div>
</div>
)
}
export function WeatherDetailsGrid(){
2025-11-17 19:10:41 +08:00
const {currentWeather} = useWeatherStore();
2025-11-17 17:55:01 +08:00
if(!currentWeather) return null;
return(
<div>
<div className="grid grid-cols-2 md:grid-cols-3 gap-3 mb-4">
<WeatherInfoItem icon={<Droplets className="w-4 h-4 text-blue-500"/>} label="湿度" value={`${currentWeather.current.humidity}%`} />
<WeatherInfoItem icon={<Wind className="w-4 h-4 text-blue-500"/>} label="风速" value={`${currentWeather.current.wind_speed} m/s`} />
<WeatherInfoItem icon={<Gauge className="w-4 h-4 text-blue-500"/>} label="气压" value={`${currentWeather.current.pressure} hPa`} />
<WeatherInfoItem icon={<Cloud className="w-4 h-4 text-blue-500"/>} label="云量" value={`${currentWeather.current.cloudcover}%`} />
<WeatherInfoItem icon={<ThermometerSun className="w-4 h-4 text-blue-500"/>} label="紫外线" value={`${currentWeather.current.uv_index} UV`} />
</div>
<div className="pt-4 border-t border-slate-200">
<div className="flex items-center justify-between text-sm mb-2">
<div className="flex items-center gap-2 text-slate-600">
<Droplets className="w-4 h-4 text-blue-500"/>
<span>:\
<span className="font-semibold">
2025-11-17 19:10:41 +08:00
{currentWeather.current.precip} mm
2025-11-17 17:55:01 +08:00
</span>
</span>
</div>
<span className=" text-slate-600">
{currentWeather.current.is_day === "yes" ? "白天" : "夜晚"}
</span>
</div>
<p className="text-xs text-center text-slate-500">
: {currentWeather.current.observation_time}
</p>
</div>
</div>
)
}