Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
]
},
"settings": {
"import/core-modules": ["#app"],
"vue-i18n": {
"localeDir": "./src/locales/*.{json,json5,yaml,yml}"
}
Expand Down
5 changes: 3 additions & 2 deletions components/DropdownMenu.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts" setup>
import { NuxtIconName } from "#app";
import { RoutesNamedLocations } from "~/.nuxt/typed-router/__routes";

export interface DropdownMenuItem {
text: string;
icon?: string;
icon?: NuxtIconName;
link?: RoutesNamedLocations;
clickFunction?: Function;
}
Expand Down Expand Up @@ -60,7 +61,7 @@ function menuItemListeners(item: DropdownMenuItem) {
class="flex items-center justify-start gap-2 px-3 py-2"
v-on="menuItemListeners(item)"
>
<IconComponent v-if="item.icon" :name="item.icon" />
<NuxtIcon v-if="item.icon" :name="item.icon" />
<span>{{ item.text }}</span>
</component>
</li>
Expand Down
4 changes: 2 additions & 2 deletions components/MediaPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ const { currentTrack } = inject(MediaPlaylistInjectionKey)!;
<div class="group select-none">
<button v-if="status === MediaPlayerStatus.Playing" @click="pause()">
<span class="flex aspect-square w-12 justify-center align-middle">
<IconComponent
<NuxtIcon
name="icon.pause.large"
class="text-3xl group-hover:text-4xl"
/>
</span>
</button>
<button v-if="status !== MediaPlayerStatus.Playing" @click="play()">
<span class="flex aspect-square w-12 justify-center align-middle">
<IconComponent name="play" class="text-3xl group-hover:text-4xl" />
<NuxtIcon name="play" class="text-3xl group-hover:text-4xl" />
</span>
</button>
</div>
Expand Down
3 changes: 2 additions & 1 deletion components/sidebar/SidebarElement.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script lang="ts" setup>
import { NuxtIconName } from "#app";
import { useAuth0 } from "@auth0/auth0-vue";
import { RoutesNamedLocations } from "~/.nuxt/typed-router/__routes";
import { version } from "~/package.json";

const links: {
title: string;
link: RoutesNamedLocations;
icon: string;
icon: NuxtIconName;
}[] = [
{ title: "Home", link: { name: "index" }, icon: "nav.home" },
{ title: "Browse", link: { name: "browse" }, icon: "nav.browse" },
Expand Down
13 changes: 3 additions & 10 deletions components/sidebar/SidebarItem.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<script lang="ts" setup>
import { NuxtIconName } from "#app";
import { RoutesNamedLocations } from "~/.nuxt/typed-router/__routes";

withDefaults(
defineProps<{
type?: "page" | "playlist" | "private-playlist";
title: string;
link: RoutesNamedLocations;
image?: string;
icon?: string;
icon: NuxtIconName;
}>(),
{
type: "page",
image: "",
icon: "",
}
);
</script>
Expand All @@ -23,12 +21,7 @@ withDefaults(
active-class="bg-tint"
class="group flex gap-2 rounded-xl px-4 py-2"
>
<ProtectedImage
v-if="image"
:src="image"
class="aspect-square h-full rounded bg-background-2"
/>
<IconComponent v-if="icon" :name="icon" class="text-xl" />
<NuxtIcon v-if="icon" :name="icon" class="text-xl" />
<span
class="transition-transform group-hover:translate-x-2"
:class="{ 'font-semibold': type == 'page', 'text-lg': type == 'page' }"
Expand Down
8 changes: 4 additions & 4 deletions components/track/TrackItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function secondsToTime(totalSeconds: number | undefined) {
<div
class="absolute inset-0 h-full w-full rounded-md bg-black-1 opacity-50"
></div>
<IconComponent
<NuxtIcon
name="play"
filled
class="absolute inset-0 flex items-center justify-center text-2xl text-white-1"
Expand Down Expand Up @@ -93,20 +93,20 @@ function secondsToTime(totalSeconds: number | undefined) {
class="px-2 py-0 opacity-0 hover:opacity-100 focus:opacity-100 group-hover:opacity-100 group-focus:opacity-100"
:aria-label="t('track.a11y.download')"
>
<IconComponent name="download" filled class="text-2xl" />
<NuxtIcon name="download" filled class="text-2xl" />
</button>
<button
class="px-2 py-0 opacity-0 hover:opacity-100 focus:opacity-100 group-hover:opacity-100 group-focus:opacity-100"
:aria-label="t('track.a11y.queue')"
>
<IconComponent name="queue" filled class="text-2xl" />
<NuxtIcon name="queue" filled class="text-2xl" />
</button>
<button
:aria-label="t('track.a11y.options')"
class="focus:bg-lime-400 rounded-lg px-2 py-0"
@click="openOptions"
>
<IconComponent name="options" filled class="text-2xl" />
<NuxtIcon name="options" filled class="text-2xl" />
</button>
</div>
</div>
Expand Down
60 changes: 60 additions & 0 deletions modules/icons/generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable import/prefer-default-export */
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
// eslint-disable-next-line import/no-extraneous-dependencies
import { Nuxt } from "@nuxt/schema";
import chalk from "chalk";
import { saveGeneratedFile } from "./output";
import { constructIconNames } from "./parser";

type CreateTypedIconsArgs = {
nuxt: Nuxt;
location: string | null;
fileExtension: string;
isHookCall?: boolean;
};

export async function CreateTypedIcons({
nuxt,
location,
fileExtension,
isHookCall = false,
}: CreateTypedIconsArgs): Promise<void> {
try {
if (!isHookCall) {
if (location) {
nuxt.hook("builder:watch", (_, watchedPath) => {
if (watchedPath.startsWith(location)) {
CreateTypedIcons({
nuxt,
location,
fileExtension,
isHookCall: true,
});
}
});
}

nuxt.hook("modules:done", () => {
CreateTypedIcons({ nuxt, location, fileExtension, isHookCall: true });
});

return;
}

if (location) {
const iconNames = await constructIconNames(
nuxt.options.rootDir,
location,
fileExtension
);
await saveGeneratedFile(nuxt, iconNames);
} else {
await saveGeneratedFile(nuxt, null);
}
} catch (e) {
console.error(
chalk.red("Error while generating icons definition model"),
`\n${e}`
);
}
}
27 changes: 27 additions & 0 deletions modules/icons/generator/output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable import/prefer-default-export */
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
// eslint-disable-next-line import/no-extraneous-dependencies
import { Nuxt } from "@nuxt/schema";
import { addTemplate } from "@nuxt/kit";

export const saveGeneratedFile = (_: Nuxt, iconNames: string[] | null) => {
addTemplate({
filename: "nuxt-icons.d.ts",
getContents: () => `// @ts-nocheck
// eslint-disable
/**
* ---------------------------------------------------
* 🚗 Generated by nuxt-icons. Do not modify !
* ---------------------------------------------------
* */

declare module '#app' {
type NuxtIconName = ${
iconNames === null
? "string"
: iconNames.map((p) => `"${p.replace(/[\\"]/g, "\\$&")}"`).join(" | ")
}
}
`,
});
};
12 changes: 12 additions & 0 deletions modules/icons/generator/parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable import/prefer-default-export */
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
import { glob } from "glob";

export const constructIconNames = async (
path: string,
location: string,
fileExtension: string
) =>
(await glob(`${location}/**/**.${fileExtension}`, { cwd: path }))
.map((p) => p.substring(location.length + 1))
.map((p) => p.substring(0, p.length - 4));
52 changes: 52 additions & 0 deletions modules/icons/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// This component is a copy of the nuxt-icon component from nuxt-icons (https://nuxt.com/modules/icons)
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
import { defineNuxtModule, createResolver, addComponent } from "@nuxt/kit";
import { CreateTypedIcons } from "./generator";

export interface ModuleOptions {
// dir: string
/**
* Enables path autocomplete and path validity for programmatic validation
*
* @default true
*/
pathCheck?: boolean;
}

export default defineNuxtModule<ModuleOptions>({
meta: {
name: "nuxt-icons",
configKey: "nuxtIcons",
compatibility: {
nuxt: "^3.0.0",
},
},
defaults: {
pathCheck: true,
},
setup(options, nuxt) {
const { resolve } = createResolver(import.meta.url);
addComponent({
name: "nuxt-icon",
global: true,
filePath: resolve("./runtime/components/nuxt-icon.vue"),
});

// Force register of type declaration
nuxt.hook("prepare:types", ({ references }) => {
references.push({
path: resolve(nuxt.options.buildDir, "nuxt-icons.d.ts"),
});
});

if (options.pathCheck) {
CreateTypedIcons({
nuxt,
location: "assets/icons",
fileExtension: "svg",
});
} else {
CreateTypedIcons({ nuxt, location: null, fileExtension: "" });
}
},
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<script setup lang="ts">
// This component is a copy of the nuxt-icon component from nuxt-icons (https://nuxt.com/modules/icons)
// with some modifications to help with Typescript support.
import { NuxtIconName } from "#app";
import { ref, watchEffect } from "#imports";

const props = withDefaults(
defineProps<{
name: string;
name: NuxtIconName;
filled?: boolean;
}>(),
{ filled: false }
Expand Down
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const modules: NuxtConfig["modules"] = [
"@nuxt/devtools",
// Use TS-path as workaround (See https://github.com/nuxt/nuxt/issues/20912)
"~/modules/figma2tailwind/index.ts", // Must be placed before "@nuxtjs/tailwindcss"
"~/modules/icons/module.ts",
"@nuxtjs/tailwindcss",
"@nuxtjs/i18n",
"nuxt-vitest",
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@nuxtjs/tailwindcss": "^6.6.6",
"@vitest/coverage-c8": "^0.30.1",
"@vue/test-utils": "^2.3.2",
"chalk": "^5.2.0",
"cypress": "^12.10.0",
"electron": "^24.1.2",
"electron-builder": "^23.6.0",
Expand All @@ -43,6 +44,7 @@
"eslint-config-airbnb-typescript": "^17.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-vitest": "^0.2.3",
"glob": "^10.2.4",
"happy-dom": "^9.9.2",
"log-symbols": "^5.1.0",
"nuxt": "^3.5.0",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.