umbraco-notifications by umbraco/umbraco-cms-backoffice-skills
npx skills add https://github.com/umbraco/umbraco-cms-backoffice-skills --skill umbraco-notifications通知通过 UMB_NOTIFICATION_CONTEXT 在 Umbraco 后台向用户提供反馈,该上下文通过 Context API 使用。peek() 方法显示具有不同类型(positive、negative、warning)的临时 toast 风格通知。通知会在用户界面中临时出现并自动消失,非常适合用于操作确认和错误消息。
在实现之前,请务必获取最新文档:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyElement extends UmbLitElement {
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
constructor() {
super();
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (context) => {
this.#notificationContext = context;
});
}
showSuccess() {
this.#notificationContext?.peek('positive', {
data: { message: '操作成功完成!' }
});
}
}
// 成功通知
this.#notificationContext?.peek('positive', {
data: { message: '保存成功!' }
});
// 错误通知
this.#notificationContext?.peek('danger', {
data: { message: '出错了!' }
});
// 警告通知
this.#notificationContext?.peek('warning', {
data: { message: '请检查您的更改。' }
});
this.#notificationContext?.peek('positive', {
data: {
headline: '成功!',
message: '您的文档已发布。'
}
});
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyController extends UmbControllerBase {
async performAction() {
try {
// 执行某些操作
const context = await this.getContext(UMB_NOTIFICATION_CONTEXT);
context?.peek('positive', {
data: { message: '操作完成!' }
});
} catch (error) {
const context = await this.getContext(UMB_NOTIFICATION_CONTEXT);
context?.peek('danger', {
data: {
headline: '错误',
message: error.message
}
});
}
}
}
import { html } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyElement extends UmbLitElement {
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
constructor() {
super();
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (context) => {
this.#notificationContext = context;
});
}
#onClick() {
this.#notificationContext?.peek('positive', {
data: { message: '按钮已点击!' }
});
}
render() {
return html`
<uui-button @click=${this.#onClick}>
点击我
</uui-button>
`;
}
}
async saveData() {
try {
const response = await fetch('/api/save', {
method: 'POST',
body: JSON.stringify(this.data)
});
if (response.ok) {
this.#notificationContext?.peek('positive', {
data: {
headline: '已保存',
message: '您的更改已保存。'
}
});
} else {
this.#notificationContext?.peek('danger', {
data: {
headline: '保存失败',
message: '无法保存您的更改。'
}
});
}
} catch (error) {
this.#notificationContext?.peek('danger', {
data: {
headline: '错误',
message: '发生意外错误。'
}
});
}
}
import { UmbMenuItemAction } from '@umbraco-cms/backoffice/menu';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyAction extends UmbMenuItemAction {
async execute() {
const context = await this.getContext(UMB_NOTIFICATION_CONTEXT);
context?.peek('positive', {
data: { message: '操作已执行!' }
});
}
}
validateAndSave() {
if (!this.title) {
this.#notificationContext?.peek('warning', {
data: {
headline: '验证错误',
message: '标题是必填项。'
}
});
return;
}
if (this.title.length < 3) {
this.#notificationContext?.peek('warning', {
data: {
message: '标题必须至少包含 3 个字符。'
}
});
return;
}
this.save();
}
positive - 成功消息(绿色)
peek('positive', { data: { message: '成功!' } })
danger - 错误消息(红色)
peek('danger', { data: { message: '发生错误!' } })
warning - 警告消息(橙色/黄色)
peek('warning', { data: { message: '请检查!' } })
UMB_NOTIFICATION_CONTEXT : 用于通知的全局上下文
peek() 方法 : 显示临时通知
Toast 风格 : 自动消失的用户界面通知
数据结构 :
headline (可选) - 粗体标题文本message (必需) - 通知正文文本上下文使用 : 使用 consumeContext() 进行订阅,或使用 getContext() 进行一次性使用
使用场景 :
就是这样!请务必获取最新文档,保持示例简洁,生成完整可用的代码。
每周安装次数
72
代码仓库
GitHub 星标数
14
首次出现
2026年2月4日
安全审计
安装于
github-copilot52
cursor25
opencode24
codex23
gemini-cli22
amp21
Notifications provide user feedback in the Umbraco backoffice through the UMB_NOTIFICATION_CONTEXT, which is consumed via the Context API. The peek() method displays temporary toast-style notifications with different types (positive, negative, warning). Notifications appear in the UI temporarily and automatically dismiss, making them ideal for action confirmations and error messages.
Always fetch the latest docs before implementing:
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyElement extends UmbLitElement {
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
constructor() {
super();
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (context) => {
this.#notificationContext = context;
});
}
showSuccess() {
this.#notificationContext?.peek('positive', {
data: { message: 'Operation completed successfully!' }
});
}
}
// Success notification
this.#notificationContext?.peek('positive', {
data: { message: 'Saved successfully!' }
});
// Error notification
this.#notificationContext?.peek('danger', {
data: { message: 'Something went wrong!' }
});
// Warning notification
this.#notificationContext?.peek('warning', {
data: { message: 'Please review your changes.' }
});
this.#notificationContext?.peek('positive', {
data: {
headline: 'Success!',
message: 'Your document has been published.'
}
});
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyController extends UmbControllerBase {
async performAction() {
try {
// Do something
const context = await this.getContext(UMB_NOTIFICATION_CONTEXT);
context?.peek('positive', {
data: { message: 'Action completed!' }
});
} catch (error) {
const context = await this.getContext(UMB_NOTIFICATION_CONTEXT);
context?.peek('danger', {
data: {
headline: 'Error',
message: error.message
}
});
}
}
}
import { html } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyElement extends UmbLitElement {
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
constructor() {
super();
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (context) => {
this.#notificationContext = context;
});
}
#onClick() {
this.#notificationContext?.peek('positive', {
data: { message: 'Button clicked!' }
});
}
render() {
return html`
<uui-button @click=${this.#onClick}>
Click me
</uui-button>
`;
}
}
async saveData() {
try {
const response = await fetch('/api/save', {
method: 'POST',
body: JSON.stringify(this.data)
});
if (response.ok) {
this.#notificationContext?.peek('positive', {
data: {
headline: 'Saved',
message: 'Your changes have been saved.'
}
});
} else {
this.#notificationContext?.peek('danger', {
data: {
headline: 'Save Failed',
message: 'Could not save your changes.'
}
});
}
} catch (error) {
this.#notificationContext?.peek('danger', {
data: {
headline: 'Error',
message: 'An unexpected error occurred.'
}
});
}
}
import { UmbMenuItemAction } from '@umbraco-cms/backoffice/menu';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
export class MyAction extends UmbMenuItemAction {
async execute() {
const context = await this.getContext(UMB_NOTIFICATION_CONTEXT);
context?.peek('positive', {
data: { message: 'Action executed!' }
});
}
}
validateAndSave() {
if (!this.title) {
this.#notificationContext?.peek('warning', {
data: {
headline: 'Validation Error',
message: 'Title is required.'
}
});
return;
}
if (this.title.length < 3) {
this.#notificationContext?.peek('warning', {
data: {
message: 'Title must be at least 3 characters.'
}
});
return;
}
this.save();
}
positive - Success messages (green)
peek('positive', { data: { message: 'Success!' } })
danger - Error messages (red)
peek('danger', { data: { message: 'Error occurred!' } })
warning - Warning messages (orange/yellow)
peek('warning', { data: { message: 'Please review!' } })
UMB_NOTIFICATION_CONTEXT : Global context for notifications
peek() Method : Display temporary notification
Toast Style : Auto-dismissing UI notifications
Data Structure :
headline (optional) - Bold title textmessage (required) - Notification body textContext Consumption : Use consumeContext() for subscription or getContext() for one-time use
Use Cases :
That's it! Always fetch fresh docs, keep examples minimal, generate complete working code.
Weekly Installs
72
Repository
GitHub Stars
14
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot52
cursor25
opencode24
codex23
gemini-cli22
amp21
Genkit JS 开发指南:AI 应用构建、错误排查与最佳实践
7,700 周安装