-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use `useNaiveDiscreteApi()` inside script setup to get access to `MessageApi`, `NotificationApi`, `DialogApi` and `LoadingBarApi` Signed-off-by: Fery Wardiyanto <[email protected]>
- Loading branch information
1 parent
728087b
commit 6890392
Showing
7 changed files
with
63 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { DialogApi, LoadingBarApi, MessageApi, NotificationApi } from 'naive-ui' | ||
import { createDiscreteApi } from 'naive-ui' | ||
|
||
export const install: AppModuleInstall = ({ app, isClient }): void => { | ||
if (!isClient) | ||
return | ||
|
||
const configProviderProps = useNaiveConfig() | ||
const { message, dialog, notification, loadingBar } = createDiscreteApi( | ||
['message', 'dialog', 'notification', 'loadingBar'], | ||
{ configProviderProps }, | ||
) | ||
|
||
app.provide('$message', message) | ||
app.provide('$dialog', dialog) | ||
app.provide('$notification', notification) | ||
app.provide('$loading', loadingBar) | ||
|
||
app.config.globalProperties.$message = message | ||
app.config.globalProperties.$dialog = dialog | ||
app.config.globalProperties.$notification = notification | ||
app.config.globalProperties.$loading = loadingBar | ||
} | ||
|
||
declare module 'vue' { | ||
interface ComponentCustomProperties { | ||
$message: MessageApi | ||
$dialog: DialogApi | ||
$notification: NotificationApi | ||
$loading: LoadingBarApi | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,26 @@ | ||
<script setup lang="ts"> | ||
import { Head as iHead } from '@inertiajs/vue3' | ||
import type { NotificationType } from 'naive-ui' | ||
import { useDialog, useNotification } from 'naive-ui' | ||
const notification = useNotification() | ||
const dialog = useDialog() | ||
const { notification } = useNaiveDiscreteApi() | ||
function notify(type: NotificationType) { | ||
notification[type]({ | ||
content: 'Test', | ||
}) | ||
} | ||
function confirm() { | ||
dialog.warning({ | ||
title: 'Test Dialog', | ||
content: 'Are you sure?', | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<i-head :title="$t('account.profile.page')" /> | ||
|
||
<h3>Helps and Supports Goes Here</h3> | ||
|
||
<n-button @click="notify('error')"> | ||
Notify | ||
<n-button @click="$message.info('test')"> | ||
Notify 1 | ||
</n-button> | ||
|
||
<n-button @click="confirm()"> | ||
Confirm | ||
<n-button @click="notify('error')"> | ||
Notify 2 | ||
</n-button> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { PageProps, Page } from '@inertiajs/core' | ||
import type { App } from 'vue' | ||
|
||
export {} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters