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

ขั้นตอน

Steps

The steps of a process, with the finished ones ticked. `current` is the index of the step in progress. Leave it out for an outline of a process that isn't running, such as the stages of a flow on a card: every step shows its number. Each step can carry a description and its own content, such as a form or a file upload, for a step-by-step task.

ใช้แสดงว่ารายการอยู่ขั้นไหนของกระบวนงานที่มีลำดับตายตัว เช่น จากคำขอถึงเบิกจ่าย หรือขั้นของฟอร์มหลายหน้า ส่งรายการขั้นและลำดับของขั้นปัจจุบัน ถ้าต้องบอกว่าใครอนุมัติและเมื่อไร ใช้ ApprovalChain ถ้าแค่บอกสถานะของรายการ ใช้ Badge ถ้าผู้ใช้ต้องกดสลับส่วน ใช้ Tabs

import { Steps } from "@bsru/ui";

ตัวอย่าง

อยู่ระหว่างกระบวนงาน

current เป็นลำดับเริ่มจาก 0 ขั้นก่อนหน้ามีเครื่องหมายถูก ขั้นปัจจุบันเป็นตัวหนา

  1. คำขอ
  2. อนุมัติ
  3. 3ใบสั่งซื้อ
  4. 4ตรวจรับ
  5. 5เบิกจ่าย
<Steps
  current={2}
  steps={[
    { label: "คำขอ" },
    { label: "อนุมัติ" },
    { label: "ใบสั่งซื้อ" },
    { label: "ตรวจรับ" },
    { label: "เบิกจ่าย" },
  ]}
/>

ขั้นแรก

  1. 1คำขอ
  2. 2อนุมัติ
  3. 3ใบสั่งซื้อ
  4. 4ตรวจรับ
  5. 5เบิกจ่าย
<Steps
  current={0}
  steps={[
    { label: "คำขอ" },
    { label: "อนุมัติ" },
    { label: "ใบสั่งซื้อ" },
    { label: "ตรวจรับ" },
    { label: "เบิกจ่าย" },
  ]}
/>

เสร็จทุกขั้น

ส่ง current เท่ากับจำนวนขั้น เพื่อให้ทุกขั้นมีเครื่องหมายถูก

  1. คำขอ
  2. อนุมัติ
  3. ใบสั่งซื้อ
  4. ตรวจรับ
  5. เบิกจ่าย
<Steps
  current={5}
  steps={[
    { label: "คำขอ" },
    { label: "อนุมัติ" },
    { label: "ใบสั่งซื้อ" },
    { label: "ตรวจรับ" },
    { label: "เบิกจ่าย" },
  ]}
/>

ลำดับขั้นในแนวตั้ง

orientation="vertical" เรียงขั้นจากบนลงล่าง ป้ายอยู่ข้างวงกลมและขึ้นบรรทัดใหม่ได้ จึงใส่ในการ์ดหรือคอลัมน์แคบได้ทุกจำนวนขั้น ไม่ส่ง current เพื่อแสดงลำดับขั้นของกระบวนงานที่ไม่ได้ดำเนินอยู่ ทุกขั้นแสดงหมายเลข ไม่มีขั้นใดเป็นขั้นปัจจุบัน

  1. 1ตั้งหนี้ค่าหอพัก
  2. 2ชำระด้วย QR
  3. 3ใบเสร็จรับเงินอิเล็กทรอนิกส์
  4. 4ตัดหนี้อัตโนมัติ
<Steps
  orientation="vertical"
  steps={[
    { label: "ตั้งหนี้ค่าหอพัก" },
    { label: "ชำระด้วย QR" },
    { label: "ใบเสร็จรับเงินอิเล็กทรอนิกส์" },
    { label: "ตัดหนี้อัตโนมัติ" },
  ]}
/>

แนวตั้ง อยู่ระหว่างกระบวนงาน

current ทำงานเหมือนแนวนอน เส้นที่เชื่อมขั้นที่เสร็จแล้วเป็นสีหลักของแอป

  1. ตั้งหนี้ค่าหอพัก
  2. ชำระด้วย QR
  3. 3ใบเสร็จรับเงินอิเล็กทรอนิกส์
  4. 4ตัดหนี้อัตโนมัติ
<Steps
  orientation="vertical"
  current={2}
  steps={[
    { label: "ตั้งหนี้ค่าหอพัก" },
    { label: "ชำระด้วย QR" },
    { label: "ใบเสร็จรับเงินอิเล็กทรอนิกส์" },
    { label: "ตัดหนี้อัตโนมัติ" },
  ]}
/>

บนการ์ดเด่น

