File size: 2,068 Bytes
e66cfb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
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"]