ข้ามไปยังเนื้อหา

การ์ด

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 อยู่ใต้เส้นคั่น สำหรับปุ่มหรือหมายเหตุ

งบประมาณหน่วยงาน ก

ปีงบประมาณ 2570

งบประมาณทั้งปี
12,500,000.00 บาท
เบิกจ่ายแล้ว
7,750,000.00 บาท
คงเหลือ
4,750,000.00 บาท
<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>

การ์ดเด่น

tone feature ใช้ไล่สีของแอปกับตัวอักษรสีขาว สำหรับการ์ดที่สำคัญที่สุดหนึ่งใบในแถว เช่น การประชุมที่ใกล้ถึง web เป็นเขียว console เป็นม่วง ปุ่มที่มุมและปุ่มแบบเงียบเป็นสีขาว เมื่อชี้จะมีพื้นขาวโปร่งแสง

ประชุมพิจารณางบประมาณ

วันนี้ 14:00–16:00 น.

ห้องประชุม 1 อาคารสำนักงานอธิการบดี

<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>

เปิดหน้าจากการ์ด

การ์ดไม่เป็นลิงก์ทั้งใบ ให้ใส่ IconButton ที่มี href ใน action เช่น ไอคอน ArrowUpRight label บอกว่าจะไปที่ไหน และเป็นชื่อของปุ่มสำหรับโปรแกรมอ่านหน้าจอ

คำขอที่รออนุมัติ

รอคุณอนุมัติ

41

<Card
  title="คำขอที่รออนุมัติ"
  description="รอคุณอนุมัติ"
  icon={ClipboardList}
  action={<IconButton icon={ArrowUpRight} label="ดูคำขอที่รออนุมัติ" href="/approvals" />}
>
  <p className="text-3xl font-semibold tabular-nums">41</p>
</Card>

ส่วนหัวที่สลับเนื้อหา

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>

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

Card props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
titlestring—The header's heading, which also names the card for screen readers.
descriptionstring—A line under the title, such as what the card counts or when it was updated.
iconLucideIcon—An outline icon from lucide-react, in a round tile beside the title.
actionReactNode—One control in the header's corner, such as an IconButton that opens the full list or a small Button.
headerReactNode—More of the header, under the title, such as a Segmented that switches what the card shows.
toneCardTone
ค่าที่ใช้ได้:"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.
hrefstring—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.
childrenReactNode—The card's content, such as a chart, a table or figures.
classNamestring—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