การ์ด
Card
A card for one piece of a page, such as a dashboard section: a header with a title, a line under it, an icon and an action in its corner; the content; and a footer for actions or a note. Every part is optional. White with no border on the shell's grey page. feature puts one card in the brand gradient, with white text. To open a page from the card, put an IconButton with href in action, such as one with the ArrowUpRight icon. Forms, inputs and tables on an app page always sit in a Card, never straight on AppShell's page. Card replaces the deprecated Panel.
ใช้เป็นการ์ดของแต่ละส่วนในหน้า เช่น ส่วนหนึ่งของหน้าภาพรวม การ์ดมีส่วนหัว (ไอคอน หัวข้อ คำอธิบายใต้หัวข้อ และปุ่มที่มุม) เนื้อหา และส่วนท้ายสำหรับปุ่มหรือหมายเหตุ การ์ดที่เป็นส่วนหนึ่งของหน้ามีส่วนหัวเสมอ: title, description สั้น ๆ และ icon จาก lucide-react ทุกส่วนของการ์ดไม่บังคับ การ์ดที่มีแค่ children จึงเป็นพื้นผิวสีขาวเรียบ ๆ ฟอร์ม ช่องกรอก และตารางในหน้าของแอปอยู่ใน Card เสมอ Card ใช้แทน Panel ที่เลิกใช้แล้ว
import { Card } from "@bsru/ui";ตัวอย่าง
ส่วนหัวและส่วนท้าย
title และ description อยู่ในส่วนหัว icon อยู่หน้าหัวข้อ action เป็นปุ่มเดียวที่มุม footer อยู่ใต้เส้นคั่น สำหรับปุ่มหรือหมายเหตุ
<Card
title="งบประมาณหน่วยงาน ก"
description="ปีงบประมาณ 2570"
icon={Wallet}
action={<IconButton icon={ArrowUpRight} label="เปิดแผนงบประมาณ" href="/budget/plans/2570" />}
footer={
<>
<Button tone="primary" size="sm" icon={Plus} label="สร้างคำขอ" href="/purchase-requests/new" />
<Button size="sm" icon={Download} label="ส่งออก" href="/budget/plans/2570/export" />
</>
}
>
<FieldList fields={fields} />
</Card>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| title | "งบประมาณหน่วยงาน ก" | string | The header's heading, which also names the card for screen readers. |
| description | "ปีงบประมาณ 2570" | string | A line under the title, such as what the card counts or when it was updated. |
| icon | "Wallet" | LucideIcon | An outline icon from lucide-react, in a round tile beside the title. |
| action | "<IconButton />" | ReactNode | One control in the header's corner, such as an IconButton that opens the full list or a small Button. |
| footer | "<Button /> <Button />" | ReactNode | The footer, under a line: actions such as Buttons, or a short note. |
การ์ดเด่น
tone feature ใช้ไล่สีของแอปกับตัวอักษรสีขาว สำหรับการ์ดที่สำคัญที่สุดหนึ่งใบในแถว เช่น การประชุมที่ใกล้ถึง web เป็นเขียว console เป็นม่วง ปุ่มที่มุมและปุ่มแบบเงียบเป็นสีขาว เมื่อชี้จะมีพื้นขาวโปร่งแสง
<Card
tone="feature"
title="ประชุมพิจารณางบประมาณ"
description="วันนี้ 14:00–16:00 น."
icon={CalendarClock}
action={<IconButton icon={ArrowUpRight} label="ดูรายละเอียดการประชุม" href={meeting.page} />}
footer={<Button size="sm" icon={Video} label="เข้าร่วมประชุม" href={meeting.url} />}
>
<p>ห้องประชุม 1 อาคารสำนักงานอธิการบดี</p>
</Card>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| tone | "feature" | CardTone ค่าที่ใช้ได้: "plain""feature""muted" | plain is white. feature is the brand gradient with white text, for at most one card in a row. muted is light grey, as for a card inside a card. |
| title | "ประชุมพิจารณางบประมาณ" | string | The header's heading, which also names the card for screen readers. |
| description | "วันนี้ 14:00–16:00 น." | string | A line under the title, such as what the card counts or when it was updated. |
| icon | "CalendarClock" | LucideIcon | An outline icon from lucide-react, in a round tile beside the title. |
| action | "<IconButton />" | ReactNode | One control in the header's corner, such as an IconButton that opens the full list or a small Button. |
| footer | "<Button />" | ReactNode | The footer, under a line: actions such as Buttons, or a short note. |
เปิดหน้าจากการ์ด
การ์ดไม่เป็นลิงก์ทั้งใบ ให้ใส่ IconButton ที่มี href ใน action เช่น ไอคอน ArrowUpRight label บอกว่าจะไปที่ไหน และเป็นชื่อของปุ่มสำหรับโปรแกรมอ่านหน้าจอ
<Card
title="คำขอที่รออนุมัติ"
description="รอคุณอนุมัติ"
icon={ClipboardList}
action={<IconButton icon={ArrowUpRight} label="ดูคำขอที่รออนุมัติ" href="/approvals" />}
>
<p className="text-3xl font-semibold tabular-nums">41</p>
</Card>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| title | "คำขอที่รออนุมัติ" | string | The header's heading, which also names the card for screen readers. |
| description | "รอคุณอนุมัติ" | string | A line under the title, such as what the card counts or when it was updated. |
| icon | "ClipboardList" | LucideIcon | An outline icon from lucide-react, in a round tile beside the title. |
| action | "<IconButton />" | ReactNode | One control in the header's corner, such as an IconButton that opens the full list or a small Button. |
ส่วนหัวที่สลับเนื้อหา
header เพิ่มส่วนควบคุมใต้หัวข้อ เช่น Segmented ที่สลับช่วงเวลา หน้าจอเก็บค่าใน state
คำขอที่รออนุมัติ
เดือนนี้
41
const [range, setRange] = useState<"month" | "year">("month");
<Card
title="คำขอที่รออนุมัติ"
description={range === "month" ? "เดือนนี้" : "ปีงบประมาณนี้"}
icon={ClipboardList}
header={<Segmented value={range} onChange={setRange} label="ช่วงเวลา" options={ranges} />}
>
<p className="text-3xl font-semibold tabular-nums">{counts[range]}</p>
</Card>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| title | "คำขอที่รออนุมัติ" | string | The header's heading, which also names the card for screen readers. |
| icon | "ClipboardList" | LucideIcon | An outline icon from lucide-react, in a round tile beside the title. |
| header | "<Segmented />" | ReactNode | More of the header, under the title, such as a Segmented that switches what the card shows. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| title | string | — | The header's heading, which also names the card for screen readers. |
| description | string | — | A line under the title, such as what the card counts or when it was updated. |
| icon | LucideIcon | — | An outline icon from lucide-react, in a round tile beside the title. |
| action | ReactNode | — | One control in the header's corner, such as an IconButton that opens the full list or a small Button. |
| header | ReactNode | — | More of the header, under the title, such as a Segmented that switches what the card shows. |
| footer | ReactNode | — | The footer, under a line: actions such as Buttons, or a short note. |
| tone | CardTone ค่าที่ใช้ได้: "plain""feature""muted" | "plain" | plain is white. feature is the brand gradient with white text, for at most one card in a row. muted is light grey, as for a card inside a card. |
| href | string | — | Makes the whole card a link to this page, through its title. Needs a title.เลิกใช้: Since 0.32.0. A card isn't a link itself: put an IconButton with href in action instead, such as action={<IconButton icon={ArrowUpRight} label="ดูทั้งหมด" href="/approvals" />}. Removed in 1.0.0. |
| children | ReactNode | — | The card's content, such as a chart, a table or figures. |
| className | string | — | Placement in the page layout only, such as lg:col-span-2. |
ชนิดข้อมูล
CardTone
How a card looks: plain white, feature in the app's brand gradient, or muted light grey.
type CardTone = "plain" | "feature" | "muted";ข้อควรปฏิบัติ
- การ์ดทุกใบที่เป็นส่วนหนึ่งของหน้ามีส่วนหัว: title บอกว่าส่วนนี้คืออะไร description สั้น ๆ หนึ่งบรรทัด เช่น ช่วงเวลาหรือสิ่งที่นับ และ icon แบบเส้นจาก lucide-react ที่สื่อถึงเนื้อหา เช่น ClipboardList สำหรับคำขอ การ์ดเล็กภายในการ์ดอื่น (tone muted) ไม่ต้องมีไอคอน
- อย่าทำให้ทั้งการ์ดเป็นลิงก์ ให้เปิดหน้าผ่าน IconButton ใน action เท่านั้น href ของ Card เลิกใช้แล้วตั้งแต่ 0.32.0 และจะถูกนำออกใน 1.0.0
- title เป็นหัวข้อระดับ 2 และเป็นชื่อของการ์ดสำหรับโปรแกรมอ่านหน้าจอ
- action มีปุ่มเดียว ใช้ IconButton หรือ Button ขนาด sm ถ้ามีหลายคำสั่ง ใส่ใน footer
- กราฟในการ์ดที่มีส่วนหัวใช้หัวข้อของการ์ด หัวข้อของกราฟเองซ่อนไว้ให้โปรแกรมอ่านหน้าจอเท่านั้น และปุ่มของกราฟย้ายไปทางขวา ยังต้องส่ง title ให้กราฟ
- ใช้ tone feature ไม่เกินหนึ่งใบต่อแถว ถ้าทุกใบเด่นก็ไม่มีใบไหนเด่น
- การ์ดเป็นสีขาวเสมอ ทั้งบนพื้นสีเทาของหน้าและในการ์ดอื่น ใช้ tone muted เมื่อต้องการการ์ดสีเทาอ่อน เช่น การ์ดเล็กในการ์ด
- ข้อความทุกตัวอยู่ในภาษาของหน้าจอแล้ว จากไฟล์ข้อความของแอป
ซอร์สโค้ด: ui/src/card.tsx