ui
ธีม รูปแบบ CarbonKanok ภาษา English
ภาพรวมติดตั้งการย้ายไป 1.0ธีมและ layerดีไซน์ Kanokปรับแต่งหน้าตาไอคอนฟอร์มและการตรวจค่าใช้กับ frameworkใช้กับ AIButtonText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderModalSide panelTearsheetNotificationToastTooltipDefinition tooltipPopoverToggletipMenuData tableStructured listPaginationContained listTree viewTabsBreadcrumbLinkPagination navContent switcherAccordionProgress indicatorUI shellTagTileCardProduct cardCode snippetCopy buttonUser avatarTruncated textListLoadingInline loadingProgress barSkeletonBadge indicatorStatus indicatorGridHeadingLayerAction setPage headerBig numberEdit in placeแนะนำText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderTabsPagination navContent switcherTooltipDefinition tooltipPopoverMenuAccordionProgress indicatorUI shellModalSide panelTearsheetNotificationToastData tableStructured listPaginationTree viewCode snippetCopy buttonTruncated textLoadingTagCardProduct cardEdit in place

Notification

Notification บอกผู้ใช้เรื่องที่เปลี่ยนไปหรือปัญหาที่เกิดขึ้น เช่น ไฟล์ที่อัปโหลดไม่สำเร็จ ร่างที่กู้คืนมา หรือนโยบายที่ใช้กับหน้านี้ element เดียวครอบคลุม notification แบบ inline, actionable, toast และ callout ของ Carbon ถ้าต้องการ toast ที่ซ้อนกันที่มุมจอ ดู Toast

HTMLReactReact + Tailwind<ui-notification kind="error" heading="อัปโหลดไม่สำเร็จ" subtitle="contract.pdf มีขนาดเกิน 25 MB"></ui-notification> <UiNotification kind="error" heading="อัปโหลดไม่สำเร็จ" subtitle="contract.pdf มีขนาดเกิน 25 MB" /> <Notification kind="error" title="อัปโหลดไม่สำเร็จ" subtitle="contract.pdf มีขนาดเกิน 25 MB" />

ติดตั้ง

npmshadcn · Web componentshadcn · React + Tailwindคัดลอกเองnpm install @purpurabog/ui npx shadcn@4 add @kanok-ui/notification npx shadcn@4 add @kanok-ui/tw-notification # Web component # 1. ติดตั้ง dependency npm install lit@^3.3.0 # 2. คัดลอก "content" ของแต่ละไฟล์จาก # https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/notification.json # ไปไว้ที่ target ของมัน: # components/ui/primitives/notification/notification.styles.ts # components/ui/primitives/notification/notification.ts # 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json): # core-notification, shared-element, shared-events, shared-field, shared-localize, shared-slots, tokens # React + Tailwind # 1. ติดตั้ง dependency npm install @purpurabog/ui@^2.3.0 # 2. คัดลอก "content" ของแต่ละไฟล์จาก # https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-notification.json # ไปไว้ที่ target ของมัน: # components/ui/react-tw/notification.tsx # 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json): # core-notification, tw-i18n, tw-theme, tw-utils

npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง

วิธีใช้

HTMLReactReact + Tailwind<script type="module">import '@purpurabog/ui/notification';</script> <ui-notification kind="success" heading="ส่งสัญญาแล้ว" subtitle="แจ้งผู้ลงนาม 3 คนแล้ว"></ui-notification> import { UiNotification } from '@purpurabog/ui/react'; <UiNotification kind="success" heading="ส่งสัญญาแล้ว" subtitle="แจ้งผู้ลงนาม 3 คนแล้ว" /> import { Notification } from '@/components/ui/react-tw/notification'; <Notification kind="success" title="ส่งสัญญาแล้ว" subtitle="แจ้งผู้ลงนาม 3 คนแล้ว" />

