@lmy54321/design-system 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,388 @@
1
+ import React, { useState, useEffect, useCallback } from "react";
2
+ import { motion, AnimatePresence } from "motion/react";
3
+ import { cn } from "@lmy54321/design-system";
4
+ import { BottomNavigationBar } from "@lmy54321/design-system";
5
+ import type { TabId } from "@lmy54321/design-system";
6
+ import { DraggablePanel, DRAWER_STATES } from "@lmy54321/design-system";
7
+ import { Btn } from "@lmy54321/design-system";
8
+ import { Tag } from "@lmy54321/design-system";
9
+ import { Dialog } from "@lmy54321/design-system";
10
+ import { Toast } from "@lmy54321/design-system";
11
+ import { IconFont } from "@lmy54321/design-system";
12
+ import { ImageWithFallback } from "@lmy54321/design-system";
13
+ import { TencentMap } from "@lmy54321/design-system";
14
+ import { SearchFlowDemo } from "./SearchFlowDemo";
15
+
16
+ /* ── 功能入口(5个均分) ── */
17
+ const serviceEntries = [
18
+ { label: "驾车", color: "#367BF6", icon: "vehicle" },
19
+ { label: "打车", color: "#FF6B35", icon: "vehicle" },
20
+ { label: "叮当", color: "#00B894", icon: "service" },
21
+ { label: "指南", color: "#6C5CE7", icon: "map-marked" },
22
+ { label: "更多", color: "#E84393", icon: "app" },
23
+ ];
24
+
25
+ /* ── Nearby POI data (含经纬度,用于地图标注联动) ── */
26
+ const nearbyPOIs = [
27
+ {
28
+ id: "1",
29
+ name: "星巴克臻选(国贸旗舰店)",
30
+ category: "咖啡厅",
31
+ distance: "320m",
32
+ rating: "4.8",
33
+ photo: "/images/scene/cafe.png",
34
+ tag: "人气推荐",
35
+ lat: 39.9088,
36
+ lng: 116.4605,
37
+ },
38
+ {
39
+ id: "2",
40
+ name: "海底捞火锅(三里屯店)",
41
+ category: "火锅",
42
+ distance: "580m",
43
+ rating: "4.7",
44
+ photo: "/images/scene/hotpot.png",
45
+ tag: "排队中",
46
+ lat: 39.9320,
47
+ lng: 116.4540,
48
+ },
49
+ {
50
+ id: "3",
51
+ name: "全聚德烤鸭(前门店)",
52
+ category: "北京菜",
53
+ distance: "1.2km",
54
+ rating: "4.5",
55
+ photo: "/images/scene/peking-duck.png",
56
+ tag: "老字号",
57
+ lat: 39.8992,
58
+ lng: 116.3974,
59
+ },
60
+ {
61
+ id: "4",
62
+ name: "朝阳大悦城",
63
+ category: "购物中心",
64
+ distance: "1.5km",
65
+ rating: "4.6",
66
+ photo: "/images/scene/mall.png",
67
+ tag: "",
68
+ lat: 39.9210,
69
+ lng: 116.4810,
70
+ },
71
+ {
72
+ id: "5",
73
+ name: "故宫博物院",
74
+ category: "景点",
75
+ distance: "2.3km",
76
+ rating: "4.9",
77
+ photo: "/images/feed-axis.png",
78
+ tag: "必去",
79
+ lat: 39.9163,
80
+ lng: 116.3972,
81
+ },
82
+ ];
83
+
84
+ /* ── Glass round button ── */
85
+ function GlassButton({
86
+ children,
87
+ onClick,
88
+ className,
89
+ }: {
90
+ children: React.ReactNode;
91
+ onClick?: () => void;
92
+ className?: string;
93
+ }) {
94
+ return (
95
+ <button
96
+ type="button"
97
+ onClick={onClick}
98
+ className={cn(
99
+ "relative flex items-center justify-center shrink-0 size-[40px] rounded-[20px]",
100
+ "bg-card/80 shadow-[0px_4px_16px_0px_rgba(0,0,0,0.10)] backdrop-blur-md border border-white/40",
101
+ "active:after:absolute active:after:inset-0 active:after:bg-foreground/10 active:after:content-[''] active:after:rounded-[inherit]",
102
+ "text-foreground transition-all duration-200",
103
+ className
104
+ )}
105
+ >
106
+ {children}
107
+ </button>
108
+ );
109
+ }
110
+
111
+ interface MapHomeProps {
112
+ activeTab: TabId;
113
+ onTabChange: (id: TabId) => void;
114
+ }
115
+
116
+ /* ── POI 标注点屏幕坐标(基于地图中心 39.909,116.42 zoom=13 的近似映射) ── */
117
+ const DEFAULT_CENTER = { lat: 39.909, lng: 116.42 };
118
+ const DEFAULT_ZOOM = 13;
119
+
120
+ export function MapHome({ activeTab, onTabChange }: MapHomeProps) {
121
+
122
+ const [selectedPOI, setSelectedPOI] = useState<(typeof nearbyPOIs)[number] | null>(null);
123
+ const [toastText, setToastText] = useState<string | null>(null);
124
+ const [panelState, setPanelState] = useState(DRAWER_STATES.SMALL);
125
+
126
+ /* ── 地图联动状态 ── */
127
+ const [mapCenter, setMapCenter] = useState(DEFAULT_CENTER);
128
+ const [mapZoom, setMapZoom] = useState(DEFAULT_ZOOM);
129
+ const [highlightedPoiId, setHighlightedPoiId] = useState<string | null>(null);
130
+
131
+ /* 点击 POI 列表项 → 联动地图 */
132
+ const handlePoiTap = useCallback((poi: typeof nearbyPOIs[number]) => {
133
+ setHighlightedPoiId(poi.id);
134
+ setMapCenter({ lat: poi.lat, lng: poi.lng });
135
+ setMapZoom(16);
136
+ setSelectedPOI(poi);
137
+ }, []);
138
+
139
+ /* 关闭 POI 详情 → 恢复地图视野 */
140
+ const handleClosePOI = useCallback(() => {
141
+ setSelectedPOI(null);
142
+ setHighlightedPoiId(null);
143
+ setMapCenter(DEFAULT_CENTER);
144
+ setMapZoom(DEFAULT_ZOOM);
145
+ }, []);
146
+
147
+ const showToast = useCallback((text: string) => {
148
+ setToastText(text);
149
+ }, []);
150
+
151
+ useEffect(() => {
152
+ if (!toastText) return;
153
+ const timer = setTimeout(() => setToastText(null), 2200);
154
+ return () => clearTimeout(timer);
155
+ }, [toastText]);
156
+
157
+ return (
158
+ <div
159
+ className="relative w-full h-[100dvh] overflow-hidden bg-background"
160
+ style={{ fontFamily: "var(--font-family-sans)" }}
161
+ >
162
+ {/* ── POI Detail Dialog ── */}
163
+ <Dialog
164
+ open={!!selectedPOI}
165
+ onOpenChange={(open) => { if (!open) handleClosePOI(); }}
166
+ title={selectedPOI?.name ?? ""}
167
+ description={selectedPOI ? `${selectedPOI.rating}分 · ${selectedPOI.category} · ${selectedPOI.distance}` : ""}
168
+ secondaryActionText="关闭"
169
+ mainActionText="开始导航"
170
+ onSecondaryAction={handleClosePOI}
171
+ onMainAction={() => { handleClosePOI(); showToast("正在规划路线..."); }}
172
+ />
173
+
174
+ {/* ── 1. 真实腾讯地图底图(联动 center/zoom + markers) ── */}
175
+ <TencentMap
176
+ className="absolute inset-0 w-full h-full"
177
+ center={mapCenter}
178
+ zoom={mapZoom}
179
+ pitch={60}
180
+ rotation={0}
181
+ />
182
+
183
+ {/* ── Left top: Compass indicator ── */}
184
+ <motion.div
185
+ className="absolute top-[56px] left-[16px] z-40"
186
+ initial={{ opacity: 0, scale: 0.8 }}
187
+ animate={{ opacity: 1, scale: 1 }}
188
+ transition={{ delay: 0.2, duration: 0.3 }}
189
+ >
190
+ <div className="flex flex-col items-center">
191
+ <div className="size-[32px] flex items-center justify-center">
192
+ <div className="relative">
193
+ <span className="text-[10px] font-bold text-destructive leading-none">N</span>
194
+ <div className="absolute -bottom-[2px] left-1/2 -translate-x-1/2 w-0 h-0 border-l-[3px] border-r-[3px] border-t-[5px] border-l-transparent border-r-transparent border-t-destructive" />
195
+ </div>
196
+ </div>
197
+ </div>
198
+ </motion.div>
199
+
200
+ {/* ── Right side: Map Controls ── */}
201
+ <motion.div
202
+ className="absolute right-[16px] top-[56px] z-40 flex flex-col gap-[8px] items-center"
203
+ initial={{ x: 20, opacity: 0 }}
204
+ animate={{ x: 0, opacity: 1 }}
205
+ transition={{ delay: 0.3, duration: 0.4 }}
206
+ >
207
+ <div className="flex flex-col items-center gap-[2px] w-[40px] h-[60px] justify-center rounded-[20px] bg-card/80 shadow-[0px_4px_16px_0px_rgba(0,0,0,0.10)] backdrop-blur-md border border-white/40">
208
+ <IconFont name="sunny" size="14px" className="text-[#FFB800]" />
209
+ <span className="text-[8px] font-medium text-foreground leading-none">31°C</span>
210
+ </div>
211
+ <div className="h-[4px]" />
212
+ <GlassButton>
213
+ <IconFont name="layers" size="20px" />
214
+ </GlassButton>
215
+ <GlassButton>
216
+ <span className="text-[12px] font-bold text-foreground">2D</span>
217
+ </GlassButton>
218
+ <GlassButton>
219
+ <IconFont name="mail" size="18px" />
220
+ </GlassButton>
221
+ </motion.div>
222
+
223
+ {/* ── Right bottom: Compass + Location ── */}
224
+ <motion.div
225
+ className="absolute right-[16px] bottom-[340px] z-40 flex flex-col gap-[8px] items-center"
226
+ initial={{ x: 20, opacity: 0 }}
227
+ animate={{ x: 0, opacity: 1 }}
228
+ transition={{ delay: 0.4, duration: 0.4 }}
229
+ >
230
+ <GlassButton onClick={() => showToast("指南针已重置")}>
231
+ <IconFont name="compass" size="20px" />
232
+ </GlassButton>
233
+ <GlassButton>
234
+ <IconFont name="focus" size="20px" className="text-accent" />
235
+ </GlassButton>
236
+ </motion.div>
237
+
238
+ {/* ── 2. Bottom Navigation — 压盖在面板上方,全屏搜索时隐藏 ── */}
239
+ {panelState !== DRAWER_STATES.FULL && (
240
+ <div className="absolute bottom-[12px] left-1/2 -translate-x-1/2 z-[1001]">
241
+ <BottomNavigationBar activeTab={activeTab} onTabChange={onTabChange} />
242
+ </div>
243
+ )}
244
+
245
+ {/* ── DraggablePanel ── */}
246
+ <DraggablePanel
247
+ state={panelState}
248
+ onStateChange={setPanelState}
249
+ customSmallHeight={260}
250
+ customMediumHeight={500}
251
+ bottomOffset={8}
252
+ fullScreenContent={
253
+ <SearchFlowDemo onBack={() => setPanelState(DRAWER_STATES.SMALL)} />
254
+ }
255
+ >
256
+ {/* Search Bar - 展示型假搜索框,点击展开面板为全屏搜索 */}
257
+ <div className="px-[16px] pb-[10px]">
258
+ <button
259
+ type="button"
260
+ onClick={() => setPanelState(DRAWER_STATES.FULL)}
261
+ className="w-full h-[48px] rounded-[24px] bg-card/50 flex items-center px-[16px] gap-[8px] active:bg-card/70 transition-colors"
262
+ >
263
+ <IconFont name="search" size="18px" className="text-muted-foreground shrink-0" />
264
+ <span className="text-[16px] text-muted-foreground font-normal">搜索地点、公交、地铁</span>
265
+ </button>
266
+ </div>
267
+
268
+ {/* 3. 金刚位 — 5个均分,grid-cols-5 */}
269
+ <div className="px-[16px] pb-[10px]">
270
+ <div className="grid grid-cols-5 gap-x-0">
271
+ {serviceEntries.map((entry) => (
272
+ <button
273
+ key={entry.label}
274
+ onClick={() => showToast(`打开${entry.label}`)}
275
+ className="flex flex-col items-center gap-[6px] active:opacity-70 transition-opacity"
276
+ >
277
+ <div
278
+ className="size-[48px] rounded-[16px] flex items-center justify-center"
279
+ style={{ backgroundColor: `${entry.color}12` }}
280
+ >
281
+ <IconFont name={entry.icon} size="24px" style={{ color: entry.color }} />
282
+ </div>
283
+ <span className="text-[12px] text-foreground font-normal leading-[1.4] whitespace-nowrap">
284
+ {entry.label}
285
+ </span>
286
+ </button>
287
+ ))}
288
+ </div>
289
+ </div>
290
+
291
+ {/* Quick shortcuts row */}
292
+ <div className="px-[16px] pb-[8px]">
293
+ <div className="flex gap-[10px]">
294
+ <button
295
+ onClick={() => showToast("正在导航回家...")}
296
+ className="flex-1 flex items-center gap-[8px] px-[12px] py-[10px] rounded-[14px] bg-card-muted active:bg-black/[0.06] transition-colors"
297
+ >
298
+ <IconFont name="home" size="16px" className="text-[#FF6B35] shrink-0" />
299
+ <span className="text-[13px] font-medium text-foreground">回家</span>
300
+ <span className="text-[12px] text-muted-foreground ml-auto">25分钟</span>
301
+ </button>
302
+ <button
303
+ onClick={() => showToast("打开帝都秋日漫步指南")}
304
+ className="flex-1 flex items-center gap-[8px] px-[12px] py-[10px] rounded-[14px] bg-card-muted active:bg-black/[0.06] transition-colors"
305
+ >
306
+ <IconFont name="map-marked" size="16px" className="text-[#6C5CE7] shrink-0" />
307
+ <span className="text-[13px] font-medium text-foreground truncate">帝都秋日漫步指南</span>
308
+ </button>
309
+ </div>
310
+ </div>
311
+
312
+ {/* === 以下内容上滑 MEDIUM 后才可见 === */}
313
+
314
+ <div className="mx-[16px] h-px bg-border/60" />
315
+
316
+ {/* Nearby Recommendations */}
317
+ <div className="px-[16px] py-[12px]">
318
+ <div className="flex items-center justify-between mb-[10px]">
319
+ <span className="text-[16px] font-medium text-foreground leading-[1.5]">附近推荐</span>
320
+ <Tag
321
+ label="查看更多"
322
+ size="sm"
323
+ showArrow
324
+ className="bg-black/[0.04] text-muted-foreground border-transparent"
325
+ />
326
+ </div>
327
+ <div className="flex flex-col gap-[4px]">
328
+ {nearbyPOIs.map((poi) => (
329
+ <div
330
+ key={poi.id}
331
+ onClick={() => handlePoiTap(poi)}
332
+ className={cn(
333
+ "flex items-center gap-[12px] py-[10px] cursor-pointer -mx-[4px] px-[4px] rounded-[14px] transition-colors",
334
+ highlightedPoiId === poi.id
335
+ ? "bg-accent/[0.06]"
336
+ : "active:bg-black/[0.03]"
337
+ )}
338
+ >
339
+ <div className="size-[56px] rounded-[14px] overflow-hidden shrink-0 bg-card-muted">
340
+ <ImageWithFallback src={poi.photo} alt={poi.name} className="size-full object-cover" />
341
+ </div>
342
+ <div className="flex-1 min-w-0">
343
+ <div className="flex items-center gap-[6px]">
344
+ <p className="text-[14px] font-medium text-foreground truncate leading-[20px]">{poi.name}</p>
345
+ {poi.tag && <Tag label={poi.tag} size="xs" className="shrink-0" />}
346
+ </div>
347
+ <div className="flex items-center gap-[6px] text-[12px] text-muted-foreground leading-[16px] mt-[3px]">
348
+ <span className="flex items-center gap-[2px]">
349
+ <IconFont name="star" variant="filled" size="12px" className="text-[#FFB800]" />
350
+ {poi.rating}
351
+ </span>
352
+ <span className="w-px h-[10px] bg-border" />
353
+ <span>{poi.category}</span>
354
+ <span className="w-px h-[10px] bg-border" />
355
+ <span>{poi.distance}</span>
356
+ </div>
357
+ </div>
358
+ <Btn
359
+ size="small"
360
+ variant="primary"
361
+ label="导航"
362
+ icon={<IconFont name="map-navigation" size="14px" />}
363
+ onClick={() => showToast(`正在规划前往${poi.name}的路线...`)}
364
+ />
365
+ </div>
366
+ ))}
367
+ </div>
368
+ </div>
369
+ </DraggablePanel>
370
+
371
+ {/* ── Toast ── */}
372
+ <div className="fixed top-[120px] left-0 right-0 z-[2000] flex justify-center pointer-events-none">
373
+ <AnimatePresence>
374
+ {toastText && (
375
+ <motion.div
376
+ className="pointer-events-auto"
377
+ initial={{ y: -10, opacity: 0 }}
378
+ animate={{ y: 0, opacity: 1 }}
379
+ exit={{ y: -10, opacity: 0 }}
380
+ >
381
+ <Toast lines={[toastText]} showIcon showClose onClose={() => setToastText(null)} />
382
+ </motion.div>
383
+ )}
384
+ </AnimatePresence>
385
+ </div>
386
+ </div>
387
+ );
388
+ }