mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-24 08:50:34 +01:00
chore: update types
This commit is contained in:
@@ -3,35 +3,9 @@ import { defineNuxtModule, installModule, addComponentsDir, addTemplate, resolve
|
||||
import { colors } from '@unocss/preset-uno'
|
||||
import defu from 'defu'
|
||||
import type { UnocssNuxtOptions } from '@unocss/nuxt'
|
||||
import type { Nuxt } from '@nuxt/schema'
|
||||
import { presetsDir } from './dirs'
|
||||
|
||||
export interface UiColorsOptions {
|
||||
/**
|
||||
* @default 'indigo'
|
||||
*/
|
||||
primary?: string
|
||||
|
||||
/**
|
||||
* @default 'zinc'
|
||||
*/
|
||||
gray?: string
|
||||
}
|
||||
|
||||
export interface UiOptions {
|
||||
/**
|
||||
* @default 'tailwindui'
|
||||
*/
|
||||
preset?: string | object
|
||||
|
||||
/**
|
||||
* @default 'u'
|
||||
*/
|
||||
prefix?: string
|
||||
|
||||
colors?: UiColorsOptions
|
||||
|
||||
unocss?: UnocssNuxtOptions
|
||||
}
|
||||
import type { UiOptions } from './types'
|
||||
|
||||
const defaults = {
|
||||
preset: 'tailwindui',
|
||||
@@ -52,7 +26,7 @@ export default defineNuxtModule<UiOptions>({
|
||||
name: '@nuxthq/ui',
|
||||
configKey: 'ui',
|
||||
defaults,
|
||||
async setup (_options, nuxt) {
|
||||
async setup (_options: UiOptions, nuxt: Nuxt) {
|
||||
const { preset, prefix, colors: { primary = 'indigo', gray = 'zinc' } = {} } = _options
|
||||
const { shortcuts = [], rules = [], variants = [], theme = {} } = _options.unocss || {}
|
||||
|
||||
@@ -220,6 +194,8 @@ export default defineNuxtModule<UiOptions>({
|
||||
}
|
||||
})
|
||||
|
||||
export * from './types'
|
||||
|
||||
declare module '@nuxt/schema' {
|
||||
interface NuxtConfig {
|
||||
ui?: UiOptions
|
||||
@@ -1,27 +1,27 @@
|
||||
import { nanoid } from 'nanoid'
|
||||
import { Ref } from 'vue'
|
||||
import { Notification } from '../types'
|
||||
import { ToastNotification, ToastPlugin } from '../types'
|
||||
import { defineNuxtPlugin, useState } from '#app'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
const notifications: Ref<Notification[]> = useState('notifications', () => [])
|
||||
const notifications: Ref<ToastNotification[]> = useState('notifications', () => [])
|
||||
|
||||
function addNotification (notification: Partial<Notification>) {
|
||||
function addNotification (notification: Partial<ToastNotification>) {
|
||||
const body = {
|
||||
id: nanoid(),
|
||||
...notification
|
||||
}
|
||||
|
||||
const index = notifications.value.findIndex((n: Notification) => n.id === body.id)
|
||||
const index = notifications.value.findIndex((n: ToastNotification) => n.id === body.id)
|
||||
if (index === -1) {
|
||||
notifications.value.push(body as Notification)
|
||||
notifications.value.push(body as ToastNotification)
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
|
||||
function removeNotification (id: string) {
|
||||
notifications.value = notifications.value.filter((n: Notification) => n.id !== id)
|
||||
notifications.value = notifications.value.filter((n: ToastNotification) => n.id !== id)
|
||||
}
|
||||
|
||||
nuxtApp.provide('toast', {
|
||||
@@ -48,6 +48,6 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
|
||||
declare module '#app' {
|
||||
interface NuxtApp {
|
||||
$toast: object
|
||||
$toast: ToastPlugin
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,31 @@
|
||||
export * from './notifications'
|
||||
export * from './organizations'
|
||||
export * from './users'
|
||||
import type { UnocssNuxtOptions } from '@unocss/nuxt'
|
||||
|
||||
export interface UiColorsOptions {
|
||||
/**
|
||||
* @default 'indigo'
|
||||
*/
|
||||
primary?: string
|
||||
|
||||
/**
|
||||
* @default 'zinc'
|
||||
*/
|
||||
gray?: string
|
||||
}
|
||||
|
||||
export interface UiOptions {
|
||||
/**
|
||||
* @default 'tailwindui'
|
||||
*/
|
||||
preset?: string | object
|
||||
|
||||
/**
|
||||
* @default 'u'
|
||||
*/
|
||||
prefix?: string
|
||||
|
||||
colors?: UiColorsOptions
|
||||
|
||||
unocss?: UnocssNuxtOptions
|
||||
}
|
||||
|
||||
export * from './toast'
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
export interface Notification {
|
||||
id: string
|
||||
title: string
|
||||
description: string
|
||||
type: string
|
||||
icon?: string
|
||||
timeout: number
|
||||
undo?: Function
|
||||
callback?: Function
|
||||
}
|
||||
17
src/types/toast.ts
Normal file
17
src/types/toast.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export interface ToastNotification {
|
||||
id: string
|
||||
title: string
|
||||
description: string
|
||||
type: string
|
||||
icon?: string
|
||||
timeout: number
|
||||
undo?: Function
|
||||
callback?: Function
|
||||
}
|
||||
|
||||
export interface ToastPlugin {
|
||||
addNotification: (notification: Partial<Notification>) => Notification
|
||||
removeNotification: (id: string) => void
|
||||
success: (options: { title?: string, description?: string }) => void
|
||||
error: (options: { title?: string, description?: string }) => void
|
||||
}
|
||||
Reference in New Issue
Block a user