heading คือหัวข้อตัวหนา (React + Tailwind ใช้ title) และ subtitle คือข้อความต่อจากหัวข้อ kind เริ่มต้นเป็น error จึงควรตั้งทุกครั้ง notification แบบ inline กว้าง 288px ถึง 832px ตามขนาดจอ

ชนิด

kind กำหนดสีและไอคอน: error, success, info, info-square, warning และ warning-alt

HTMLReactReact + Tailwind<ui-notification kind="error" heading="ชำระเงินไม่สำเร็จ" subtitle="ธนาคารปฏิเสธการโอน"></ui-notification> <ui-notification kind="success" heading="ลงนามครบแล้ว" subtitle="ทุกฝ่ายลงนามแล้ว"></ui-notification> <ui-notification kind="info" heading="มีแบบฟอร์มใหม่" subtitle="สัญญาเช่า 2569 พร้อมใช้แล้ว"></ui-notification> <ui-notification kind="info-square" heading="อ่านอย่างเดียว" subtitle="สัญญานี้ถูกเก็บเข้าคลังแล้ว"></ui-notification> <ui-notification kind="warning" heading="ยังไม่ได้ชำระอากรแสตมป์" subtitle="ชำระก่อนยื่นสัญญา"></ui-notification> <ui-notification kind="warning-alt" heading="ใกล้หมดอายุ" subtitle="สัญญาเช่าสิ้นสุด 31 ตุลาคม 2569"></ui-notification> <UiNotification kind="error" heading="ชำระเงินไม่สำเร็จ" subtitle="ธนาคารปฏิเสธการโอน" /> <UiNotification kind="success" heading="ลงนามครบแล้ว" subtitle="ทุกฝ่ายลงนามแล้ว" /> <UiNotification kind="info" heading="มีแบบฟอร์มใหม่" subtitle="สัญญาเช่า 2569 พร้อมใช้แล้ว" /> <UiNotification kind="info-square" heading="อ่านอย่างเดียว" subtitle="สัญญานี้ถูกเก็บเข้าคลังแล้ว" /> <UiNotification kind="warning" heading="ยังไม่ได้ชำระอากรแสตมป์" subtitle="ชำระก่อนยื่นสัญญา" /> <UiNotification kind="warning-alt" heading="ใกล้หมดอายุ" subtitle="สัญญาเช่าสิ้นสุด 31 ตุลาคม 2569" /> <Notification kind="error" title="ชำระเงินไม่สำเร็จ" subtitle="ธนาคารปฏิเสธการโอน" /> <Notification kind="success" title="ลงนามครบแล้ว" subtitle="ทุกฝ่ายลงนามแล้ว" /> <Notification kind="info" title="มีแบบฟอร์มใหม่" subtitle="สัญญาเช่า 2569 พร้อมใช้แล้ว" /> <Notification kind="info-square" title="อ่านอย่างเดียว" subtitle="สัญญานี้ถูกเก็บเข้าคลังแล้ว" /> <Notification kind="warning" title="ยังไม่ได้ชำระอากรแสตมป์" subtitle="ชำระก่อนยื่นสัญญา" /> <Notification kind="warning-alt" title="ใกล้หมดอายุ" subtitle="สัญญาเช่าสิ้นสุด 31 ตุลาคม 2569" />

คอนทราสต์ต่ำ

ค่าเริ่มต้น notification เป็นสีเข้ม (พื้นผิวกลับสี) low-contrast เปลี่ยนเป็นพื้นสีอ่อนตามชนิดพร้อมกรอบบาง ๆ ซึ่งดูกลมกลืนกับฟอร์มมากกว่า

