UNPKG

ftt-ui-components

Version:

some components for vuetify3/element-plus/... with vue3.

30 lines (25 loc) 791 B
import type { App } from 'vue' import { SFCWithInstall, SFCInstallWithContext } from './typescript' export const withInstallFunction = <T>(fn: T, name: string) => { ;(fn as SFCWithInstall<T>).install = (app: App) => { ;(fn as SFCInstallWithContext<T>)._context = app._context app.config.globalProperties[name] = fn } return fn as SFCInstallWithContext<T> } export const withInstall = <T, E extends Record<string, any>>( main: T, extra?: E ) => { ;(main as SFCWithInstall<T>).install = (app): void => { for (const comp of [main, ...Object.values(extra ?? {})]) { app.component(comp.name, comp) } } if (extra) { for (const [key, comp] of Object.entries(extra)) { ;(main as any)[key] = comp } } return main as SFCWithInstall<T> & E }