ray-template/packages/ui/src/services.ts
XiaoDaiGua-Ray 403fdd589a feat!: rebuild Ray Template as a monorepo
Share workspace packages between Ray Admin and the interactive docs.

BREAKING CHANGE: v6 is a new major line. v5 stays on legacy/v5.
2026-11-04 14:01:28 +08:00

22 lines
794 B
TypeScript

import type { IconName } from '@ray-template/icons'
import type { createStorage } from '@ray-template/utils/storage'
import { hasInjectionContext, inject, provide } from 'vue'
import type { InjectionKey } from 'vue'
export interface UiServices {
locale?: () => string
dark?: () => boolean
chartTheme?: string
translate?: (key: string, params?: Record<string, unknown>) => string
columnStorage?: ReturnType<typeof createStorage>
reportError?: (message: string) => void
iconUrl?: (name: IconName, prefix: string) => string
}
const servicesKey: InjectionKey<UiServices> = Symbol('ray-ui-services')
export const provideUiServices = (services: UiServices) =>
provide(servicesKey, services)
export const useUiServices = () =>
hasInjectionContext() ? inject(servicesKey, {}) : {}