HTMLReactReact + Tailwind<ui-notification kind="info" low-contrast heading="บันทึกอัตโนมัติเปิดอยู่" subtitle="บันทึกการแก้ไขทุกหนึ่งนาที"></ui-notification> <ui-notification kind="warning" low-contrast heading="เจ้าของงานลาอยู่" subtitle="อนัญญา พ. ลาถึง 20 ตุลาคม"></ui-notification> <UiNotification kind="info" lowContrast heading="บันทึกอัตโนมัติเปิดอยู่" subtitle="บันทึกการแก้ไขทุกหนึ่งนาที" /> <UiNotification kind="warning" lowContrast heading="เจ้าของงานลาอยู่" subtitle="อนัญญา พ. ลาถึง 20 ตุลาคม" /> <Notification kind="info" lowContrast title="บันทึกอัตโนมัติเปิดอยู่" subtitle="บันทึกการแก้ไขทุกหนึ่งนาที" /> <Notification kind="warning" lowContrast title="เจ้าของงานลาอยู่" subtitle="อนัญญา พ. ลาถึง 20 ตุลาคม" />

ลิงก์และเนื้อหาอื่น

ถ้าหัวข้อหรือ subtitle ต้องใช้ markup ให้ใส่ใน slot="title" หรือ slot="subtitle" เนื้อหาที่ไม่มี slot จะต่อท้าย subtitle เช่น ลิงก์ หรือรายการสั้น ๆ React + Tailwind รับ markup ใน title และ subtitle และรับเนื้อหาเพิ่มเป็น children

ยังไม่ได้ชำระสำหรับ CT-2026-0142 ชำระเลย
HTMLReactReact + Tailwind<ui-notification kind="warning" low-contrast heading="อากรแสตมป์"> <span slot="subtitle">ยังไม่ได้ชำระสำหรับ <strong>CT-2026-0142</strong></span> <a href="#notification-pay">ชำระเลย</a> </ui-notification> <UiNotification kind="warning" lowContrast heading="อากรแสตมป์"> <span slot="subtitle">ยังไม่ได้ชำระสำหรับ <strong>CT-2026-0142</strong></span> <a href="/stamp-duty">ชำระเลย</a> </UiNotification> <Notification kind="warning" lowContrast title="อากรแสตมป์" subtitle={<>ยังไม่ได้ชำระสำหรับ <strong>CT-2026-0142</strong></>}> <a href="/stamp-duty">ชำระเลย</a> </Notification>

มีปุ่มคำสั่ง

action-label เพิ่มปุ่มสำหรับคำสั่งด่วนหนึ่งอย่าง เช่น เลิกทำ หรือลองอีกครั้ง (actionable notification ของ Carbon) กดแล้วจะส่ง ui-action แต่ไม่ปิด notification notification ที่มีปุ่มคำสั่งจะเป็น alertdialog: ตอนแสดงขึ้นมา โฟกัสจะย้ายไปที่ปุ่มคำสั่ง Tab จะวนอยู่ในตัวมัน และกด Esc เพื่อปิดได้ระหว่างที่โฟกัสอยู่ข้างใน (เหมือน Carbon: Esc ที่ตั้งใจกดให้อย่างอื่น เช่น modal จะไม่ปิดมัน) ใส่ no-autofocus ถ้ามันอยู่ในหน้าตั้งแต่แรกอย่างในตัวอย่างนี้ จะได้ไม่แย่งโฟกัสจากหน้าเว็บ

คำสั่ง:

HTMLReactReact + Tailwind<ui-notification id="notification-undo" kind="info" heading="ลบร่างแล้ว" subtitle="ร่างสัญญาเช่าชั้น 3" action-label="เลิกทำ" no-autofocus></ui-notification> <p>คำสั่ง: <output id="notification-undo-out"></output></p> <script type="module"> const note = document.getElementById('notification-undo'); note.addEventListener('ui-action', () => { document.getElementById('notification-undo-out').value = 'กู้คืนแล้ว'; note.close(); }); </script> <UiNotification kind="info" heading="ลบร่างแล้ว" subtitle="ร่างสัญญาเช่าชั้น 3" actionLabel="เลิกทำ" noAutofocus onUiAction={restore} /> const [open, setOpen] = useState(true); <Notification kind="info" title="ลบร่างแล้ว" subtitle="ร่างสัญญาเช่าชั้น 3" actionLabel="เลิกทำ" noAutofocus onAction={() => { restore(); setOpen(false); }} open={open} onClose={() => setOpen(false)} />

