Spaces:
Sleeping
Sleeping
| """ | |
| layout/Chapter_card.py ← 向下相容 shim | |
| ---------------------------------------- | |
| create_card 已整合進 layout/renderer/ 的 cards 模組。 | |
| 此 shim 讓舊 import 繼續正常運作: | |
| from layout.Chapter_card import create_card ← 仍可用 | |
| """ | |
| from .renderer.renderer import render_doc as _ # 確保 renderer 已初始化 # noqa: F401 | |
| # Chapter_card 的原始功能直接在此定義(避免 components/ 路徑問題) | |
| from dash import html | |
| import dash_mantine_components as dmc | |
| from dash_iconify import DashIconify | |
| def create_card(data: dict) -> dmc.Card: | |
| """章節總覽卡片(原 Chapter_card.py)。""" | |
| buttons = [ | |
| dmc.Anchor( | |
| href=data["link"], | |
| children=dmc.Button("單元學習", variant="light", color="orange", size="sm", radius="xl"), | |
| ) | |
| ] | |
| if "trick" in data: | |
| buttons.append( | |
| dmc.Anchor( | |
| href=data["trick"], | |
| children=dmc.Button("技巧學習", variant="outline", color="gray", size="sm", radius="xl"), | |
| ) | |
| ) | |
| buttons.append( | |
| dmc.Anchor( | |
| href=data["test"], | |
| children=dmc.Button("小測驗", variant="filled", color="blue", size="sm", radius="xl"), | |
| ) | |
| ) | |
| desc_items = [dmc.Text(line, size="sm", c="dimmed") for line in data["description"]] | |
| desc_items += [dmc.Text(" ", size="sm") for _ in range(4 - len(data["description"]))] | |
| return dmc.Card( | |
| children=[ | |
| dmc.Text(data["title"], fw=700, size="lg"), | |
| dmc.Group( | |
| gap="xs", mt="xs", mb="sm", | |
| children=[dmc.Badge(label, color=color, radius="md") for label, color in data["badges"]], | |
| ), | |
| dmc.Stack(gap=0, style={"minHeight": 100}, children=desc_items), | |
| dmc.Flex(gap="sm", wrap="wrap", justify="flex-start", mt="sm", children=buttons), | |
| ], | |
| withBorder=True, shadow="sm", radius="md", | |
| style={"width": {"base": 280, "sm": 320, "md": 350, "lg": 400}}, | |
| ) | |
| __all__ = ["create_card"] | |