-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add customComponent option (#148)
- Loading branch information
Showing
7 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
// https://nuxt.com/docs/guide/concepts/typescript | ||
"extends": "./.nuxt/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { fileURLToPath } from 'node:url' | ||
import { describe, it, expect } from 'vitest' | ||
import { setup, $fetch } from '@nuxt/test-utils' | ||
import type { NuxtConfig } from 'nuxt/schema' | ||
import type { ModuleOptions } from '../src/module' | ||
|
||
describe('defaultImport: componentext', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL('./fixtures/component', import.meta.url)), | ||
nuxtConfig: { | ||
svgo: { | ||
defaultImport: 'componentext', | ||
customComponent: 'TestWrapper' | ||
} as ModuleOptions | ||
} as NuxtConfig | ||
}) | ||
|
||
it('renders the svg as TestWrapper component', async () => { | ||
const html = await $fetch('/') | ||
expect(html).toContain(`test-icon`) | ||
expect(html).toContain(`test--fill`) | ||
}) | ||
|
||
it('renders the svg from assets/icons folder', async () => { | ||
// Get response to a server-rendered page with `$fetch`. | ||
const html = await $fetch('/') | ||
|
||
expect(html).toContain( | ||
'><path d="M13.5 1.515a3 3 0 0 0-3 0L3 5.845a2 2 0 0 0-1 1.732V21a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-6h4v6a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V7.577a2 2 0 0 0-1-1.732l-7.5-4.33z"></path></svg>' | ||
) | ||
expect(html).toContain( | ||
'><path d="M13.5 1.515a3 3 0 0 0-3 0L3 5.845a2 2 0 0 0-1 1.732V21a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1v-6h4v6"></path></svg>' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<template> | ||
<component | ||
:is="icon" | ||
:class="{ | ||
'test-icon': fontControlled, | ||
'test--fill': !filled | ||
}" | ||
/> | ||
</template> | ||
|
||
<script lang="ts"> | ||
// file imported from https://github.com/gitFoxCode/nuxt-icons/blob/89e53649e5868c31fc97869918ede96504ae1a04/src/runtime/components/nuxt-icon.vue | ||
// with modifications | ||
export default { | ||
props: { | ||
filled: { | ||
type: Boolean, | ||
required: false, | ||
default: false | ||
}, | ||
fontControlled: { | ||
type: Boolean, | ||
required: false, | ||
default: true | ||
}, | ||
icon: { | ||
type: Object, | ||
required: true | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
.test-icon { | ||
width: 1em; | ||
height: 1em; | ||
margin-bottom: 0.125em; | ||
vertical-align: middle; | ||
} | ||
.test--fill, | ||
.test--fill * { | ||
fill: currentColor; | ||
} | ||
</style> |