close() ปิดแบบเดียวกับการกด × รายละเอียดอยู่ในหัวข้อ การปิด

Callout

variant="callout" คือกล่องคำแนะนำที่อยู่กับหน้าเว็บ ไม่ใช่ข้อความเรื่องที่เพิ่งเกิดขึ้น มันไม่มี role ไม่มีปุ่มปิด และไม่ดึงโฟกัส ปุ่มคำสั่งของมันใช้หัวข้อเป็นคำอธิบาย

HTMLReactReact + Tailwind<ui-notification variant="callout" kind="info" heading="ปิดรับการลงนามวันศุกร์" subtitle="ผู้ลงนามสองคนยังไม่ได้เปิดเอกสาร" action-label="ส่งการแจ้งเตือน"></ui-notification> <ui-notification variant="callout" kind="warning" low-contrast heading="นโยบายการเก็บรักษา" subtitle="คำขอที่เก็บเข้าคลังจะถูกลบหลัง 10 ปี"></ui-notification> <UiNotification variant="callout" kind="info" heading="ปิดรับการลงนามวันศุกร์" subtitle="ผู้ลงนามสองคนยังไม่ได้เปิดเอกสาร" actionLabel="ส่งการแจ้งเตือน" onUiAction={remind} /> <UiNotification variant="callout" kind="warning" lowContrast heading="นโยบายการเก็บรักษา" subtitle="คำขอที่เก็บเข้าคลังจะถูกลบหลัง 10 ปี" /> <Notification variant="callout" kind="info" title="ปิดรับการลงนามวันศุกร์" subtitle="ผู้ลงนามสองคนยังไม่ได้เปิดเอกสาร" actionLabel="ส่งการแจ้งเตือน" onAction={remind} /> <Notification variant="callout" kind="warning" lowContrast title="นโยบายการเก็บรักษา" subtitle="คำขอที่เก็บเข้าคลังจะถูกลบหลัง 10 ปี" />

หน้าตาแบบ toast

variant="toast" คือการ์ดกว้าง 288px มีเงา ที่ Carbon ใช้กับ toast ข้อความเรียงซ้อนกัน caption เพิ่มบรรทัดเล็ก ๆ (มักเป็นเวลา) และปุ่มคำสั่งจะเป็นปุ่ม tertiary ใต้ข้อความ ถ้าจะแสดง toast ที่มุมจอและให้ซ้อนกัน ให้ใช้ toaster: Toast

HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start"> <ui-notification variant="toast" kind="success" heading="ส่งสัญญาแล้ว" subtitle="แจ้งผู้ลงนาม 3 คนแล้ว" caption="10:42 น."></ui-notification> <ui-notification variant="toast" kind="error" low-contrast heading="อัปโหลดไม่สำเร็จ" subtitle="ลองใช้ไฟล์ที่เล็กลง" action-label="ลองอีกครั้ง" no-autofocus></ui-notification> </div> <UiNotification variant="toast" kind="success" heading="ส่งสัญญาแล้ว" subtitle="แจ้งผู้ลงนาม 3 คนแล้ว" caption="10:42 น." /> <UiNotification variant="toast" kind="error" lowContrast heading="อัปโหลดไม่สำเร็จ" subtitle="ลองใช้ไฟล์ที่เล็กลง" actionLabel="ลองอีกครั้ง" noAutofocus /> <Notification variant="toast" kind="success" title="ส่งสัญญาแล้ว" subtitle="แจ้งผู้ลงนาม 3 คนแล้ว" caption="10:42 น." /> <Notification variant="toast" kind="error" lowContrast title="อัปโหลดไม่สำเร็จ" subtitle="ลองใช้ไฟล์ที่เล็กลง" actionLabel="ลองอีกครั้ง" noAutofocus />

ปิดเองเมื่อครบเวลา

