Files
zhimingge/components/shared/region-select.tsx
T
dekun fff77dac3f Implement three divination modes, learn pages, and PM2 deploy on port 3130.
Add liuyao/bazi/combined flows with shared calc and AI infrastructure, 64-gua learn routes, and update Ubuntu PM2 deployment docs for port 3130.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-10 20:19:49 +08:00

65 lines
1.7 KiB
TypeScript

"use client";
import { getProvinces, getCities, getRegionLocation } from "@/lib/data/regions";
interface RegionSelectProps {
provinceCode: string;
cityCode: string;
onProvinceChange: (code: string) => void;
onCityChange: (code: string) => void;
label?: string;
}
export default function RegionSelect({
provinceCode,
cityCode,
onProvinceChange,
onCityChange,
label = "出生地域",
}: RegionSelectProps) {
const provinces = getProvinces();
const cities = provinceCode ? getCities(provinceCode) : [];
return (
<div className="space-y-2">
<label className="text-sm font-medium">{label}</label>
<div className="grid gap-2 sm:grid-cols-2">
<select
className="rounded-md border bg-background px-3 py-2 text-sm"
value={provinceCode}
onChange={(e) => {
onProvinceChange(e.target.value);
onCityChange("");
}}
>
<option value=""></option>
{provinces.map((p) => (
<option key={p.code} value={p.code}>
{p.name}
</option>
))}
</select>
<select
className="rounded-md border bg-background px-3 py-2 text-sm"
value={cityCode}
onChange={(e) => onCityChange(e.target.value)}
disabled={!provinceCode}
>
<option value="">/</option>
{cities.map((c) => (
<option key={c.code} value={c.code}>
{c.name}
</option>
))}
</select>
</div>
</div>
);
}
export function useRegionLocation(provinceCode: string, cityCode: string) {
return provinceCode
? getRegionLocation(provinceCode, cityCode)
: null;
}