chore: update types

This commit is contained in:
Benjamin Canac
2021-12-15 13:07:11 +01:00
parent c6dcbd1b2b
commit befa0b37fc
8 changed files with 492 additions and 261 deletions

View File

@@ -1,7 +1,8 @@
export default {
entries: [
'./src/index',
'./src/module',
{ input: './src/components/', outDir: 'dist/components' },
{ input: './src/composables/', outDir: 'dist/composables' },
{ input: './src/presets/', outDir: 'dist/presets' },
{ input: './src/plugins/', outDir: 'dist/plugins' },
{ input: './src/types/', outDir: 'dist/types' },

View File

@@ -5,13 +5,13 @@
"license": "MIT",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
"require": "./dist/module.cjs",
"import": "./dist/module.mjs"
}
},
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"main": "dist/module.mjs",
"module": "dist/module.mjs",
"types": "dist/module.d.ts",
"files": [
"dist"
],
@@ -40,7 +40,7 @@
"@vueuse/components": "^7.3.0",
"@vueuse/core": "^7.3.0",
"eslint": "8.4.1",
"nuxt3": "3.0.0-27319101.3e82f0f",
"nuxt3": "3.0.0-27324955.23397e6",
"unbuild": "0.6.3"
}
}

View File

@@ -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

View File

@@ -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
}
}

View File

@@ -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'

View File

@@ -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
View 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
}

629
yarn.lock

File diff suppressed because it is too large Load Diff