Skip to content

Commit

Permalink
types: Fix nuxi typecheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed Sep 3, 2023
1 parent 31b0a1d commit eed57a0
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@


<script setup lang="ts">
import { ThemeConfig, NavbarRoute, TabbarRoute } from "@bg-dev/nuxt-naiveui"
import { ThemeConfig, NavbarRoute, TabbarRoute } from "../src/module"
import { theme } from "#tailwind-config";
const navbarRoutes: NavbarRoute[] = [
Expand Down Expand Up @@ -87,7 +87,7 @@ const tabBarRoutes: TabbarRoute[] = [
const themeConfig: ThemeConfig = {
shared: {
common: {
fontFamily: theme.fontFamily.sans,
fontFamily: theme.fontFamily.sans.join(", "),
lineHeight: theme.lineHeight.normal,
},
},
Expand Down
20 changes: 9 additions & 11 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ import { fileURLToPath } from "url";
import naive from "naive-ui";
import { name, version } from "../package.json";
import { defu } from "defu";
import type { ThemeConfig, ColorModePreference } from "./runtime/types";
export type { NavbarRoute, ThemeConfig, TabbarRoute } from "./runtime/types";
import type { PublicConfig } from "./runtime/types";
export type { NavbarRoute, ThemeConfig, TabbarRoute, PublicConfig } from "./runtime/types";

// Module options TypeScript inteface definition
export interface ModuleOptions {
themeConfig?: ThemeConfig;
colorModePreference: ColorModePreference;
iconSize: number;
}
export interface ModuleOptions extends PublicConfig { }

export default defineNuxtModule<ModuleOptions>({
meta: {
Expand Down Expand Up @@ -84,10 +80,12 @@ export default defineNuxtModule<ModuleOptions>({
});

// Pass module options to runtimeConfig object
nuxt.options.runtimeConfig.public.naiveui = defu(
nuxt.options.runtimeConfig.public.naiveui,
options
);
nuxt.options.runtimeConfig = defu(nuxt.options.runtimeConfig, {
app: {},
public: {
naiveui: options
}
})

// Add imports for naive-ui components
const naiveComponents = Object.keys(naive).filter((name) =>
Expand Down
13 changes: 8 additions & 5 deletions src/runtime/components/NaiveConfig.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<n-config-provider :theme-overrides="naiveTheme" :inline-theme-disabled="true">
<slot></slot>
</n-config-provider>
<n-config-provider
:theme-overrides="naiveTheme"
:inline-theme-disabled="true"
>
<slot />
</n-config-provider>
</template>

<script setup lang="ts">
Expand All @@ -11,7 +14,7 @@ import {
} from "#imports"
import { NConfigProvider, GlobalThemeOverrides, ConfigProviderProps } from "naive-ui"
import { defu } from "defu"
import type { ThemeConfig } from "../types"
import type { ThemeConfig,PublicConfig } from "../types"
const defaultDarkTheme: GlobalThemeOverrides = {
common: {
Expand Down Expand Up @@ -225,7 +228,7 @@ interface NaiveConfigProps
extends /* @vue-ignore */ Omit<ConfigProviderProps, "themeOverrides" | "theme"> {
themeConfig?: ThemeConfig;
}
const config = useRuntimeConfig().public.naiveui
const config = useRuntimeConfig().public.naiveui as PublicConfig
const props = defineProps<NaiveConfigProps>()
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/components/NaiveIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
</template>

<script setup lang="ts">
import type {PublicConfig} from "../types"
//@ts-ignore
import { computed, useRuntimeConfig } from '#imports'
import { Icon } from '@iconify/vue/dist/offline'
import { loadIcon } from '@iconify/vue'
import { NIconWrapper } from "naive-ui"
const config = useRuntimeConfig().public.naiveui
const config = useRuntimeConfig().public.naiveui as PublicConfig
const props = defineProps<{ name: string; size?: number, color?: string, borderRadius?: number, iconColor?: string }>()
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components/NaiveNavbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import { ref, computed, h, useRoute, useRouter, watchEffect, useNaiveTheme } from "#imports"
import { NDrawer, NMenu, NDrawerContent, NButton } from "naive-ui"
import { NuxtLink, NaiveIcon } from "#components"
import type { StyleValue } from "vue"
import type { StyleValue , Component} from "vue"
import type { MenuOption } from "naive-ui"
import type { NavbarRoute } from "../types"
Expand Down Expand Up @@ -113,7 +113,7 @@ const menuOptions = computed<MenuOption[]>(() => {
const menuOption: MenuOption =
{
label: route.path ? () => h(NuxtLink, { to: route.path }, { default: () => route.label }) : route.label,
icon: route.icon ? () => h(NaiveIcon, { name: route.icon }) : undefined,
icon: route.icon ? () => h(NaiveIcon as Component, { name: route.icon }) : undefined,
key: route.path || route.label,
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/plugins/colorMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import {
} from "#imports";
import { setCookie, setResponseHeader } from "h3";
import colorModeMiddleware from "../middleware/colorMode";
import type { ColorModePreference } from "../types";
import type { ColorModePreference , PublicConfig} from "../types";

export default defineNuxtPlugin((nuxtApp) => {
const event = useRequestEvent();
const config = useRuntimeConfig().public.naiveui;
const config = useRuntimeConfig().public.naiveui as PublicConfig
const { colorMode, colorModePreference, colorModeForced } =
useNaiveColorMode();

Expand Down
6 changes: 6 additions & 0 deletions src/runtime/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ export type ColorMode = "light" | "dark";
export type ColorModePreference = "light" | "dark" | "system";

export type ColorModeForce = ColorMode | false;

export interface PublicConfig {
themeConfig?: ThemeConfig;
colorModePreference: ColorModePreference;
iconSize: number;
}
6 changes: 2 additions & 4 deletions test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import MyModule from '../../../src/module'

export default defineNuxtConfig({
export default defineNuxtConfig({
modules: [
MyModule
"../../../src/module.ts"
]
})

0 comments on commit eed57a0

Please sign in to comment.