timeout ปิด notification เองเมื่อครบจำนวนมิลลิวินาทีที่ตั้ง (reason timeout) การนับเวลาจะหยุดชั่วคราวระหว่างที่เมาส์ชี้อยู่หรือโฟกัสอยู่ข้างใน และ notification ที่มีปุ่มคำสั่งจะไม่ปิดเอง ผู้ใช้จึงไม่พลาดข้อความที่กำลังอ่าน ลองชี้ที่ toast ด้านล่างเพื่อให้มันค้างไว้

แสดงอีกครั้ง
HTMLReactReact + Tailwind<ui-notification id="notification-timeout" variant="toast" kind="info" heading="บันทึกแล้ว" subtitle="ข้อความนี้จะปิดเองใน 5 วินาที" timeout="5000"></ui-notification> <ui-button id="notification-timeout-again" kind="tertiary" size="sm">แสดงอีกครั้ง</ui-button> <script type="module"> const note = document.getElementById('notification-timeout'); document.getElementById('notification-timeout-again').addEventListener('click', () => (note.open = true)); </script> <UiNotification variant="toast" kind="info" heading="บันทึกแล้ว" subtitle="ข้อความนี้จะปิดเองใน 5 วินาที" timeout={5000} /> <Notification variant="toast" kind="info" title="บันทึกแล้ว" subtitle="ข้อความนี้จะปิดเองใน 5 วินาที" timeout={5000} />

ตั้ง open กลับเป็น true จะแสดงอีกครั้งและเริ่มนับเวลาใหม่

เต็มความกว้าง

full-width ทำให้ notification แบบ inline หรือ callout กว้างเต็มกล่องที่อยู่ แทนที่จะหยุดที่ความกว้างของ Carbon เช่น แถบประกาศบนสุดของหน้าหรือของการ์ด ส่วน toast ยังกว้าง 288px

HTMLReactReact + Tailwind<ui-notification kind="info" low-contrast full-width heading="ปิดปรับปรุงระบบ" subtitle="ระบบสัญญาจะอ่านได้อย่างเดียวคืนนี้ เวลา 22:00 ถึง 23:00 น."></ui-notification> <UiNotification kind="info" lowContrast fullWidth heading="ปิดปรับปรุงระบบ" subtitle="ระบบสัญญาจะอ่านได้อย่างเดียวคืนนี้ เวลา 22:00 ถึง 23:00 น." /> <Notification kind="info" lowContrast fullWidth title="ปิดปรับปรุงระบบ" subtitle="ระบบสัญญาจะอ่านได้อย่างเดียวคืนนี้ เวลา 22:00 ถึง 23:00 น." />

การปิด

× กด Esc (เฉพาะแบบมีปุ่มคำสั่ง) และการครบเวลา จะส่ง ui-request-close ซึ่งยกเลิกได้ และมี reason เป็น close-button, escape หรือ timeout ถ้าไม่เรียก preventDefault() notification จะตั้ง open เป็น false (ยังอยู่ในหน้าแต่ถูกซ่อน) แล้วส่ง ui-close ถ้าโฟกัสอยู่ข้างใน โฟกัสจะกลับไปที่เดิมก่อนหน้านั้น hide-close-button เอาปุ่ม × ออก ใช้เมื่อข้อความต้องอยู่จนกว่าจะแก้ปัญหาเสร็จ

