Skip to content

Commit 4145b25

Browse files
feat!: move base options from nuxt config to app config
1 parent f280631 commit 4145b25

File tree

7 files changed

+26
-24
lines changed

7 files changed

+26
-24
lines changed

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,15 @@ $nt.show({
147147
> **note:** the `theme` property is used to customize the toaster behavior. Each `theme.containerId` will have their own context (e.g. the `maxToasts` will count how many toaster are visible in the container with matching id).
148148
149149
150-
### Using `@cssninja/nuxt-toaster` module options
150+
### Using `toaster` app config
151151
152-
To avoid to repeat yourself, you can set defaults values for ninjaToaster.show method in the module options.
152+
To avoid to repeat yourself, you can set defaults values for ninjaToaster.show method in the nuxt `app.config.ts` at the root of your project.
153153
154154
```ts
155-
// nuxt.config.ts
156-
export default defineNuxtConfig({
157-
modules: [
158-
'@cssninja/nuxt-toaster'
159-
],
155+
// app.config.ts
156+
export default defineAppConfig({
160157
toaster: {
161-
base: {
162-
// default options for ninjaToaster.show
163-
}
158+
// default options for ninjaToaster.show
164159
}
165160
})
166161
```

playground/app.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default defineAppConfig({
2+
toaster: {
3+
maxToasts: 5
4+
}
5+
})

playground/nuxt.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import NinjaNuxtToaster from '..'
33

44
export default defineNuxtConfig({
55
modules: [NinjaNuxtToaster],
6-
toaster: {},
76
app: {
87
head: {
98
script: [

src/module.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ import { addImports, addPlugin, defineNuxtModule } from '@nuxt/kit'
44
import type { NinjaToasterBaseProps } from './props'
55

66
export interface ModuleOptions {
7-
base?: NinjaToasterBaseProps
87
installPlugin?: boolean
98
}
109

10+
declare module '@nuxt/schema' {
11+
interface AppConfigInput {
12+
/** nuxt-icon configuration */
13+
toaster?: NinjaToasterBaseProps
14+
}
15+
}
16+
1117
export default defineNuxtModule<ModuleOptions>({
1218
meta: {
1319
name: '@cssninja/nuxt-toaster',
14-
configKey: 'toaster'
20+
configKey: 'toaster',
21+
compatibility: {
22+
nuxt: '^3.0.0-rc.9'
23+
}
1524
},
1625
defaults: {
17-
base: {},
1826
installPlugin: true
1927
},
2028
setup(options, nuxt) {
@@ -40,7 +48,5 @@ export default defineNuxtModule<ModuleOptions>({
4048
if (options.installPlugin) {
4149
addPlugin(resolve(runtimeDir, 'plugin'))
4250
}
43-
44-
nuxt.options.runtimeConfig.public.nt = options.base as any
4551
}
4652
})

src/runtime/components/NinjaToaster.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export default defineComponent({
143143
})
144144
}
145145

146+
// @todo: check if nested element has focus, then pause the timer
146147
function onMouseover() {
147148
isHovered.value = true
148149
toggleTimer(true)

src/runtime/create.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import type { NinjaToasterRenderQueue } from './queue'
77
import { type NinjaToastEventBus, createEventBus } from './events'
88
import NinjaToaster from './components/NinjaToaster'
99

10-
// @ts-expect-error - Nuxt 3 auto-imports
11-
import { useNuxtApp, useRuntimeConfig } from '#app'
10+
import { useAppConfig, useNuxtApp, useRuntimeConfig } from '#imports'
1211

1312
function createElement() {
14-
// @ts-expect-error - Nuxt 3 context
1513
if (process.server) {
1614
return null
1715
}
@@ -51,7 +49,7 @@ export function createNinjaToaster(
5149
const queues: Map<string, NinjaToasterRenderQueue> = new Map()
5250

5351
function show(options: NinjaToasterProps | string | number) {
54-
const config = useRuntimeConfig()
52+
const appConfigProps = (useAppConfig() as any).toaster as NinjaToasterProps
5553
const app = useNuxtApp().vueApp
5654
const userProps =
5755
typeof options === 'string' ||
@@ -60,7 +58,7 @@ export function createNinjaToaster(
6058
? { content: options }
6159
: options
6260
const props: NinjaToasterProps = defu(
63-
config.public.nt,
61+
appConfigProps,
6462
createOptions,
6563
userProps
6664
)
@@ -79,7 +77,6 @@ export function createNinjaToaster(
7977
}
8078
})
8179

82-
// @ts-expect-error - Nuxt 3 context
8380
if (process.server) {
8481
resolve({
8582
el: null,

src/runtime/plugin.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createNinjaToaster } from './create'
22

3-
// @ts-expect-error - Nuxt 3 auto-imports
4-
import { defineNuxtPlugin } from '#app'
3+
import { defineNuxtPlugin } from '#imports'
54

65
export default defineNuxtPlugin(() => {
76
return {

0 commit comments

Comments
 (0)