บน Card แบบ feature ขั้นเปลี่ยนเป็นสีขาวบนพื้นสีหลัก ขั้นที่เสร็จเป็นวงกลมสีขาวมีเครื่องหมายถูก ขั้นปัจจุบันเป็นวงขาวทึบ ขั้นที่ยังไม่ถึงเป็นวงขาวโปร่ง หน้าจอไม่ต้องส่งอะไรเพิ่ม

ค่าหอพัก

4 ขั้น

  1. ตั้งหนี้ค่าหอพัก
  2. ชำระด้วย QR
  3. 3ใบเสร็จรับเงินอิเล็กทรอนิกส์
  4. 4ตัดหนี้อัตโนมัติ
<Card tone="feature" title="ค่าหอพัก" description="4 ขั้น" icon={BedDouble}>
  <Steps orientation="vertical" current={2} steps={steps} />
</Card>

คำอธิบายใต้แต่ละขั้น

description แสดงใต้ป้ายของขั้น เช่น ใครทำ ต้องใช้อะไร หรือเสร็จเมื่อไร ทั้งแนวตั้งและแนวนอน

  1. คำขอนายทดสอบ มีสุข ส่งเมื่อ 1 ต.ค. 2569
  2. อนุมัติหัวหน้าหน่วยงานอนุมัติเมื่อ 2 ต.ค. 2569
  3. 3
    ใบสั่งซื้อเจ้าหน้าที่พัสดุกำลังออกใบสั่งซื้อ
  4. 4
    ตรวจรับคณะกรรมการตรวจรับพัสดุ
  5. 5
    เบิกจ่ายการเงินจ่ายเงินให้ผู้ขาย
<Steps
  orientation="vertical"
  current={2}
  steps={[
    {
      label: "คำขอ",
      description: "นายทดสอบ มีสุข ส่งเมื่อ 1 ต.ค. 2569",
    },
    {
      label: "อนุมัติ",
      description: "หัวหน้าหน่วยงานอนุมัติเมื่อ 2 ต.ค. 2569",
    },
    {
      label: "ใบสั่งซื้อ",
      description: "เจ้าหน้าที่พัสดุกำลังออกใบสั่งซื้อ",
    },
    { label: "ตรวจรับ", description: "คณะกรรมการตรวจรับพัสดุ" },
    { label: "เบิกจ่าย", description: "การเงินจ่ายเงินให้ผู้ขาย" },
  ]}
/>

ฟอร์มในแต่ละขั้น

content เป็นพื้นที่ของขั้นนั้นเอง ใต้ป้ายและคำอธิบาย ใส่ส่วนประกอบใดก็ได้ เช่น TextInput FileDrop และปุ่ม แนวตั้งแสดง content ของทุกขั้นที่ส่งมา จึงส่ง content เฉพาะขั้นปัจจุบันเมื่อทำทีละขั้น ลองกดถัดไปและย้อนกลับ

  1. ผู้ยื่นคำขอนายทดสอบ มีสุข หน่วยงาน ก
  2. 2
    รายละเอียดคำขอบอกว่าจะซื้อหรือจ้างอะไร
  3. 3
    แนบเอกสารใบเสนอราคาและรายละเอียดคุณลักษณะ
  4. 4
    ส่งคำขอตรวจทานแล้วส่ง
const [step, setStep] = useState(1);

// Only the current step gets content: its form, then Back and Next.
const steps: Step[] = [
  { label: "ผู้ยื่นคำขอ", description: "นายทดสอบ มีสุข หน่วยงาน ก" },
  {
    label: "รายละเอียดคำขอ",
    description: "บอกว่าจะซื้อหรือจ้างอะไร",
    content: step === 1 && (
      <div className="flex flex-col gap-3">
        <TextInput label="เรื่อง" value={subject} onValueChange={setSubject} required />
        <StepNav step={step} onStep={setStep} />
      </div>
    ),
  },
  {
    label: "แนบเอกสาร",
    description: "ใบเสนอราคาและรายละเอียดคุณลักษณะ",
    content: step === 2 && (
      <FileDrop title="ลากไฟล์มาวาง หรือกดเพื่อเลือก" hint="PDF ไม่เกิน 10 MB" multiple accept=".pdf" value={files} onFiles={setFiles} />
    ),
  },
  { label: "ส่งคำขอ", description: "ตรวจทานแล้วส่ง" },
];

<Steps orientation="vertical" current={step} steps={steps} />

Badge ชิป และปุ่มในขั้น

ทุกขั้นแสดง content ของตัวเองพร้อมกันได้ เช่น Badge บอกสถานะ ชิปให้เลือก และปุ่มของขั้นสุดท้าย

  1. 1
    สถานะงบประมาณตรวจจากระบบงบประมาณ
    วงเงินพอ คงเหลือ 4,750,000.00 บาท
  2. 2
    ประเภทของที่จะซื้อเลือกได้มากกว่าหนึ่งประเภท
  3. 3
    ขั้นตอนถัดไป