แสดงอีกครั้ง ปิดด้วย:
HTMLReactReact + Tailwind<ui-notification id="notification-close" kind="success" heading="ส่งคำขออนุมัติแล้ว" subtitle="ชัยยา ร. จะได้รับอีเมล"></ui-notification> <ui-notification kind="error" hide-close-button heading="ยังไม่มีบัญชีธนาคาร" subtitle="เพิ่มบัญชีของผู้ขายก่อนจ่ายเงิน"></ui-notification> <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center"> <ui-button id="notification-close-again" kind="tertiary" size="sm">แสดงอีกครั้ง</ui-button> <span>ปิดด้วย: <output id="notification-close-out"></output></span> </div> <script type="module"> const note = document.getElementById('notification-close'); note.addEventListener('ui-close', (event) => (document.getElementById('notification-close-out').value = event.detail.reason)); document.getElementById('notification-close-again').addEventListener('click', () => (note.open = true)); </script> <UiNotification kind="success" heading="ส่งคำขออนุมัติแล้ว" subtitle="ชัยยา ร. จะได้รับอีเมล" open={open} onUiClose={(e) => { setOpen(false); setReason(e.detail.reason); }} /> <UiNotification kind="error" hideCloseButton heading="ยังไม่มีบัญชีธนาคาร" subtitle="เพิ่มบัญชีของผู้ขายก่อนจ่ายเงิน" /> // คืนค่า false จาก onClose เพื่อให้เปิดค้างไว้ <Notification kind="success" title="ส่งคำขออนุมัติแล้ว" subtitle="ชัยยา ร. จะได้รับอีเมล" open={open} onClose={(reason) => { setOpen(false); setReason(reason); }} /> <Notification kind="error" hideCloseButton title="ยังไม่มีบัญชีธนาคาร" subtitle="เพิ่มบัญชีของผู้ขายก่อนจ่ายเงิน" />

ถ้าไม่ตั้ง open notification ของ React + Tailwind จะซ่อนตัวเองเมื่อปิด

Error หลังส่งฟอร์ม

notification ใช้สรุปสิ่งที่ทำให้ส่งฟอร์มไม่ได้ ค่าเริ่มต้นเป็น status ซึ่งอ่านแบบสุภาพ role="alert" ทำให้ screen reader อ่านทันที ใช้กับ error ที่ผู้ใช้ต้องจัดการเดี๋ยวนี้ ลองกดตรวจด้านล่าง

ตรวจสัญญา
HTMLReactReact + Tailwind<ui-notification id="notification-check" kind="error" role="alert" open="false" heading="พบ 2 ปัญหา" subtitle="เพิ่มเลขประจำตัวผู้เสียภาษีของคู่สัญญาและวันเริ่มต้น"></ui-notification> <ui-button id="notification-check-run">ตรวจสัญญา</ui-button> <script type="module"> const note = document.getElementById('notification-check'); document.getElementById('notification-check-run').addEventListener('click', () => (note.open = true)); </script> <UiNotification kind="error" role="alert" open={errors.length > 0} heading={`พบ ${errors.length} ปัญหา`} subtitle={errors.join(' ')} /> <UiButton onClick={check}>ตรวจสัญญา</UiButton> <Notification kind="error" role="alert" open={errors.length > 0} title={`พบ ${errors.length} ปัญหา`} subtitle={errors.join(' ')} /> <Button onClick={check}>ตรวจสัญญา</Button>

คีย์บอร์ด

ปุ่ม ทำอะไร
Tab ไปที่ลิงก์ในเนื้อหา ปุ่มคำสั่ง และ × ตามลำดับ ในแบบที่มีปุ่มคำสั่ง Tab จะวนอยู่ในตัวมัน
Enter, Space กดปุ่มที่โฟกัสอยู่
Esc ปิด notification แบบมีปุ่มคำสั่งระหว่างที่โฟกัสอยู่ข้างใน (close-on-escape="false" ปิดความสามารถนี้)

Accessibility

  • role เริ่มต้นเป็น status (อ่านแบบสุภาพ) callout ไม่มี role และแบบมีปุ่มคำสั่งเป็น alertdialog ที่ใช้หัวข้อเป็นชื่อและ subtitle เป็นคำอธิบาย role ใช้ตั้ง role อื่น เช่น alert
  • screen reader อ่านสิ่งที่เปลี่ยนใน live region notification ที่เพิ่มเข้ามาในหน้าพร้อมข้อความอาจไม่ถูกอ่าน toaster จึงมี region เดียวที่อยู่ในหน้าไว้ก่อนสำหรับ toast ทุกตัว ทุกตัวจึงถูกอ่าน
  • ไอคอนมีชื่อตามชนิด ("error icon") เปลี่ยนได้ด้วย icon-label ปุ่ม × มีชื่อว่า "ปิดการแจ้งเตือน" ตามภาษาของหน้า เปลี่ยนได้ด้วย close-label
  • อย่าตั้ง timeout กับข้อความที่ผู้ใช้ต้องลงมือทำอะไร

ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Notification

