🔥 認識我們的新專案 t0ggles - 您終極的專案管理工具! 🔥

通知 Vue 元件

使用通知元件,您可以顯示看起來像推播(或本地)系統通知的必要訊息。

通知元件

包含以下元件

  • 通知

通知屬性

名稱類型預設值描述
顏色物件

具有 Tailwind CSS 顏色類別的物件

colors.bgIos字串'bg-white dark:bg-[#1e1e1e]'

iOS 主題中的通知背景顏色

colors.bgMaterial字串'bg-md-light-surface-5 dark:bg-md-dark-surface-5'

Material 主題中的通知背景顏色

colors.deleteIconIos字串'fill-stone-400 active:fill-stone-200 dark:fill-stone-500 dark:active:fill-stone-700'

IOS 主題中的通知刪除圖示顏色

colors.deleteIconMd字串'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant'

Material 主題中的通知刪除圖示顏色

colors.subtitleIos字串'text-black dark:text-white'

IOS 主題中的通知副標題顏色

colors.textMaterial字串'text-md-light-on-surface-variant dark:text-md-dark-on-surface-variant'

Material 主題中的通知文字顏色

colors.titleIos字串'text-black dark:text-white'

IOS 主題中的通知標題顏色

colors.titleRightIos字串'text-opacity-45 text-black dark:text-white dark:text-opacity-45'

IOS 主題中的通知右側文字顏色

colors.titleRightMd字串'text-md-light-on-surface-variant before:bg-md-light-on-surface-variant dark:text-md-dark-on-surface-variant before:dark:bg-md-dark-on-surface-variant'

Material 主題中的通知右側文字顏色

component字串'div'

元件的 HTML 元素

opened布林值未定義

允許開啟/關閉通知並設定其初始狀態

subtitle字串

通知「副標題」區域的內容

text字串

通知「文字」區域的內容

title字串

通知「標題」區域的內容

titleRightText字串

通知「標題右側文字」區域的內容

translucent布林值true

在 iOS 主題中,使通知背景呈現半透明效果(使用 backdrop-filter: blur

通知事件

名稱類型描述
close函數 (e)

點擊關閉元素的處理常式

通知插槽

名稱描述
button

通知按鈕內容

icon

通知圖示 HTML 版面配置或影像

subtitle

通知「副標題」區域的內容

text

通知「文字」區域的內容

title

通知「標題」區域的內容

titlerighttext

通知「標題右側文字」區域的內容

範例

Notification.vue
<template>
<k-page>
<k-navbar title="Notification" />
<k-notification
:opened="opened.notificationFull"
title="Konsta UI"
title-right-text="now"
subtitle="This is a subtitle"
text="This is a simple notification message"
>
<template #icon>
<demo-icon />
</template>
</k-notification>
<k-notification
:opened="opened.notificationWithButton"
title="Konsta UI"
subtitle="Notification with close button"
text="Click (x) button to close me"
@click="() => (opened.notificationWithButton = false)"
>
<template #icon>
<demo-icon />
</template>
<template #button />
</k-notification>
<k-notification
:opened="opened.notificationCloseOnClick"
title="Konsta UI"
title-right-text="now"
subtitle="Notification with close on click"
text="Click me to close"
@click="() => (opened.notificationCloseOnClick = false)"
>
<template #icon>
<demo-icon />
</template>
</k-notification>
<k-notification
:opened="opened.notificationCallbackOnClose"
title="Konsta UI"
title-right-text="now"
subtitle="Notification with close on click"
text="Click me to close"
@click="
() => {
opened.notificationCallbackOnClose = false;
alertOpened = true;
}
"
>
<template #icon>
<demo-icon />
</template>
</k-notification>
<k-dialog
:opened="alertOpened"
@backdropclick="() => (alertOpened = false)"
>
<template #title>Konsta UI</template>
Notification closed
<template #buttons>
<k-dialog-button @click="() => (alertOpened = false)">
Ok
</k-dialog-button>
</template>
</k-dialog>
<k-block strong-ios outline-ios class="space-y-4">
<p>
Konsta UI comes with simple Notifications component that allows you to
show some useful messages to user and request basic actions.
</p>
<p>
<k-button @click="() => openNotification('notificationFull')">
Full layout notification
</k-button>
</p>
<p>
<k-button @click="() => openNotification('notificationWithButton')">
With Close Button
</k-button>
</p>
<p>
<k-button @click="() => openNotification('notificationCloseOnClick')">
Click to Close
</k-button>
</p>
<p>
<k-button
@click="() => openNotification('notificationCallbackOnClose')"
>
Callback on Close
</k-button>
</p>
</k-block>
</k-page>
</template>
<script>
import { ref, watch } from 'vue';
import {
kPage,
kNavbar,
kNavbarBackLink,
kBlock,
kNotification,
kButton,
kDialog,
kDialogButton,
useTheme,
} from 'konsta/vue';
import DemoIcon from '../components/DemoIcon.vue';
export default {
components: {
kPage,
kNavbar,
kNavbarBackLink,
kBlock,
kNotification,
kButton,
kDialog,
kDialogButton,
DemoIcon,
},
setup() {
const opened = ref({
notificationFull: false,
notificationWithButton: false,
notificationCloseOnClick: false,
notificationCallbackOnClose: false,
});
const alertOpened = ref(false);
const theme = useTheme();
const openNotification = (setter) => {
opened.value = {
notificationFull: false,
notificationWithButton: false,
notificationCloseOnClick: false,
notificationCallbackOnClose: false,
};
opened.value[setter] = true;
};
const autoCloseNotificationFull = () => {
if (opened.value.notificationFull) {
setTimeout(() => {
opened.value.notificationFull = false;
}, 3000);
}
};
watch(() => opened.value.notificationFull, autoCloseNotificationFull);
return {
opened,
alertOpened,
openNotification,
theme,
};
},
};
</script>
程式碼授權於 MIT.
2022 © Konsta UI by nolimits4web.