const steps: Step[] = [
  {
    label: "สถานะงบประมาณ",
    description: "ตรวจจากระบบงบประมาณ",
    content: <Badge tone="approved" icon={Check}>วงเงินพอ คงเหลือ 4,750,000.00 บาท</Badge>,
  },
  {
    label: "ประเภทของที่จะซื้อ",
    description: "เลือกได้มากกว่าหนึ่งประเภท",
    content: (
      <div className="flex flex-wrap gap-2">
        {kinds.map((k) => (
          <Chip key={k.value} pressed={chosen.includes(k.value)} onPressedChange={(on) => choose(k.value, on)}>
            {k.label}
          </Chip>
        ))}
      </div>
    ),
  },
  {
    label: "ขั้นตอนถัดไป",
    content: (
      <div className="flex flex-wrap gap-2">
        <Button label="สร้างคำขอ" tone="primary" size="sm" onClick={createRequest} />
        <Button label="บันทึกร่าง" size="sm" onClick={saveDraft} />
      </div>
    ),
  },
];

<Steps orientation="vertical" steps={steps} />

แนวนอน เนื้อหาของขั้นปัจจุบันอยู่ใต้แถว

แถวไม่มีที่ให้เนื้อหาของทุกขั้น จึงแสดงเฉพาะ content ของขั้นปัจจุบันใต้แถว ส่ง content ให้ทุกขั้นได้ แล้วเปลี่ยน current เพื่อเลื่อนขั้น

  1. 1ข้อมูลผู้ขาย
  2. 2รายการสินค้า
  3. 3เงื่อนไขการส่งมอบ

ตัวอย่างนี้ไม่บันทึกข้อมูล

const steps: Step[] = forms.map((form, i) => ({
  label: form.label,
  description: i < step ? "เสร็จแล้ว" : undefined,
  content: <VendorStep form={form} onBack={() => setStep(i - 1)} onNext={() => setStep(i + 1)} />,
}));

<Steps current={step} steps={steps} />

props ทั้งหมด

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

Steps props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
steps* จำเป็นreadonly Step[]—The steps, in order.
currentnumber—The index of the step in progress, from 0. Steps before it are ticked, and this one is bold with aria-current="step". Use steps.length when all are done. Leave it out for a plain outline: no step is ticked, bold or current.
orientationStepsOrientation
ค่าที่ใช้ได้:"horizontal""vertical"
"horizontal"horizontal, the default, puts the steps in a row, with each label under its circle; on a narrow screen the row scrolls sideways. vertical stacks them, with each label beside its circle and a line joining the circles, so long labels wrap and any number of steps fits a card or a narrow column.
classNamestring—Extra classes for the list, such as spacing.

ชนิดข้อมูล

Step

One step of a process.

Step fields
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
label* จำเป็นReactNode—The step's name, already in the screen language.
descriptionReactNode—A line or two under the label, such as who acts, what the step needs, or when it was done.
contentReactNode—The step's own area, under its label and description: any of the library's components, such as a form, a FileDrop, Chips, a Badge or Buttons. Vertical steps show every step's content. A row has no room for it, so horizontal steps show only the current step's content, under the row.

StepsOrientation

How Steps lays out: a row with each label under its circle, or a column with each label beside its circle.

type StepsOrientation = "horizontal" | "vertical";

ข้อควรปฏิบัติ

  • ขั้นปัจจุบันมี aria-current="step" ส่ง label ในภาษาของหน้าจอ และสั้นพอให้อยู่ใต้วงกลม
  • เครื่องหมายถูกของขั้นที่เสร็จเป็นไอคอนตกแต่ง โปรแกรมอ่านหน้าจอไม่ได้ยินว่าเสร็จแล้ว บอกสถานะของรายการเป็นข้อความด้วย เช่น Badge
  • วงกลมและป้ายของขั้นกดไม่ได้ ถ้าให้ย้อนกลับไปแก้ขั้นก่อนหน้า ใส่ปุ่มย้อนกลับไว้ใน content ของขั้น
  • content ใส่ส่วนประกอบของไลบรารีเท่านั้น เช่น ฟอร์ม FileDrop Chip Badge และ Button จัดวางด้วย flex หรือ grid ได้ แต่ไม่ใส่สีหรือขอบเอง
  • ในงานที่ทำทีละขั้น ส่ง content ให้ขั้นปัจจุบันเท่านั้น และให้คำอธิบายของขั้นที่เสร็จแล้วสรุปสิ่งที่กรอกไว้
  • บนจอแคบ รายการแนวนอนเลื่อนไปด้านข้างได้ ใช้ไม่เกินประมาณ 6 ขั้น ถ้ามีมากกว่านั้น ป้ายยาว หรืออยู่ในการ์ด ใช้ orientation="vertical"

ซอร์สโค้ด: ui/src/progress.tsx