API

สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)

<ui-notification> · React UiNotification

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
title
role
variant variant NotificationVariant 'inline' Inline (default) or toast.
kind kind NotificationKind 'error' Status kind; sets the colour and the icon.
low-contrast lowContrast boolean false Tinted surface with primary text instead of the inverse surface.
heading heading string '' Bold title; the title slot replaces it when markup is needed. (Before 0.5: the title attribute, still accepted.)
subtitle subtitle string '' Body text; the subtitle slot replaces it when markup is needed.
caption caption string '' Toast only: small text under the subtitle, e.g. the time.
action-label actionLabel string '' Label of the action button; set it to get Carbon's actionable notification.
timeout timeout number 0 Milliseconds after which the notification closes itself (toast); 0 = never. Paused on hover / focus; ignored with action-label.
hide-close-button hideCloseButton boolean false
close-on-escape closeOnEscape boolean true Esc closes an actionable notification while focus is inside it (Carbon closeOnEscape).
no-autofocus noAutofocus boolean false Keep focus where it is instead of moving it to the action button (Carbon hasFocus={false}).
full-width fullWidth boolean false Fills its container instead of Carbon's 288–832px cap (inline / callout; a toast stays 288px).
close-label closeLabel string '' Accessible name of the close button.
icon-label iconLabel string '' Accessible description of the status icon; defaults to "kind icon" (e.g. "error icon") like Carbon.
open open boolean true False once closed (reflects open="false"); set back to true to show it again.

Property

Property ชนิด คำอธิบาย
role NotificationRole | null ARIA role of the notification box; defaults to status, or alertdialog when there is an action button. A role attribute is read and moved inside.

Method

Method คำอธิบาย
close(reason) Asks to close (ui-request-close, cancelable); hides and fires ui-close unless prevented.
focus(options) Focus the action button, else the close button.

Event

Event React คำอธิบาย
ui-close onUiClose After it closed
ui-action onUiAction The action button was pressed
ui-request-close onUiRequestClose Cancelable; detail: { reason: 'close-button' | 'escape' | 'timeout' }

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) Extra content after the subtitle (links, details)
title Title with markup; the heading attribute is the plain-text fallback
subtitle Subtitle with markup; the subtitle attribute is the plain-text fallback

CSS part

Part คำอธิบาย
base The notification box
icon The status icon
title The title
subtitle The subtitle
caption The toast caption
action-button The action button
close-button The close button

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-notification-radius Corner radius (default 0; Kanok: 8px)
--ui-notification-bar-width Width of the status bar at the start (default 3px; Kanok: 0, the icon tells the kind)
--ui-notification-frame-start Low contrast: the frame's start side (default 0, the bar is there; Kanok: 1px)
--ui-notification-background / --ui-notification-ink / --ui-notification-edge - The high-contrast box: fill, text and an extra box-shadow (default Carbon's inverse block, none; Kanok: the raised floating surface)
--ui-notification-link / --ui-notification-hover / --ui-notification-focus - On that box: links and the action, the action's hover and the focus ring (default link-inverse, inverse hover, inverse ink)
--ui-toast-shadow A toast's shadow (default 0 2px 6px 0 rgb(0 0 0 / 0.2))
--ui-close-size Size of the × button (default 48px; Kanok: 32px)
--ui-close-inset Margin that sets the × in from the corner (default 0; Kanok: 8px)
--ui-icon-control-radius Corners of the ×, its hover fill and its ring (default 0; Kanok: round)
--ui-focus-offset outline-offset of the ×'s focus ring (default -2px: inside; Kanok: 2px outside)